public static function cron30($_eqlogic_id = null) { if ($_eqlogic_id !== null) { $eqLogics = array(eqLogic::byId($_eqlogic_id)); } else { $eqLogics = eqLogic::byType('wazeintime'); sleep(rand(0, 120)); } foreach ($eqLogics as $wazeintime) { if ($wazeintime->getIsEnable() == 1) { try { $start = $wazeintime->getPosition('start'); $end = $wazeintime->getPosition('end'); $row = $wazeintime->getConfiguration('NOA') ? '' : 'row-'; $wazeRouteurl = 'https://www.waze.com/' . $row . 'RoutingManager/routingRequest?from=x%3A' . $start['lon'] . '+y%3A' . $start['lat'] . '&to=x%3A' . $end['lon'] . '+y%3A' . $end['lat'] . '&at=0&returnJSON=true&returnGeometries=true&returnInstructions=true&timeout=60000&nPaths=3&options=AVOID_TRAILS%3At'; $request_http = new com_http($wazeRouteurl); $request_http->setUserAgent('User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0'); $json = json_decode($request_http->exec(6, 2), true); if (isset($json['error'])) { throw new Exception($json['error']); } $data = self::extractInfo($json); $wazeRoutereturl = 'https://www.waze.com/' . $row . 'RoutingManager/routingRequest?from=x%3A' . $end['lon'] . '+y%3A' . $end['lat'] . '&to=x%3A' . $start['lon'] . '+y%3A' . $start['lat'] . '&at=0&returnJSON=true&returnGeometries=true&returnInstructions=true&timeout=60000&nPaths=3&options=AVOID_TRAILS%3At'; $request_http = new com_http($wazeRoutereturl); $request_http->setUserAgent('User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0'); $json = json_decode($request_http->exec(6, 2), true); if (isset($json['error'])) { throw new Exception($json['error']); } $data = array_merge($data, self::extractInfo($json, 'ret')); log::add('wazeintime', 'debug', 'Data : ' . print_r($data, true)); foreach ($wazeintime->getCmd('info') as $cmd) { if ($cmd->getLogicalId() == 'lastrefresh') { $cmd->event(date('H:i')); continue; } if (!isset($data[$cmd->getLogicalId()])) { continue; } if ($cmd->formatValue($data[$cmd->getLogicalId()]) != $cmd->execCmd()) { $cmd->setCollectDate(''); $cmd->event($data[$cmd->getLogicalId()]); } } $wazeintime->refreshWidget(); } catch (Exception $e) { log::add('wazeintime', 'error', $e->getMessage()); } } } }
public function updateIP() { $externalIP = $this->getCmd(null, 'externalIP'); if (!is_object($externalIP)) { throw new Exception(__('Commande externalIP inexistante', __FILE__)); } $ip = $externalIP->execCmd(null, 2); switch ($this->getConfiguration('type')) { case 'dyndnsorg': $url = 'https://' . $this->getConfiguration('username') . ':' . $this->getConfiguration('password') . '@members.dyndns.org/nic/update?hostname=' . $this->getConfiguration('hostname') . '&myip=' . $ip; $request_http = new com_http($url); $request_http->setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12'); $result = $request_http->exec(); if (strpos($result, 'good') === false) { throw new Exception(__('Erreur de mise à jour de dyndns.org : ', __FILE__) . $result); } break; case 'noipcom': $url = 'https://' . $this->getConfiguration('username') . ':' . $this->getConfiguration('password') . '@dynupdate.no-ip.com/nic/update?hostname=' . $this->getConfiguration('hostname') . '&myip=' . $ip; $request_http = new com_http($url); $request_http->setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12'); $result = $request_http->exec(); if (strpos($result, 'good') === false || strpos($result, 'nochg') === false) { throw new Exception(__('Erreur de mise à jour de noip.com : ', __FILE__) . $result); } break; case 'ovhcom': $url = 'https://' . $this->getConfiguration('username') . ':' . $this->getConfiguration('password') . '@www.ovh.com/nic/update?system=dyndns&hostname=' . $this->getConfiguration('hostname') . '&myip=' . $ip; $request_http = new com_http($url); $request_http->setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12'); $result = $request_http->exec(); if (strpos($result, 'good') === false && strpos($result, 'nochg') === false) { throw new Exception(__('Erreur de mise à jour de ovh.com : ', __FILE__) . $result); } break; } }