Пример #1
0
 function access($policy)
 {
     if (!is_array($policy)) {
         $policy = explode(',', $policy);
     }
     $canAccess = false;
     foreach ($policy as $p) {
         switch ($p) {
             case 'local':
                 if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') {
                     $canAccess = true;
                 }
                 break;
             case 'internal':
                 $i = $_SERVER['REMOTE_ADDR'];
                 $f = CutSegment('.', $i);
                 if ($f == '10' && $_SERVER['HTTP_X_FORWARDED_FOR'] == '') {
                     $canAccess = true;
                 }
                 break;
             case 'auth':
                 if ($_SESSION['uid'] > 0) {
                     $canAccess = true;
                 }
                 break;
         }
     }
     if (!$canAccess) {
         header('location: ' . actionUrl('signin', 'accounts'));
         die;
     }
     return $canAccess;
 }
Пример #2
0
 function dparam($value)
 {
     $key = CutSegment('=', $value);
     $this->deviceDS['d_' . $key] = $value;
     $this->save();
     broadcast(array('type' => 'dparam_' . $key, 'device' => $this->deviceDS['d_key'], 'value' => $value));
 }
Пример #3
0
function getServiceFlags()
{
    return dataCache('hm-service-flags', function () {
        $hmSvc = array();
        foreach (HMRPC('getServiceMessages') as $svc) {
            $id = $svc[0];
            $did = CutSegment(':', $id);
            $hmSvc[$did][] = $svc;
        }
        return $hmSvc;
    });
}
Пример #4
0
 static function getGroupsByDevice($deviceDS)
 {
     $matchingGroups = array();
     foreach (o(db)->get('SELECT * FROM #nvstore WHERE nv_key LIKE "group/%" ORDER BY nv_key') as $grpData) {
         $gName = $grpData['nv_key'];
         CutSegment('/', $gName);
         $gList = json_decode($grpData['nv_data']);
         if (is_array($gList) && array_search($deviceDS['d_key'], $gList) !== false) {
             $matchingGroups[] = $gName;
         }
     }
     return $matchingGroups;
 }
Пример #5
0
 function textToConfig($text, $cfg = array())
 {
     $lines = explode(chr(10), $text);
     foreach ($lines as $value) {
         $value = trim($value);
         if ($value != '') {
             $key = CutSegment('=', $value);
             $radiatorName = CutSegment('.', $key);
             $cfg[$radiatorName][$key] = $value;
         }
     }
     ksort($cfg);
     return $cfg;
 }
Пример #6
0
 function receiveData()
 {
     if (substr($_SERVER['QUERY_STRING'], 0, 1) == '/') {
         $qry = substr($_SERVER['QUERY_STRING'], 1);
         $_REQUEST['controller'] = CutSegment('/', $qry);
         $_REQUEST['action'] = CutSegment('&', $qry);
         if ($qry != '') {
             parse_str($qry, $r);
             foreach ($r as $k => $v) {
                 $_REQUEST[$k] = $v;
             }
         }
     }
     return $this;
 }
