Virtual.php 45 KB

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