Exemple #1
0
/**
 * Summary of php_syntax_error
 * @param mixed $code Code
 * @return bool|string
 */
function php_syntax_error($code)
{
    $code .= "\n echo 'zzz';";
    $code = '<?' . $code . '?>';
    //echo DOC_ROOT;exit;
    $fileName = md5(time() . rand(0, 10000)) . '.php';
    $filePath = DOC_ROOT . '/cached/' . $fileName;
    SaveFile($filePath, $code);
    if (substr(php_uname(), 0, 7) == "Windows") {
        $cmd = DOC_ROOT . '/../server/php/php -l ' . $filePath;
    } else {
        $cmd = 'php -l ' . $filePath;
    }
    exec($cmd, $out);
    unlink($filePath);
    if (preg_match('/no syntax errors detected/is', $out[0])) {
        return false;
    } elseif (!trim(implode("\n", $out))) {
        return false;
    } else {
        $res = implode("\n", $out);
        $res = preg_replace('/Errors parsing.+/is', '', $res);
        return trim($res) . "\n";
    }
}
Exemple #2
0
 /**
 * Title
 *
 * Description
 *
 * @access public
 */
  function GoogleTTS($message, $lang='ru') {
   $filename=md5($message).'.mp3';

   if (file_exists(ROOT.'cached/voice/'.$filename)) {
    @touch(ROOT.'cached/voice/'.$filename);
    return ROOT.'cached/voice/'.$filename;
   }

   $base_url = 'http://translate.google.com/translate_tts?';
   $qs = http_build_query(array(
    'tl' => $lang,
    'ie' => 'UTF-8',
    'q' => $message
   ));
   $contents = file_get_contents($base_url . $qs);
   if ($contents) {
    if (!is_dir(ROOT.'cached/voice')) {
     @mkdir(ROOT.'cached/voice', 0777);
    }
    SaveFile(ROOT.'cached/voice/'.$filename, $contents);
    return ROOT.'cached/voice/'.$filename;
   } else {
    return 0;
   }
  }
Exemple #3
0
/**
 * YandexTTS
 * @param mixed $message Message
 * @param mixed $lang    Language (default 'ru-RU')
 * @return int|string
 */
function YandexTTS($message, $lang = 'ru-RU')
{
    $filename = md5($message) . '_ya.mp3';
    $cachedVoiceDir = ROOT . 'cached/voice';
    $cachedFileName = $cachedVoiceDir . '/' . $filename;
    $base_url = 'https://tts.voicetech.yandex.net/generate?';
    if (file_exists($cachedFileName)) {
        @touch($cachedFileName);
        return $cachedFileName;
    }
    $qs = http_build_query(array('format' => 'mp3', 'lang' => $lang, 'speaker' => 'omazh', 'key' => SETTINGS_YANDEX_TTS_KEY, 'text' => $message));
    try {
        $contents = file_get_contents($base_url . $qs);
    } catch (Exception $e) {
        registerError('yandextts', get_class($e) . ', ' . $e->getMessage());
    }
    if (isset($contents)) {
        CreateDir($cachedVoiceDir);
        SaveFile($cachedFileName, $contents);
        return $cachedFileName;
    }
    return 0;
}
Exemple #4
0
function YandexTTS($message, $lang = 'ru')
{
    $filename = md5($message) . '_ya.mp3';
    if (file_exists(ROOT . 'cached/voice/' . $filename)) {
        @touch(ROOT . 'cached/voice/' . $filename);
        return ROOT . 'cached/voice/' . $filename;
    }
    $base_url = 'https://tts.voicetech.yandex.net/generate?';
    $qs = http_build_query(array('format' => 'mp3', 'lang' => 'ru-RU', 'speaker' => 'omazh', 'key' => SETTINGS_YANDEX_TTS_KEY, 'text' => $message));
    try {
        $contents = file_get_contents($base_url . $qs);
    } catch (Exception $e) {
        registerError('yandextts', get_class($e) . ', ' . $e->getMessage());
    }
    if ($contents) {
        if (!is_dir(ROOT . 'cached/voice')) {
            @mkdir(ROOT . 'cached/voice', 0777);
        }
        SaveFile(ROOT . 'cached/voice/' . $filename, $contents);
        return ROOT . 'cached/voice/' . $filename;
    } else {
        return 0;
    }
}
Exemple #5
0
/**
 * Write Exceptions
 * @param $errorMessage string Exception message
 * @param $logLevel string exception level, default=debug
 */
