public function l($str) { if (function_exists("fwLog")) { fwLog($str); } else { print "LOG: {$str}\n"; } }
function getServices() { global $v; // Asterisk user $astuser = "******"; // We want to switch to the asterisk user and ask for the port mappings. try { if (!$v->checkFile("bin/getservices")) { // That should ALREADY throw if there's an error throw new \Exception("Failed"); } } catch (\Exception $e) { fwLog("Can't validate bin/getservices"); return array(); } // Make sure it's executable $s = stat("/var/www/html/admin/modules/firewall/bin/getservices"); if ($s['mode'] !== 0755) { chmod("/var/www/html/admin/modules/firewall/bin/getservices", 0755); } exec("su -c /var/www/html/admin/modules/firewall/bin/getservices {$astuser}", $out, $ret); $getservices = @json_decode($out[0], true); if (!is_array($getservices) || !isset($getservices['smartports'])) { fwLog("Unparseable output from getservices - " . json_encode($out) . " - returned {$ret}"); return array(); } return $getservices; }
function wall($msg = false) { if (!$msg) { // wat. fwLog("Asked to wall a blank message?"); return; } // Open a process handle to wall $fds = array(0 => array("pipe", "r"), 1 => array("file", "/dev/null", "a"), 2 => array("file", "/dev/null", "a")); $pipes = array(); $ph = proc_open("/usr/bin/wall", $fds, $pipes, "/tmp"); fwrite($pipes[0], $msg); fclose($pipes[0]); $ret = proc_close($ph); fwLog("Wall: '{$msg}' returned {$ret}"); return $ret; }