コード例 #1
0
ファイル: Client.php プロジェクト: pezzabros/Loki
 /**
  * Sends a JSON-RPC request
  * @param Tivoka_Request $request A Tivoka request
  * @return void
  */
 public function __call($method, $args)
 {
     $request = Tivoka::createRequest($this->id++, $method, $args);
     $this->connection->send($request);
     if ($request->isError()) {
         throw new Tivoka_Exception($request->errorMessage, $request->error);
     }
     return $request->result;
 }
コード例 #2
0
ファイル: MiniDLNA.php プロジェクト: BillTheBest/MetaNAS
 public function isAuthorized($session)
 {
     $request = Tivoka::createRequest('1', 'plugins.is_authenticated', array($session));
     $rpc = $this->getRpc();
     $rpc->send($request);
     if ($request->isError() || $request->result !== TRUE) {
         exit("Not authorized");
     }
 }
コード例 #3
0
ファイル: Request.php プロジェクト: pezzabros/Loki
 /**
  * Send this request to a remote server directly
  * @param string $target The URL of the remote server
  */
 public function send($target)
 {
     Tivoka::connect($target)->send($this);
 }
コード例 #4
0
ファイル: Connection.php プロジェクト: BillTheBest/MetaNAS
 /**
  * Send a notification directly
  * @param string $method
  * @param array $params
  */
 public function sendNotification($method, $params = null)
 {
     $this->send(Tivoka::createNotification($method, $params));
 }
コード例 #5
0
ファイル: server.php プロジェクト: BillTheBest/MetaNAS
<?php