function DebMes($errorMessage, $logLevel = "debug")
{
    // DEBUG MESSAGE LOG
    if (!is_dir(ROOT . 'debmes')) {
        mkdir(ROOT . 'debmes', 0777);
    }
    if (!file_exists(ROOT . 'debmes/' . date('Y-m-d') . '.log')) {
        SaveFile(ROOT . 'debmes/' . date('Y-m-d') . '.log', "Added " . date('Y-m-d H:i:s' . "\n"));
    }
    $log = Logger::getRootLogger();
    if (defined('SETTINGS_LOGGER_DESTINATION')) {
        $errorDestination = strtolower(SETTINGS_LOGGER_DESTINATION);
        if ($errorDestination == "database") {
            $log = Logger::getLogger('dblog');
        }
        if ($errorDestination == "both") {
            $log = Logger::getLogger('db_and_file');
        }
    }
    //$dbLog = Logger::getLogger('dblog');
    switch ($logLevel) {
        case "trace":
            $log->trace($errorMessage);
            //$dbLog->trace($errorMessage);
            break;
        case "fatal":
            $log->fatal($errorMessage);
            //$dbLog->fatal($errorMessage);
            break;
        case "error":
            $log->error($errorMessage);
            //$dbLog->error($errorMessage);
            break;
        case "warn":
            $log->warn($errorMessage);
            //$dbLog->warn($errorMessage);
            break;
        case "info":
            $log->info($errorMessage);
            //$dbLog->info($errorMessage);
            break;
        default:
            $log->debug($errorMessage);
            //$dbLog->debug($errorMessage);
    }
}
Exemple #6
0
        }
    }
}
// END: language constants
if (!headers_sent()) {
    header("HTTP/1.0: 200 OK\n");
    header('Content-Type: text/html; charset=utf-8');
}
function echobig($string, $bufferSize = 8192)
{
    $chars = strlen($string) - 1;
    for ($start = 0; $start <= $chars; $start += $bufferSize) {
        echo substr($string, $start, $bufferSize);
    }
}
startMeasure('final_echo');
ob_start("ob_gzhandler");
// should be un-commented for production server
echobig($result);
endMeasure('final_echo', 1);
if ($cache_filename != '' && $cached_result == '') {
    SaveFile(ROOT . 'cached/' . $cache_filename, $result);
}
$session->save();
// closing database connection
$db->Disconnect();
// end calculation of execution time
endMeasure('TOTAL');
// print performance report
performanceReport();
// ob_end_flush();
 /**
 * Title
 *
 * Description
 *
 * @access public
 */
 function upload(&$out)
 {
     set_time_limit(0);
     global $restore;
     global $file;
     global $file_name;
     global $folder;
     if (!$folder) {
         if (substr(php_uname(), 0, 7) == "Windows") {
             $folder = '/.';
         } else {
             $folder = '/';
         }
     } else {
         $folder = '/' . $folder;
     }
     if ($restore != '') {
         //$file=ROOT.'saverestore/'.$restore;
         $file = $restore;
     } elseif ($file != '') {
         copy($file, ROOT . 'saverestore/' . $file_name);
         //$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 (substr(php_uname(), 0, 7) == "Windows") {
             // for windows only
             exec(DOC_ROOT . '/gunzip ../' . $file, $output, $res);
             exec(DOC_ROOT . '/tar xvf ../' . str_replace('.tgz', '.tar', $file), $output, $res);
             //@unlink('../'.str_replace('.tgz', '.tar', $file));
         } else {
             exec('tar xzvf ../' . $file, $output, $res);
         }
         @unlink(ROOT . 'saverestore/temp' . $folder . '/config.php');
         //print_r($output);exit;
         if (1) {
             chdir('../../');
             if ($this->method == 'direct') {
                 // UPDATING FILES DIRECTLY
                 $this->copyTree(ROOT . 'saverestore/temp' . $folder, ROOT, 1);
                 // restore all files
             } elseif ($this->method == 'ftp') {
                 // UPDATING FILES BY FTP
                 $conn_id = @ftp_connect($this->config['FTP_HOST']);
                 if ($conn_id) {
                     $login_result = @ftp_login($conn_id, $this->config['FTP_USERNAME'], $this->config['FTP_PASSWORD']);
                     if ($login_result) {
                         $systyp = ftp_systype($conn_id);
                         if (@ftp_chdir($conn_id, $this->config['FTP_FOLDER'] . 'saverestore')) {
                             @ftp_chdir($conn_id, $this->config['FTP_FOLDER']);
                             // ok, we're in. updating!
                             $log = '';
                             $files = $this->getLocalFilesTree(ROOT . 'saverestore/temp' . $folder, '.+', 'installed', $log, 0);
                             $total = count($files);
                             $modules_processed = array();
                             for ($i = 0; $i < $total; $i++) {
                                 $file = $files[$i];
                                 $file['REMOTE_FILENAME'] = preg_replace('/^' . preg_quote(ROOT . 'saverestore/temp/' . $folder, '/') . '/is', $this->config['FTP_FOLDER'], $file['FILENAME']);
                                 $file['REMOTE_FILENAME'] = str_replace('//', '/', $file['REMOTE_FILENAME']);
                                 $res_f = $this->ftpput($conn_id, $file['REMOTE_FILENAME'], $file['FILENAME'], FTP_BINARY);
                                 if (preg_match('/\\.class\\.php$/', basename($file['FILENAME'])) && !$modules_processed[dirname($file['REMOTE_FILENAME'])]) {
                                     // if this a module then we should update attributes for folder and remove 'installed' file
                                     $modules_processed[dirname($file['REMOTE_FILENAME'])] = 1;
                                     @ftp_site($conn_id, "CHMOD 0777 " . dirname($file['REMOTE_FILENAME']));
                                     @ftp_delete($conn_id, dirname($file['REMOTE_FILENAME']) . '/installed');
                                 }
                             }
                         } else {
                             $out['FTP_ERR'] = 'Incorrect folder (' . $ftp_folder . ')';
                         }
                     } else {
                         $out['FTP_ERR'] = 'Incorrect username/password';
                     }
                     ftp_close($conn_id);
                 } else {
                     $out['FTP_ERR'] = 'Cannot connect to host (' . $ftp_host . ')';
                     $this->redirect("?err_msg=" . urlencode($out['FTP_ERR']));
                 }
             }
             //if (is_dir(ROOT.'saverestore/temp/'.$folder.'modules')) {
             // code restore
             $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");
             @SaveFile(ROOT . 'reboot', 'updated');
             //}
             if (file_exists(ROOT . 'saverestore/temp' . $folder . '/dump.sql')) {
                 // data restore
                 $this->restoredatabase(ROOT . 'saverestore/temp' . $folder . '/dump.sql');
             }
             $this->config['LATEST_UPDATED_ID'] = $out['LATEST_ID'];
             $this->saveConfig();
             $this->redirect("?mode=clear&ok_msg=" . urlencode("Updates Installed!"));
         }
     }
     /*
          require 'Tar.php';
          $tar_object = new Archive_Tar($file);
          if ($tar_object->extract(ROOT.'skins/'.$basename)) {
           $out['OK_EXT']=1;
          } else {
           $out['ERR_FORMAT']=1;
          }
     */
 }
 /**
 * Title
 *
 * Description
 *
 * @access public
 */
 function apiCall($command)
 {
     $this->getConfig();
     $command = preg_replace('/^\\//', '', $command);
     $url = $this->config['ZWAVE_API_URL'] . $command;
     $cookie_file = ROOT . 'cached/zwave_cookie.txt';
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json, text/javascript', 'Content-Type: application/json'));
     curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
     curl_setopt($ch, CURLOPT_TIMEOUT, 30);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
     $result = curl_exec($ch);
     curl_close($ch);
     if (preg_match('/307 Temporary Redirect/is', $result)) {
         if ($this->connect()) {
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json, text/javascript', 'Content-Type: application/json'));
             curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
             curl_setopt($ch, CURLOPT_URL, $url);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
             curl_setopt($ch, CURLOPT_TIMEOUT, 30);
             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
             $result = curl_exec($ch);
             curl_close($ch);
         } else {
             return false;
         }
     }
     SaveFile(ROOT . 'cached/zwave_api.txt', $url . "\n\n" . $result);
     return json_decode($result);
 }