Пример #7
0
function hubbub2_loadurl($url)
{
    $content = HubbubEndpoint::request($url);
    $html = trim($content['body']);
    $entity = array();
    // case 1, this is a json array
    if (substr($html, 0, 1) == '{') {
        $entity = json_decode($html);
    } else {
        if (stristr($html, '<!-- hubbub2:{') != '') {
            CutSegment('<!-- hubbub2:{', $html);
            $seg = '{' . trim(CutSegment('-->', $html));
            $entity = json_decode($seg, true);
        }
    }
    return $entity;
}
Пример #8
0
 function display($ds)
 {
     $renderType = cfg('deviceTypeAliases/' . $ds['d_type']);
     if (!$renderType) {
         $renderType = $ds['d_type'];
     }
     $id = $ds['d_id'];
     $idRoot = CutSegment(':', $id);
     $ds['flags'] = $this->serviceFlags[$idRoot];
     $ds['statusIcons'] = array();
     if (is_array($this->serviceFlags[$idRoot])) {
         foreach ($this->serviceFlags[$idRoot] as $f) {
             if ($f[1] == 'LOWBAT') {
                 $ds['statusIcons'][] = '<i class="fa fa-laptop_battery"></i>';
             }
             if ($f[1] == 'UNREACH') {
                 $ds['statusIcons'][] = '<i class="fa fa-exclamation-circle"></i>';
             }
             if ($f[1] == 'STICKY_UNREACH') {
                 $ds['statusIcons'][] = '<i class="fa fa-exclamation-triangle"></i>';
             }
         }
     }
     $ds['statusIconStr'] = implode(' ', $ds['statusIcons']);
     $renderFunc = 'display' . $renderType;
     $renderFuncBus = $renderFunc . $ds['d_bus'];
     if (method_exists($this, $renderFuncBus)) {
         $this->{$renderFuncBus}($ds);
     } else {
         if (method_exists($this, $renderFunc)) {
             $this->{$renderFunc}($ds);
         }
     }
     #else
     #  print('<div class="device_line">'.$ds['d_type'].'</div>');
 }
Пример #9
0
function http_parse_request_ex($result, $headerMode = true)
{
    $resHeaders = array();
    $resBody = array();
    foreach (explode("\n", $result) as $line) {
        if ($headerMode) {
            if (strStartsWith($line, 'HTTP/')) {
                $httpInfoRecord = explode(' ', trim($line));
                if ($httpInfoRecord[1] == '100') {
                    $ignoreUntilHTTP = true;
                } else {
                    $ignoreUntilHTTP = false;
                    $resHeaders['code'] = $httpInfoRecord[1];
                    $resHeaders['HTTP'] = $line;
                }
            } else {
                if (trim($line) == '') {
                    if (!$ignoreUntilHTTP) {
                        $headerMode = false;
                    }
                } else {
                    $hdr_key = trim(CutSegment(':', $line));
                    $resHeaders[strtolower($hdr_key)] = trim($line);
                }
            }
        } else {
            $resBody[] = $line;
        }
    }
    $body = trim(implode("\n", $resBody));
    $data = json_decode($body, true);
    return array('result' => $resHeaders['code'], 'headers' => $resHeaders, 'data' => $data, 'body' => $body);
}
Пример #10
0
  <tr>
    <td style="text-align:right">
      <span class="faint">Direction</span>   
    </td>
    <td width="*">
      <?php 
$dirText = array(0 => 'None', 1 => 'Sender', 2 => 'Receiver');
print $dirText[$dev['DIRECTION']];
?>
</div>
    </td>  
  </tr>
  <?php 