include '../include.php';
$methods = array('demo.sayHello' => function ($request) {
    $request->result('Hello World!');
}, 'demo.substract' => function ($request) {
    if (!is_array($request->params)) {
        return $request->error(-32602);
    }
    return $request->result(intval($request->params[0]) - intval($request->params[1]));
});
Tivoka::createServer($methods);
コード例 #6
0
ファイル: function.php プロジェクト: pezzabros/Loki
function runPendingProcess()
{
    global $conn;
    $pid_query = "select *  from process JOIN setprocess ON ( process.idSetProcess = setprocess.idSetProcess ) WHERE (idProcessStatus = 2 OR idProcessStatus = 3) AND (idProcessNumMaster <> idProcessNum OR idProcessNumMaster is null)";
    $rswrk = $conn->Execute($pid_query);
    $num_process_running = $rswrk->RecordCount();
    spool_video_all_folders();
    spool_document();
    downloadPendingImages();
    checkFinishedTraining();
    addNewConcept();
    $log = "";
    if ($num_process_running) {
        ///PARTE DI CONTROLLO SE I PROCESSI ATTIVI SONO ANCORA IN ESECUZIONE O IN TIMEOUT - INIZIO
        echo "{$num_process_running} Processes  running. <br>";
        while (!$rswrk->EOF) {
            //PsExec("ls /var/www/octo/");
            echo "Stampa controllo esecuzione processo <br>";
            $pid = $rswrk->fields("OSProcessId");
            //verifica timeout
            $to_time = time();
            $from_time = strtotime($rswrk->fields("start"));
            $second_in_execution = round(abs($to_time - $from_time));
            echo "Controllo timeout. Processo in esecuzione da " . $rswrk->fields("start") . " -> {$second_in_execution} secondi.<br>";
            switch ($rswrk->fields('idProcessType')) {
                case "1":
                    //caso di un eseguibile
                    $timeout_limit = 60 * 60;
                    //60 minuti
                    break;
                case "2":
                    //caso di un web service http
                    $timeout_limit = 2 * 60;
                    //2 minuti
                    break;
                case "3":
                    //caso di un JSONRPC
                    $timeout_limit = 60 * 60;
                    //60 minuti
                    break;
            }
            if ($second_in_execution > $timeout_limit) {
                echo "Processo andato in timeout (più di {$timeout_limit} secondi). Fermato.";
                //setProcessEnd($rswrk->fields("processId"));
                setProcessStatus($rswrk->fields("processId"), 6);
            } else {
                switch ($rswrk->fields('idProcessType')) {
                    case "1":
                        //caso di un eseguibile
                        echo "Controllo esecuzione eseguibile<br>";
                        //eseguo la chiamata per verificare se il processo è ancora in esecuzione
                        $exeCall = "ps --pid " . $pid;
                        $result = exec($exeCall);
                        //echo "primo <pre>".$result."</pre>";
                        if ($result == "  PID TTY          TIME CMD") {
                            //il processo non è più attivo. lo blocco dal gestionale
                            $log_terminate = "Il processo non è più " . $pid . " attivo ";
                            add_log('runPendingProcess:finishing', $log_terminate);
                            setProcessEnd($rswrk->fields("processId"));
                        } else {
                            echo "il processo " . $pid . " attivo<br>";
                        }
                        break;
                    case "2":
                        //caso di un web service http
                        echo "Controllo esecuzione web service http<br>";
                        $to_time = time();
                        $from_time = strtotime($rswrk->fields("start"));
                        $second_in_execution = round(abs($to_time - $from_time));
                        echo "Controllo timeout. Processo in esecuzione da " . $rswrk->fields("start") . " -> {$second_in_execution} secondi.<br>";
                        if ($second_in_execution > 120) {
                            echo "Processo andato in timeout (più di 120 secondi). Fermato.";
                            //setProcessEnd($rswrk->fields("processId"));
                            setProcessStatus($rswrk->fields("processId"), 6);
                        }
                        break;
                    case "3":
                        //caso di un JSONRPC
                        echo "Controllo esecuzione web service JSON-RPC (con getResults)<br>";
                        $processId = (int) $rswrk->fields("processId");
                        $target = EW_VIDEODROME_SERVER_URL;
                        $request = Tivoka::createRequest(56, 'getResults', array('processId' => $processId));
                        Tivoka::connect($target)->send($request);
                        if ($request->isError()) {
                            // an error occured
                            var_dump($request->error);
                            var_dump($request->errorMessage);
                            var_dump($request->response);
                        } else {
                            echo "<br>Stato processo: " . $request->result['status'] . "<br> log: ";
                            var_dump($request->result);
                        }
                        switch (strtolower($request->result['status'])) {
                            case "completed":
                                echo "<br>PROCESSO COMPLETATO ";
                                echo "Output:<pre>";
                                var_dump($request->result['output']);
                                echo "</pre>";
                                setProcessOutput($rswrk->fields("processId"), $request->result['output']);
                                setProcessEnd($rswrk->fields("processId"));
                                break;
                            case 'not found':
                                echo "<br>PROCESSO NON TROVATO (FERMATO) ";
                                setProcessEnd($processId);
                                break;
                            default:
                                echo "Process running";
                        }
                        break;
                }
            }
            $rswrk->MoveNext();
        }
    }
    ///PARTE DI CONTROLLO SE I PROCESSI ATTIVI SONO ANCORA IN ESECUZIONE O IN TIMEOUT - FINE
    echo "terminato controllo processi in esecuzione";
    echo "limite processi in parallelo: " . EW_MAX_PROCESS_IN_EXECUTION;
    if ($num_process_running < EW_MAX_PROCESS_IN_EXECUTION) {
        // caso di nessun processo in esecuzione->quindi cerco se ce n'è qualcuno da eseguire
        $select_query = "SELECT * FROM process JOIN setprocess ON ( process.idSetProcess = setprocess.idSetProcess ) WHERE idProcessStatus =1 OR  idProcessStatus =8  ORDER BY process.priority,idProcessNum";
        $rswrk = $conn->Execute($select_query);
        while (!$rswrk->EOF) {
            // esiste un processo da eseguire
            //controllo se il processo non è un sotto processo di una coda già in esecuzione
            $pending_previous = ew_ExecuteScalar("SELECT count(*) FROM process WHERE idProcessNumMaster = '" . $rswrk->fields('idProcessNumMaster') . "' AND (idProcessStatus = 2 OR idProcessStatus = 3) AND (idProcessNumMaster <> idProcessNum)");
            if ($pending_previous) {
                $rswrk->MoveNext();
                continue;
            }
            //metto il servizio su starting
            $query_update_status = "UPDATE process set idProcessStatus = 2, start = now() WHERE idProcessNum = " . $rswrk->fields("idProcessNum");
            $conn->Execute($query_update_status);
            add_log('runPendingProcess:starting process', "INIZIALIZZATO PROCESSO " . $rswrk->fields("idProcessNum"));
            //aumento il numero di processi in esecuzione
            $num_process_running++;
            //caso del processo master di un multiprocess
            if ($rswrk->fields('idProcessNumMaster') == $rswrk->fields('idProcessNum')) {
                echo "Pipeline id " . $rswrk->fields("idProcessNum") . " running";
                runPendingProcess();
                return;
            }
            switch ($rswrk->fields('idProcessType')) {
                case "1":
                    //caso di un eseguibile
                    $command_to_append = "lynx -dump http://" . EW_ABS_HOST . "/eutv-tools/process/service/lib/setProcessEnd.php?processId=" . $rswrk->fields("processId");
                    $command_complete = "( " . $rswrk->fields("command") . " ; " . $command_to_append . " )";
                    $log .= "<br>Report IdProcess: " . $rswrk->fields("idProcessNum") . " <br><br>The command executed is: " . $command_complete . " on server " . $rswrk->fields("server") . "<br><br>.";
                    $result = PsExec($command_complete);
                    //aggiorno l'OSProcessId eseguito
                    $query_update_status = "UPDATE process set OSProcessId ='" . $result . "' WHERE idProcessNum = " . $rswrk->fields("idProcessNum");
                    $conn->Execute($query_update_status);
                    break;
                case "2":
                    //caso di un web service http
                    add_log('runPendingProcess:startingwebservice', "URL executed:" . $rswrk->fields("command"));
                    $runCall = "" . $rswrk->fields("command");
                    $log .= "\n<br><br>Report IdProcess: " . $rswrk->fields("idProcessNum") . " <br><br>The command (service) executed is: " . $rswrk->fields("command") . " of service " . $rswrk->fields("service") . ".";
                    $runCall = str_replace(" ", "%20", $runCall);
                    $log .= "Calling service: " . $runCall;
                    //$result = "";
                    $result = file_get_contents($runCall);
                    $log .= $result;
                    break;
                case "3":
                    //caso di un JSONRPC
                    add_log('runPendingProcess:startingwebserviceJSONRPC', "URL executed:" . $rswrk->fields("server"));
                    $method = "";
                    //caricamento parametri processo
                    $sSqlWrk = "SELECT * from processparams as pp JOIN processparamsvalue as ppv ON (pp.idProcessParams = ppv.idProcessParams) WHERE idProcessNum = " . $rswrk->fields("idProcessNum") . "";
                    $rswrk_params = $conn->Execute($sSqlWrk);
                    while (!$rswrk_params->EOF) {
                        //recupero il valore della variabile
                        $value = $rswrk_params->fields('value');
                        //recupero il nome della variabile
                        $var_name = $rswrk_params->fields('code');
                        if ($var_name == "method") {
                            $method = $value;
                        } else {
                            echo "ANALISI parametro {$var_name} con valore {$value}<br><br>";
                            //faccio alcuni controlli
                            if ($value == "true") {
                                echo "Parametro {$var_name} di tipologia true<br>";
                                $value = true;
                            } elseif ($value == "false") {
                                echo "Parametro {$var_name} di tipologia false<br>";
                                $value = false;
                            } elseif (is_numeric($value)) {
                                echo "Parametro {$var_name} di tipologia int<br>";
                                $value = (int) $value;
                            } elseif ($value == 'MEDIA_NAME_DB') {
                                echo "<br>Entrato valore speciale MEDIA_NAME_DB";
                                $id_media = ew_ExecuteScalar("SELECT value FROM  processparams as pp JOIN processparamsvalue as ppv ON (pp.idProcessParams = ppv.idProcessParams) WHERE idProcessNum = " . $rswrk->fields("idProcessNum") . " AND code = 'id_media'");
                                echo "<br>Recuperato id_media{$id_media} ";
                                $conn->Execute("SET SESSION group_concat_max_len = 1000000;");
                                $list_image = ew_ExecuteScalar("SELECT GROUP_CONCAT(distinct thumbnail) FROM " . EW_CONN_DB_MEDIA . ".annotations WHERE id_media = '{$id_media}'");
                                //echo "<br>Recuperata lista immagini <em>$list_image</em>";
                                if ($list_image != "") {
                                    $array_images = explode(',', $list_image);
                                } else {
                                    $array_images = array();
                                }
                                echo "<br><br>Array immagini:<br><em>" . serialize($array_images) . "</em><br><br><br>";
                                $value = $array_images;
                            }
                        }
                        echo "<br><br>Inserisco il parametro {$var_name} con valore:<br><em>" . serialize($value) . "</em><br><br><br>";
                        $params_input[$var_name] = $value;
                        $rswrk_params->MoveNext();
                    }
                    //eseguo l'analisi
                    $params_input['processId'] = (int) $rswrk->fields("processId");
                    $target = EW_VIDEODROME_SERVER_URL;
                    echo "<br>Method: {$method}<br>Params: <pre>";
                    var_dump($params_input);
                    echo "</pre>";
                    $request = Tivoka::createRequest(1, $method, $params_input);
                    start_crono('analysis');
                    add_log('analyzeBowImage:analysis', "Analysis started. Method: {$method} - Params input: " . serialize($params_input));
                    Tivoka::connect($target)->send($request);
                    if ($request->isError()) {
                        // an error occured
                        var_dump($request->error);
                        var_dump($request->errorMessage);
                        var_dump($request->response);
                    } else {
                        if ($debug) {
                            var_dump($request->result);
                        }
                    }
                    // the result
                    ?>
 </pre><br /><br />
<?php 
                    break;
                default:
            }
            echo $log;
            add_log('runPendingProcess:starting REPORT', $log);
            //se sono al numero massimo di processi in esecuzione contemporanea non ne eseguo più
            if ($num_process_running >= EW_MAX_PROCESS_IN_EXECUTION) {
                echo "Numero di processi massimi in esecuzione";
                break;
            }
            //ho eseguito il primo programma in esecuzione
            $rswrk->MoveNext();
        }
        if ($rswrk->RecordCount() == 0) {
            echo "<br><br>No process pending.";
            //sendTweet(date(DATE_RFC822)." - No process pending");
            syncroNewConcept();
        }
        /*$log_activity = "INSERT INTO logs (type,text) VALUES ('runPendingProcess:test_cron','test call');";
        		$conn->Execute($log_activity);
        */
    }
    //fine caso di esecuzione processo
}
コード例 #7
0
ファイル: client.php プロジェクト: BillTheBest/MetaNAS
<pre>
<?php 
include '../include.php';
$target = 'http://' . $_SERVER['SERVER_NAME'] . dirname($_SERVER['SCRIPT_NAME']) . '/server.php';
$request = Tivoka::createRequest('1', 'demo.substract', array(43, 1));
$greeting = Tivoka::createRequest('2', 'demo.sayHello');
Tivoka::connect($target)->send($request, $greeting);
/*
 * Display the Results...
 */
