/** * Dumps a SQL database for having a snapshot. * @param $vchamilo object The Vchamilo object. * @param $outputfilerad string The output SQL file radical. * @return bool If TRUE, dumping database was a success, otherwise FALSE. */ function vchamilo_dump_databases($vchamilo, $outputfilerad) { global $CFG; // Separating host and port, if sticked. if (strstr($vchamilo->db_host, ':') !== false) { list($host, $port) = split(':', $vchamilo->db_host); } else { $host = $vchamilo->db_host; } // By default, empty password. $pass = ''; $pgm = null; if (empty($port)) { $port = 3306; } // Password. if (!empty($vchamilo->db_password)) { $pass = "******" . escapeshellarg($vchamilo->db_password); } // Making the commands for each database. $cmds = array(); if ($CFG->ostype == 'WINDOWS') { $cmd_main = "-h{$host} -P{$port} -u{$vchamilo->db_user} {$pass} {$vchamilo->main_database}"; $cmds[] = $cmd_main . ' > ' . $outputfilerad . '_main.sql'; if ($vchamilo->statistics_database != $vchamilo->main_database) { $cmd_stats = "-h{$host} -P{$port} -u{$vchamilo->db_user} {$pass} {$vchamilo->statistics_database}"; $cmds[] = $cmd_stats . ' > ' . $outputfilerad . '_statistics.sql'; } if ($vchamilo->user_personal_database != $vchamilo->main_database && $vchamilo->user_personal_database != $vchamilo->statistics_database) { $cmd_user = "******"; $cmds[] = $cmd_user . ' > ' . $outputfilerad . '_user_personal.sql'; } } else { $cmd_main = "-h{$host} -P{$port} -u{$vchamilo->db_user} {$pass} {$vchamilo->main_database}"; $cmds[] = $cmd_main . ' > ' . escapeshellarg($outputfilerad . '_main.sql'); if ($vchamilo->statistics_database != $vchamilo->main_database) { $cmd_stats = "-h{$host} -P{$port} -u{$vchamilo->db_user} {$pass} {$vchamilo->statistics_database}"; $cmds[] = $cmd_stats . ' > ' . escapeshellarg($outputfilerad . '_statistics.sql'); } if ($vchamilo->user_personal_database != $vchamilo->main_database && $vchamilo->user_personal_database != $vchamilo->statistics_database) { $cmd_user = "******"; $cmds[] = $cmd_user . ' > ' . escapeshellarg($outputfilerad . '_user_personal.sql'); } } $mysqldumpcmd = vchamilo_get_config('vchamilo', 'cmd_mysqldump', true); $pgm = !empty($mysqldumpcmd) ? stripslashes($mysqldumpcmd) : false; if (!$pgm) { $erroritem = new StdClass(); $erroritem->message = "Database dump command not available"; return array($erroritem); } else { $phppgm = str_replace("\\", '/', $pgm); $phppgm = str_replace("\"", '', $phppgm); $pgm = str_replace('/', DIRECTORY_SEPARATOR, $pgm); if (!is_executable($phppgm)) { $erroritem = new StdClass(); $erroritem->message = "Database dump command {$phppgm} does not match any executable"; return array($erroritem); } // executing all commands foreach ($cmds as $cmd) { // Final command. $cmd = $pgm . ' ' . $cmd; // ctrace($cmd); // Be carefull there, this could divulgate DB password // Prints log messages in the page and in 'cmd.log'. if ($LOG = fopen(dirname($outputfilerad) . '/cmd.log', 'a')) { fwrite($LOG, $cmd . "\n"); } // Executes the SQL command. exec($cmd, $execoutput, $returnvalue); if ($LOG) { foreach ($execoutput as $execline) { fwrite($LOG, $execline . "\n"); } fwrite($LOG, $returnvalue . "\n"); fclose($LOG); } } } // End with success. return 0; }
//the plugin title $plugin_info['title'] = 'Chamilo Virtualization'; //the comments that go with the plugin $plugin_info['comment'] = "Holds chamilo virtualisation tools"; //the plugin version $plugin_info['version'] = '1.0'; //the plugin author $plugin_info['author'] = 'Valery Fremaux'; /* Plugin optional settings */ /* * This form will be showed in the plugin settings once the plugin was installed * in the plugin/hello_world/index.php you can have access to the value: $plugin_info['settings']['hello_world_show_type'] */ $form = new FormValidator('vchamilo_form'); $plugininstance = VChamiloPlugin::create(); $form_settings = array('enable_virtualisation' => vchamilo_get_config('vchamilo', 'enable_virtualisation', true), 'httpproxyhost' => vchamilo_get_config('vchamilo', 'httpproxyhost', true), 'httpproxyport' => vchamilo_get_config('vchamilo', 'httpproxyport', true), 'httpproxybypass' => vchamilo_get_config('vchamilo', 'httpproxybypass', true), 'httpproxyuser' => vchamilo_get_config('vchamilo', 'httpproxyuser', true), 'httpproxypassword' => vchamilo_get_config('vchamilo', 'httpproxypassword', true), 'cmd_mysql' => vchamilo_get_config('vchamilo', 'cmd_mysql', true), 'cmd_mysqldump' => vchamilo_get_config('vchamilo', 'cmd_mysqldump', true), 'course_real_root' => vchamilo_get_config('vchamilo', 'course_real_root', true), 'archive_real_root' => vchamilo_get_config('vchamilo', 'archive_real_root', true), 'home_real_root' => vchamilo_get_config('vchamilo', 'home_real_root', true)); $form->setDefaults($form_settings); $wwwroot = $_configuration['root_web']; //A simple select $options = array(0 => $plugininstance->get_lang('no'), 1 => $plugininstance->get_lang('yes')); $form->addElement('static', 'enable_vchamilo_manager', '<a href="' . api_get_path(WEB_PLUGIN_PATH) . 'vchamilo/views/manage.php">' . $plugininstance->get_lang('manage_instances') . '</a>'); $form->addElement('static', 'sync_vchamilo_settings', '<a href="' . api_get_path(WEB_PLUGIN_PATH) . 'vchamilo/views/syncparams.php">' . $plugininstance->get_lang('sync_settings') . '</a>'); $form->addElement('header', $plugininstance->get_lang('enabling')); $form->addElement('select', 'enable_virtualisation', $plugininstance->get_lang('enable_virtualisation'), $options); $form->addElement('text', 'course_real_root', $plugininstance->get_lang('courserealroot')); $form->addElement('text', 'archive_real_root', $plugininstance->get_lang('archiverealroot')); $form->addElement('text', 'home_real_root', $plugininstance->get_lang('homerealroot')); $form->addElement('header', $plugininstance->get_lang('proxysettings')); $form->addElement('text', 'httpproxyhost', $plugininstance->get_lang('httpproxyhost')); $form->addElement('text', 'httpproxyport', $plugininstance->get_lang('httpproxyport')); $form->addElement('text', 'httpproxybypass', $plugininstance->get_lang('httpproxybypass'));
$archive_folder = $matches[1]; // prepare it now if ($absalternatehome = vchamilo_get_config('vchamilo', 'home_real_root')) { $homedir = str_replace('//', '/', $absalternatehome . '/' . $home_folder); } else { $homedir = api_get_path(SYS_PATH) . 'home/' . $home_folder; } $standardlocation = $_configuration['root_sys'] . 'home/' . $home_folder; // where it should be echo "Deleting {$homedir} \n"; removeDir($homedir); if (is_link($standardlocation)) { unlink($standardlocation); } // delete archive if ($absalternatearchive = vchamilo_get_config('vchamilo', 'archive_real_root')) { $archivedir = str_replace('//', '/', $absalternatearchive . '/' . $archive_folder); } else { $archivedir = $_configuration['root_sys'] . 'archive/' . $archive_folder; } $standardlocation = $_configuration['root_sys'] . 'archive/' . $archive_folder; // where it should be echo "Deleting {$archivedir} \n"; removeDir($archivedir); if (is_link($standardlocation)) { unlink($standardlocation); } echo '</pre>'; echo "Removing vchamilo record \n"; $sql = "\n DELETE FROM\n {$table}\n WHERE\n id = {$instance->id}\n "; Database::query($sql);
* @package vchamilo * @category plugin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL */ // Loading configuration. require_once '../../../main/inc/global.inc.php'; require_once $_configuration['root_sys'] . '/local/classes/mootochamlib.php'; require_once $_configuration['root_sys'] . '/local/classes/database.class.php'; require_once api_get_path(SYS_PLUGIN_PATH) . 'vchamilo/lib/vchamilo_plugin.class.php'; require_once api_get_path(SYS_PLUGIN_PATH) . 'vchamilo/lib.php'; global $DB; $DB = new DatabaseManager(); $plugininstance = VChamiloPlugin::create(); // Retrieve parameters for database connection test. $dataroot = $_REQUEST['dataroot']; $absalternatecourse = vchamilo_get_config('vchamilo', 'course_real_root'); if (!empty($absalternatecourse)) { // this is the relocated case $coursedir = str_replace('//', '/', $absalternatecourse . '/' . $dataroot); } else { // this is the standard local case $coursedir = api_get_path(SYS_PATH) . $dataroot; } if (is_dir($coursedir)) { $DIR = opendir($coursedir); $cpt = 0; $hasfiles = false; while (($file = readdir($DIR)) && !$hasfiles) { if (!preg_match("/^\\./", $file)) { $hasfiles = true; }