Exemple #1
0
 /**
  * Export a configuration
  * 
  * @return	bool						true if exported
  */
 public function export()
 {
     if ($this->isCloud()) {
         // Don't need to export if Cloud, skipping
         return true;
     } else {
         //Import running, if doesn't exist import startup and if it doesn't exist impost initial config.
         $running_config = '/tmp/iou/lab_' . $this->lab_id . '/dev_' . $this->id . '/running-config';
         $startup_config = '/tmp/iou/lab_' . $this->lab_id . '/dev_' . $this->id . '//startup-config';
         //$initial_config = '/tmp/iou/lab_'.$this -> lab_id.'/dev_'.$this -> id.'/config-'.sprintf("%05d", $this -> id);
         $name = $this->lab_name . ' - ' . $this->name;
         if (file_exists($running_config)) {
             $import_file = $running_config;
         } elseif (file_exists($startup_config)) {
             $import_file = $startup_config;
         } else {
             error_log('FILE: cannot find any config to export.');
             return false;
         }
         try {
             $fp = fopen($import_file, 'r');
             $content = fread($fp, filesize($import_file));
             if (cfg_add($name, $content, $this->folder_id)) {
                 return true;
             } else {
                 return false;
             }
             fclose($fp);
             return true;
         } catch (Exception $e) {
             error_log('FILE: cannot export ' . $import_file . ' with error "' . $e . '".');
             return false;
         }
     }
 }
Exemple #2
0
  *************************************************************************/
 case 'cfg_add':
     if (isset($_POST['action'])) {
         // Form completed, updating the DB
         if (isset($_POST['cfg_name']) && preg_match('/^[A-Za-z0-9_+\\s-]+$/', $_POST['cfg_name']) && (isset($_POST['cfg_config']) || $_FILES['cfg_file']['error'] == 0)) {
             $cfg_name = $_POST['cfg_name'];
             if ($_FILES['cfg_file']['error'] == 0) {
                 // load from file
                 $hndl = fopen($_FILES['cfg_file']['tmp_name'], 'r');
                 $cfg_config = '';
                 $cfg_config = fread($hndl, $_FILES['cfg_file']['size']);
             } else {
                 // load from web
                 $cfg_config = $_POST['cfg_config'];
             }
             cfg_add($cfg_name, $cfg_config, $_SESSION['current_folder']->id);
             header("Cache-Control: no-cache, must-revalidate");
             // HTTP/1.1
             header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
             // Date in the past
             header("Location: " . BASE_WWW . "/laboratories.php");
             exit;
         } else {
             header('Cache-Control: no-cache, must-revalidate');
             // HTTP/1.1
             header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
             // Date in the past
             header('HTTP/1.1 403 Forbidden');
             // Forbidden
             exit;
         }