Exemple #9
0
 function upload(&$out)
 {
     set_time_limit(0);
     global $restore;
     global $file;
     global $file_name;
     global $folder;
     if (!$folder) {
         if (substr(php_uname(), 0, 7) == "Windows") {
             $folder = '/.';
         } else {
             $folder = '/';
         }
     } 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 (substr(php_uname(), 0, 7) == "Windows") {
             // 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");
         @SaveFile(ROOT . 'reboot', 'updated');
         global $name;
         global $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!"));
     }
 }
Exemple #10
0
 /**
 * Title
 *
 * Description
 *
 * @access public
 */
 function checkAllHosts($limit = 1000)
 {
     // ping hosts
     $pings = SQLSelect("SELECT * FROM pinghosts WHERE CHECK_NEXT<=NOW() ORDER BY CHECK_NEXT LIMIT " . $limit);
     $total = count($pings);
     for ($i = 0; $i < $total; $i++) {
         $host = $pings[$i];
         echo "Checking " . $host['HOSTNAME'] . "\n";
         $online_interval = $host['ONLINE_INTERVAL'];
         if (!$online_interval) {
             $online_interval = 60;
         }
         $offline_interval = $host['OFFLINE_INTERVAL'];
         if (!$offline_interval) {
             $offline_interval = $online_interval;
         }
         if ($host['STATUS'] == '1') {
             $host['CHECK_NEXT'] = date('Y-m-d H:i:s', time() + $online_interval);
         } else {
             $host['CHECK_NEXT'] = date('Y-m-d H:i:s', time() + $offline_interval);
         }
         SQLUpdate('pinghosts', $host);
         $online = 0;
         // checking
         if (!$host['TYPE']) {
             //ping host
             $online = ping(processTitle($host['HOSTNAME']));
         } else {
             //web host
             $online = getURL(processTitle($host['HOSTNAME']), 0);
             SaveFile("./cached/host_" . $host['ID'] . '.html', $online);
             if ($host['SEARCH_WORD'] != '' && !is_integer(strpos($online, $host['SEARCH_WORD']))) {
                 $online = 0;
             }
             if ($online) {
                 $online = 1;
             }
         }
         if ($online) {
             $new_status = 1;
         } else {
             $new_status = 2;
         }
         $old_status = $host['STATUS'];
         if ($host['COUNTER_REQUIRED']) {
             $old_status_expected = $host['STATUS_EXPECTED'];
             $host['STATUS_EXPECTED'] = $new_status;
             if ($old_status_expected != $host['STATUS_EXPECTED']) {
                 $host['COUNTER_CURRENT'] = 0;
                 $host['LOG'] = date('Y-m-d H:i:s') . ' tries counter reset (status: ' . $host['STATUS_EXPECTED'] . ')' . "\n" . $host['LOG'];
             } elseif ($host['STATUS'] != $host['STATUS_EXPECTED']) {
                 $host['COUNTER_CURRENT']++;
                 $host['LOG'] = date('Y-m-d H:i:s') . ' tries counter increased to ' . $host['COUNTER_CURRENT'] . ' (status: ' . $host['STATUS_EXPECTED'] . ')' . "\n" . $host['LOG'];
             }
             if ($host['COUNTER_CURRENT'] >= $host['COUNTER_REQUIRED']) {
                 $host['STATUS'] = $host['STATUS_EXPECTED'];
                 $host['COUNTER_CURRENT'] = 0;
             } else {
                 $interval = min($online_interval, $offline_interval, 20);
                 $online_interval = $interval;
                 $offline_interval = $interval;
             }
         } else {
             $host['STATUS'] = $new_status;
             $host['STATUS_EXPECTED'] = $host['STATUS'];
             $host['COUNTER_CURRENT'] = 0;
         }
         $host['CHECK_LATEST'] = date('Y-m-d H:i:s');
         if ($host['LINKED_OBJECT'] != '' && $host['LINKED_PROPERTY'] != '') {
             setGlobal($host['LINKED_OBJECT'] . '.' . $host['LINKED_PROPERTY'], $host['STATUS']);
         }
         if ($host['STATUS'] == '1') {
             $host['CHECK_NEXT'] = date('Y-m-d H:i:s', time() + $online_interval);
         } else {
             $host['CHECK_NEXT'] = date('Y-m-d H:i:s', time() + $offline_interval);
         }
         if ($old_status != $host['STATUS']) {
             if ($host['STATUS'] == 2) {
                 $host['LOG'] .= date('Y-m-d H:i:s') . ' Host is offline' . "\n";
             } elseif ($host['STATUS'] == 1) {
                 $host['LOG'] .= date('Y-m-d H:i:s') . ' Host is online' . "\n";
             }
             $tmp = explode("\n", $host['LOG']);
             $total = count($tmp);
             if ($total > 50) {
                 $tmp = array_slice($tmp, 0, 50);
                 $host['LOG'] = implode("\n", $tmp);
             }
         }
         SQLUpdate('pinghosts', $host);
         if ($old_status != $host['STATUS'] && $old_status != 0) {
             // do some status change actions
             $run_script_id = 0;
             $run_code = '';
             if ($old_status == 2 && $host['STATUS'] == 1) {
                 // got online
                 if ($host['SCRIPT_ID_ONLINE']) {
                     $run_script_id = $host['SCRIPT_ID_ONLINE'];
                 } elseif ($host['CODE_ONLINE']) {
                     $run_code = $host['CODE_ONLINE'];
                 }
             } elseif ($old_status == 1 && $host['STATUS'] == 2) {
                 // got offline
                 if ($host['SCRIPT_ID_OFFLINE']) {
                     $run_script_id = $host['SCRIPT_ID_OFFLINE'];
                 } elseif ($host['CODE_OFFLINE']) {
                     $run_code = $host['CODE_OFFLINE'];
                 }
             }
             if ($run_script_id) {
                 //run script
                 runScript($run_script_id);
             } elseif ($run_code) {
                 //run code
                 try {
                     $code = $run_code;
                     $success = eval($code);
                     if ($success === false) {
                         DebMes("Error in hosts online code: " . $code);
                         registerError('ping_hosts', "Error in hosts online code: " . $code);
                     }
                 } catch (Exception $e) {
                     DebMes('Error: exception ' . get_class($e) . ', ' . $e->getMessage() . '.');
                     registerError('ping_hosts', get_class($e) . ', ' . $e->getMessage());
                 }
             }
         }
     }
 }
