Example #1
0
 /**
  * Constructor. Perform some checks about the OS and setserial
  *
  * @return phpSerial
  */
 function phpSerial()
 {
     setlocale(LC_ALL, "en_US");
     $isWindows = IsWindowsOS();
     if (!$isWindows) {
         $this->_os = "linux";
         if ($this->_exec("stty --version") === 0) {
             register_shutdown_function(array($this, "deviceClose"));
         } else {
             trigger_error("No stty availible, unable to run.", E_USER_ERROR);
         }
     } elseif ($isWindows) {
         $this->_os = "windows";
         register_shutdown_function(array($this, "deviceClose"));
     } else {
         trigger_error("Host OS is neither linux nor windows, unable tu run.", E_USER_ERROR);
         exit;
     }
 }
Example #2
0
 /**
  * Функция создает поток на отдельном экране в LINUX
  * @param mixed $filename File name
  * @param mixed $display  Display
  * @param mixed $params   Params
  * @throws ThreadsException
  * @return double|int
  */
 public function newXThread($filename, $display = '101', $params = array())
 {
     if (IsWindowsOS()) {
         throw new ThreadsException('FOR_LINUX_ONLY');
     }
     if (!file_exists($filename)) {
         throw new ThreadsException('FILE_NOT_FOUND');
     }
     $params = addcslashes(serialize($params), '"');
     $command = 'DISPLAY=:' . $display . ' ' . $this->phpPath . ' ' . $filename . ' --params "' . $params . '"';
     ++$this->lastId;
     $this->commandLines[$this->lastId] = $command;
     $this->handles[$this->lastId] = proc_open($command, $this->descriptorSpec, $pipes);
     stream_set_timeout($pipes[0], $this->timeout);
     stream_set_timeout($pipes[1], $this->timeout);
     stream_set_blocking($pipes[0], 0);
     stream_set_blocking($pipes[1], 0);
     $this->streams[$this->lastId] = $pipes[1];
     $this->pipes[$this->lastId] = $pipes;
     return $this->lastId;
 }
