diff --git a/app/registrations/app_languages.php b/app/registrations/app_languages.php index 5db1418c10..6801b4648e 100644 --- a/app/registrations/app_languages.php +++ b/app/registrations/app_languages.php @@ -361,6 +361,26 @@ $text['header-registrations']['ru-ru'] = "Регистрация"; $text['header-registrations']['sv-se'] = "Registreringar"; $text['header-registrations']['uk-ua'] = "Реєстрації"; +$text['description-registrations']['en-us'] = "Manage current extensions registered to the system."; +$text['description-registrations']['ar-eg'] = "Manage current extensions registered to the system."; +$text['description-registrations']['de-at'] = "Manage current extensions registered to the system."; +$text['description-registrations']['de-ch'] = "Manage current extensions registered to the system."; +$text['description-registrations']['de-de'] = "Manage current extensions registered to the system."; +$text['description-registrations']['es-cl'] = "Manage current extensions registered to the system."; +$text['description-registrations']['es-mx'] = "Manage current extensions registered to the system."; +$text['description-registrations']['fr-ca'] = "Manage current extensions registered to the system."; +$text['description-registrations']['fr-fr'] = "Manage current extensions registered to the system."; +$text['description-registrations']['he-il'] = "Manage current extensions registered to the system."; +$text['description-registrations']['it-it'] = "Manage current extensions registered to the system."; +$text['description-registrations']['nl-nl'] = "Manage current extensions registered to the system."; +$text['description-registrations']['pl-pl'] = "Manage current extensions registered to the system."; +$text['description-registrations']['pt-br'] = "Manage current extensions registered to the system."; +$text['description-registrations']['pt-pt'] = "Manage current extensions registered to the system."; +$text['description-registrations']['ro-ro'] = "Manage current extensions registered to the system."; +$text['description-registrations']['ru-ru'] = "Manage current extensions registered to the system."; +$text['description-registrations']['sv-se'] = "Manage current extensions registered to the system."; +$text['description-registrations']['uk-ua'] = "Manage current extensions registered to the system."; + $text['error-event-socket']['en-us'] = "Connection to Event Socket failed."; $text['error-event-socket']['ar-eg'] = ""; $text['error-event-socket']['de-at'] = "Verbindung zum Event Socket fehlgeschlagen."; //copied from de-de @@ -441,4 +461,164 @@ $text['button-provision']['ru-ru'] = "Обеспечение"; $text['button-provision']['sv-se'] = "Provisionera"; $text['button-provision']['uk-ua'] = "Provision "; -?> +$text['button-all_profiles']['en-us'] = "All Profiles"; +$text['button-all_profiles']['ar-eg'] = "All Profiles"; +$text['button-all_profiles']['de-at'] = "All Profiles"; +$text['button-all_profiles']['de-ch'] = "All Profiles"; +$text['button-all_profiles']['de-de'] = "All Profiles"; +$text['button-all_profiles']['es-cl'] = "All Profiles"; +$text['button-all_profiles']['es-mx'] = "All Profiles"; +$text['button-all_profiles']['fr-ca'] = "All Profiles"; +$text['button-all_profiles']['fr-fr'] = "All Profiles"; +$text['button-all_profiles']['he-il'] = "All Profiles"; +$text['button-all_profiles']['it-it'] = "All Profiles"; +$text['button-all_profiles']['nl-nl'] = "All Profiles"; +$text['button-all_profiles']['pl-pl'] = "All Profiles"; +$text['button-all_profiles']['pt-br'] = "All Profiles"; +$text['button-all_profiles']['pt-pt'] = "All Profiles"; +$text['button-all_profiles']['ro-ro'] = "All Profiles"; +$text['button-all_profiles']['ru-ru'] = "All Profiles"; +$text['button-all_profiles']['sv-se'] = "All Profiles"; +$text['button-all_profiles']['uk-ua'] = "All Profiles"; + +$text['button-single_profile']['en-us'] = "Single Profile"; +$text['button-single_profile']['ar-eg'] = "Single Profile"; +$text['button-single_profile']['de-at'] = "Single Profile"; +$text['button-single_profile']['de-ch'] = "Single Profile"; +$text['button-single_profile']['de-de'] = "Single Profile"; +$text['button-single_profile']['es-cl'] = "Single Profile"; +$text['button-single_profile']['es-mx'] = "Single Profile"; +$text['button-single_profile']['fr-ca'] = "Single Profile"; +$text['button-single_profile']['fr-fr'] = "Single Profile"; +$text['button-single_profile']['he-il'] = "Single Profile"; +$text['button-single_profile']['it-it'] = "Single Profile"; +$text['button-single_profile']['nl-nl'] = "Single Profile"; +$text['button-single_profile']['pl-pl'] = "Single Profile"; +$text['button-single_profile']['pt-br'] = "Single Profile"; +$text['button-single_profile']['pt-pt'] = "Single Profile"; +$text['button-single_profile']['ro-ro'] = "Single Profile"; +$text['button-single_profile']['ru-ru'] = "Single Profile"; +$text['button-single_profile']['sv-se'] = "Single Profile"; +$text['button-single_profile']['uk-ua'] = "Single Profile"; + +$text['message-registrations_unregistered']['en-us'] = "Registrations Unregistered"; +$text['message-registrations_unregistered']['ar-eg'] = "Registrations Unregistered"; +$text['message-registrations_unregistered']['de-at'] = "Registrations Unregistered"; +$text['message-registrations_unregistered']['de-ch'] = "Registrations Unregistered"; +$text['message-registrations_unregistered']['de-de'] = "Registrations Unregistered"; +$text['message-registrations_unregistered']['es-cl'] = "Registrations Unregistered"; +$text['message-registrations_unregistered']['es-mx'] = "Registrations Unregistered"; +$text['message-registrations_unregistered']['fr-ca'] = "Registrations Unregistered"; +$text['message-registrations_unregistered']['fr-fr'] = "Registrations Unregistered"; +$text['message-registrations_unregistered']['he-il'] = "Registrations Unregistered"; +$text['message-registrations_unregistered']['it-it'] = "Registrations Unregistered"; +$text['message-registrations_unregistered']['nl-nl'] = "Registrations Unregistered"; +$text['message-registrations_unregistered']['pl-pl'] = "Registrations Unregistered"; +$text['message-registrations_unregistered']['pt-br'] = "Registrations Unregistered"; +$text['message-registrations_unregistered']['pt-pt'] = "Registrations Unregistered"; +$text['message-registrations_unregistered']['ro-ro'] = "Registrations Unregistered"; +$text['message-registrations_unregistered']['ru-ru'] = "Registrations Unregistered"; +$text['message-registrations_unregistered']['sv-se'] = "Registrations Unregistered"; +$text['message-registrations_unregistered']['uk-ua'] = "Registrations Unregistered"; + +$text['message-registrations_provisioned']['en-us'] = "Registrations Provisioned"; +$text['message-registrations_provisioned']['ar-eg'] = "Registrations Provisioned"; +$text['message-registrations_provisioned']['de-at'] = "Registrations Provisioned"; +$text['message-registrations_provisioned']['de-ch'] = "Registrations Provisioned"; +$text['message-registrations_provisioned']['de-de'] = "Registrations Provisioned"; +$text['message-registrations_provisioned']['es-cl'] = "Registrations Provisioned"; +$text['message-registrations_provisioned']['es-mx'] = "Registrations Provisioned"; +$text['message-registrations_provisioned']['fr-ca'] = "Registrations Provisioned"; +$text['message-registrations_provisioned']['fr-fr'] = "Registrations Provisioned"; +$text['message-registrations_provisioned']['he-il'] = "Registrations Provisioned"; +$text['message-registrations_provisioned']['it-it'] = "Registrations Provisioned"; +$text['message-registrations_provisioned']['nl-nl'] = "Registrations Provisioned"; +$text['message-registrations_provisioned']['pl-pl'] = "Registrations Provisioned"; +$text['message-registrations_provisioned']['pt-br'] = "Registrations Provisioned"; +$text['message-registrations_provisioned']['pt-pt'] = "Registrations Provisioned"; +$text['message-registrations_provisioned']['ro-ro'] = "Registrations Provisioned"; +$text['message-registrations_provisioned']['ru-ru'] = "Registrations Provisioned"; +$text['message-registrations_provisioned']['sv-se'] = "Registrations Provisioned"; +$text['message-registrations_provisioned']['uk-ua'] = "Registrations Provisioned"; + +$text['message-registrations_rebooted']['en-us'] = "Registrations Rebooted"; +$text['message-registrations_rebooted']['ar-eg'] = "Registrations Rebooted"; +$text['message-registrations_rebooted']['de-at'] = "Registrations Rebooted"; +$text['message-registrations_rebooted']['de-ch'] = "Registrations Rebooted"; +$text['message-registrations_rebooted']['de-de'] = "Registrations Rebooted"; +$text['message-registrations_rebooted']['es-cl'] = "Registrations Rebooted"; +$text['message-registrations_rebooted']['es-mx'] = "Registrations Rebooted"; +$text['message-registrations_rebooted']['fr-ca'] = "Registrations Rebooted"; +$text['message-registrations_rebooted']['fr-fr'] = "Registrations Rebooted"; +$text['message-registrations_rebooted']['he-il'] = "Registrations Rebooted"; +$text['message-registrations_rebooted']['it-it'] = "Registrations Rebooted"; +$text['message-registrations_rebooted']['nl-nl'] = "Registrations Rebooted"; +$text['message-registrations_rebooted']['pl-pl'] = "Registrations Rebooted"; +$text['message-registrations_rebooted']['pt-br'] = "Registrations Rebooted"; +$text['message-registrations_rebooted']['pt-pt'] = "Registrations Rebooted"; +$text['message-registrations_rebooted']['ro-ro'] = "Registrations Rebooted"; +$text['message-registrations_rebooted']['ru-ru'] = "Registrations Rebooted"; +$text['message-registrations_rebooted']['sv-se'] = "Registrations Rebooted"; +$text['message-registrations_rebooted']['uk-ua'] = "Registrations Rebooted"; + +$text['confirm-unregister']['en-us'] = "Do you really want to UNREGISTER these?"; +$text['confirm-unregister']['ar-eg'] = "Do you really want to UNREGISTER these?"; +$text['confirm-unregister']['de-at'] = "Do you really want to UNREGISTER these?"; +$text['confirm-unregister']['de-ch'] = "Do you really want to UNREGISTER these?"; +$text['confirm-unregister']['de-de'] = "Do you really want to UNREGISTER these?"; +$text['confirm-unregister']['es-cl'] = "Do you really want to UNREGISTER these?"; +$text['confirm-unregister']['es-mx'] = "Do you really want to UNREGISTER these?"; +$text['confirm-unregister']['fr-ca'] = "Do you really want to UNREGISTER these?"; +$text['confirm-unregister']['fr-fr'] = "Do you really want to UNREGISTER these?"; +$text['confirm-unregister']['he-il'] = "Do you really want to UNREGISTER these?"; +$text['confirm-unregister']['it-it'] = "Do you really want to UNREGISTER these?"; +$text['confirm-unregister']['nl-nl'] = "Do you really want to UNREGISTER these?"; +$text['confirm-unregister']['pl-pl'] = "Do you really want to UNREGISTER these?"; +$text['confirm-unregister']['pt-br'] = "Do you really want to UNREGISTER these?"; +$text['confirm-unregister']['pt-pt'] = "Do you really want to UNREGISTER these?"; +$text['confirm-unregister']['ro-ro'] = "Do you really want to UNREGISTER these?"; +$text['confirm-unregister']['ru-ru'] = "Do you really want to UNREGISTER these?"; +$text['confirm-unregister']['sv-se'] = "Do you really want to UNREGISTER these?"; +$text['confirm-unregister']['uk-ua'] = "Do you really want to UNREGISTER these?"; + +$text['confirm-provision']['en-us'] = "Do you really want to PROVISION these?"; +$text['confirm-provision']['ar-eg'] = "Do you really want to PROVISION these?"; +$text['confirm-provision']['de-at'] = "Do you really want to PROVISION these?"; +$text['confirm-provision']['de-ch'] = "Do you really want to PROVISION these?"; +$text['confirm-provision']['de-de'] = "Do you really want to PROVISION these?"; +$text['confirm-provision']['es-cl'] = "Do you really want to PROVISION these?"; +$text['confirm-provision']['es-mx'] = "Do you really want to PROVISION these?"; +$text['confirm-provision']['fr-ca'] = "Do you really want to PROVISION these?"; +$text['confirm-provision']['fr-fr'] = "Do you really want to PROVISION these?"; +$text['confirm-provision']['he-il'] = "Do you really want to PROVISION these?"; +$text['confirm-provision']['it-it'] = "Do you really want to PROVISION these?"; +$text['confirm-provision']['nl-nl'] = "Do you really want to PROVISION these?"; +$text['confirm-provision']['pl-pl'] = "Do you really want to PROVISION these?"; +$text['confirm-provision']['pt-br'] = "Do you really want to PROVISION these?"; +$text['confirm-provision']['pt-pt'] = "Do you really want to PROVISION these?"; +$text['confirm-provision']['ro-ro'] = "Do you really want to PROVISION these?"; +$text['confirm-provision']['ru-ru'] = "Do you really want to PROVISION these?"; +$text['confirm-provision']['sv-se'] = "Do you really want to PROVISION these?"; +$text['confirm-provision']['uk-ua'] = "Do you really want to PROVISION these?"; + +$text['confirm-reboot']['en-us'] = "Do you really want to REBOOT these?"; +$text['confirm-reboot']['ar-eg'] = "Do you really want to REBOOT these?"; +$text['confirm-reboot']['de-at'] = "Do you really want to REBOOT these?"; +$text['confirm-reboot']['de-ch'] = "Do you really want to REBOOT these?"; +$text['confirm-reboot']['de-de'] = "Do you really want to REBOOT these?"; +$text['confirm-reboot']['es-cl'] = "Do you really want to REBOOT these?"; +$text['confirm-reboot']['es-mx'] = "Do you really want to REBOOT these?"; +$text['confirm-reboot']['fr-ca'] = "Do you really want to REBOOT these?"; +$text['confirm-reboot']['fr-fr'] = "Do you really want to REBOOT these?"; +$text['confirm-reboot']['he-il'] = "Do you really want to REBOOT these?"; +$text['confirm-reboot']['it-it'] = "Do you really want to REBOOT these?"; +$text['confirm-reboot']['nl-nl'] = "Do you really want to REBOOT these?"; +$text['confirm-reboot']['pl-pl'] = "Do you really want to REBOOT these?"; +$text['confirm-reboot']['pt-br'] = "Do you really want to REBOOT these?"; +$text['confirm-reboot']['pt-pt'] = "Do you really want to REBOOT these?"; +$text['confirm-reboot']['ro-ro'] = "Do you really want to REBOOT these?"; +$text['confirm-reboot']['ru-ru'] = "Do you really want to REBOOT these?"; +$text['confirm-reboot']['sv-se'] = "Do you really want to REBOOT these?"; +$text['confirm-reboot']['uk-ua'] = "Do you really want to REBOOT these?"; + +?> \ No newline at end of file diff --git a/app/registrations/registration_reload.php b/app/registrations/registration_reload.php index 0ec1c01ec6..487578bad1 100644 --- a/app/registrations/registration_reload.php +++ b/app/registrations/registration_reload.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2008-2018 + Portions created by the Initial Developer are Copyright (C) 2008-2019 the Initial Developer. All Rights Reserved. Contributor(s): @@ -86,7 +86,7 @@ } var requestTime = function() { - var url = 'registrations.php?template=false&profile=&show='; + var url = 'registrations.php?reload&show='; new loadXmlHttp(url, 'ajax_response'); +?> \ No newline at end of file diff --git a/app/registrations/registrations.php b/app/registrations/registrations.php index 67ee17307f..a9d5f1591e 100644 --- a/app/registrations/registrations.php +++ b/app/registrations/registrations.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2008-2018 + Portions created by the Initial Developer are Copyright (C) 2008-2019 the Initial Developer. All Rights Reserved. Contributor(s): @@ -43,300 +43,189 @@ $language = new text; $text = $language->get(); -//get the http values and set them as variables - $search = $_REQUEST["search"]; +//get common submitted data + $search = $_REQUEST['search']; + $profile = $_REQUEST['profile']; -//set the format - $template = true; - if ($_REQUEST["template"] == "false" && permission_exists('registration_reload')) { - $template = false; +//define query string array + if ($search) { $qs['search'] = "&search=".urlencode($search); } + if ($profile) { $qs['profile'] = "&profile=".urlencode($profile); } + +//get posted data + if (is_array($_POST['registrations'])) { + $action = $_POST['action']; + $registrations = $_POST['registrations']; } -//show the header - if ($template) { - require_once "resources/header.php"; - $document['title'] = $text['header-registrations']; +//process posted data + if ($action != '' && is_array($registrations) && @sizeof($registrations) != 0) { + + //perform action + switch ($action) { + //unregister the registrations + case 'unregister': + $obj = new registrations; + $obj->unregister($registrations); + break; + //provision the registrations + case 'provision': + $obj = new registrations; + $obj->provision($registrations); + break; + //reboot the registrations + case 'reboot': + $obj = new registrations; + $obj->reboot($registrations); + break; + } + + //redirect + header('Location: registrations.php'.($search || $profile ? '?' : null).$qs['search'].$qs['profile']); + exit; + } -//check permissions - if (permission_exists("registration_domain") || permission_exists("registration_all") || if_group("superadmin")) { - //access granted - } - else { - echo "access denied"; - exit; - } +//get the registrations + $obj = new registrations; + $registrations = $obj->get(!$profile ? 'all' : $profile); -//add multi-lingual support - $language = new text; - $text = $language->get(); +//order the array + require_once "resources/classes/array_order.php"; + $order = new array_order(); + $registrations = $order->sort($registrations, 'sip-auth-realm', 'user'); -//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 +//get registration count + $num_rows = 0; if (is_array($registrations)) { + foreach ($registrations as $row) { + $matches = preg_grep("/".$search."/i", $row); + if ($matches != false) { + $num_rows++; + } + } + } + +//create token + $object = new token; + $token = $object->create($_SERVER['PHP_SELF']); + +//detect page reload via ajax + $reload = isset($_GET['reload']) && permission_exists('registration_reload') ? true : false; + +//define location url + $location = 'registrations'.($reload ? '_reload' : null).'.php'; + +//include the header + if (!$reload) { + $document['title'] = $text['header-registrations']; + require_once "resources/header.php"; + } + +//show the content + echo "
\n"; + echo "
".$text['header-registrations']." (".$num_rows.")
\n"; + echo "
\n"; + if (!$reload) { + echo button::create(['type'=>'button','label'=>$text['button-refresh'],'icon'=>$_SESSION['theme']['button_icon_refresh'],'link'=>$location.($qs ? '?' : null).$qs['search'].$qs['profile']]); + } + echo button::create(['type'=>'button','label'=>$text['button-unregister'],'title'=>$text['button-unregister'],'icon'=>'user-slash','style'=>'margin-left: 15px;','onclick'=>"if (confirm('".$text['confirm-unregister']."')) { list_action_set('unregister'); list_form_submit('form_list'); } else { this.blur(); return false; }"]); + echo button::create(['type'=>'button','label'=>$text['button-provision'],'title'=>$text['button-provision'],'icon'=>'fax','onclick'=>"if (confirm('".$text['confirm-provision']."')) { list_action_set('provision'); list_form_submit('form_list'); } else { this.blur(); return false; }"]); + echo button::create(['type'=>'button','label'=>$text['button-reboot'],'title'=>$text['button-reboot'],'icon'=>'power-off','onclick'=>"if (confirm('".$text['confirm-reboot']."')) { list_action_set('reboot'); list_form_submit('form_list'); } else { this.blur(); return false; }"]); + echo "\n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + + echo $text['description-registrations']."\n"; + echo "

