protected function execute($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $con = $databaseManager->getDatabase($options['connection'])->getConnection();
     $this->log("[INFO] " . date("d/m/y : H:i:s", time()));
     $context = sfContext::createInstance(sfProjectConfiguration::getApplicationConfiguration('app', 'dev', true));
     $response = diagnostic::getAgentFiles('diagnostic');
     $this->log("[INFO] " . date("d/m/y : H:i:s", time()));
     return;
 }
示例#2
0
 public function executeJsonDiagnostic(sfWebRequest $request)
 {
     $method = $request->getParameter('method');
     if ($method == 'diagnostic') {
         $this->updateSetting(EtvaSettingPeer::_SMTP_SERVER_, $request->getParameter('smtpserver'));
         $this->updateSetting(EtvaSettingPeer::_SMTP_PORT_, $request->getParameter('port'));
         $this->updateSetting(EtvaSettingPeer::_SMTP_USE_AUTH_, $request->getParameter('useauth'));
         $this->updateSetting(EtvaSettingPeer::_SMTP_USERNAME_, $request->getParameter('username'));
         $this->updateSetting(EtvaSettingPeer::_SMTP_KEY_, $request->getParameter('key'));
         $this->updateSetting(EtvaSettingPeer::_SMTP_SECURITY_, $request->getParameter('security_type'));
     }
     error_log("[METHOD] {$method}");
     $result = diagnostic::getAgentFiles($method);
     if (!$result['success']) {
         $error = $this->setJsonError($result);
         return $this->renderText($error);
     }
     $json_encoded = json_encode($result);
     $this->getResponse()->setHttpHeader('Content-type', 'application/json');
     return $this->renderText($json_encoded);
 }
示例#3
0
 public static function getAgentFiles($method)
 {
     $apli = new Appliance();
     switch ($method) {
         case 'get_diagnostic_progress':
             $action = $apli->getStage(Appliance::BACKUP_STAGE);
             error_log("[ACTION] {$action}");
             switch ($action) {
                 case Appliance::DB_BACKUP:
                     $txt = 'Perfoming DB backup...';
                     $result = array('success' => true, 'txt' => $txt, 'action' => $action);
                     break;
                 case Appliance::ARCHIVE_BACKUP:
                     $txt = 'Creating compressed archive...';
                     $result = array('success' => true, 'txt' => $txt, 'action' => $action);
                     break;
                 default:
                     $result = array('success' => true, 'txt' => $action, 'action' => $action);
             }
             break;
         case 'diagnostic':
             #                $force = $request->getParameter('force');
             $result = $apli->backup(true, true);
             // generate tarball with logs
             $filepath = sfConfig::get("app_remote_log_file");
             $scriptfile = sfConfig::get("app_remote_log_script");
             #                putenv("ETVADIAGNOSTIC=symfony");
             $command = "/bin/bash {$scriptfile} {$filepath}";
             $node_list = EtvaNodePeer::doSelect(new Criteria());
             foreach ($node_list as $node) {
                 $name = $node->getName();
                 $ip = $node->getIp();
                 $port = $node->getPort();
                 $command .= " {$name} {$ip} {$port}";
             }
             $command .= ' 2>&1';
             error_log('[COMMAND]' . $command);
             $path = sfConfig::get('sf_root_dir') . DIRECTORY_SEPARATOR . "utils";
             error_log("[INFO] PATH TO SUDOEXEC" . $path . DIRECTORY_SEPARATOR);
             ob_start();
             passthru('echo ' . $command . ' | sudo /usr/bin/php -f ' . $path . DIRECTORY_SEPARATOR . 'sudoexec.php', $return);
             #$content_grabbed=ob_get_contents();
             ob_end_clean();
             #$output = shell_exec($command);
             error_log("[INFO] Script diagnostic_ball has exited.");
             error_log("[INFO] " . $return);
             if ($return != 0) {
                 $result['success'] = false;
             } else {
                 $mail_success = diagnostic::sendDiagnosticEmail();
                 if (!$mail_success) {
                     //$str = implode("\n", $mail_success);
                     $result['mail_errors'] = 'email errors';
                 }
             }
             if (!$result['success']) {
                 if ($result['action'] == Appliance::LOGIN_BACKUP) {
                     $result['txt'] = 'Could not login!';
                 }
                 if ($result['action'] == Appliance::DB_BACKUP) {
                     $result['txt'] = 'DB backup error...';
                 }
                 if ($result['action'] == Appliance::MA_BACKUP) {
                     $result['txt'] = 'MA backup error...';
                 }
             }
             break;
         default:
             $result = array('success' => true, 'data' => array());
             break;
     }
     return $result;
 }