$related = array();
$idnr = $ds['d_id'];
$idroot = CutSegment(':', $idnr);
foreach (o(db)->get('SELECT d_key,d_id,d_alias,d_type FROM devices WHERE d_id LIKE "' . $idroot . '%" ORDER BY d_id') as $dds) {
    $related[] = '<a href="' . actionUrl('params', 'devices', array('key' => $dds['d_key'])) . '" style="' . ($dds['d_key'] == $ds['d_key'] ? 'font-weight:bold;' : '') . '">' . htmlspecialchars(first($dds['d_alias'], $dds['d_type'])) . ' ' . $dds['d_id'] . '</a>';
    //array($ds['d_id'] => $ds['d_id'].' ('.first($ds['d_alias'], $ds['d_id']).')');
}
print '<tr><td valign="top" style="text-align:right"><span class="faint">Compound</span></td><td>' . implode(', ', $related) . '</td></tr></table>';
function showParam($val, $p, $k)
{
    global $actionEvents;
    switch ($p['TYPE']) {
        case 'BOOL':
            if ($p['WRITABLE'] && $p['ID'] != 'AES_ACTIVE') {
                return '<select name="' . $p['ID'] . '"><option' . ($val === true ? ' selected' : '') . '>Yes</option><option' . ($val != true ? ' selected' : '') . '>No</option></select>';
            } else {
                return $val === true ? 'Yes' : 'No';
            }
Пример #11
0
function stringParamsToArray($paramStr)
{
    $result = array();
    foreach (explode(',', $paramStr) as $line) {
        $k = CutSegment('=', $line);
        $result[$k] = $line;
    }
    return $result;
}
Пример #12
0
<thead>
  <tr>
    <th></th>
    <th>Type</th>
    <th>#</th>
    <th>Vis.</th>
    <th>Address</th>
    <th>Name</th>
    <th>Alias</th>
    <th>Room</th>
  </tr>
</thead><?php 
db()->get('UPDATE #devices SET d_added = ' . time() . ' WHERE d_added = 0');
foreach (o(db)->get('SELECT * FROM devices ORDER BY d_room,d_id') as $ds) {
    $id = $ds['d_id'];
    $did = CutSegment(':', $id);
    $info = '';
    if ($deviceFlags[$did]) {
        $flags = array();
        $img = 'error';
        foreach ($deviceFlags[$did] as $f) {
            $flags[] = $f[1];
            if ($f[1] == 'LOWBAT') {
                $img = 'laptop_battery';
            }
        }
        $info = '<img src="icons/' . $img . '.png" width="22" style="margin:-4px;" title="' . implode(', ', $flags) . '"/>';
    }
    $icon = $deviceIcons[strtoupper($ds['d_type'])];
    if (!$icon) {
        $icon = $deviceIcons['default'];
Пример #13
0
 function linkFromId($idkey, $options = array())
 {
     if (!isset($GLOBALS['entitycache'][$idkey])) {
         $GLOBALS['entitycache'][$idkey] = DB_GetDataset('entities', $idkey);
     }
     $entity = $GLOBALS['entitycache'][$idkey];
     $entityName = $entity['name'];
     if ($options['short']) {
         $entityName = CutSegment(' ', $entityName);
     }
     if ($options['nolink']) {
         return getDefault($entityName, '(unknown)');
     }
     if (object('user')->entity == $idkey) {
         return '<a href="' . actionUrl('index', 'profile') . '">' . getDefault($entityName, '(unknown)') . '</a>';
     } else {
         return '<a href="' . actionUrl($idkey + 0, 'profile') . '">' . getDefault($entityName, '(unknown)') . '</a>';
     }
 }
Пример #14
0
 function callHandlers($handlers, $data)
 {
     foreach (array('', '_rev') as $addressType) {
         $reverseAction = $addressType == '_rev';
         $where = array();
         foreach ($handlers as $h) {
             $where[] = 'e_address' . $addressType . ' = ?';
         }
         foreach (o(db)->get('SELECT * FROM events
     WHERE (' . implode(' OR ', $where) . ')
     ORDER BY e_order ASC', $handlers) as $eds) {
             $GLOBALS['log'][] = 'event handler called: ' . $eds['e_address' . $addressType];
             broadcast(array('type' => 'eventHandled', 'address' => $eds['e_address' . $addressType]));
             $this->ignoreExecution = false;
             $emitterRoot = $data['device'];
             $emitterRoot = CutSegment(':', $emitterRoot);
             if ($emitterRoot != $data['device']) {
                 $emitterRootDS = getDeviceDS($emitterRoot);
             } else {
                 $emitterRootDS = $data['ds'];
             }
             $this->executeScript($eds['e_code'], array('emitter_id' => $data['device'], 'emitter_param' => $data['param'], 'emitter_value' => $data['value'], 'emitter_alias' => $emitterRootDS['d_alias'], 'emitter_root' => $emitterRoot, 'emitter_name' => first($emitterRootDS['d_name'], $emitterRootDS['d_id']), 'emitter' => $data['ds'], 'call' => $data, 'eventDS' => &$eds, 'reverseAction' => $reverseAction, 'event' => $eds['e_address' . $addressType]));
             if (!$this->ignoreExecution) {
                 o(db)->query('UPDATE events SET e_lastcalled = ' . time() . ' WHERE e_key = ' . $eds['e_key']);
             }
         }
     }
     return $this;
 }