\n"; + + echo "
\n"; + echo "\n"; + echo "\n"; + echo ""; + + 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"; + + if (is_array($registrations) && @sizeof($registrations) != 0) { $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; + foreach ($registrations as $row) { + $matches = preg_grep('/'.$search.'/i', $row); + if ($matches != false) { + $user = explode('@', $row['user']); + if ($user[1] == $_SESSION['domains'][$_SESSION['domain_uuid']]['domain_name']) { + $user = "".escape($row['user'])."".escape($user[0])."@..."; } - //unset rows that were not selected - if (!isset($row['checked'])) { - unset($registrations[$x]); + else { + $user = escape($row['user']); } - //increment the id + 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"; $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($profile) > 0 && strlen($user) > 0) { - if ($action == "unregister") { - $command = "sofia profile ".$profile." flush_inbound_reg ".$user." reboot"; - } - if (strlen($vendor) > 0 && $action == "provision" && strlen($host) > 0) { - $command = "lua app.lua event_notify ".$profile." check_sync ".$user." ".$vendor." ".$host; - } - if (strlen($vendor) > 0 && $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); - } - } } } } + unset($registrations); -//show the response - if (isset($response)) { - message::add($text['label-event']." ".escape(ucwords($cmd))."     ".$text['label-response'].escape($response)); - } + echo "
\n"; + echo " \n"; + 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']." 
\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " ".$user."".escape($row['agent'])."".escape(explode('"',$row['contact'])[1])."".escape($row['network-port'])."".escape($row['host'])."".escape($row['status'])."".escape($row['ping-time'])."".escape($row['sip_profile_name'])."\n"; + echo button::create(['type'=>'submit','title'=>$text['button-unregister'],'icon'=>'user-slash fa-fw','onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('unregister'); list_form_submit('form_list')"]); + echo button::create(['type'=>'submit','title'=>$text['button-provision'],'icon'=>'fax fa-fw','onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('provision'); list_form_submit('form_list')",'style'=>'margin-left: 0; margin-right: 0;']); + echo button::create(['type'=>'submit','title'=>$text['button-reboot'],'icon'=>'power-off fa-fw','onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('reboot'); list_form_submit('form_list')"]); + echo "
\n"; + echo "
\n"; + echo "
".$paging_controls."
\n"; -//define variables - $c = 0; - $row_style["0"] = "row_style0"; - $row_style["1"] = "row_style1"; + echo "\n"; -//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); - } + echo "\n"; //get the footer - if ($template) { + if (!$reload) { require_once "resources/footer.php"; } -?> +?> \ No newline at end of file diff --git a/app/registrations/resources/classes/registrations.php b/app/registrations/resources/classes/registrations.php index 23df699d9d..ce240214ba 100644 --- a/app/registrations/resources/classes/registrations.php +++ b/app/registrations/resources/classes/registrations.php @@ -1,22 +1,56 @@ + Portions created by the Initial Developer are Copyright (C) 2008-2019 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +//define the registrations class if (!class_exists('registrations')) { class registrations { /** - * Called when the object is created + * declare private variables + */ + private $app_name; + private $app_uuid; + private $permission_prefix; + private $list_page; + + /** + * called when the object is created */ public function __construct() { + //assign private variables + $this->app_name = 'registrations'; + $this->app_uuid = '5d9e7cd7-629e-3553-4cf5-f26e39fefa39'; + $this->permission_prefix = 'registration_'; + $this->list_page = 'registrations.php'; + } /** - * Called when there are no references to a particular object + * called when there are no references to a particular object * unset the variables used in the class */ public function __destruct() { @@ -204,13 +238,156 @@ if (!class_exists('registrations')) { return $count; } - } + /** + * unregister registrations + */ + public function unregister($registrations) { + $this->switch('unregister', $registrations); + } + + /** + * provision registrations + */ + public function provision($registrations) { + $this->switch('provision', $registrations); + } + + /** + * reboot registrations + */ + public function reboot($registrations) { + $this->switch('reboot', $registrations); + } + + /** + * switch api calls + */ + private function switch($action, $records) { + if (permission_exists($this->permission_prefix.'domain') || permission_exists($this->permission_prefix.'all') || if_group('superadmin')) { + + //add multi-lingual support + $language = new text; + $text = $language->get(); + + //validate the token + $token = new token; + if (!$token->validate($_SERVER['PHP_SELF'])) { + message::add($text['message-invalid_token'],'negative'); + header('Location: '.$this->list_page); + exit; + } + + //filter out unchecked registrations + if (is_array($records) && @sizeof($records) != 0) { + foreach($records as $record) { + if ( + $record['checked'] == 'true' && + $record['user'] != '' && + $record['profile'] != '' + ) { + $registrations[] = $record; + } + } + } + + //process checked registrations + if (is_array($registrations) && @sizeof($registrations) != 0) { + + //retrieve sip profiles list + $sql = "select sip_profile_name as name from v_sip_profiles "; + $database = new database; + $sip_profiles = $database->select($sql, null, 'all'); + unset($sql); + + //create the event socket connection + $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); + + //loop through registrations + if ($fp) { + foreach ($registrations as $registration) { + + //validate the submitted profile + if ($registration['profile'] != '' && is_array($sip_profiles) && @sizeof($sip_profiles) != 0) { + foreach ($sip_profiles as $field) { + if ($field['name'] == $registration['profile']) { + $profile = $registration['profile']; + break; + } + } + } + else { + header('Location: '.$this->list_page); + exit; + } + + //validate the submitted user + if ($registration['user'] != '') { + $user = preg_replace('#[^a-zA-Z0-9_\-\.\@]#', '', $registration['user']); + } + + //validate the submitted host + if ($registration['host'] != '') { + $host = preg_replace('#[^a-zA-Z0-9_\-\.]#', '', $registration['host']); + } + + //lookup vendor by agent + if ($registration['agent'] != '') { + $vendor = device::get_vendor_by_agent($registration['agent']); + } + + //prepare the api command + if ($profile && $user) { + switch ($action) { + case 'unregister': + $command = "sofia profile ".$profile." flush_inbound_reg ".$user." reboot"; + $response_message = $text['message-registrations_unregistered']; + break; + case 'provision': + if ($vendor && $host) { + $command = "lua app.lua event_notify ".$profile." check_sync ".$user." ".$vendor." ".$host; + $response_message = $text['message-registrations_provisioned']; + } + break; + case 'reboot': + if ($vendor && $host) { + $command = "lua app.lua event_notify ".$profile." reboot ".$user." ".$vendor." ".$host; + $response_message = $text['message-registrations_rebooted']; + } + break; + default: + header('Location: '.$this->list_page); + exit; + } + } + + //send the api command + if ($command && $fp) { + $response_api[$registration['user']]['command'] = event_socket_request($fp, "api ".$command); + $response_api[$registration['user']]['log'] = event_socket_request($fp, "api log notice ".$command); + } + + } + + //set message + if (is_array($response_api)) { + $message = $response_message; + foreach ($response_api as $registration_user => $response) { + $message .= "
\n".$registration_user.": ".$response['command']; + } + message::add($message, 'positive', '7000'); + } + + } + else { + message::add($text['error-event-socket'], 'negative', 5000); + } + + } + + } + } //method + + } //class } -/* -$obj = new registrations; -$registrations = $obj->get('all'); -print($registrations); -*/ - -?> +?> \ No newline at end of file