Virtual.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Cocur\Slugify\Slugify;
  4. use Symfony\Component\Finder\Finder;
  5. use Symfony\Component\Console\Input\ArrayInput;
  6. use Symfony\Component\Console\Output\StreamOutput;
  7. use Symfony\Component\Console\Application;
  8. use Doctrine\ORM\EntityManager;
  9. /**
  10. * Class Virtual
  11. */
  12. class Virtual
  13. {
  14. /**
  15. * @param array $_configuration
  16. */
  17. public static function hookConfiguration(& $_configuration)
  18. {
  19. global $virtualChamilo;
  20. if (defined('CLI_SCRIPT') && !defined('CLI_VCHAMILO_OVERRIDE')) {
  21. return;
  22. }
  23. // provides an effective value for the virtual root_web based on domain analysis
  24. self::getHostName($_configuration);
  25. // We are on physical chamilo. Let original config play
  26. $virtualChamiloWebRoot = rtrim($_configuration['vchamilo_web_root'], '/') . '/';
  27. $virtualChamilo = [];
  28. if ($_configuration['root_web'] == $virtualChamiloWebRoot) {
  29. return;
  30. }
  31. // pre hook to chamilo main table and get alternate configuration.
  32. // sure Database object is not set up. Soo use bootstrap connection
  33. /** @var \Doctrine\DBAL\Connection $connection */
  34. $connection = Virtual::bootConnection($_configuration);
  35. $query = "SELECT * FROM vchamilo WHERE root_web = '$virtualChamiloWebRoot'";
  36. $result = $connection->executeQuery($query);
  37. if ($result->rowCount()) {
  38. $data = $result->fetch();
  39. $excludes = array('id', 'name');
  40. $query = "SELECT * FROM settings_current WHERE subkey = 'vchamilo'";
  41. $virtualSettings = $connection->executeQuery($query);
  42. $virtualSettings = $virtualSettings->fetchAll();
  43. $homePath = '';
  44. $coursePath = '';
  45. $archivePath = '';
  46. $uploadPath = '';
  47. $passwordEncryption = '';
  48. foreach ($virtualSettings as $setting) {
  49. switch ($setting['variable']) {
  50. case 'vchamilo_upload_real_root':
  51. $uploadPath = $setting['selected_value'];
  52. break;
  53. case 'vchamilo_home_real_root':
  54. $homePath = $setting['selected_value'];
  55. break;
  56. case 'vchamilo_course_real_root':
  57. $coursePath = $setting['selected_value'];
  58. break;
  59. case 'vchamilo_archive_real_root':
  60. $archivePath = $setting['selected_value'];
  61. break;
  62. case 'vchamilo_password_encryption':
  63. $passwordEncryption = $setting['selected_value'];
  64. break;
  65. }
  66. }
  67. if (empty($homePath) || empty($coursePath) || empty($archivePath) || empty($uploadPath)) {
  68. echo 'Configure correctly the vchamilo plugin';
  69. exit;
  70. }
  71. // Only load if is visible
  72. if ($data && $data['visible'] === '1') {
  73. foreach ($data as $key => $value) {
  74. if (!in_array($key, $excludes)) {
  75. // Avoid empty password_encryption
  76. if ($key == 'password_encryption' && empty($value)) {
  77. continue;
  78. }
  79. $_configuration[$key] = $value;
  80. }
  81. $_configuration['virtual'] = $data['root_web'].'/';
  82. }
  83. $data['SYS_ARCHIVE_PATH'] = self::addTrailingSlash($archivePath).$data['slug'];
  84. $data['SYS_HOME_PATH'] = self::addTrailingSlash($homePath).$data['slug'];
  85. $data['SYS_COURSE_PATH'] = self::addTrailingSlash($coursePath).$data['slug'];
  86. $data['SYS_UPLOAD_PATH'] = self::addTrailingSlash($uploadPath).$data['slug'];
  87. if (!empty($passwordEncryption)) {
  88. $_configuration['password_encryption'] = $passwordEncryption;
  89. }
  90. $virtualChamilo = $data;
  91. } else {
  92. exit("This portal is disabled. Please contact your administrator");
  93. }
  94. } else {
  95. // Platform was not configured yet
  96. //die("VChamilo : Could not fetch virtual chamilo configuration");
  97. }
  98. }
  99. /**
  100. * @param array $_configuration
  101. */
  102. public static function getHostName(&$_configuration)
  103. {
  104. if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
  105. $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_configuration['force_https_forwarded_proto'])
  106. ) {
  107. $protocol = 'https';
  108. } else {
  109. if ($_SERVER['HTTPS']) {
  110. $protocol = 'https';
  111. } else {
  112. $protocol = 'http';
  113. }
  114. }
  115. if (defined('CLI_VCHAMILO_OVERRIDE')) {
  116. $_configuration['vchamilo_web_root'] = CLI_VCHAMILO_OVERRIDE;
  117. $_configuration['vchamilo_name'] = preg_replace('#https?://#', '', CLI_VCHAMILO_OVERRIDE);
  118. // remove radical from override for name
  119. // fake the server signature
  120. global $_SERVER;
  121. $_SERVER['SERVER_NAME'] = $_configuration['vchamilo_name'];
  122. $_SERVER['HTTP_HOST'] = $_configuration['vchamilo_name'];
  123. $_SERVER['QUERY_STRING'] = '';
  124. $_SERVER['REQUEST_URI'] = CLI_VCHAMILO_OVERRIDE;
  125. return;
  126. }
  127. $contentPrefix = '/';
  128. if (isset($_SERVER['CONTEXT_PREFIX']) && !empty($_SERVER['CONTEXT_PREFIX'])) {
  129. $contentPrefix = $_SERVER['CONTEXT_PREFIX'];
  130. } else {
  131. // Getting url_append from URL
  132. if (isset($_SERVER['REQUEST_URI'])) {
  133. $requestUri = $_SERVER['REQUEST_URI'];
  134. if (strpos($requestUri, '/courses/') !== false) {
  135. $result = substr($requestUri, 0, strpos($requestUri, '/courses/'));
  136. if (!empty($result) && $result != '/') {
  137. $contentPrefix = $result;
  138. }
  139. }
  140. }
  141. }
  142. $_configuration['vchamilo_web_root'] = "{$protocol}://".@$_SERVER['HTTP_HOST'].$contentPrefix;
  143. $_configuration['vchamilo_name'] = @$_SERVER['HTTP_HOST'];
  144. if (empty($_configuration['vchamilo_name'])) { // try again with another source if has failed
  145. $_configuration['vchamilo_name'] = "{$protocol}://".$_SERVER['SERVER_NAME'];
  146. if ($_SERVER['SERVER_PORT'] != 80) {
  147. $_configuration['vchamilo_name'] .= ':'.$_SERVER['SERVER_PORT'];
  148. }
  149. $_configuration['vchamilo_name'] = $_SERVER['SERVER_NAME'];
  150. }
  151. }
  152. /**
  153. * @param string $path
  154. * @return string
  155. */
  156. public static function addTrailingSlash($path)
  157. {
  158. return substr($path, -1) == '/' ? $path : $path.'/';
  159. }
  160. /**
  161. * provides a side connection to a vchamilo database
  162. * @param array $_configuration
  163. *
  164. * @return \Doctrine\DBAL\Driver\Connection
  165. */
  166. public static function bootConnection(&$_configuration)
  167. {
  168. $dbParams = array(
  169. 'driver' => 'pdo_mysql',
  170. 'host' => $_configuration['db_host'],
  171. 'user' => $_configuration['db_user'],
  172. 'password' => $_configuration['db_password'],
  173. 'dbname' => isset($_configuration['main_database']) ? $_configuration['main_database'] : '',
  174. // Only relevant for pdo_sqlite, specifies the path to the SQLite database.
  175. 'path' => isset($_configuration['db_path']) ? $_configuration['db_path'] : '',
  176. // Only relevant for pdo_mysql, pdo_pgsql, and pdo_oci/oci8,
  177. 'port' => isset($_configuration['db_port']) ? $_configuration['db_port'] : '',
  178. );
  179. try {
  180. $database = new \Database();
  181. $connection = $database->connect(
  182. $dbParams,
  183. $_configuration['root_sys'],
  184. $_configuration['root_sys'],
  185. true
  186. );
  187. } catch (Exception $e) {
  188. echo('Side connection failure with '.$_configuration['db_host'].', '.$_configuration['db_user'].', ******** ');
  189. die();
  190. }
  191. return $connection;
  192. }
  193. /**
  194. * @param string $url
  195. */
  196. public static function redirect($url)
  197. {
  198. if (preg_match('#https?://#', $url)) {
  199. header('location: '.$url);
  200. } else {
  201. header('location: ' . api_get_path(WEB_PATH).$url);
  202. }
  203. exit;
  204. }
  205. /**
  206. * @param string $course_folder
  207. * @return string
  208. */
  209. public static function getHtaccessFragment($course_folder)
  210. {
  211. $str = "
  212. # Change this file to fit your configuration and save it as .htaccess in the courses folder #
  213. # Chamilo mod rewrite
  214. # Comment lines start with # and are not processed
  215. <IfModule mod_rewrite.c>
  216. RewriteEngine On
  217. # Rewrite base is the dir chamilo is installed in with trailing slash
  218. RewriteBase /{$course_folder}/
  219. # Do not rewrite on the main dir
  220. # Change this path to the path of your main folder
  221. RewriteCond %{REQUEST_URI} !^/main/
  222. #replace nasty ampersands by 3 slashes, we change these back in download.php
  223. RewriteRule ([^/]+)/document/(.*)&(.*)$ $1/document/$2///$3 [N]
  224. # Rewrite everything in the scorm folder of a course to the download script
  225. RewriteRule ([^/]+)/scorm/(.*)$ /main/document/download_scorm.php?doc_url=/$2&cDir=$1 [QSA,L]
  226. # Rewrite everything in the document folder of a course to the download script
  227. RewriteRule ([^/]+)/document/(.*)$ /main/document/download.php?doc_url=/$2&cDir=$1 [QSA,L]
  228. # Rewrite everything in the work folder
  229. RewriteRule ([^/]+)/work/(.*)$ /main/work/download.php?file=work/$2&cDir=$1 [QSA,L]
  230. </IfModule>
  231. ";
  232. return $str;
  233. }
  234. /**
  235. * @return string
  236. */
  237. public static function getDefaultCourseIndexFragment()
  238. {
  239. return "<html><head></head><body></body></html>";
  240. }
  241. /**
  242. * @param string $template
  243. * @return bool
  244. */
  245. public static function templateExists($template)
  246. {
  247. global $_configuration;
  248. // Find and checktemplate directory (files and SQL).
  249. $separator = DIRECTORY_SEPARATOR;
  250. $templatefoldername = 'plugin'.$separator.'vchamilo'.$separator.'templates';
  251. $relative_datadir = $templatefoldername.$separator.$template.'_sql';
  252. $absolute_datadir = $_configuration['root_sys'].$relative_datadir;
  253. return is_dir($absolute_datadir);
  254. }
  255. /**
  256. * drop a vchamilo instance databases using the physical connection
  257. * @param stdClass $params
  258. * return an array of errors or false if ok
  259. */
  260. public static function dropDatabase($params)
  261. {
  262. $params = clone $params;
  263. if (empty($params->main_database)) {
  264. Display::addFlash(Display::return_message('No database found'));
  265. return;
  266. }
  267. $databaseToDelete = $params->main_database;
  268. unset($params->main_database);
  269. $connection = self::getConnectionFromInstance($params);
  270. if ($connection) {
  271. $databases = $connection->getSchemaManager()->listDatabases();
  272. if (in_array($databaseToDelete, $databases)) {
  273. $connection->getSchemaManager()->dropDatabase(
  274. $databaseToDelete
  275. );
  276. Display::addFlash(
  277. Display::return_message(
  278. 'Database deleted: '.$databaseToDelete
  279. )
  280. );
  281. } else {
  282. Display::addFlash(
  283. Display::return_message(
  284. 'Database does not exist: '.$databaseToDelete
  285. )
  286. );
  287. }
  288. } else {
  289. Display::addFlash(
  290. Display::return_message(
  291. "Cannot connect DB: $databaseToDelete"
  292. )
  293. );
  294. }
  295. return false;
  296. }
  297. /**
  298. * @param stdClass $params
  299. * @return bool
  300. */
  301. public static function createDatabase($params)
  302. {
  303. $params = clone $params;
  304. $databaseName = $params->main_database;
  305. unset($params->main_database);
  306. $connection = Virtual::getConnectionFromInstance($params);
  307. if ($connection) {
  308. $databaseList = $connection->getSchemaManager()->listDatabases();
  309. if (!in_array($databaseName, $databaseList)) {
  310. $connection->getSchemaManager()->createDatabase($databaseName);
  311. Display::addFlash(
  312. Display::return_message("Creating DB ".$databaseName)
  313. );
  314. } else {
  315. Display::addFlash(
  316. Display::return_message("DB already exists: ".$databaseName)
  317. );
  318. }
  319. return true;
  320. }
  321. return false;
  322. }
  323. /**
  324. * get a proper SQLdump command
  325. * @param object $vchamilodata the complete new host information
  326. * @return string the shell command
  327. */
  328. public static function getDatabaseDumpCmd($vchamilodata)
  329. {
  330. $pgm = self::getConfig('vchamilo', 'mysql_cmd');
  331. if (!$pgm) {
  332. $pgm = '/usr/bin/mysql';
  333. }
  334. $phppgm = str_replace("\\", '/', $pgm);
  335. $phppgm = str_replace("\"", '', $phppgm);
  336. $pgm = str_replace("/", DIRECTORY_SEPARATOR, $pgm);
  337. if (!is_executable($phppgm)) {
  338. throw new Exception('databasecommanddoesnotmatchanexecutablefile');
  339. }
  340. // Retrieves the host configuration (more secure).
  341. $vchamilodata = empty($vchamilodata) ? Virtual::makeThis() : $vchamilodata;
  342. if (strstr($vchamilodata->db_host, ':') !== false) {
  343. list($vchamilodata->db_host, $vchamilodata->db_port) = explode(
  344. ':',
  345. $vchamilodata->db_host
  346. );
  347. }
  348. // Password.
  349. $databasePassword = '';
  350. if (!empty($vchamilodata->db_password)) {
  351. $databasePassword = '-p'.escapeshellarg($vchamilodata->db_password).' ';
  352. }
  353. // Making the command line (see 'vconfig.php' file for defining the right paths).
  354. $sqlcmd = $pgm.' -h'.$vchamilodata->db_host.(isset($vchamilodata->db_port) ? ' -P'.$vchamilodata->db_port.' ' : ' ' );
  355. $sqlcmd .= '-u'.$vchamilodata->db_user.' '.$databasePassword;
  356. $sqlcmd .= '%DATABASE% < ';
  357. return $sqlcmd;
  358. }
  359. /**
  360. * @param stdClass $vchamilo
  361. * @param string $template
  362. * @return bool
  363. */
  364. public static function loadDbTemplate($vchamilo, $template)
  365. {
  366. global $_configuration;
  367. // Make template directory (files and SQL).
  368. $separator = DIRECTORY_SEPARATOR;
  369. $templatefoldername = 'plugin'.$separator.'vchamilo'.$separator.'templates';
  370. $absolute_datadir = $_configuration['root_sys'].$templatefoldername.$separator.$template.$separator.'dump.sql';
  371. if (!$sqlcmd = Virtual::getDatabaseDumpCmd($vchamilo)) {
  372. return false;
  373. }
  374. $sqlcmd = str_replace('%DATABASE%', $vchamilo->main_database, $sqlcmd);
  375. // Make final commands to execute, depending on the database type.
  376. $import = $sqlcmd.$absolute_datadir;
  377. // Execute the command.
  378. Display::addFlash(Display::return_message("Load database from template dump: \n $import "));
  379. if (!defined('CLI_SCRIPT')) {
  380. putenv('LANG=en_US.utf-8');
  381. }
  382. // ensure utf8 is correctly handled by php exec()
  383. // @see http://stackoverflow.com/questions/10028925/call-a-program-via-shell-exec-with-utf-8-text-input
  384. exec($import, $output, $return);
  385. if (!empty($output)) {
  386. Display::addFlash(Display::return_message(implode("\n", $output)."\n"));
  387. }
  388. return true;
  389. }
  390. /**
  391. * Backups a database for having a snapshot.
  392. * @param $vchamilo object The Vchamilo object.
  393. * @param $outputfilerad string The output SQL file radical.
  394. * @return bool If TRUE, dumping database was a success, otherwise FALSE.
  395. */
  396. public static function backupDatabase($vchamilo, $outputfilerad)
  397. {
  398. // Separating host and port, if sticked.
  399. if (strstr($vchamilo->db_host, ':') !== false) {
  400. list($host, $port) = explode(':', $vchamilo->db_host);
  401. } else {
  402. $host = $vchamilo->db_host;
  403. }
  404. // By default, empty password.
  405. $pass = '';
  406. $pgm = null;
  407. if (empty($port)) {
  408. $port = 3306;
  409. }
  410. // Password.
  411. if (!empty($vchamilo->db_password)) {
  412. $pass = "-p".escapeshellarg($vchamilo->db_password);
  413. }
  414. // Making the commands for each database.
  415. $cmds = array();
  416. //if ($CFG->ostype == 'WINDOWS') {
  417. if (false) {
  418. $cmd_main = "-h{$host} -P{$port} -u{$vchamilo->db_user} {$pass} {$vchamilo->main_database}";
  419. $cmds[] = $cmd_main . ' > ' . $outputfilerad;
  420. } else {
  421. $cmd_main = "-h{$host} -P{$port} -u{$vchamilo->db_user} {$pass} {$vchamilo->main_database}";
  422. $cmds[] = $cmd_main . ' > ' . escapeshellarg($outputfilerad);
  423. }
  424. $mysqldumpcmd = self::getConfig('vchamilo', 'cmd_mysqldump', true);
  425. $pgm = !empty($mysqldumpcmd) ? stripslashes($mysqldumpcmd) : false;
  426. if (!$pgm) {
  427. $message = "Database dump command not available check here: ";
  428. $url = api_get_path(WEB_CODE_PATH).'admin/configure_plugin.php?name=vchamilo';
  429. $message .= Display::url($url, $url);
  430. Display::addFlash(Display::return_message($message));
  431. return false;
  432. } else {
  433. $phppgm = str_replace("\\", '/', $pgm);
  434. $phppgm = str_replace("\"", '', $phppgm);
  435. $pgm = str_replace('/', DIRECTORY_SEPARATOR, $pgm);
  436. if (!is_executable($phppgm)) {
  437. $message = "Database dump command $phppgm does not match any executable";
  438. Display::addFlash(Display::return_message($message));
  439. return false;
  440. }
  441. // executing all commands
  442. foreach ($cmds as $cmd) {
  443. // Final command.
  444. $cmd = $pgm.' '.$cmd;
  445. // Executes the SQL command.
  446. exec($cmd, $execoutput, $returnvalue);
  447. }
  448. }
  449. // End with success.
  450. return 1;
  451. }
  452. /**
  453. * read manifest values in vchamilo template.
  454. */
  455. public static function getVmanifest($version)
  456. {
  457. $file = api_get_path(SYS_PATH).'/plugin/vchamilo/templates/'.$version.'/manifest.php';
  458. if (file_exists($file)) {
  459. include $file;
  460. $manifest = new stdClass();
  461. $manifest->templatewwwroot = $templatewwwroot;
  462. // $manifest->templatevdbprefix = $templatevdbprefix;
  463. // $manifest->coursefolder = $coursefolder;
  464. return $manifest;
  465. }
  466. return false;
  467. }
  468. /**
  469. * make a fake vchamilo that represents the current host
  470. */
  471. public static function makeThis()
  472. {
  473. global $_configuration;
  474. $thisPortal = new stdClass();
  475. $thisPortal->root_web = $_configuration['root_web'];
  476. $thisPortal->db_host = $_configuration['db_host'];
  477. $thisPortal->db_user = $_configuration['db_user'];
  478. $thisPortal->db_password = $_configuration['db_password'];
  479. $thisPortal->main_database = $_configuration['main_database'];
  480. return $thisPortal;
  481. }
  482. /**
  483. * Get available templates for defining a new virtual host.
  484. * @return array The available templates, or EMPTY array.
  485. */
  486. public static function getAvailableTemplates()
  487. {
  488. global $_configuration;
  489. $separator = DIRECTORY_SEPARATOR;
  490. $templatefoldername = 'plugin'.$separator.'vchamilo'.$separator.'templates';
  491. $tempDir = $_configuration['root_sys'].$templatefoldername;
  492. // Scans the templates.
  493. if (!is_dir($tempDir)) {
  494. mkdir($tempDir, 0777, true);
  495. }
  496. $finder = new \Symfony\Component\Finder\Finder();
  497. $dirs = $finder->in($tempDir)->depth('== 0');
  498. // Retrieves template(s) name(s). Should be hostnames.
  499. $templates = [];
  500. /*if ($addEmptyTemplate) {
  501. $templates = array('' => $plugin->get_lang('emptysite'));
  502. }*/
  503. $template = self::getConfig('vchamilo', 'default_template');
  504. if ($dirs) {
  505. /** @var Symfony\Component\Finder\SplFileInfo $dir */
  506. foreach ($dirs as $dir) {
  507. if (is_dir($dir->getPathname())) {
  508. // A template is considered when a dump.sql exists.
  509. if (file_exists($dir->getPathname().'/dump.sql')) {
  510. $templateName = $dir->getRelativePathname();
  511. if ($templateName == $template) {
  512. $templateName .= ' (default)';
  513. }
  514. $templates[$dir->getRelativePathname()] = $templateName;
  515. }
  516. }
  517. }
  518. }
  519. return $templates;
  520. }
  521. /**
  522. * this function set will map standard moodle API calls to chamilo
  523. * internal primitives. This avoids too many changes to do in imported
  524. * code
  525. */
  526. public static function getConfig($module, $key, $isplugin = true)
  527. {
  528. if ($isplugin) {
  529. $key = $module.'_'.$key;
  530. }
  531. $params = array('variable = ? AND subkey = ?' => [$key, $module]);
  532. $result = api_get_settings_params_simple($params);
  533. if ($result) {
  534. return $result['selected_value'];
  535. }
  536. return false;
  537. }
  538. /**
  539. * @param stdClass $vchamilo
  540. * @param string $template
  541. */
  542. public static function loadFilesFromTemplate($vchamilo, $template)
  543. {
  544. global $_configuration;
  545. // Make template directory (files and SQL).
  546. $separator = DIRECTORY_SEPARATOR;
  547. $templateDir = $_configuration['root_sys'].'plugin'.$separator.'vchamilo'.$separator.'templates'.$separator.$template;
  548. $vchamilo->virtual = true;
  549. $coursePath = self::getConfig('vchamilo', 'course_real_root').$separator.$vchamilo->slug;
  550. $homePath = self::getConfig('vchamilo', 'home_real_root').$separator.$vchamilo->slug;
  551. $archivePath = self::getConfig('vchamilo', 'archive_real_root').$separator.$vchamilo->slug;
  552. $uploadPath = self::getConfig('vchamilo', 'upload_real_root').$separator.$vchamilo->slug;
  553. // get the protocol free hostname
  554. Display::addFlash(
  555. Display::return_message("Copying {$templateDir}/data/courses => $coursePath")
  556. );
  557. copyDirTo(
  558. self::chopLastSlash($templateDir.'/data/courses'),
  559. self::chopLastSlash($coursePath),
  560. false
  561. );
  562. Display::addFlash(
  563. Display::return_message("Copying {$templateDir}/data/archive => $archivePath")
  564. );
  565. copyDirTo(
  566. self::chopLastSlash($templateDir.'/data/archive'),
  567. self::chopLastSlash($archivePath),
  568. false
  569. );
  570. Display::addFlash(
  571. Display::return_message("Copying {$templateDir}/data/home => $homePath")
  572. );
  573. copyDirTo(
  574. self::chopLastSlash($templateDir.'/data/home'),
  575. self::chopLastSlash($homePath),
  576. false
  577. );
  578. // Upload
  579. Display::addFlash(
  580. Display::return_message("Copying {$templateDir}/data/upload => $uploadPath")
  581. );
  582. copyDirTo(
  583. self::chopLastSlash($templateDir.'/data/upload/'),
  584. self::chopLastSlash($uploadPath),
  585. false
  586. );
  587. }
  588. /**
  589. * @param string $path
  590. *
  591. * @return mixed
  592. */
  593. public static function chopLastSlash($path)
  594. {
  595. return preg_replace('/\/$/', '', $path);
  596. }
  597. /**
  598. * @param string $str
  599. */
  600. public static function ctrace($str)
  601. {
  602. error_log($str);
  603. Display::addFlash(Display::return_message($str, 'normal', false));
  604. }
  605. /**
  606. * @param $file
  607. * @param $component
  608. * @param bool $return
  609. * @return string
  610. */
  611. public static function requireJs($file, $component, $return = false)
  612. {
  613. global $_configuration, $htmlHeadXtra;
  614. if (preg_match('/^local_/', $component)) {
  615. $component = str_replace('local_', '', $component);
  616. $path = 'local/';
  617. } else {
  618. $path = 'plugin/';
  619. }
  620. // Secure the postslashing of the roots.
  621. $root_web = $_configuration['root_web'].'/';
  622. $root_web = preg_replace('#//$#', '/', $root_web);
  623. $str = '<script type="text/javascript" src="'.$root_web.$path.$component.'/js/'.$file.'"></script>'."\n";
  624. if ($return === 'head') {
  625. $htmlHeadXtra[] = $str;
  626. }
  627. if ($return) {
  628. return $str;
  629. }
  630. echo $str;
  631. }
  632. /**
  633. * @param $file
  634. * @param $component
  635. * @param bool $return
  636. * @return string
  637. */
  638. public static function requireCss($file, $component, $return = false)
  639. {
  640. global $_configuration, $htmlHeadXtra;
  641. if (preg_match('/^local_/', $component)) {
  642. $component = str_replace('local_', '', $component);
  643. $path = 'local/';
  644. } else {
  645. $path = 'plugin/';
  646. }
  647. // Secure the postslashing of the roots.
  648. $root_web = $_configuration['root_web'].'/';
  649. $root_web = preg_replace('#//$#', '/', $root_web);
  650. $str = '<link rel="stylesheet" type="text/css" href="'.$root_web.$path.$component.'/'.$file.'.css" />'."\n";
  651. if ($return === 'head') {
  652. $htmlHeadXtra[] = $str;
  653. }
  654. if ($return) {
  655. return $str;
  656. }
  657. echo $str;
  658. }
  659. /**
  660. * @param string $url
  661. * @return string
  662. */
  663. public static function getSlugFromUrl($url)
  664. {
  665. $slugify = new Slugify();
  666. $urlInfo = parse_url($url);
  667. if (isset($urlInfo['host'])) {
  668. $path = $urlInfo['path'] != '/' ? '_'.$urlInfo['path'] : '';
  669. return $slugify->slugify($urlInfo['host'].$path);
  670. }
  671. return false;
  672. }
  673. /**
  674. * Check if all settings are complete
  675. */
  676. public static function checkSettings()
  677. {
  678. $enabled = self::getConfig('vchamilo', 'enable_virtualisation');
  679. if (empty($enabled)) {
  680. api_not_allowed(true, 'Plugin is not enabled');
  681. }
  682. global $virtualChamilo;
  683. if (!isset($virtualChamilo)) {
  684. api_not_allowed(
  685. true,
  686. 'You have to edit the configuration.php. Please check the readme file.'
  687. );
  688. }
  689. $coursePath = self::getConfig('vchamilo', 'course_real_root');
  690. $homePath = self::getConfig('vchamilo', 'home_real_root');
  691. $archivePath = self::getConfig('vchamilo', 'archive_real_root');
  692. $uploadPath = self::getConfig('vchamilo', 'upload_real_root');
  693. $cmdSql = self::getConfig('vchamilo', 'cmd_mysql');
  694. $cmdMySql = self::getConfig('vchamilo', 'cmd_mysqldump');
  695. if (empty($coursePath) || empty($homePath) || empty($uploadPath) || empty($archivePath) || empty($cmdSql) || empty($cmdMySql)) {
  696. api_not_allowed(true, 'You have to complete all plugin settings.');
  697. }
  698. $separator = DIRECTORY_SEPARATOR;
  699. $templatePath = api_get_path(SYS_PATH).'plugin'.$separator.'vchamilo'.$separator.'templates';
  700. $paths = [
  701. $coursePath,
  702. $homePath,
  703. $archivePath,
  704. $uploadPath,
  705. $templatePath
  706. ];
  707. foreach ($paths as $path) {
  708. $path = trim($path);
  709. if (is_dir($path)) {
  710. if (!is_writable($path)) {
  711. Display::addFlash(
  712. Display::return_message("Directory must have writable permissions: '$path'", 'warning')
  713. );
  714. };
  715. } else {
  716. Display::addFlash(
  717. Display::return_message("Directory doesn't exist: '$path'", 'warning')
  718. );
  719. }
  720. }
  721. }
  722. /**
  723. * @param object $instance
  724. * @return bool|\Doctrine\DBAL\Connection
  725. */
  726. public static function getConnectionFromInstance($instance, $getManager = false)
  727. {
  728. $dbParams = array(
  729. 'driver' => 'pdo_mysql',
  730. 'host' => $instance->db_host,
  731. 'user' => $instance->db_user,
  732. 'password' => $instance->db_password,
  733. //'dbname' => $instance->main_database,
  734. // Only relevant for pdo_sqlite, specifies the path to the SQLite database.
  735. //'path' => isset($_configuration['db_path']) ? $_configuration['db_path'] : '',
  736. // Only relevant for pdo_mysql, pdo_pgsql, and pdo_oci/oci8,
  737. //'port' => isset($_configuration['db_port']) ? $_configuration['db_port'] : '',
  738. );
  739. if (!empty($instance->main_database)) {
  740. $dbParams['dbname'] = $instance->main_database;
  741. }
  742. try {
  743. $database = new \Database();
  744. $manager = $database->connect(
  745. $dbParams,
  746. api_get_configuration_value('root_sys'),
  747. api_get_configuration_value('root_sys'),
  748. false,
  749. true
  750. );
  751. if ($getManager) {
  752. return $manager;
  753. }
  754. return $manager->getConnection();
  755. } catch (Exception $e) {
  756. error_log($e->getMessage());
  757. }
  758. return false;
  759. }
  760. /**
  761. * @param $data
  762. */
  763. public static function addInstance($data)
  764. {
  765. if (isset($data->what)) {
  766. unset($data->what);
  767. }
  768. if (isset($data->submitbutton)) {
  769. unset($data->submitbutton);
  770. }
  771. if (isset($data->id)) {
  772. unset($data->id);
  773. }
  774. if (isset($data->vid)) {
  775. unset($data->vid);
  776. }
  777. if (isset($data->testconnection)) {
  778. unset($data->testconnection);
  779. }
  780. if (isset($data->testdatapath)) {
  781. unset($data->testdatapath);
  782. }
  783. $registeronly = $data->registeronly;
  784. unset($data->registeronly);
  785. $data->lastcron = 0;
  786. $data->lastcrongap = 0;
  787. $data->croncount = 0;
  788. if (isset($data->template) && !empty($data->template)) {
  789. $template = $data->template;
  790. } else {
  791. $template = '';
  792. }
  793. $mainDatabase = api_get_configuration_value('main_database');
  794. if ($mainDatabase == $data->main_database) {
  795. Display::addFlash(
  796. Display::return_message('You cannot use the same database as the chamilo master', 'error')
  797. );
  798. return ;
  799. }
  800. $databaseName = $data->main_database;
  801. $data->main_database = '';
  802. $connection = Virtual::getConnectionFromInstance($data);
  803. $data->main_database = $databaseName;
  804. if (!$connection) {
  805. Display::addFlash(
  806. Display::return_message(
  807. 'Cannot connect to database with params: '.print_r($data, 1),
  808. 'error'
  809. )
  810. );
  811. return ;
  812. }
  813. $data->root_web = api_add_trailing_slash($data->root_web);
  814. if (substr($data->root_web, 4) != 'http') {
  815. $data->root_web = api_get_protocol().'://'.$data->root_web;
  816. }
  817. self::ctrace('Registering: '.$data->root_web);
  818. $tablename = Database::get_main_table('vchamilo');
  819. $sql = "SELECT * FROM $tablename
  820. WHERE root_web = '".Database::escape_string($data->root_web)."'";
  821. $result = Database::query($sql);
  822. if (Database::num_rows($result)) {
  823. Database::update($tablename, $data, ['root_web = ?' => $data->root_web]);
  824. $virtualInfo = Database::fetch_array($result);
  825. $slug = $virtualInfo['slug'];
  826. } else {
  827. $slug = $data->slug = Virtual::getSlugFromUrl($data->root_web);
  828. if (empty($slug)) {
  829. Display::addFlash(
  830. Display::return_message('Cannot create slug from url: '.$data->root_web, 'error')
  831. );
  832. return ;
  833. }
  834. Database::insert($tablename, (array) $data);
  835. }
  836. if ($registeronly) {
  837. // Stop it now.
  838. self::ctrace('Registering only. out.');
  839. Virtual::redirect(api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php');
  840. }
  841. // or we continue with physical creation
  842. self::createDirsFromSlug($slug);
  843. if (!$template) {
  844. // Create empty database for install
  845. self::ctrace("Creating database");
  846. Virtual::createDatabase($data);
  847. } else {
  848. // Deploy template database
  849. self::ctrace("Creating databases from template '$template'");
  850. Virtual::createDatabase($data);
  851. self::ctrace("Loading data template '$template'");
  852. Virtual::loadDbTemplate($data, $template);
  853. self::ctrace("Coying files from template '$template'");
  854. Virtual::loadFilesFromTemplate($data, $template);
  855. }
  856. // pluging in site name institution
  857. $settingstable = $data->main_database.'.settings_current';
  858. $accessurltable = $data->main_database.'.access_url';
  859. $sitename = Database::escape_string($data->sitename);
  860. $institution = Database::escape_string($data->institution);
  861. $sqls[] = "UPDATE {$settingstable} SET selected_value = '{$sitename}'
  862. WHERE variable = 'siteName' AND category = 'Platform' ";
  863. $sqls[] = "UPDATE {$settingstable} SET selected_value = '{$institution}'
  864. WHERE variable = 'institution' AND category = 'Platform' ";
  865. $sqls[] = "UPDATE {$accessurltable} SET url = '{$data->root_web}' WHERE id = '1' ";
  866. foreach ($sqls as $sql) {
  867. Database::query($sql);
  868. }
  869. self::ctrace("Finished");
  870. }
  871. /**
  872. * @param stdClass $data
  873. * @param string $fromVersion
  874. */
  875. public static function importInstance($data, $fromVersion)
  876. {
  877. if (isset($data->what)) {
  878. unset($data->what);
  879. }
  880. if (isset($data->submitbutton)) {
  881. unset($data->submitbutton);
  882. }
  883. if (isset($data->id)) {
  884. unset($data->id);
  885. }
  886. if (isset($data->vid)) {
  887. unset($data->vid);
  888. }
  889. if (isset($data->testconnection)) {
  890. unset($data->testconnection);
  891. }
  892. if (isset($data->testdatapath)) {
  893. unset($data->testdatapath);
  894. }
  895. $fromCoursePath = $data->course_path;
  896. $fromHomePath = $data->home_path;
  897. $fromUploadPath = $data->upload_path;
  898. unset($data->course_path);
  899. unset($data->home_path);
  900. unset($data->upload_path);
  901. $newDatabase = clone $data;
  902. $newDatabase->main_database = $newDatabase->import_to_main_database;
  903. $newDatabase->db_user = $newDatabase->import_to_db_user;
  904. $newDatabase->db_password = $newDatabase->import_to_db_password;
  905. $newDatabase->db_host = $newDatabase->import_to_db_host;
  906. unset($newDatabase->import_to_main_database);
  907. unset($newDatabase->import_to_db_user);
  908. unset($newDatabase->import_to_db_password);
  909. unset($newDatabase->import_to_db_host);
  910. unset($data->import_to_main_database);
  911. unset($data->import_to_db_user);
  912. unset($data->import_to_db_password);
  913. unset($data->import_to_db_host);
  914. $data->lastcron = 0;
  915. $data->lastcrongap = 0;
  916. $data->croncount = 0;
  917. $mainDatabase = api_get_configuration_value('main_database');
  918. if ($mainDatabase == $data->main_database) {
  919. Display::addFlash(
  920. Display::return_message('You cannot use the same database as the chamilo master', 'error')
  921. );
  922. return false;
  923. }
  924. self::ctrace('Registering: '.$data->root_web);
  925. $table = Database::get_main_table('vchamilo');
  926. $sql = "SELECT * FROM $table
  927. WHERE root_web = '".Database::escape_string($data->root_web)."'";
  928. $result = Database::query($sql);
  929. $id = null;
  930. if (Database::num_rows($result)) {
  931. Display::addFlash(
  932. Display::return_message('Instance was already added: '.$data->root_web, 'error')
  933. );
  934. return false;
  935. } else {
  936. /** @var EntityManager $em */
  937. $em = Virtual::getConnectionFromInstance($data, true);
  938. if ($em) {
  939. $connection = $em->getConnection();
  940. $statement = $connection->query('SELECT * FROM settings_current');
  941. $settings = $statement->fetchAll();
  942. $settings = array_column(
  943. $settings,
  944. 'selected_value',
  945. 'variable'
  946. );
  947. $institution = $settings['Institution'];
  948. $siteName = $settings['siteName'];
  949. $newDatabase->sitename = $siteName;
  950. $newDatabase->institution = $institution;
  951. $slug = $newDatabase->slug = $data->slug = Virtual::getSlugFromUrl($data->root_web);
  952. $id = Database::insert($table, (array)$newDatabase);
  953. }
  954. }
  955. if (!$id) {
  956. var_dump($data);
  957. throw new Exception('Was not registered');
  958. }
  959. if (empty($slug)) {
  960. throw new Exception('Slug is empty');
  961. }
  962. self::createDirsFromSlug($slug);
  963. $databaseCreated = Virtual::createDatabase($newDatabase);
  964. if (!$databaseCreated) {
  965. Display::addFlash(
  966. Display::return_message('Error while creating a DB', 'error')
  967. );
  968. return false;
  969. }
  970. $coursePath = self::getConfig('vchamilo', 'course_real_root').'/'.$slug;
  971. $homePath = self::getConfig('vchamilo', 'home_real_root').'/'.$slug;
  972. $uploadPath = self::getConfig('vchamilo', 'upload_real_root').'/'.$slug;
  973. $dumpFile = api_get_path(SYS_ARCHIVE_PATH).uniqid($data->main_database.'_dump_', true).'.sql';
  974. self::ctrace('Create backup from "'.$data->main_database.'" here: '.$dumpFile.' ');
  975. Virtual::backupDatabase($data, $dumpFile);
  976. $sqlcmd = Virtual::getDatabaseDumpCmd($newDatabase);
  977. $sqlcmd = str_replace('%DATABASE%', $newDatabase->main_database, $sqlcmd);
  978. $import = $sqlcmd.$dumpFile;
  979. // Execute the command.
  980. if (!defined('CLI_SCRIPT')) {
  981. putenv('LANG=en_US.utf-8');
  982. }
  983. // ensure utf8 is correctly handled by php exec()
  984. // @see http://stackoverflow.com/questions/10028925/call-a-program-via-shell-exec-with-utf-8-text-input
  985. $result = exec($import, $output, $return);
  986. self::ctrace('Restore backup here "'.$newDatabase->main_database.'" : <br />'.$import.' ');
  987. self::ctrace($result);
  988. $command = new \Chash\Command\Installation\UpgradeDatabaseCommand();
  989. // Creates the helper set
  990. $helperSet = \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($em);
  991. $helpers = array(
  992. 'configuration' => new Chash\Helpers\ConfigurationHelper(),
  993. 'dialog' => new \Symfony\Component\Console\Helper\QuestionHelper(),
  994. );
  995. foreach ($helpers as $name => $helper) {
  996. $helperSet->set($helper, $name);
  997. }
  998. $command->setHelperSet($helperSet);
  999. $tmpFile = tmpfile();
  1000. $outputStream = new \Symfony\Component\Console\Output\BufferedOutput($tmpFile);
  1001. $arguments = array(
  1002. 'from-version' => $fromVersion, // @todo change value
  1003. 'to-version' => '1.11.x',
  1004. 'host' => $newDatabase->db_host,
  1005. 'username' => $newDatabase->db_user,
  1006. 'password' => $newDatabase->db_password,
  1007. 'db_name' => $newDatabase->main_database,
  1008. 'root_sys' => api_get_configuration_value('root_sys')
  1009. );
  1010. $input = new ArrayInput($arguments);
  1011. $command->run($input, $outputStream);
  1012. error_log($outputStream->fetch());
  1013. if (file_exists($dumpFile)) {
  1014. unlink($dumpFile);
  1015. }
  1016. // Course
  1017. self::ctrace("Copy from '$fromCoursePath' to backup '$coursePath' ");
  1018. copyDirTo(
  1019. self::chopLastSlash($fromCoursePath),
  1020. self::chopLastSlash($coursePath),
  1021. false
  1022. );
  1023. // Home
  1024. self::ctrace("Copy from '$fromHomePath' to backup '$homePath' ");
  1025. copyDirTo(
  1026. self::chopLastSlash($fromHomePath),
  1027. self::chopLastSlash($homePath),
  1028. false
  1029. );
  1030. // Upload
  1031. self::ctrace("Copy from '$fromUploadPath' to backup '$uploadPath' ");
  1032. copyDirTo(
  1033. self::chopLastSlash($fromUploadPath),
  1034. self::chopLastSlash($uploadPath),
  1035. false
  1036. );
  1037. self::ctrace("Finished");
  1038. }
  1039. /**
  1040. * @param string $slug
  1041. *
  1042. * @return string
  1043. */
  1044. public static function createDirsFromSlug($slug)
  1045. {
  1046. // We continue with physical creation
  1047. // Create course directory for operations.
  1048. // this is very important here (DO NOT USE api_get_path() !!) because storage may be remotely located
  1049. $absAlternateCourse = Virtual::getConfig('vchamilo', 'course_real_root');
  1050. $courseDir = $absAlternateCourse.'/'.$slug;
  1051. if (!is_dir($courseDir)) {
  1052. self::ctrace("Creating physical course dir in $courseDir");
  1053. mkdir($courseDir, 0777, true);
  1054. // initiate default index
  1055. $indexFile = $courseDir.'/index.html';
  1056. if ($indexFile) {
  1057. file_put_contents($indexFile, self::getDefaultCourseIndexFragment());
  1058. }
  1059. $htaccessFile = $courseDir.'/.htaccess';
  1060. if ($htaccessFile) {
  1061. file_put_contents($htaccessFile, self::getHtaccessFragment($slug));
  1062. }
  1063. }
  1064. $absAlternateHome = Virtual::getConfig('vchamilo', 'home_real_root');
  1065. $absAlternateArchive = Virtual::getConfig('vchamilo', 'archive_real_root');
  1066. $absAlternateUpload = Virtual::getConfig('vchamilo', 'upload_real_root');
  1067. // absalternatehome is a vchamilo config setting that tells where the
  1068. // real physical storage for home pages are.
  1069. $homeDir = $absAlternateHome.'/'.$slug;
  1070. $archiveDir = $absAlternateArchive.'/'.$slug;
  1071. $uploadDir = $absAlternateUpload.'/'.$slug;
  1072. $dirs = [
  1073. $homeDir,
  1074. $archiveDir,
  1075. $uploadDir
  1076. ];
  1077. foreach ($dirs as $dir) {
  1078. self::ctrace("Making dir as $dir");
  1079. if (!is_dir($dir)) {
  1080. if (!mkdir($dir, 0777, true)) {
  1081. self::ctrace("Error creating dir $dir \n");
  1082. }
  1083. }
  1084. }
  1085. }
  1086. /**
  1087. * @param $id
  1088. * @return array|mixed
  1089. */
  1090. public static function getInstance($id)
  1091. {
  1092. $vhost = new stdClass();
  1093. if ($id) {
  1094. $id = (int) $id;
  1095. $sql = "SELECT * FROM vchamilo WHERE id = $id";
  1096. $result = Database::query($sql);
  1097. $vhost = (object) Database::fetch_array($result, 'ASSOC');
  1098. }
  1099. return $vhost;
  1100. }
  1101. /**
  1102. * @param stdClass $instance
  1103. *
  1104. * @return bool|string returns the original version of the app
  1105. */
  1106. public static function canBeUpgraded($instance)
  1107. {
  1108. $connection = Virtual::getConnectionFromInstance($instance);
  1109. if ($connection) {
  1110. $sql = 'SELECT * FROM settings_current WHERE variable = "chamilo_database_version"';
  1111. $statement = $connection->query($sql);
  1112. $settings = $statement->fetchAll();
  1113. $settings = array_column($settings, 'selected_value', 'variable');
  1114. $version = $settings['chamilo_database_version'];
  1115. $versionParts = explode('.', $version);
  1116. $version = implode('.', [$versionParts[0], $versionParts[1], '0']);
  1117. $currentVersion = api_get_setting('chamilo_database_version');
  1118. $versionParts = explode('.', $currentVersion);
  1119. $currentVersion = implode(
  1120. '.',
  1121. [$versionParts[0], $versionParts[1], '0']
  1122. );
  1123. if (version_compare($version, $currentVersion, '<')) {
  1124. return $version;
  1125. }
  1126. }
  1127. return false;
  1128. }
  1129. /**
  1130. * @return array
  1131. */
  1132. public static function getEncryptList()
  1133. {
  1134. $encryptList = [
  1135. 'bcrypt',
  1136. 'sha1',
  1137. 'md5',
  1138. 'none'
  1139. ];
  1140. return array_combine($encryptList, $encryptList);
  1141. }
  1142. }