/**
* Title
*
* Description
*
* @access public
*/
 function getURL($url, $cache=600, $username='', $password='') {
  $cache_file=ROOT.'cached/urls/'.preg_replace('/\W/is', '_', str_replace('http://', '', $url)).'.html';
  if (!$cache || !is_file($cache_file) || ((time()-filemtime($cache_file))>$cache)) {
   //download
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $url);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
   if ($username!='') {
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ) ;
    curl_setopt($ch, CURLOPT_USERPWD, $username.":".$password); 
   }
   $result = curl_exec($ch);
   if ($cache>0) {
    if (!is_dir(ROOT.'cached/urls')) {
     @mkdir(ROOT.'cached/urls', 0777);
    }
    SaveFile($cache_file, $result);
   }
  } else {
   $result=LoadFile($cache_file);
  }
  return $result;
 }
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
    $result = curl_exec($ch);
    curl_close($ch);
    SaveFile(ROOT . 'cached/zwave_login.txt', $result);
    //RECHECK
    $url = $this->config['ZWAVE_API_URL'];
    $fields = array();
    foreach ($fields as $key => $value) {
        $fields_string .= $key . '=' . urlencode($value) . '&';
    }
    rtrim($fields_string, '&');
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, count($fields));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
    $result = curl_exec($ch);
    curl_close($ch);
    SaveFile(ROOT . 'cached/zwave_recheck.txt', $result);
    if (preg_match('/307 Temporary Redirect/is', $result)) {
        return false;
    }
}
return 1;
 /**
 * Title
 *
 * Description
 *
 * @access public
 */
 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=ROOT.'saverestore/'.$restore;
         $file = $restore;
     } elseif ($file != '') {
         copy($file, ROOT . 'saverestore/' . $file_name);
         //$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);
             exec(DOC_ROOT . '/tar xvf ../' . str_replace('.tgz', '.tar', $file), $output, $res);
             //@unlink('../'.str_replace('.tgz', '.tar', $file));
         } else {
             exec('tar xzvf ../' . $file, $output, $res);
         }
         @unlink(ROOT . 'saverestore/temp' . $folder . '/config.php');
         //print_r($output);exit;
         chdir('../../');
         $ignores = SQLSelect("SELECT * FROM ignore_updates ORDER BY NAME");
         $total = count($ignores);
         for ($i = 0; $i < $total; $i++) {
             $name = $ignores[$i]['NAME'];
             if (is_dir(ROOT . 'saverestore/temp/modules/' . $name)) {
                 $this->removeTree(ROOT . 'saverestore/temp/modules/' . $name);
             }
             if (is_dir(ROOT . 'saverestore/temp/templates/' . $name)) {
                 $this->removeTree(ROOT . 'saverestore/temp/templates/' . $name);
             }
         }
         // UPDATING FILES DIRECTLY
         $this->copyTree(ROOT . 'saverestore/temp' . $folder, ROOT, 1);
         // restore all files
         //if (is_dir(ROOT.'saverestore/temp/'.$folder.'modules')) {
         // code restore
         $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");
         @SaveFile(ROOT . 'reboot', 'updated');
         //}
         if (file_exists(ROOT . 'saverestore/temp' . $folder . '/dump.sql')) {
             // data restore
             $this->restoredatabase(ROOT . 'saverestore/temp' . $folder . '/dump.sql');
         }
         $this->config['LATEST_UPDATED_ID'] = $out['LATEST_ID'];
         setGlobal('UpdateVersion', $this->config['LATEST_UPDATED_ID']);
         $this->saveConfig();
         global $with_extensions;
         $this->redirect("?mode=clear&ok_msg=" . urlencode("Updates Installed!") . "&with_extensions=" . $with_extensions);
     }
     /*
          require 'Tar.php';
          $tar_object = new Archive_Tar($file);
          if ($tar_object->extract(ROOT.'skins/'.$basename)) {
           $out['OK_EXT']=1;
          } else {
           $out['ERR_FORMAT']=1;
          }
     */
 }
