Ejemplo n.º 1
0
 function MakeRequest($mode, $entityInfo)
 {
   $result = cqrequest('http://hubbub.at/ab', array(
     'mode' => $mode, 
     'entity' => $entityInfo, 
     'callback' => actionUrl('abconfirm', 'endpoint', array(), true)));    
   return($result['data']);
 }
Ejemplo n.º 2
0
<pre><?php 
$owFileName = 'data/openweather.json';
$weatherReportFile = 'data/weather.json';
if (time() - filemtime($owFileName) > 60 * 2) {
    print 'last called: ' . (time() - filemtime($owFileName)) . ' seconds ago' . chr(10);
    $weatherReq = cqrequest(array(array('url' => 'http://api.openweathermap.org/data/2.5/weather?q=' . urlencode(cfg('geo/city')) . '&mode=json&units=metric&APPID=' . cfg('openweathermap/api_key'))));
    $owd = $weatherReq['data'];
    if (sizeof($owd) > 0) {
        unlink('data/openweather.json');
        unlink('data/weather.json');
        file_put_contents($owFileName, json_encode($owd));
        foreach ($owd['weather'] as $w) {
            $wif = 'w/' . $w['icon'] . '.png';
            $data['icon'] = 'http://openweathermap.org/img/' . $wif;
            if (!file_exists('icons/' . $wif)) {
                mkdir('icons/w/');
                shell_exec('curl "' . $data['icon'] . '" > icons/' . $wif);
            }
            $desc[] = $w['description'];
        }
        $data['description'] = implode(', ', $desc);
        $data['tecur'] = number_format($owd['main']['temp'], 1);
        $data['wscur'] = number_format($owd['wind']['speed'], 1);
        $data['wind'] = $owd['wind'];
        $data['rain'] = $owd['rain'];
        $data['clouds'] = $owd['clouds'];
        $data['temp'] = $owd['main'];
        include 'lib/moon.php';
        $moon = new Solaris\MoonPhase();
        $data['moonlight'] = number_format($moon->illumination(), 1) * 100;
        $data['moonstage'] = $moon->phase() < 0.5 ? 'waxing' : 'waning';
Ejemplo n.º 3
0
function file_get_fromurl($url, $post = array(), $timeout = 2)
{
    $fle = cqrequest($url, $post, $timeout);
    return $fle['body'];
}
Ejemplo n.º 4
0
 function ABNewEntry($entityDS, $commentText)
 {
   $entityDS['comment'] = $commentText;
   $entityDS['email'] = md5($this->user->ds['u_email']);
   $entityInfo = json_encode($entityDS);
   // this is important: we need to prepare the endpoint API to give out
   // the confirmation before we send the request to the AB, because the AB
   // may hold the request until it's completed ITS confirmation request 
   // back to us!
   h2_nv_store('abreq/'.$entityDS['_key'], array(
     'abrequest' => 'pending', 
     'checksum' => md5($entityInfo)));
   // now, make the request to add our info to the AB
   $result = cqrequest('http://hubbub.at/ab', array(
     'mode' => 'new', 
     'entity' => $entityInfo, 
     'callback' => actionUrl('abconfirm', 'endpoint', array(), true)));
   return($result['data']);
 }
Ejemplo n.º 5
0
{
  $btype = 'smallwin';
  $lastPing = filectime('log/cron.last.log');
  $lastPingText = 'Last ping: '.ageToString($lastPing, 'very recently');
}
else
{
  $btype = 'fail';
  $lastPingText = 'Waiting for ping from '.$pingServer.'...'; 
}  
if(cfg('ping/remote') && cfg('ping/server') != '')
{
  $pingStatus = h2_nv_retrieve('ping/status');
  if($pingStatus['server'] != $pingServer)
  {
    $pingRequest = cqrequest($pingServer, array('origin' => 'http://'.cfg('service/server').'/cron.php', 'request' => 'activate', 'password' => cfg('ping/password')), 2);   
    if($pingRequest['data']['result'] == 'OK')
    {
      $btype = 'win';
      $lastPingText = 'Connection with ping server established, waiting for ping from '.$pingServer.'...';
      $pingStatus = $pingRequest['data'];
      $pingStatus['server'] = $pingServer;
      h2_nv_store('ping/status', $pingStatus);
      @unlink('log/cron.last.log');
    }
    else
    {
      $btype = 'fail';
      $reason = $pingRequest['data']['reason'];
      $lastPingText = 'Could not establish connection with ping server. Reason: '.getDefault($reason, 'server not found');
    }
Ejemplo n.º 6
0
$_SESSION['installer']['server_base'] = $_REQUEST['serverurl'];
$_SESSION['installer']['admin_password'] = $_REQUEST['adminpw'];
$_SESSION['installer']['remote_cron_svc'] = $_REQUEST['pingsvc'];

$_SESSION['installer']['cfg']['service']['server'] = $_REQUEST['serverurl'];
$_SESSION['installer']['cfg']['service']['adminpw'] = $_REQUEST['adminpw'];
unset($_SESSION['installer']['cfg']['cron']);
$_SESSION['installer']['cfg']['ping']['remote'] = $_REQUEST['pingsvc'] == 'Y';
$_SESSION['installer']['cfg']['ping']['password'] = getDefault($_SESSION['installer']['cfg']['ping']['password'], randomHashId());
$_SESSION['installer']['cfg']['ping']['server'] = getDefault($_SESSION['installer']['cfg']['ping']['server'], 'http://ping.openfu.net');

if($_REQUEST['pingsvc'] == 'Y')
{
  newFile('conf/pingpassword', $_SESSION['installer']['cfg']['ping']['password']);
  $pingRequest = cqrequest($_SESSION['installer']['cfg']['ping']['server'], array('origin' => 'http://'.$_SESSION['installer']['server_base'].'/cron.php', 'request' => 'activate', 
    'password' => $_SESSION['installer']['cfg']['ping']['password']), 2);   
  unlink('conf/pingpassword');
  if($pingRequest['data']['result'] == 'OK')
  {
    $msg .= '<div class="green">✔ &nbsp; Joined remote ping service ('.$_SESSION['installer']['cfg']['ping']['server'].')</div>';
    $pingStatus = $pingRequest['data'];
    $pingStatus['server'] = $pingServer;
  }
  else
  {
    $pingStatus = array();
    $msg .= '<div class="red">✘ &nbsp; Could not establish a connection with ping server ('.$pingRequest['data']['reason'].')</div>';
  }
}
else
{
Ejemplo n.º 7
0
 protected function request($url, $method = 'GET', $params = array())
 {
     if ($method != 'POST') {
         $get_params = '?' . http_build_query($params, '', '&');
     }
     $rq = cqrequest($url . $get_params, $method == 'POST' ? $params : array(), 5, true, $method == 'HEAD');
     if ($method == 'HEAD') {
         foreach ($rq['headers'] as $name => $header) {
             $name = strtolower($name);
             $headers[$name] = trim($header);
             # Following possible redirections. The point is just to have
             # claimed_id change with them, because get_headers() will
             # follow redirections automatically.
             # We ignore redirections with relative paths.
             # If any known provider uses them, file a bug report.
             if ($name == 'location') {
                 if (strpos($headers[$name], 'http') === 0) {
                     $this->claimed_id = $headers[$name];
                 } elseif ($headers[$name][0] == '/') {
                     $parsed_url = parse_url($this->claimed_id);
                     $this->claimed_id = $parsed_url['scheme'] . '://' . $parsed_url['host'] . $headers[$name];
                 }
             }
         }
         return $headers;
     }
     return $rq['body'];
     if (!$this->hostExists($url)) {
         throw new ErrorException('Invalid request.');
     }
     $params = http_build_query($params, '', '&');
     switch ($method) {
         case 'GET':
             $opts = array('http' => array('method' => 'GET', 'header' => 'Accept: application/xrds+xml, */*', 'ignore_errors' => true));
             $url = $url . ($params ? '?' . $params : '');
             break;
         case 'POST':
             $opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $params, 'ignore_errors' => true));
             break;
         case 'HEAD':
             # We want to send a HEAD request,
             # but since get_headers doesn't accept $context parameter,
             # we have to change the defaults.
             $default = stream_context_get_options(stream_context_get_default());
             stream_context_get_default(array('http' => array('method' => 'HEAD', 'header' => 'Accept: application/xrds+xml, */*', 'ignore_errors' => true)));
             $url = $url . ($params ? '?' . $params : '');
             $headers_tmp = get_headers($url);
             if (!$headers_tmp) {
                 return array();
             }
             # Parsing headers.
             $headers = array();
             foreach ($headers_tmp as $header) {
                 $pos = strpos($header, ':');
                 $name = strtolower(trim(substr($header, 0, $pos)));
                 $headers[$name] = trim(substr($header, $pos + 1));
                 # Following possible redirections. The point is just to have
                 # claimed_id change with them, because get_headers() will
                 # follow redirections automatically.
                 # We ignore redirections with relative paths.
                 # If any known provider uses them, file a bug report.
                 if ($name == 'location') {
                     if (strpos($headers[$name], 'http') === 0) {
                         $this->claimed_id = $headers[$name];
                     } elseif ($headers[$name][0] == '/') {
                         $parsed_url = parse_url($this->claimed_id);
                         $this->claimed_id = $parsed_url['scheme'] . '://' . $parsed_url['host'] . $headers[$name];
                     }
                 }
             }
             # And restore them.
             stream_context_get_default($default);
             return $headers;
     }
     $context = stream_context_create($opts);
     return file_get_contents($url, false, $context);
 }
Ejemplo n.º 8
0
function deviceCommand($deviceKey, $commandType, $value, $by = 'API', $fireEvent = false)
{
    $device = getDeviceDS($deviceKey);
    if (!approveAction(array('type' => 'deviceCommand', 'device' => $deviceKey, 'deviceType' => $device['d_type'], 'ds' => $device, 'command' => $commandType, 'value' => $value, 'by' => $by))) {
        return;
    }
    if ($device['d_auto'] != 'A' && $GLOBALS['command-mode'] == 'trigger') {
        return;
    }
    $GLOBALS['log'][$device['d_key']] = array('type' => 'deviceCommand', 'device' => $deviceKey, 'param' => $commandType, 'value' => $value);
    $config = json_decode($device['d_config'], true);
    if (sizeof($device) > 0 && $device['d_state'] != $value) {
        if ($device['d_bus'] == 'HE') {
            $pv = $value + 0;
            $pv = reviewParams($device, $commandType, $pv);
            $reqUrl = 'http://localhost:1080/?cmd=update&bus=' . $device['d_bus'] . '&param=' . $commandType . '&key=' . $device['d_key'] . '&stxt=' . urlencode(first($GLOBALS['command-source'], $by)) . '&id=' . $device['d_id'] . '&value=' . $pv;
            cqrequest(array(array('url' => $reqUrl)));
        } else {
            if ($device['d_bus'] == 'HM') {
                sendHMCommand($device, $commandType, $value, first($GLOBALS['command-source'], $by), $config, $fireEvent);
                return;
            }
        }
        $sds = array('si_bus' => $device['d_bus'], 'si_name' => $device['d_id'], 'si_param' => $commandType, 'si_value' => $pv, 'si_time' => time(), 'si_devicekey' => $device['d_key'], 'si_by' => $by, 'si_event' => $GLOBALS['command-source'], 'si_mode' => 'TX', 'si_uid' => $_SESSION['uid'] + 0, 'si_ip' => first($_SERVER['HTTP_X_FORWARDED_FOR'], $_SERVER['REMOTE_ADDR']));
        o(db)->commit('stateinfo', $sds);
        /*WriteToFile('log/stats.'.gmdate('Y-m').'.log', 
          json_encode(array(
            'type' => 'dp', 'key' => $device['d_key'], 'id' => $device['d_id'], 'bus' => $device['d_bus'], 'param' => $commandType, 'value' => $pv, 'tr' => 'tx')).
          chr(10)
          );*/
        $device['d_state'] = $value;
        $device['d_statustext'] = first($GLOBALS['command-source'], $by);
        $device['d_statuschanged'] = time();
        o(db)->commit('devices', $device);
    }
}
Ejemplo n.º 9
0
 function request($url, $postData = array(), $options = array())
 {
     return cqrequest($url, $postData, 3);
 }