Portions created by the Initial Developer are Copyright (C) 2008-2018 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane James Rose */ //includes include "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; //check permissions if (permission_exists("registration_domain") || permission_exists("registration_all") || if_group("superadmin")) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //get the http values and set them as variables $search = $_REQUEST["search"]; //set the format $template = true; if ($_REQUEST["template"] == "false" && permission_exists('registration_reload')) { $template = false; } //show the header if ($template) { require_once "resources/header.php"; $document['title'] = $text['header-registrations']; } //check permissions if (permission_exists("registration_domain") || permission_exists("registration_all") || if_group("superadmin")) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //debug //echo "
\n";
	//print_r($_REQUEST);
	//echo "
\n"; //get the HTTP values and set as variables $profile = trim($_REQUEST["profile"]); $search = trim($_REQUEST["search"]); $show = trim($_REQUEST["show"]); if ($show == "all") { $profile = 'all'; } //set the registrations variable $registrations = $_REQUEST["registrations"]; //get the action and remove items from the array that are not checked if (is_array($registrations)) { $x = 0; foreach ($registrations as &$row) { //get the action switch ($row['action']) { case "unregister": $row['checked'] = 'true'; $action = 'unregister'; break; case "provision": $row['checked'] = 'true'; $action = 'provision'; break; case "reboot": $row['checked'] = 'true'; $action = 'reboot'; break; } //unset rows that were not selected if (!isset($row['checked'])) { unset($registrations[$x]); } //increment the id $x++; } } //get the list $sql = "select sip_profile_name as name from v_sip_profiles "; $database = new database; $sip_profiles = $database->select($sql, null, 'all'); //create the event socket connection $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); //user registrations if (isset($action)) { if (is_array($registrations)) { foreach ($registrations as $row) { if ($fp) { //validate the profile foreach($sip_profiles as $field) { if ($field['name'] == $row['profile']) { $profile = $row['profile']; } } //validate the user if (strlen($row['user']) > 0) { $user = preg_replace('#[^a-zA-Z0-9_\-\.\@]#', '', $row['user']); } //validate the host if (strlen($row['host']) > 0) { $host = preg_replace('#[^a-zA-Z0-9_\-\.]#', '', $row['host']); } //get the vendor $vendor = device::get_vendor_by_agent($row['agent']); //prepare and send the command if (strlen($vendor) > 0 && strlen($profile) > 0 && strlen($user) > 0) { if ($action == "unregister") { $command = "sofia profile ".$profile." flush_inbound_reg ".$user." reboot"; } if ($action == "provision" && strlen($host) > 0) { $command = "lua app.lua event_notify ".$profile." check_sync ".$user." ".$vendor." ".$host; } if ($action == "reboot" && strlen($host) > 0) { $command = "lua app.lua event_notify ".$profile." reboot ".$user." ".$vendor." ".$host; } $response = event_socket_request($fp, "api ".$command); $response = event_socket_request($fp, "api log notice ".$command); } } } } } //show the response if (isset($response)) { message::add($text['label-event']." ".escape(ucwords($cmd))."     ".$text['label-response'].escape($response)); } //define variables $c = 0; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; //show the error message or show the content if (strlen($msg) > 0) { echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
".$text['label-message']."
$msg
\n"; echo "
\n"; } else { //get the registrations $obj = new registrations; $registrations = $obj->get($profile); //count the registrations $registration_count = 0; if (is_array($registrations)) { foreach ($registrations as $row) { $matches = preg_grep ("/$search/i",$row); if ($matches != FALSE) { $registration_count++; } } } //define the checkbox_toggle function echo "\n"; //show the registrations echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo ""; echo "\n"; echo "\n"; echo "
\n"; echo " ".$text['header-registrations']." (".escape($registration_count).")\n"; echo ""; if ($template) { echo " "; echo " "; echo " "; echo " "; } echo ""; if (permission_exists('registration_all')) { if ($template) { $location = 'registrations.php'; } else { $location = 'registration_reload.php'; } if ($show == "all") { echo " \n"; } else { echo " \n"; } } if ($template) { echo " \n"; } echo "
\n"; echo "
\n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "\n"; //order the array require_once "resources/classes/array_order.php"; $order = new array_order(); $registrations = $order->sort($registrations, 'sip-auth-realm', 'user'); //display the array if (is_array($registrations)) { $x = 0; foreach ($registrations as $row) { //search $matches = preg_grep ("/$search/i",$row); if ($matches != FALSE) { //set the user agent $agent = $row['agent']; //set the user id $user_id = str_replace('@', '_', $row['user']); //show the registrations echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "\n"; if ($c==0) { $c=1; } else { $c=0; } $x++; } } } echo "
\n"; echo " "; echo " ".$text['label-user']."".$text['label-agent']."".$text['label-contact']."".$text['label-lan_ip']."".$text['label-ip']."".$text['label-port']."".$text['label-hostname']."".$text['label-status']."".$text['label-ping']."".$text['label-sip_profile_name']."".$text['label-tools']." 
".escape($row['user'])." ".escape($row['agent'])." ".escape(explode('"',$row['contact'])[1])."".escape($row['lan-ip'])."".escape($row['network-ip'])."".escape($row['network-port'])."".escape($row['host'])."".escape($row['status'])."".escape($row['ping-time'])."".escape($row['sip_profile_name'])."\n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo "\n"; echo "
\n"; //close the connection and unset the variable fclose($fp); unset($xml); } //get the footer if ($template) { require_once "resources/footer.php"; } ?>