Exemple #14
0
                 * Скругленные углы
                 */
                $file = RoundedCorners($T, $_GET['file'], $size, 10, 10);
                break;
            case 'fx':
                /**
                 * Фиксированный ресайз
                 */
                $file = FixedResize($T, $_GET['file'], $size);
                break;
            default:
                header("HTTP/1.0 404 Not Found");
                die;
                break;
        }
        SaveFile($T, $file);
    } catch (Exception $e) {
        header("HTTP/1.0 404 Not Found");
        die;
    }
} else {
    header("HTTP/1.0 404 Not Found");
    die;
}
/**
 * Обычный ресайз
 *
 * Стандартное изменение размера картинки, по двум сторонам
 * или только по ширине, если параметр $size[1] не будет задан.
 *
 * @param   Object    $T (phpThumb)
Exemple #15
0
    } else {
        $shorttext = $text;
    }
    $handle = fopen($path, "w");
    fwrite($handle, $shorttext);
    fclose($handle);
}
$wikiword = $HTTP_GET_VARS["wikiword"];
if ($_SERVER['REQUEST_METHOD'] == "GET") {
    ?>
asdf

<?php 
} else {
    $input = $GLOBALS['HTTP_RAW_POST_DATA'];
    $value = $json->decode($input);
    class Response
    {
        var $status;
        var $remoteentry;
        var $remoteversion;
    }
    $response = new Response();
    $response->remoteentry = $value->entry;
    $response->remoteversion = 0;
    $response->status = "failed";
    SaveFile($wikiword, $value->entry);
    $response->status = "saved";
    $output = $json->encode($response);
    print $output;
}
                $N_height = $N_height / 25.4;
            }
            if ($N_width > $N_height) {
                $tmp = $N_height;
                $N_height = $N_width;
                $N_width = $tmp;
            }
            $paper->{$add} = json_decode('{"width":' . $N_width * 25.4 . ',"height":' . $N_height * 25.4 . '}');
            $message = false;
        }
    } else {
        $message = true;
    }
}
if ($add != null || $del != null) {
    SaveFile("config/paper.json", json_encode($paper));
}
echo '<ul>';
$ct = 0;
foreach ($paper as $key => $val) {
    $ct++;
    echo '<li><a onclick="return confirm(\'Delete the paper size ' . html(js($key)) . '\')" class="tool icon del" href="index.php?page=Paper%20Manager&amp;delete=' . url($key) . '"><span class="tip">Delete</span></a> ' . html($key) . ' <div class="code tool">' . number_format(round($val->{"width"} / 25.4, 2), 2, '.', ',') . 'x' . str_pad(number_format(round($val->{"height"} / 25.4, 2), 2, '.', ','), 5, ' ', STR_PAD_LEFT) . '<span class="tip">' . $val->{"width"} . 'x' . $val->{"height"} . ' millimeters</span></div></li>';
}
echo "</ul>";
if ($ct == 0) {
    echo "There are no paper sizes on file.";
}
if ($del != null) {
    $del = html($del);
    Print_Message("Deleted:", "The paper size {$del} has been deleted.", "center");
}
Exemple #17
0
 /**
 * Title
 *
 * Description
 *
 * @access public
 */
 function import_scene()
 {
     global $file;
     global $overwrite;
     $data = unserialize(LoadFile($file));
     if ($data['SCENE_DATA']) {
         $rec = $data['SCENE_DATA'];
         if (!$rec['WALLPAPER']) {
             unset($rec['WALLPAPER']);
         }
         $rec['TITLE'] .= ' (imported)';
         $elements = $rec['ELEMENTS'];
         unset($rec['ID']);
         unset($rec['ELEMENTS']);
         $rec['ID'] = SQLInsert('scenes', $rec);
         $total = count($elements);
         for ($i = 0; $i < $total; $i++) {
             $states = $elements[$i]['STATES'];
             unset($elements[$i]['STATES']);
             unset($elements[$i]['ID']);
             $elements[$i]['SCENE_ID'] = $rec['ID'];
             $elements[$i]['ID'] = SQLInsert('elements', $elements[$i]);
             $totalE = count($states);
             for ($iE = 0; $iE < $totalE; $iE++) {
                 unset($states[$iE]['ID']);
                 $states[$iE]['ELEMENT_ID'] = $elements[$i]['ID'];
                 SQLInsert('elm_states', $states[$iE]);
             }
         }
         if ($data['BACKGROUND_IMAGE']) {
             $filename = ROOT . $rec['BACKGROUND'];
             SaveFile($filename, base64_decode($data['BACKGROUND_IMAGE']));
         }
         if ($data['WALLPAPER_IMAGE']) {
             $filename = ROOT . $rec['WALLPAPER'];
             SaveFile($filename, base64_decode($data['WALLPAPER_IMAGE']));
         }
         $this->redirect("?view_mode=edit_scenes&id=" . $rec['ID']);
     }
     $this->redirect("?");
 }
Exemple #18
0
}*/
function SaveFile($url, $path, $fileName = false)
{
    $file = file_get_contents($url);
    if (!$fileName) {
        return $fileName = basename($url);
    }
    $resultSave = file_put_contents($path . $fileName, $file);
    if ($resultSave || $resultSave > 0) {
        return true;
    } else {
        return false;
    }
    return false;
}
$result = SaveFile('http://sknt.ru/job/frontend/data.json', './row/', 'info.json');
if (!$result) {
    echo 'not file saved!';
}
$file_read = file_get_contents('./row/info.json');
$output_result_json = json_decode($file_read);
/// true если вывести вв виде ассоциативного массива!
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="user-scalable=no, width=device-width,initial-scale=1.0"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/material-design-iconic-font/2.2.0/css/material-design-iconic-font.min.css">
<link rel="stylesheet" href="css/grid.css">
<title>Artem Rogov</title>
/**
* Title
*
* Description
*
* @access public
*/
 function checkUpdatesSVN(&$out) {
  include_once DIR_MODULES.'saverestore/phpsvnclient.php';

  $url = 'http://majordomo-sl.googlecode.com/svn/';

  $phpsvnclient = new phpsvnclient($url);

  set_time_limit(0);
  //$phpsvnclient->createOrUpdateWorkingCopy('trunk/', ROOT.'saverestore/temp', true);

  $cached_name=ROOT.'saverestore/svn_tree.txt';
  if (!file_exists($cached_name) || (time()-filemtime($cached_name)>8*60*60)) {
   $directory_tree = $phpsvnclient->getDirectoryTree('/trunk/');
   SaveFile($cached_name, serialize($directory_tree));
  } else {
   $directory_tree=unserialize(LoadFile($cached_name));
  }

  $updated=array();
  $total=count($directory_tree);
  for($i=0;$i<$total;$i++) {
   $item=$directory_tree[$i];
   if ($item['type']!='file' || $item['path']=='trunk/config.php') {
    continue;
   }
   $filename=str_replace('trunk/', ROOT, $item['path']);
   @$fsize=filesize($filename);
   $r_rfsize=$item['size'];
   if ($fsize!=$r_rfsize || !file_exists($filename)) {
    $updated[]=$item;
   }

  }


  $out['OK_CHECK']=1;
  if (!$updated[0]) {
   $out['NO_UPDATES']=1; 
  } else {
     foreach($updated as $item) {
      $item['path']=str_replace('trunk/', '', $item['path']);
      $out['TO_UPDATE'][]=array('FILE'=>$item['path'], 'VERSION'=>$item['version'].' ('.$item['last-mod'].')');
     }
  }

 }
