public static function postJsonRpc(&$_result) { if (is_array($_result)) { if (config::byKey('market::allowDNS') == 1) { $dnsRestart = false; if (isset($_result['register::ngrokAddr']) && config::byKey('ngrok::addr') != $_result['register::ngrokAddr']) { config::save('ngrok::addr', $_result['register::ngrokAddr']); $dnsRestart = true; } if (isset($_result['register::ngrokToken']) && config::byKey('ngrok::token') != $_result['register::ngrokToken']) { config::save('ngrok::token', $_result['register::ngrokToken']); $dnsRestart = true; } if ($dnsRestart) { if (network::dns_run()) { network::dns_stop(); } network::dns_start(); } if (isset($_result['jeedom::url']) && config::byKey('jeedom::url') != $_result['jeedom::url']) { config::save('jeedom::url', $_result['jeedom::url']); } } if (isset($_result['register::ngrokAddr'])) { unset($_result['register::ngrokAddr']); } if (isset($_result['register::ngrokPort'])) { unset($_result['register::ngrokPort']); } if (isset($_result['register::ngrokToken'])) { unset($_result['register::ngrokToken']); } if (isset($_result['jeedom::url'])) { unset($_result['jeedom::url']); } if (isset($_result['register::hwkey_nok']) && $_result['register::hwkey_nok'] == 1) { config::save('jeedom::installKey', ''); } } }
public static function cron() { if (config::byKey('market::allowDNS') == 1 && !network::dns_run()) { network::dns_start(); } if (!jeedom::isCapable('sudo')) { return; } $gws = self::checkGw(); if (count($gws) == 0) { log::add('network', 'error', __('Aucune interface réseau trouvée, je redemarre tous le réseaux', __FILE__)); exec('sudo service networking restart'); return; } foreach ($gws as $iface => $gw) { if ($gw['ping'] != 'ok') { if (strpos($iface, 'tun') !== false) { continue; } if (strpos($iface, 'br0') !== false) { continue; } log::add('network', 'error', __('La passerelle distance de l\'interface ', __FILE__) . $iface . __(' est injoignable je la redemarre pour essayer de corriger', __FILE__)); exec('sudo ifdown ' . $iface); sleep(5); exec('sudo ifup --force ' . $iface); } } }
network::dns_start(); $jsonrpc->makeSuccess(); } if ($jsonrpc->getMethod() == 'network::stopNgrok') { config::save('market::allowDNS', 0); network::dns_stop(); $jsonrpc->makeSuccess(); } if ($jsonrpc->getMethod() == 'network::ngrokRun') { if (!isset($params['proto'])) { $params['proto'] = 'https'; } if (!isset($params['port'])) { $params['port'] = 80; } if (!isset($params['name'])) { $params['name'] = ''; } $jsonrpc->makeSuccess(network::dns_run()); } /* * ************************************************************************ */ } throw new Exception('Aucune méthode correspondante : ' . $jsonrpc->getMethod(), -32500); /* * *********Catch exeption*************** */ } catch (Exception $e) { $message = $e->getMessage(); $jsonrpc = new jsonrpc(init('request')); $errorCode = is_numeric($e->getCode()) ? -32000 - $e->getCode() : -32599; $jsonrpc->makeError($errorCode, $message); } }
* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Jeedom. If not, see <http://www.gnu.org/licenses/>. */ try { require_once dirname(__FILE__) . '/../../core/php/core.inc.php'; include_file('core', 'authentification', 'php'); if (!isConnect('admin')) { throw new Exception(__('401 - Accès non autorisé', __FILE__)); } if (init('action') == 'restartNgrok') { config::save('market::allowDNS', 1); if (network::dns_run()) { network::dns_stop(); } network::dns_start(); ajax::success(); } if (init('action') == 'stopNgrok') { config::save('market::allowDNS', 0); network::dns_stop(); ajax::success(); } if (init('action') == 'listWifi') { ajax::success(network::listWifi()); } if (init('action') == 'writeInterfaceFile') { ajax::success(network::writeInterfaceFile());