/*
 * Display reponse
 */
if ($request->isError()) {
    // an error occured
    var_dump($request->error);
    var_dump($request->errorMessage);
    var_dump($request->reponse);
} else {
    var_dump($request->result);
}
// the result
if ($greeting->isError()) {
    // an error occured
    var_dump($greeting->error);
    var_dump($greeting->errorMessage);
    var_dump($greeting->response);
} else {
    var_dump($greeting->result);
}
// the result
コード例 #8
0
 public function editAction()
 {
     $em = Zend_Registry::get('em');
     $minidlna = $em->getRepository('Entity\\MiniDLNA')->findAll();
     if (count($minidlna) != 0) {
         $minidlna = $minidlna[0];
     } else {
         $minidlna = new Entity\MiniDLNA();
     }
     $form = new MetaNAS_Form_Edit();
     $jail = Tivoka::createRequest('1', 'plugins.jail.info');
     $this->lib->getRpc()->send($jail);
     $jail = json_decode($jail->result);
     $form->media_dir->setAttrib('root', $jail[0]->fields->jail_path . '/' . $jail[0]->fields->jail_name);
     if ($this->getRequest()->isPost()) {
         $this->_helper->viewRenderer->setNoRender(TRUE);
         $this->getResponse()->setHeader('Content-type', 'application/json');
         if ($form->isValid($_POST)) {
             $values = $form->getValues();
             $minidlna->setMediaDir($values['media_dir']);
             if (isset($values['inotify'])) {
                 $minidlna->setInotify($values['inotify']);
             }
             $minidlna->setNotifyInterval($values['notify_interval']);
             $minidlna->setFriendlyName($values['friendly_name']);
             if (isset($values['tivo'])) {
                 $minidlna->setTivo($values['tivo']);
             }
             $minidlna->setRescan($values['rescan']);
             $minidlna->setStrictDLNA($values['strict_dlna']);
             $minidlna->setModelNumber($values['model_number']);
             $minidlna->setSerial($values['serial']);
             $minidlna->setAuxiliary($values['auxiliary']);
             $em->persist($minidlna);
             $em->flush();
             $this->lib->writeConf($minidlna);
             echo json_encode(array('error' => false, 'message' => 'Settings successfully updated'));
         } else {
             /*
              * This is an internal API of the MetaNAS GUI
              *
              * The JSON returned in case of form validation error must
              * return the following object:
              * {
              * 'error': true,
              * 'type': 'form',
              * 'formid': 'formid', // Id of the dijit form
              * 'errors': {   // Array of errors with fieldnames as keys
              *  'fieldname': ['error 1', 'error 2'],
              *   }
              * }
              */
             $data = array('error' => true, 'type' => 'form', 'formid' => $_POST['__form_id']);
             $errors = array();
             foreach ($form->getMessages() as $field => $val) {
                 $errors[$field] = array();
                 foreach ($val as $error => $msg) {
                     $errors[$field][] = $msg;
                 }
             }
             $data['errors'] = $errors;
             echo json_encode($data);
         }
     } else {
         $form->media_dir->setValue($minidlna->getMediaDir());
         $form->port->setValue($minidlna->getPort());
         $form->inotify->setValue($minidlna->getInotify());
         $form->notify_interval->setValue($minidlna->getNotifyInterval());
         $form->friendly_name->setValue($minidlna->getFriendlyName());
         $form->tivo->setValue($minidlna->getTivo());
         $form->strict_dlna->setValue($minidlna->getStrictDLNA());
         $form->model_number->setValue($minidlna->getModelNumber());
         $form->serial->setValue($minidlna->getSerial());
         $form->auxiliary->setValue($minidlna->getAuxiliary());
         $form->rescan->setValue($minidlna->getRescan());
         $this->view->form = $form;
     }
 }