Exemple #20
0
        $theme = 'dark';
    }
    if (!$language) {
        $language = 'en';
    }
    $settings = array(array('NAME' => 'SITE_LANGUAGE', 'TITLE' => 'Language', 'TYPE' => 'text', 'DEFAULT' => 'en', 'VALUE' => $language), array('NAME' => 'VOICE_LANGUAGE', 'TITLE' => 'Voice notifications language', 'TYPE' => 'text', 'DEFAULT' => 'en', 'VALUE' => $language), array('NAME' => 'SITE_TIMEZONE', 'TITLE' => 'Time zone', 'TYPE' => 'text', 'DEFAULT' => 'Europe/Moscow', 'VALUE' => $tz), array('NAME' => 'BLUETOOTH_CYCLE', 'TITLE' => 'Run bluetooth scanner on startup', 'TYPE' => 'onoff', 'DEFAULT' => '0', 'PRIORITY' => '51'), array('NAME' => 'SKYPE_CYCLE', 'TITLE' => 'Run Skype script on startup', 'TYPE' => 'onoff', 'DEFAULT' => '0', 'PRIORITY' => '50'), array('NAME' => 'THEME', 'TITLE' => 'Color theme', 'TYPE' => 'text', 'DEFAULT' => 'dark', 'VALUE' => $theme), array('NAME' => 'TWITTER_CKEY', 'TITLE' => 'Twitter Consumer key', 'TYPE' => 'text', 'DEFAULT' => '', 'PRIORITY' => '30'), array('NAME' => 'TWITTER_CSECRET', 'TITLE' => 'Twitter Consumer secret', 'TYPE' => 'text', 'DEFAULT' => '', 'PRIORITY' => '29'), array('NAME' => 'TWITTER_ATOKEN', 'TITLE' => 'Twitter Access token', 'TYPE' => 'text', 'DEFAULT' => '', 'PRIORITY' => '28'), array('NAME' => 'TWITTER_ASECRET', 'TITLE' => 'Twitter Access token secret', 'TYPE' => 'text', 'DEFAULT' => '', 'PRIORITY' => '27'), array('NAME' => 'DEBUG_HISTORY', 'TITLE' => 'Save debug information to history', 'TYPE' => 'onoff', 'DEFAULT' => '0', 'PRIORITY' => '0'), array('NAME' => 'TTS_GOOGLE', 'TITLE' => 'Use Google Text-to-Speech engine', 'TYPE' => 'onoff', 'DEFAULT' => '1', 'PRIORITY' => '60'), array('NAME' => 'SPEAK_SIGNAL', 'TITLE' => 'Play sound signal before speaking', 'TYPE' => 'onoff', 'DEFAULT' => '1', 'PRIORITY' => '0'), array('NAME' => 'PUSHOVER_USER_KEY', 'TITLE' => 'Pushover.net user key', 'TYPE' => 'text', 'DEFAULT' => '', 'PRIORITY' => '0'), array('NAME' => 'PUSHOVER_LEVEL', 'TITLE' => 'Pushover.net message minimum level', 'TYPE' => 'text', 'DEFAULT' => '1', 'PRIORITY' => '0'), array('NAME' => 'GROWL_ENABLE', 'TITLE' => 'Forward notification to Growl service', 'TYPE' => 'onoff', 'DEFAULT' => '0', 'PRIORITY' => '43'), array('NAME' => 'GROWL_HOST', 'TITLE' => 'Growl service hostname', 'TYPE' => 'text', 'DEFAULT' => '', 'PRIORITY' => '42'), array('NAME' => 'GROWL_PASSWORD', 'TITLE' => 'Growl service password (optional)', 'TYPE' => 'text', 'DEFAULT' => '', 'PRIORITY' => '41'), array('NAME' => 'GROWL_LEVEL', 'TITLE' => 'Growl notification minimum level', 'TYPE' => 'text', 'DEFAULT' => '1', 'PRIORITY' => '40'), array('NAME' => 'HOOK_BEFORE_SAY', 'TITLE' => 'Before SAY (code)', 'TYPE' => 'text', 'DEFAULT' => '', 'PRIORITY' => '30'), array('NAME' => 'HOOK_AFTER_SAY', 'TITLE' => 'After SAY (code)', 'TYPE' => 'text', 'DEFAULT' => '', 'PRIORITY' => '29'));
    foreach ($settings as $k => $v) {
        $rec = SQLSelectOne("SELECT * FROM settings WHERE NAME='" . $v['NAME'] . "'");
        if (!$rec['ID']) {
            $rec['NAME'] = $v['NAME'];
            if (!isset($v['VALUE'])) {
                $rec['VALUE'] = $v['DEFAULT'];
            } else {
                $rec['VALUE'] = $v['VALUE'];
            }
            $rec['DEFAULTVALUE'] = $v['DEFAULT'];
            $rec['TITLE'] = $v['TITLE'];
            $rec['TYPE'] = $v['TYPE'];
            $rec['PRIORITY'] = (int) $v['PRIORITY'];
            $rec['NOTES'] = '';
            $rec['ID'] = SQLInsert('settings', $rec);
        } elseif (isset($v['VALUE'])) {
            $rec['VALUE'] = $v['VALUE'];
            SQLUpdate('settings', $rec);
        }
        Define('SETTINGS_' . $rec['NAME'], $v['VALUE']);
    }
    @unlink(ROOT . 'modules/control_modules/installed');
    SaveFile(ROOT . 'reboot', '1');
    $this->redirect("/");
}
 function setDescription($dir, $file, $descr) {
  $descriptions=getDescriptions($dir);
  $descriptions[$file]=$descr;
  $data=array();
  foreach($descriptions as $k=>$v) {
   $data[]="\"$k\"\t$v";
  }
  SaveFile($dir."Descript.ion", join("\n", $data));
 }
<?php