Example #3
0
function ping($host)
{
    if (IsWindowsOS()) {
        exec(sprintf('ping -n 1 %s', escapeshellarg($host)), $res, $rval);
    } else {
        exec(sprintf('ping -c 1 -W 5 %s', escapeshellarg($host)), $res, $rval);
    }
    return $rval === 0 && preg_match('/ttl/is', join('', $res));
}
Example #4
0
        closedir($lib_dir);
    }
}
$threads = new Threads();
if (defined('PATH_TO_PHP')) {
    $threads->phpPath = PATH_TO_PHP;
} else {
    $threads->phpPath = IsWindowsOS() ? '..\\server\\php\\php.exe' : 'php';
}
foreach ($cycles as $path) {
    if (file_exists($path)) {
        DebMes("Starting " . $path . " ... ");
        echo "Starting " . $path . " ... ";
        if (preg_match("/_X/", $path)) {
            //для начала убедимся, что мы в Линуксе. Иначе удаленный запуск этих скриптов не делаем
            if (!IsWindowsOS()) {
                $display = '101';
                //Попробуем получить номер Дисплея из имени файла
                if (preg_match("/_X(.+)_/", $path, $displays)) {
                    if (count($displays) > 1) {
                        $display = $displays[1];
                    }
                }
                //запускаем Линуксовый поцесс на дисплее, номер которого в имени файла после _X
                $pipe_id = $threads->newXThread($path, $display);
            }
        } else {
            $pipe_id = $threads->newThread($path);
        }
        $pipes[$pipe_id] = $path;
        echo "OK" . PHP_EOL;
Example #5
0
/**
* Title
*
* Description
*
* @access public
*/
function execInBackground($cmd)
{
    if (IsWindowsOS()) {
        //pclose(popen("start /B ". $cmd, "r"));
        try {
            //pclose(popen("start /B ". $cmd, "r"));
            system($cmd);
            //$WshShell = new COM("WScript.Shell");
            //$oExec = $WshShell->Run("cmd /C ".$cmd, 0, false);
            //exec($cmd);
        } catch (Exception $e) {
            DebMes('Error: exception ' . get_class($e) . ', ' . $e->getMessage() . '.');
        }
    } else {
        exec($cmd . " > /dev/null &");
    }
}
 private function _curlRequest($url, $method, $data = NULL, $sendAsJSON = TRUE, $auth = TRUE)
 {
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Access-Token: ' . $this->_apiKey));
     if ($method == 'GET' && $data !== NULL) {
         $url .= '?' . http_build_query($data);
     }
     curl_setopt($curl, CURLOPT_URL, $url);
     if ($auth) {
         curl_setopt($curl, CURLOPT_USERPWD, $this->_apiKey);
     }
     curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
     if ($method == 'POST' && $data !== NULL) {
         if ($sendAsJSON) {
             $data = json_encode($data);
             curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data)));
         }
         curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
     }
     if (IsWindowsOS()) {
         curl_setopt($curl, CURLOPT_CAINFO, ROOT . 'modules\\app_pushbullet\\ca-bundle.crt');
     }
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
     $response = curl_exec($curl);
     if ($response === FALSE) {
         $curlError = curl_error($curl);
         curl_close($curl);
         throw new PushBulletException('cURL Error: ' . $curlError);
     }
     $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     if ($httpCode >= 400) {
         curl_close($curl);
         throw new PushBulletException('HTTP Error ' . $httpCode);
     }
     curl_close($curl);
     return json_decode($response, true);
 }
    exit;
}
$bt_devices = array();
//windows file
$devices_file = SERVER_ROOT . "/apps/bluetoothview/devices.txt";
//linux command
$bts_cmd = 'hcitool scan | grep ":"';
$first_run = 1;
$skip_counter = 0;
echo "Running bluetooth scanner\n";
while (1) {
    $skip_counter++;
    if ($skip_counter >= 30) {
        $skip_counter = 0;
        $data = '';
        if (IsWindowsOS()) {
            // windows scanner
            $isDelete = unlink($devices_file);
            exec(SERVER_ROOT . '/apps/bluetoothview/bluetoothview.exe /stab ' . $devices_file);
            if (file_exists($devices_file)) {
                $data = LoadFile($devices_file);
                sleep(5);
            }
        } else {
            //linux scanner
            ob_start();
            passthru($bts_cmd);
            $bt_scan_arr = explode("\n", ob_get_contents());
            ob_end_clean();
            $lines = array();
            $btScanArrayLength = count($bt_scan_arr) - 1;
Example #8
0
 /**
 * Title
 *
 * Description
 *
 * @access public
 */
 function backupdatabase($filename)
 {
     /*
     global $db;
     
     $tables1 = SQLSelect("SHOW TABLES;");
     foreach($tables1 as $t) {
      foreach($t as $k=>$v) {
       $tables[]=$v;
      }
     }
     $ignores=array('statistic', 'pot_accesslog', 'pot_add_data', 'pot_documents', 'pot_exit_targets', 'pot_hostnames', 
                    'pot_operating_systems', 'pot_referers', 'pot_search_engines', 'pot_user_agents', 'pot_visitors');
     for($i=0;$i<count($ignores);$i++) {
      $ignore[$ignores[$i]]=1;
     }
     
     $newfile="";
     for($i=0;$i<count($tables);$i++) {
      $table=$tables[$i];
      if (!IsSet($ignore[$table])) {
              $newfile .= "\n# ----------------------------------------------------------\n#\n";
              $newfile .= "# structur for table '$table'\n#\n";
              $newfile .= $db->get_mysql_def($table);
              $newfile .= "\n\n";
              $newfile .= "#\n# data for table '$table'\n#\n";
              $newfile .= $db->get_mysql_content($table);
              $newfile .= "\n\n";   
      }
     }
     
     $fp = fopen ($filename,"w");
     fwrite ($fp,$newfile);
     fclose ($fp);
     */
     if (defined('PATH_TO_MYSQLDUMP')) {
         $pathToMysqlDump = PATH_TO_MYSQLDUMP;
     } else {
         $pathToMysqlDump = IsWindowsOS() ? SERVER_ROOT . "/server/mysql/bin/mysqldump" : "/usr/bin/mysqldump";
     }
     exec($pathToMysqlDump . " --user="******" --password="******" --no-create-db --add-drop-table --databases " . DB_NAME . ">" . $filename);
 }
Example #9
0
 function upload(&$out)
 {
     set_time_limit(0);
     global $restore;
     global $file;
     global $file_name;
     global $folder;
     if (!$folder) {
         $folder = IsWindowsOS() ? '/.' : '/';
     } else {
         $folder = '/' . $folder;
     }
     if ($restore != '') {
         $file = $restore;
     } elseif ($file != '') {
         copy($file, ROOT . 'saverestore/' . $file_name);
         $file = $file_name;
     }
     umask(0);
     @mkdir(ROOT . 'saverestore/temp', 0777);
     if ($file != '') {
         // && mkdir(ROOT.'saverestore/temp', 0777)
         chdir(ROOT . 'saverestore/temp');
         if (IsWindowsOS()) {
             // for windows only
             exec(DOC_ROOT . '/gunzip ../' . $file, $output, $res);
             //echo DOC_ROOT.'/tar xvf ../'.str_replace('.tgz', '.tar', $file);exit;
             exec(DOC_ROOT . '/tar xvf ../' . str_replace('.tgz', '.tar', $file), $output, $res);
         } else {
             exec('tar xzvf ../' . $file, $output, $res);
         }
         $x = 0;
         $dir = opendir('./');
         while (($filec = readdir($dir)) !== false) {
             if ($filec == '.' || $filec == '..') {
                 continue;
             }
             if (is_Dir($filec)) {
                 $latest_dir = $filec;
             } elseif (is_File($filec)) {
                 $latest_file = $filec;
             }
             $x++;
         }
         if ($x == 1 && $latest_dir) {
             $folder = '/' . $latest_dir;
         }
         @unlink(ROOT . 'saverestore/temp' . $folder . '/config.php');
         @unlink(ROOT . 'saverestore/temp' . $folder . '/README.md');
         chdir('../../');
         // UPDATING FILES DIRECTLY
         $this->copyTree(ROOT . 'saverestore/temp' . $folder, ROOT, 1);
         // restore all files
         $source = ROOT . 'modules';
         if ($dir = @opendir($source)) {
             while (($file = readdir($dir)) !== false) {
                 if (Is_Dir($source . "/" . $file) && $file != '.' && $file != '..') {
                     // && !file_exists($source."/".$file."/installed")
                     @unlink(ROOT . "modules/" . $file . "/installed");
                 }
             }
         }
         @unlink(ROOT . "modules/control_modules/installed");
         global $name;
         global $version;
         DebMes("Installing/updating plugin {$name} ({$version})");
         $rec = SQLSelectOne("SELECT * FROM plugins WHERE MODULE_NAME LIKE '" . DBSafe($name) . "'");
         $rec['MODULE_NAME'] = $name;
         $rec['CURRENT_VERSION'] = $version;
         $rec['IS_INSTALLED'] = 1;
         $rec['LATEST_UPDATE'] = date('Y-m-d H:i:s');
         if ($rec['ID']) {
             SQLUpdate('plugins', $rec);
         } else {
             SQLInsert('plugins', $rec);
         }
         $this->redirect("?mode=clear&ok_msg=" . urlencode("Updates Installed!"));
     }
 }