$preview = "Preview_" . substr($file, 0, -3) . "jpg";
if (isset($_POST['file-text'])) {
    // 1_Mar_8_2012~11-22-41.txt  1_Mar_8_2012~11-22-41-edit-42.txt
    $edit = strpos($file, '-edit-');
    $name = is_bool($edit) ? substr($file, 0, -4) : substr($file, 0, $edit);
    $int = 1;
    while (file_exists("scans/thumb/Preview_{$name}-edit-{$int}.jpg")) {
        $int++;
    }
    copy("scans/thumb/{$preview}", "scans/Preview_{$name}-edit-{$int}.jpg");
    if (SaveFile("scans/file/Scan_{$name}-edit-{$int}.txt", $_POST['file-text'])) {
        Print_Message("Saved", "You have successfully edited {$file}", 'center');
        $file = "{$name}-edit-{$int}.txt";
    }
}
echo "<div class=\"box box-full\" id=\"text-editor\"><div id=\"preview_links\"></div>" . "<img src=\"scans/thumb/{$preview}\"><br/>" . '<form action="index.php?page=Edit&file=' . $file . '" method="POST"><textarea name="file-text">' . html(file_get_contents("scans/file/Scan_{$file}")) . "</textarea><br/>" . '<input value="Save" type="submit"/><input type="button" value="Cancel" onclick="history.go(-1);"/></forum></div>';
Update_Links("Scan_{$file}", $PAGE);
 global $read_community;
 $rec['READ_COMMUNITY'] = trim($read_community);
 global $write_community;
 $rec['WRITE_COMMUNITY'] = trim($write_community);
 //UPDATING RECORD
 if ($ok) {
     if ($rec['ID']) {
         SQLUpdate($table_name, $rec);
         // update
     } else {
         $new_rec = 1;
         $rec['ID'] = SQLInsert($table_name, $rec);
         // adding new record
         $tmp = SQLSelectOne("SELECT COUNT(*) as TOTAL FROM snmpdevices");
         if ($tmp['TOTAL'] == 1) {
             @SaveFile(ROOT . 'reboot');
             // first device added, need reboot
         }
     }
     //updating 'MIB_FILE' (file)
     global $mib_file;
     global $mib_file_name;
     global $delete_mib_file;
     if ($mib_file != "" && file_exists($mib_file) && !$delete_mib_file) {
         $filename = strtolower(basename($mib_file_name));
         $ext = strtolower(end(explode(".", basename($mib_file_name))));
         if (filesize($mib_file) <= 0 * 1024 || 0 == 0) {
             $filename = $rec["ID"] . "_mib_file_" . time() . "." . $ext;
             if ($rec["MIB_FILE"] != '') {
                 @Unlink(ROOT . './cms/snmpdevices/' . $rec["MIB_FILE"]);
             }
$errors_total = 0;
while (1) {
    $updated = array();
    setGlobal(str_replace('.php', '', basename(__FILE__)) . 'Run', time(), 1);
    $r = $knx->connection->EIBGetBusmonitorPacket($buf);
    if ($r > 0) {
        $errors_total = 0;
        $data = date('H:i:s') . ' ' . $buf->buffer;
        $log .= $data . "\n";
        $tmp = explode("\n", $log);
        $total = count($tmp);
        if ($total > 50) {
            $tmp = array_slice($tmp, -50, 50);
            $log = implode("\n", $tmp);
        }
        SaveFile(ROOT . 'cached/knx_monitor.txt', $log);
        if (preg_match('/from (.+?) to (.+?) hops/', $data, $m)) {
            $from = $m[1];
            $from = str_replace('.', '/', $from);
            $updated[$from] = 1;
            $to = $m[2];
            $to = str_replace('.', '/', $to);
            $updated[$to] = 1;
        }
        foreach ($updated as $k => $v) {
            $knx_data->addressUpdated($k);
        }
    } else {
        $errors_total++;
        echo "Error: " . $knx->connection->GetLastError();
        sleep(10);
 function dynamic($content) {

  $h=md5($content);

  $content="<!-- begin_data [aj_".$h."] -->".$content."<!-- end_data [aj_".$h."] -->";

  $filename=ROOT.'templates_ajax/'.$this->name.'_'.$h.'.html';

  if (!file_exists($filename)) {
   SaveFile($filename, $content);
  }

  $url=$this->makeRealURL("?");
  if (preg_match('/\?/is', $url)) {
   $url.="&ajt=".$h;
  } else {
   $url.="?ajt=".$h;
  }

  $res.="<div id='aj_".$h."'>Loading...</div><script language='javascript' type='text/JavaScript'>getBlockData('aj_".$h."', '".$url."')</script>";

  return $res;

 }
/**
* Title
*
* Description
*
* @access public
*/
function getURL($url, $cache = 600, $username = '', $password = '')
{
    $cache_file = ROOT . 'cached/urls/' . preg_replace('/\\W/is', '_', str_replace('http://', '', $url)) . '.html';
    if (!$cache || !is_file($cache_file) || time() - filemtime($cache_file) > $cache) {
        //download
        try {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_USERAGENT, 'Opera/9.80 (Windows NT 6.1; WOW64) Presto/2.12.388 Version/12.14');
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
            // bad style, I know...
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
            curl_setopt($ch, CURLOPT_TIMEOUT, 15);
            if ($username != '' || $password != '') {
                curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
                curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
            }
            $tmpfname = ROOT . 'cached/cookie.txt';
            curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfname);
            curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfname);
            $result = curl_exec($ch);
        } catch (Exception $e) {
            registerError('geturl', $url . ' ' . get_class($e) . ', ' . $e->getMessage());
        }
        if ($cache > 0) {
            if (!is_dir(ROOT . 'cached/urls')) {
                @mkdir(ROOT . 'cached/urls', 0777);
            }
            SaveFile($cache_file, $result);
        }
    } else {
        $result = LoadFile($cache_file);
    }
    return $result;
}
    /*
    global $details;
    $rec['DETAILS']=$details;
    */
    //UPDATING RECORD
    if ($ok) {
        if ($rec['ID']) {
            SQLUpdate($table_name, $rec);
            // update
        } else {
            $new_rec = 1;
            $rec['ID'] = SQLInsert($table_name, $rec);
            // adding new record
        }
        if ($rec['TYPE'] == 'html') {
            SaveFile(ROOT . 'cms/layouts/' . $rec['ID'] . '.html', $rec['CODE']);
        }
        $out['OK'] = 1;
    } else {
        $out['ERR'] = 1;
    }
}
//options for 'TYPE' (select)
$tmp = explode('|', DEF_TYPE_OPTIONS);
foreach ($tmp as $v) {
    if (preg_match('/(.+)=(.+)/', $v, $matches)) {
        $value = $matches[1];
        $title = $matches[2];
    } else {
        $value = $v;
        $title = $v;
Exemple #28
0
 /**
 * Title
 *
 * Description
 *
 * @access public
 */
 function sendData(&$out, $silent = 0)
 {
     global $send_menu;
     global $send_objects;
     global $send_scripts;
     global $send_patterns;
     $this->config['SEND_MENU'] = (int) $send_menu;
     $this->config['SEND_OBJECTS'] = (int) $send_objects;
     $this->config['SEND_SCRIPTS'] = (int) $send_scripts;
     $this->config['SEND_PATTERNS'] = (int) $send_patterns;
     $this->saveConfig();
     $data = array();
     if ($this->config['SEND_MENU']) {
         // menu items
         $data['COMMANDS'] = SQLSelect("SELECT * FROM commands");
         $total = count($data['COMMANDS']);
         for ($i = 0; $i < $total; $i++) {
             if (!$this->config['CONNECT_SYNC']) {
                 unset($data['COMMANDS'][$i]['CUR_VALUE']);
                 unset($data['COMMANDS'][$i]['RENDER_TITLE']);
                 unset($data['COMMANDS'][$i]['RENDER_DATA']);
             }
         }
     }
     if ($this->config['SEND_OBJECTS']) {
         // objects and classes
         $data['CLASSES'] = SQLSelect("SELECT * FROM classes");
         $data['OBJECTS'] = SQLSelect("SELECT * FROM objects");
         $data['METHODS'] = SQLSelect("SELECT * FROM methods");
         $total = count($data['METHODS']);
         for ($i = 0; $i < $total; $i++) {
             unset($data['METHODS'][$i]['EXECUTED_PARAMS']);
             unset($data['METHODS'][$i]['EXECUTED']);
         }
         $data['PROPERTIES'] = SQLSelect("SELECT * FROM properties");
     }
     if ($this->config['SEND_SCRIPTS']) {
         // objects scripts
         $data['SCRIPTS'] = SQLSelect("SELECT * FROM scripts");
         $data['SCRIPT_CATEGORIES'] = SQLSelect("SELECT * FROM script_categories");
     }
     if ($this->config['SEND_PATTERNS']) {
         // patterns
         $data['PATTERNS'] = SQLSelect("SELECT * FROM patterns");
     }
     // POST TO SERVER
     $url = 'http://connect.smartliving.ru/upload/';
     $datafile_name = ROOT . 'cached/connect_data.txt';
     SaveFile($datafile_name, serialize($data));
     $fields = array('datafile' => '@' . realpath($datafile_name) . ';filename=datafile.txt');
     //print_r($fields);exit;
     //url-ify the data for the POST
     //foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
     //rtrim($fields_string, '&');
     //sleep(1);
     //open connection
     $ch = curl_init();
     //set the url, number of POST vars, POST data
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_POST, count($fields));
     curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
     curl_setopt($ch, CURLOPT_TIMEOUT, 120);
     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
     curl_setopt($ch, CURLOPT_USERPWD, $this->config['CONNECT_USERNAME'] . ":" . $this->config['CONNECT_PASSWORD']);
     //execute post
     $result = curl_exec($ch);
     //close connection
     curl_close($ch);
     if (!$silent) {
         $this->redirect("?uploaded=1&result=" . urlencode($result));
     }
 }
 /**
 * Title
 *
 * Description
 *
 * @access public
 */
 function removeFromList($id)
 {
     $product = SQLSelectOne("SELECT * FROM products WHERE ID='" . (int) $id . "'");
     if ($product['ID']) {
         SQLExec("DELETE FROM shopping_list_items WHERE PRODUCT_ID='" . (int) $id . "'");
         if (defined('DROPBOX_SHOPPING_LIST')) {
             $data = LoadFile(DROPBOX_SHOPPING_LIST);
             $data = str_replace("\r", '', $data);
             $lines = explode("\n", $data);
             $total = count($lines);
             $found = 0;
             $res_lines = array();
             for ($i = 0; $i < $total; $i++) {
                 if (is_integer(strpos($lines[$i], $product['TITLE']))) {
                     $found = 1;
                 } else {
                     $res_lines[] = $lines[$i];
                 }
             }
             if ($found) {
                 $data = implode("\n", $res_lines);
                 SaveFile(DROPBOX_SHOPPING_LIST, $data);
             }
         }
     }
 }
/**
* Title
*
* Description
*
* @access public
*/
 function checkAllHosts($limit=1000) {

  // ping hosts
  $pings=SQLSelect("SELECT * FROM pinghosts WHERE CHECK_NEXT<=NOW() ORDER BY CHECK_NEXT LIMIT ".$limit);
  $total=count($pings);
  for($i=0;$i<$total;$i++) {
   $host=$pings[$i];
   echo "Checking ".$host['HOSTNAME']."\n";
   $online_interval=$host['ONLINE_INTERVAL'];
   if (!$online_interval) {
    $online_interval=60;
   }
   $offline_interval=$host['OFFLINE_INTERVAL'];
   if (!$offline_interval) {
    $offline_interval=$online_interval;
   }

   if ($host['STATUS']=='1') {
    $host['CHECK_NEXT']=date('Y-m-d H:i:s', time()+$online_interval);
   } else {
    $host['CHECK_NEXT']=date('Y-m-d H:i:s', time()+$offline_interval);
   }
   SQLUpdate('pinghosts', $host);

   $online=0;
   // checking
   if (!$host['TYPE']) {
    //ping host
    $online=ping($host['HOSTNAME']);
   } else {
    //web host
    $online=file_get_contents($host['HOSTNAME']);
    SaveFile("./cached/host_".$host['ID'].'.html', $online);
    if ($host['SEARCH_WORD']!='' && !is_integer(strpos($online, $host['SEARCH_WORD']))) {
     $online=0;
    }
    if ($online) {
     $online=1;
    }
   }

   $old_status=$host['STATUS'];
   if ($online) {
    $new_status=1;
   } else {
    $new_status=2;
   }

   $host['CHECK_LATEST']=date('Y-m-d H:i:s');
   $host['STATUS']=$new_status;

   if ($host['STATUS']=='1') {
    $host['CHECK_NEXT']=date('Y-m-d H:i:s', time()+$online_interval);
   } else {
    $host['CHECK_NEXT']=date('Y-m-d H:i:s', time()+$offline_interval);
   }

   if ($old_status!=$new_status) {
    if ($new_status==2) {
     $host['LOG']=date('Y-m-d H:i:s').' Host is offline'."\n".$host['LOG'];
    } elseif ($new_status==1) {
     $host['LOG']=date('Y-m-d H:i:s').' Host is online'."\n".$host['LOG'];
    }
   }

   SQLUpdate('pinghosts', $host);

   if ($old_status!=$new_status && $old_status!=0) {
    // do some status change actions
    $run_script_id=0;
    $run_code='';
    if ($old_status==2 && $new_status==1) {
     // got online
     if ($host['SCRIPT_ID_ONLINE']) {
      $run_script_id=$host['SCRIPT_ID_ONLINE'];
     } elseif ($host['CODE_ONLINE']) {
      $run_code=$host['CODE_ONLINE'];
     }
    } elseif ($old_status==1 && $new_status==2) {
     // got offline
     if ($host['SCRIPT_ID_OFFLINE']) {
      $run_script_id=$host['SCRIPT_ID_OFFLINE'];
     } elseif ($host['CODE_OFFLINE']) {
      $run_code=$host['CODE_OFFLINE'];
     }
    }

    if ($run_script_id) {
     //run script
     runScript($run_script_id);
    } elseif ($run_code) {
     //run code
     eval($run_code);
    }

   }
   

  } 


 }