diff --git a/app/gateways/app_languages.php b/app/gateways/app_languages.php index 837d557206..cdfe7c5b97 100644 --- a/app/gateways/app_languages.php +++ b/app/gateways/app_languages.php @@ -81,6 +81,86 @@ $text['message-maximum_gateways']['ru-ru'] = "Максимум Шлюзов:"; $text['message-maximum_gateways']['sv-se'] = "Max antal Gateways:"; $text['message-maximum_gateways']['uk-ua'] = "Максимальна кількість шлюзів"; +$text['message-gateway_started']['en-us'] = "Gateway(s) Started"; +$text['message-gateway_started']['ar-eg'] = "Gateway(s) Started"; +$text['message-gateway_started']['de-at'] = "Gateway(s) Started"; +$text['message-gateway_started']['de-ch'] = "Gateway(s) Started"; +$text['message-gateway_started']['de-de'] = "Gateway(s) Started"; +$text['message-gateway_started']['es-cl'] = "Gateway(s) Started"; +$text['message-gateway_started']['es-mx'] = "Gateway(s) Started"; +$text['message-gateway_started']['fr-ca'] = "Gateway(s) Started"; +$text['message-gateway_started']['fr-fr'] = "Gateway(s) Started"; +$text['message-gateway_started']['he-il'] = "Gateway(s) Started"; +$text['message-gateway_started']['it-it'] = "Gateway(s) Started"; +$text['message-gateway_started']['nl-nl'] = "Gateway(s) Started"; +$text['message-gateway_started']['pl-pl'] = "Gateway(s) Started"; +$text['message-gateway_started']['pt-br'] = "Gateway(s) Started"; +$text['message-gateway_started']['pt-pt'] = "Gateway(s) Started"; +$text['message-gateway_started']['ro-ro'] = "Gateway(s) Started"; +$text['message-gateway_started']['ru-ru'] = "Gateway(s) Started"; +$text['message-gateway_started']['sv-se'] = "Gateway(s) Started"; +$text['message-gateway_started']['uk-ua'] = "Gateway(s) Started"; + +$text['message-gateway_stopped']['en-us'] = "Gateway(s) Stopped"; +$text['message-gateway_stopped']['ar-eg'] = "Gateway(s) Stopped"; +$text['message-gateway_stopped']['de-at'] = "Gateway(s) Stopped"; +$text['message-gateway_stopped']['de-ch'] = "Gateway(s) Stopped"; +$text['message-gateway_stopped']['de-de'] = "Gateway(s) Stopped"; +$text['message-gateway_stopped']['es-cl'] = "Gateway(s) Stopped"; +$text['message-gateway_stopped']['es-mx'] = "Gateway(s) Stopped"; +$text['message-gateway_stopped']['fr-ca'] = "Gateway(s) Stopped"; +$text['message-gateway_stopped']['fr-fr'] = "Gateway(s) Stopped"; +$text['message-gateway_stopped']['he-il'] = "Gateway(s) Stopped"; +$text['message-gateway_stopped']['it-it'] = "Gateway(s) Stopped"; +$text['message-gateway_stopped']['nl-nl'] = "Gateway(s) Stopped"; +$text['message-gateway_stopped']['pl-pl'] = "Gateway(s) Stopped"; +$text['message-gateway_stopped']['pt-br'] = "Gateway(s) Stopped"; +$text['message-gateway_stopped']['pt-pt'] = "Gateway(s) Stopped"; +$text['message-gateway_stopped']['ro-ro'] = "Gateway(s) Stopped"; +$text['message-gateway_stopped']['ru-ru'] = "Gateway(s) Stopped"; +$text['message-gateway_stopped']['sv-se'] = "Gateway(s) Stopped"; +$text['message-gateway_stopped']['uk-ua'] = "Gateway(s) Stopped"; + +$text['confirm-start_gateways']['en-us'] = "Are you sure you wish to START these gateways?"; +$text['confirm-start_gateways']['ar-eg'] = "Are you sure you wish to START these gateways?"; +$text['confirm-start_gateways']['de-at'] = "Are you sure you wish to START these gateways?"; +$text['confirm-start_gateways']['de-ch'] = "Are you sure you wish to START these gateways?"; +$text['confirm-start_gateways']['de-de'] = "Are you sure you wish to START these gateways?"; +$text['confirm-start_gateways']['es-cl'] = "Are you sure you wish to START these gateways?"; +$text['confirm-start_gateways']['es-mx'] = "Are you sure you wish to START these gateways?"; +$text['confirm-start_gateways']['fr-ca'] = "Are you sure you wish to START these gateways?"; +$text['confirm-start_gateways']['fr-fr'] = "Are you sure you wish to START these gateways?"; +$text['confirm-start_gateways']['he-il'] = "Are you sure you wish to START these gateways?"; +$text['confirm-start_gateways']['it-it'] = "Are you sure you wish to START these gateways?"; +$text['confirm-start_gateways']['nl-nl'] = "Are you sure you wish to START these gateways?"; +$text['confirm-start_gateways']['pl-pl'] = "Are you sure you wish to START these gateways?"; +$text['confirm-start_gateways']['pt-br'] = "Are you sure you wish to START these gateways?"; +$text['confirm-start_gateways']['pt-pt'] = "Are you sure you wish to START these gateways?"; +$text['confirm-start_gateways']['ro-ro'] = "Are you sure you wish to START these gateways?"; +$text['confirm-start_gateways']['ru-ru'] = "Are you sure you wish to START these gateways?"; +$text['confirm-start_gateways']['sv-se'] = "Are you sure you wish to START these gateways?"; +$text['confirm-start_gateways']['uk-ua'] = "Are you sure you wish to START these gateways?"; + +$text['confirm-stop_gateways']['en-us'] = "Are you sure you wish to STOP these gateways?"; +$text['confirm-stop_gateways']['ar-eg'] = "Are you sure you wish to STOP these gateways?"; +$text['confirm-stop_gateways']['de-at'] = "Are you sure you wish to STOP these gateways?"; +$text['confirm-stop_gateways']['de-ch'] = "Are you sure you wish to STOP these gateways?"; +$text['confirm-stop_gateways']['de-de'] = "Are you sure you wish to STOP these gateways?"; +$text['confirm-stop_gateways']['es-cl'] = "Are you sure you wish to STOP these gateways?"; +$text['confirm-stop_gateways']['es-mx'] = "Are you sure you wish to STOP these gateways?"; +$text['confirm-stop_gateways']['fr-ca'] = "Are you sure you wish to STOP these gateways?"; +$text['confirm-stop_gateways']['fr-fr'] = "Are you sure you wish to STOP these gateways?"; +$text['confirm-stop_gateways']['he-il'] = "Are you sure you wish to STOP these gateways?"; +$text['confirm-stop_gateways']['it-it'] = "Are you sure you wish to STOP these gateways?"; +$text['confirm-stop_gateways']['nl-nl'] = "Are you sure you wish to STOP these gateways?"; +$text['confirm-stop_gateways']['pl-pl'] = "Are you sure you wish to STOP these gateways?"; +$text['confirm-stop_gateways']['pt-br'] = "Are you sure you wish to STOP these gateways?"; +$text['confirm-stop_gateways']['pt-pt'] = "Are you sure you wish to STOP these gateways?"; +$text['confirm-stop_gateways']['ro-ro'] = "Are you sure you wish to STOP these gateways?"; +$text['confirm-stop_gateways']['ru-ru'] = "Are you sure you wish to STOP these gateways?"; +$text['confirm-stop_gateways']['sv-se'] = "Are you sure you wish to STOP these gateways?"; +$text['confirm-stop_gateways']['uk-ua'] = "Are you sure you wish to STOP these gateways?"; + $text['label-username']['en-us'] = "Username"; $text['label-username']['ar-eg'] = "اسم المستخدم"; $text['label-username']['de-at'] = "Benutzername"; //copied from de-de @@ -1361,24 +1441,4 @@ $text['description-auth_username']['ru-ru'] = "Введите имя польз $text['description-auth_username']['sv-se'] = "Ange 'uth-username' här."; $text['description-auth_username']['uk-ua'] = "Enter the auth-username here."; -$text['confirm-copy']['en-us'] = "Do you really want to copy this?"; -$text['confirm-copy']['ar-eg'] = ""; -$text['confirm-copy']['de-at'] = "Wollen Sie das wirklich kopieren?"; //copied from de-de -$text['confirm-copy']['de-ch'] = "Wollen Sie das wirklich kopieren?"; //copied from de-de -$text['confirm-copy']['de-de'] = "Wollen Sie das wirklich kopieren?"; -$text['confirm-copy']['es-cl'] = "¿Realmente desea copiar esto?"; -$text['confirm-copy']['es-mx'] = "¿Realmente desea copiar esto?"; //copied from es-cl -$text['confirm-copy']['fr-ca'] = "Voulez-vous vraiment copier cela?"; //copied from fr-fr -$text['confirm-copy']['fr-fr'] = "Voulez-vous vraiment copier cela?"; -$text['confirm-copy']['he-il'] = "? בטוח שאתה רוצה להעתיק"; -$text['confirm-copy']['it-it'] = "Vuoi veramente copiarlo?"; -$text['confirm-copy']['nl-nl'] = ""; -$text['confirm-copy']['pl-pl'] = "Czy na pewno chcesz to skopiować?"; -$text['confirm-copy']['pt-br'] = "Deseja realmente copiar isto?"; //copied from pt-pt -$text['confirm-copy']['pt-pt'] = "Deseja realmente copiar isto?"; -$text['confirm-copy']['ro-ro'] = "Chiar doriți să copiați acest lucru?"; -$text['confirm-copy']['ru-ru'] = "Вы действительно хотите это скопировать?"; -$text['confirm-copy']['sv-se'] = "Vill du verkligen kopiera detta?"; -$text['confirm-copy']['uk-ua'] = "Ви дійсно бажаєте це копіювати?"; - -?> +?> \ No newline at end of file diff --git a/app/gateways/gateways.php b/app/gateways/gateways.php index ce20d193cf..cc2ba23c96 100644 --- a/app/gateways/gateways.php +++ b/app/gateways/gateways.php @@ -28,6 +28,7 @@ require_once "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; + require_once "resources/paging.php"; //check permissions if (permission_exists('gateway_view')) { @@ -42,38 +43,77 @@ $language = new text; $text = $language->get(); -//additional includes - require_once "resources/header.php"; - require_once "resources/paging.php"; +//get posted data + if (is_array($_POST['gateways'])) { + $action = $_POST['action']; + $search = $_POST['search']; + $gateways = $_POST['gateways']; + } -//get variables used to control the order - $order_by = $_GET["order_by"]; - $order = $_GET["order"]; +//copy the gateways + if (permission_exists('gateway_add')) { + if ($action == 'copy' && is_array($gateways) && @sizeof($gateways) != 0) { + //copy + $obj = new gateways; + $obj->copy($gateways); + //redirect + header('Location: gateways.php'.($search != '' ? '?search='.urlencode($search) : null)); + exit; + } + } + +//toggle the gateways + if (permission_exists('gateway_edit')) { + if ($action == 'toggle' && is_array($gateways) && @sizeof($gateways) != 0) { + //toggle + $obj = new gateways; + $obj->toggle($gateways); + //redirect + header('Location: gateways.php'.($search != '' ? '?search='.urlencode($search) : null)); + exit; + } + } + +//delete the gateways + if (permission_exists('gateway_delete')) { + if ($action == 'delete' && is_array($gateways) && @sizeof($gateways) != 0) { + //delete + $obj = new gateways; + $obj->delete($gateways); + //redirect + header('Location: gateways.php'.($search != '' ? '?search='.urlencode($search) : null)); + exit; + } + } //connect to event socket $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); - if ($fp) { - if (strlen($_GET["a"]) > 0 && is_uuid($_GET["gateway"])) { - $profile = $_GET["profile"]; - if (strlen($profile) == 0) { - $profile = 'external'; - } - if ($_GET["a"] == "stop") { - $gateway_uuid = $_GET["gateway"]; - $cmd = 'api sofia profile '.$profile.' killgw '.$gateway_uuid; - $response = trim(event_socket_request($fp, $cmd)); - $msg = 'Stop Gateway:
'.$response.'
'; - } - if ($_GET["a"] == "start") { - $gateway_uuid = $_GET["gateway"]; - $cmd = 'api sofia profile '.$profile.' rescan'; - $response = trim(event_socket_request($fp, $cmd)); - $msg = 'Start Gateway:
'.$response.'
'; - } - } - if (!function_exists('switch_gateway_status')) { - function switch_gateway_status($gateway_uuid, $result_type = 'xml') { +//control the gateways + if ($fp && is_array($gateways) && @sizeof($gateways) != 0) { + if ($action == 'start') { + //start + $obj = new gateways; + $obj->start($gateways); + //redirect + header('Location: gateways.php'.($search != '' ? '?search='.urlencode($search) : null)); + exit; + } + if ($action == 'stop') { + //stop + $obj = new gateways; + $obj->stop($gateways); + //redirect + header('Location: gateways.php'.($search != '' ? '?search='.urlencode($search) : null)); + exit; + } + } + +//gateway status function + if (!function_exists('switch_gateway_status')) { + function switch_gateway_status($gateway_uuid, $result_type = 'xml') { + global $fp; + if ($fp) { $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); $cmd = 'api sofia xmlstatus gateway '.$gateway_uuid; $response = trim(event_socket_request($fp, $cmd)); @@ -86,47 +126,52 @@ } } -//show the content - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
".$text['title-gateways'].""; - if (permission_exists('gateway_all')) { - if ($_GET['show'] == 'all') { - echo " "; - } - else { - echo " \n"; - } +//get order and order by + $order_by = $_GET["order_by"]; + $order = $_GET["order"]; + +//add the search term + $search = strtolower($_GET["search"]); + if (strlen($search) > 0) { + $sql_search = "and ("; + $sql_search .= "lower(gateway) like :search "; + $sql_search .= "or lower(username) like :search "; + $sql_search .= "or lower(auth_username) like :search "; + $sql_search .= "or lower(from_user) like :search "; + $sql_search .= "or lower(from_domain) like :search "; + $sql_search .= "or lower(from_domain) like :search "; + $sql_search .= "or lower(proxy) like :search "; + $sql_search .= "or lower(register_proxy) like :search "; + $sql_search .= "or lower(outbound_proxy) like :search "; + $sql_search .= "or lower(description) like :search "; + $sql_search .= ") "; + $parameters['search'] = '%'.$search.'%'; } - echo " \n"; - echo "
\n"; - echo " \n"; - echo " ".$text['description-gateway']."\n"; - echo " \n"; - echo "
\n"; - echo "
\n"; //get total gateway count from the database - $sql = "select count(*) from v_gateways "; + $sql = "select count(*) from v_gateways where true "; if (!($_GET['show'] == "all" && permission_exists('gateway_all'))) { - $sql .= "where (domain_uuid = :domain_uuid ".(permission_exists('gateway_domain') ? " or domain_uuid is null " : null).") "; + $sql .= "and (domain_uuid = :domain_uuid ".(permission_exists('gateway_domain') ? " or domain_uuid is null " : null).") "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; } $database = new database; $total_gateways = $database->select($sql, $parameters, 'column'); + $num_rows = $total_gateways; + +//prepare to page the results + if ($sql_search) { + $sql .= $sql_search; + $database = new database; + $num_rows = $database->select($sql, $parameters, 'column'); + } //prepare to page the results $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; - $param = "&order_by=".escape($order_by)."&order=".escape($order); - if (!isset($_GET['page'])) { $_GET['page'] = 0; } - $_GET['page'] = check_str($_GET['page']); - list($paging_controls, $rows_per_page, $var_3) = paging($total_gateways, $param, $rows_per_page); + $param = "&search=".$search; + $param .= $order_by ? "&order_by=".$order_by."&order=".$order : null; + $page = is_numeric($_GET['page']) ? $_GET['page'] : 0; + list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page); + list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true); $offset = $rows_per_page * $_GET['page']; //get the list @@ -137,73 +182,148 @@ $gateways = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); - $c = 0; - $row_style["0"] = "row_style0"; - $row_style["1"] = "row_style1"; +//create token + $object = new token; + $token = $object->create($_SERVER['PHP_SELF']); - echo "\n"; - echo "\n"; +//additional includes + require_once "resources/header.php"; + +//show the content + echo "
\n"; + echo "
".$text['title-gateways']." (".$num_rows.")
\n"; + echo "
\n"; + if (permission_exists('gateway_edit') && $gateways) { + echo button::create(['type'=>'button','label'=>$text['button-stop'],'icon'=>$_SESSION['theme']['button_icon_stop'],'onclick'=>"if (confirm('".$text['confirm-stop_gateways']."')) { list_action_set('stop'); list_form_submit('form_list'); } else { this.blur(); return false; }"]); + echo button::create(['type'=>'button','label'=>$text['button-start'],'icon'=>$_SESSION['theme']['button_icon_start'],'onclick'=>"if (confirm('".$text['confirm-start_gateways']."')) { list_action_set('start'); list_form_submit('form_list'); } else { this.blur(); return false; }"]); + } + echo button::create(['type'=>'button','label'=>$text['button-refresh'],'icon'=>$_SESSION['theme']['button_icon_refresh'],'style'=>'margin-right: 15px;','link'=>'gateways.php']); + if (permission_exists('gateway_add')) { + echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'link'=>'gateway_edit.php']); + } + if (permission_exists('gateway_add') && $gateways) { + echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'onclick'=>"if (confirm('".$text['confirm-copy']."')) { list_action_set('copy'); list_form_submit('form_list'); } else { this.blur(); return false; }"]); + } + if (permission_exists('gateway_edit') && $gateways) { + echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'onclick'=>"if (confirm('".$text['confirm-toggle']."')) { list_action_set('toggle'); list_form_submit('form_list'); } else { this.blur(); return false; }"]); + } + if (permission_exists('gateway_delete') && $gateways) { + echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'onclick'=>"if (confirm('".$text['confirm-delete']."')) { list_action_set('delete'); list_form_submit('form_list'); } else { this.blur(); return false; }"]); + } + echo "\n"; + if (permission_exists('gateway_all')) { + if ($_GET['show'] == 'all') { + echo " "; + } + else { + echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$_SESSION['theme']['button_icon_all'],'link'=>'?show=all']); + } + } + echo ""; + echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search','style'=>($search != '' ? 'display: none;' : null)]); + echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'gateways.php','style'=>($search == '' ? 'display: none;' : null)]); + if ($paging_controls_mini != '') { + echo "".$paging_controls_mini.""; + } + echo " \n"; + echo "
\n"; + echo "
\n"; + echo "
\n"; + + echo $text['description-gateway']."\n"; + echo "

\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + + echo "
\n"; + echo "\n"; + if (permission_exists('gateway_add') || permission_exists('gateway_edit') || permission_exists('gateway_delete')) { + echo " \n"; + } if ($_GET['show'] == "all" && permission_exists('gateway_all')) { echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, $param); } echo th_order_by('gateway', $text['label-gateway'], $order_by, $order); echo th_order_by('context', $text['label-context'], $order_by, $order); if ($fp) { - echo "\n"; - echo "\n"; + echo "\n"; + if (permission_exists('gateway_edit')) { + echo "\n"; + } echo "\n"; } - echo th_order_by('hostname', $text['label-hostname'], $order_by, $order); - echo th_order_by('enabled', $text['label-enabled'], $order_by, $order); - echo th_order_by('description', $text['label-description'], $order_by, $order); - echo "\n"; } - echo "\n"; echo "\n"; - if (is_array($gateways)) { + if (is_array($gateways) && @sizeof($gateways) != 0) { + $x = 0; foreach($gateways as $row) { - $tr_link = (permission_exists('gateway_edit')) ? "href='gateway_edit.php?id=".escape($row['gateway_uuid'])."'" : null; - echo "\n"; + if (permission_exists('gateway_edit')) { + $list_row_url = "gateway_edit.php?id=".urlencode($row['gateway_uuid']); + } + echo "\n"; + if (permission_exists('gateway_add') || permission_exists('gateway_edit') || permission_exists('gateway_delete')) { + echo " \n"; + } if ($_GET['show'] == "all" && permission_exists('gateway_all')) { - if (strlen($_SESSION['domains'][$row['domain_uuid']]['domain_name']) > 0) { - $domain = $_SESSION['domains'][$row['domain_uuid']]['domain_name']; + echo " \n"; + echo "\n"; } - echo " \n"; - echo " \n"; + echo " \n"; + echo " \n"; if ($fp) { if ($row["enabled"] == "true") { $response = switch_gateway_status($row["gateway_uuid"]); if ($response == "Invalid Gateway!") { //not running - echo " \n"; - echo " \n"; - echo " \n"; + echo " \n"; + if (permission_exists('gateway_edit')) { + echo " \n"; +// echo " \n"; + } + echo " \n"; } else { //running try { $xml = new SimpleXMLElement($response); $state = $xml->state; - echo " \n"; - echo " \n"; - echo " \n"; //REGED, NOREG, UNREGED + echo " \n"; + if (permission_exists('gateway_edit')) { + echo " \n"; +// echo " \n"; + } + echo " \n"; //REGED, NOREG, UNREGED } catch(Exception $e) { //echo $e->getMessage(); @@ -211,41 +331,44 @@ } } else { - echo " \n"; - echo " \n"; - echo " \n"; + echo " \n"; + if (permission_exists('gateway_edit')) { + echo " \n"; + } + echo " \n"; } - echo " \n"; - if ($row["enabled"] == "true") { - echo " \n"; - } - else { - echo " \n"; - } - echo " \n"; - echo " \n"; - echo "\n"; } - $c = $c ? 0 : 1; + echo " \n"; + if (permission_exists('gateway_edit')) { + echo " \n"; + echo " \n"; + if (permission_exists('gateway_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { + echo " \n"; + } + echo "\n"; + $x++; } } - unset($gateways, $row); + unset($gateways); - echo "\n"; echo "
\n"; + echo " \n"; + echo " ".$text['label-status']."".$text['label-action']."".$text['label-status']."".$text['label-action']."".$text['label-state'].""; - if (permission_exists('gateway_add')) { - if ($_SESSION['limit']['gateways']['numeric'] == '' || ($_SESSION['limit']['gateways']['numeric'] != '' && $total_gateways < $_SESSION['limit']['gateways']['numeric'])) { - echo "".$v_link_label_add.""; - } + echo th_order_by('hostname', $text['label-hostname'], $order_by, $order, null, "class='hide-sm-dn'"); + echo th_order_by('enabled', $text['label-enabled'], $order_by, $order, null, "class='center'"); + echo th_order_by('description', $text['label-description'], $order_by, $order, null, "class='hide-sm-dn'"); + if (permission_exists('gateway_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { + echo "  
\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " "; + if (is_uuid($row['domain_uuid'])) { + echo escape($_SESSION['domains'][$row['domain_uuid']]['domain_name']); } else { - $domain = $text['label-global']; + echo $text['label-global']; } - echo " ".escape($domain).""; + echo " "; if (permission_exists('gateway_edit')) { - echo "".escape($row["gateway"]).""; + echo "".escape($row['gateway']).""; } else { - echo $row["gateway"]; + echo escape($row['gateway']); } - echo "".escape($row["context"])."".escape($row["context"])."".$text['label-status-stopped']."".$text['label-action-start']." ".$text['label-status-stopped']."".$text['label-action-start']." ".$text['label-status-running']."".$text['label-action-stop']."".escape($state)."".$text['label-status-running']."".$text['label-action-stop']."".escape($state)."      ".escape($row["hostname"])."".$text['label-true']."".$text['label-false']."".escape($row["description"])." "; - if (permission_exists('gateway_edit')) { - echo "$v_link_label_edit"; - } - if (permission_exists('gateway_delete')) { - echo "$v_link_label_delete"; - } - echo "
".escape($row["hostname"]).""; + echo $text['label-'.$row['enabled']]; + } + echo " ".escape($row["description"])." "; + echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]); + echo "
\n"; echo "
\n"; + echo "
".$paging_controls."
\n"; - echo $paging_controls."\n"; - echo "

\n"; + echo "\n"; + + echo "\n"; //include the footer require_once "resources/footer.php"; -?> +?> \ No newline at end of file diff --git a/app/gateways/resources/classes/gateways.php b/app/gateways/resources/classes/gateways.php new file mode 100644 index 0000000000..171ae28b0c --- /dev/null +++ b/app/gateways/resources/classes/gateways.php @@ -0,0 +1,579 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2019 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +//define the gateways class +if (!class_exists('gateways')) { + class gateways { + + /** + * declare private variables + */ + private $app_name; + private $app_uuid; + private $permission_prefix; + private $list_page; + private $table; + private $uuid_prefix; + private $toggle_field; + private $toggle_values; + + /** + * called when the object is created + */ + public function __construct() { + + //assign private variables + $this->app_name = 'gateways'; + $this->app_uuid = '297ab33e-2c2f-8196-552c-f3567d2caaf8'; + $this->permission_prefix = 'gateway_'; + $this->list_page = 'gateways.php'; + $this->table = 'gateways'; + $this->uuid_prefix = 'gateway_'; + $this->toggle_field = 'enabled'; + $this->toggle_values = ['true','false']; + + } + + /** + * called when there are no references to a particular object + * unset the variables used in the class + */ + public function __destruct() { + foreach ($this as $key => $value) { + unset($this->$key); + } + } + + /** + * start gateways + */ + public function start($records) { + if (permission_exists($this->permission_prefix.'edit')) { + + //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; + } + + //start the checked gateways + if (is_array($records) && @sizeof($records) != 0) { + + //filter out unchecked gateways, build where clause for below + foreach($records as $record) { + if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { + $record_uuids[] = $this->uuid_prefix."uuid = '".$record['uuid']."'"; + } + } + + //get necessary gateway details + if (is_array($record_uuids) && @sizeof($record_uuids) != 0) { + $sql = "select ".$this->uuid_prefix."uuid as uuid, gateway, profile, enabled from v_".$this->table." "; + $sql .= "where (domain_uuid = :domain_uuid ".(permission_exists('gateway_domain') ? " or domain_uuid is null " : null).") "; + $sql .= "and ( ".implode(' or ', $record_uuids)." ) "; + $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $database = new database; + $rows = $database->select($sql, $parameters, 'all'); + if (is_array($rows) && @sizeof($rows) != 0) { + foreach ($rows as $row) { + $gateways[$row['uuid']]['name'] = $row['gateway']; + $gateways[$row['uuid']]['profile'] = $row['profile']; + $gateways[$row['uuid']]['enabled'] = $row['enabled']; + } + } + unset($sql, $parameters, $rows, $row); + } + + if (is_array($gateways) && @sizeof($gateways) != 0) { + //create the event socket connection + $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); + + if ($fp) { + //start gateways + foreach ($gateways as $gateway_uuid => $gateway) { + if ($gateway['enabled'] == 'true') { + $cmd = 'api sofia profile '.$gateway['profile'].' rescan'; + $responses[$gateway_uuid]['gateway'] = $gateway['name']; + $responses[$gateway_uuid]['message'] = trim(event_socket_request($fp, $cmd)); + } + } + //set message + if (is_array($responses) && @sizeof($responses) != 0) { + $message = $text['message-gateway_started']; + foreach ($responses as $response) { + $message .= "
".$response['gateway'].": ".$response['message']; + } + message::add($message, 'positive', 7000); + } + } + } + } + + } + } + + /** + * stop gateways + */ + public function stop($records) { + if (permission_exists($this->permission_prefix.'edit')) { + + //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; + } + + //stop the checked gateways + if (is_array($records) && @sizeof($records) != 0) { + + //filter out unchecked gateways, build where clause for below + foreach($records as $record) { + if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { + $record_uuids[] = $this->uuid_prefix."uuid = '".$record['uuid']."'"; + } + } + + //get necessary gateway details + if (is_array($record_uuids) && @sizeof($record_uuids) != 0) { + $sql = "select ".$this->uuid_prefix."uuid as uuid, gateway, profile, enabled from v_".$this->table." "; + $sql .= "where (domain_uuid = :domain_uuid ".(permission_exists('gateway_domain') ? " or domain_uuid is null " : null).") "; + $sql .= "and ( ".implode(' or ', $record_uuids)." ) "; + $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $database = new database; + $rows = $database->select($sql, $parameters, 'all'); + if (is_array($rows) && @sizeof($rows) != 0) { + foreach ($rows as $row) { + $gateways[$row['uuid']]['name'] = $row['gateway']; + $gateways[$row['uuid']]['profile'] = $row['profile']; + $gateways[$row['uuid']]['enabled'] = $row['enabled']; + } + } + unset($sql, $parameters, $rows, $row); + } + + if (is_array($gateways) && @sizeof($gateways) != 0) { + //create the event socket connection + $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); + + if ($fp) { + //stop gateways + foreach ($gateways as $gateway_uuid => $gateway) { + if ($gateway['enabled'] == 'true') { + $cmd = 'api sofia profile '.$gateway['profile'].' killgw '.$gateway_uuid; + $responses[$gateway_uuid]['gateway'] = $gateway['name']; + $responses[$gateway_uuid]['message'] = trim(event_socket_request($fp, $cmd)); + } + } + //set message + if (is_array($responses) && @sizeof($responses) != 0) { + $message = $text['message-gateway_stopped']; + foreach ($responses as $response) { + $message .= "
".$response['gateway'].": ".$response['message']; + } + message::add($message, 'positive', 7000); + } + } + } + } + + } + } + + /** + * delete records + */ + public function delete($records) { + if (permission_exists($this->permission_prefix.'delete')) { + + //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; + } + + //delete multiple records + if (is_array($records) && @sizeof($records) != 0) { + + //filter out unchecked gateways, build where clause for below + foreach ($records as $record) { + if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { + $record_uuids[] = $this->uuid_prefix."uuid = '".$record['uuid']."'"; + } + } + + //get necessary gateway details + if (is_array($record_uuids) && @sizeof($record_uuids) != 0) { + $sql = "select ".$this->uuid_prefix."uuid as uuid, gateway, profile from v_".$this->table." "; + $sql .= "where (domain_uuid = :domain_uuid ".(permission_exists('gateway_domain') ? " or domain_uuid is null " : null).") "; + $sql .= "and ( ".implode(' or ', $record_uuids)." ) "; + $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $database = new database; + $rows = $database->select($sql, $parameters, 'all'); + if (is_array($rows) && @sizeof($rows) != 0) { + foreach ($rows as $row) { + $gateways[$row['uuid']]['name'] = $row['gateway']; + $gateways[$row['uuid']]['profile'] = $row['profile']; + } + } + unset($sql, $parameters, $rows, $row); + } + + //create the event socket connection + if (!$fp) { + $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); + } + + //loop through gateways + $x = 0; + foreach ($gateways as $gateway_uuid => $gateway) { + + //remove gateway from session variable + unset($_SESSION['gateways'][$gateway_uuid]); + + //remove the xml file (if any) + if ($_SESSION['switch']['sip_profiles']['dir'] != '') { + $gateway_xml_file = $_SESSION['switch']['sip_profiles']['dir']."/".$gateway['profile']."/v_".$gateway_uuid.".xml"; + if (file_exists($gateway_xml_file)) { + unlink($gateway_xml_file); + } + } + + //send the api command to stop the gateway + $cmd = 'api sofia profile '.$gateway['profile'].' killgw '.$gateway_uuid; + $response = event_socket_request($fp, $cmd); + unset($cmd); + + //build delete array + $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $gateway_uuid; + $x++; + + } + + //delete the checked rows + if (is_array($array) && @sizeof($array) != 0) { + + //execute delete + $database = new database; + $database->app_name = $this->app_name; + $database->app_uuid = $this->app_uuid; + $database->delete($array); + unset($array); + + //syncrhonize configuration + save_gateway_xml(); + + //clear the cache + $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); + $hostname = trim(event_socket_request($fp, 'api switchname')); + $cache = new cache; + $cache->delete("configuration:sofia.conf:".$hostname); + + //create the event socket connection + if (!$fp) { + $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); + } + + //rescan the sip profile to look for new or stopped gateways + if ($fp) { + //get distinct profiles from gateways + foreach ($gateways as $gateway) { + $array[] = $gateway['profile']; + } + $profiles = array_unique($array); + + //send the api command to rescan each profile + foreach ($profiles as $profile) { + $cmd = 'api sofia profile '.$profile.' rescan'; + $response = event_socket_request($fp, $cmd); + } + unset($cmd); + + //close the connection + fclose($fp); + } + usleep(1000); + + //clear the apply settings reminder + $_SESSION["reload_xml"] = false; + + //set message + message::add($text['message-delete']); + } + unset($records); + } + } + } + + /** + * toggle records + */ + public function toggle($records) { + if (permission_exists($this->permission_prefix.'edit')) { + + //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; + } + + //toggle the checked records + if (is_array($records) && @sizeof($records) != 0) { + + //get current toggle state + foreach($records as $record) { + if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { + $record_uuids[] = $this->uuid_prefix."uuid = '".$record['uuid']."'"; + } + } + if (is_array($record_uuids) && @sizeof($record_uuids) != 0) { + $sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as state, gateway, profile from v_".$this->table." "; + $sql .= "where (domain_uuid = :domain_uuid ".(permission_exists('gateway_domain') ? " or domain_uuid is null " : null).") "; + $sql .= "and ( ".implode(' or ', $record_uuids)." ) "; + $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $database = new database; + $rows = $database->select($sql, $parameters, 'all'); + if (is_array($rows) && @sizeof($rows) != 0) { + foreach ($rows as $row) { + $gateways[$row['uuid']]['state'] = $row['state']; + $gateways[$row['uuid']]['name'] = $row['gateway']; + $gateways[$row['uuid']]['profile'] = $row['profile']; + } + } + unset($sql, $parameters, $rows, $row); + } + + //build update array + $x = 0; + foreach($gateways as $uuid => $gateway) { + $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid; + $array[$this->table][$x][$this->toggle_field] = $gateway['state'] == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0]; + $x++; + } + + //save the changes + if (is_array($array) && @sizeof($array) != 0) { + + //save the array + $database = new database; + $database->app_name = $this->app_name; + $database->app_uuid = $this->app_uuid; + $database->save($array); + unset($array); + + //update gateway session variables or remove xml files (if necessary) + foreach ($gateways as $gateway_uuid => $gateway) { + if ($gateway['state'] == 'true') { + $_SESSION['gateways'][$gateway_uuid] = $gateway['name']; + } + else { + unset($_SESSION['gateways'][$gateway_uuid]); + + //remove the xml file (if any) + if ($_SESSION['switch']['sip_profiles']['dir'] != '') { + $gateway_xml_file = $_SESSION['switch']['sip_profiles']['dir']."/".$gateway['profile']."/v_".$gateway_uuid.".xml"; + if (file_exists($gateway_xml_file)) { + unlink($gateway_xml_file); + } + } + } + } + + //syncrhonize configuration + save_gateway_xml(); + + //clear the cache + $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); + $hostname = trim(event_socket_request($fp, 'api switchname')); + $cache = new cache; + $cache->delete("configuration:sofia.conf:".$hostname); + + //create the event socket connection + if (!$fp) { + $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); + } + + //rescan the sip profile to look for new or stopped gateways + if ($fp) { + //get distinct profiles from gateways + foreach ($gateways as $gateway) { + $array[] = $gateway['profile']; + } + $profiles = array_unique($array); + + //send the api command to rescan each profile + foreach ($profiles as $profile) { + $cmd = 'api sofia profile '.$profile.' rescan'; + $response = event_socket_request($fp, $cmd); + } + unset($cmd); + + //close the connection + fclose($fp); + } + usleep(1000); + + //clear the apply settings reminder + $_SESSION["reload_xml"] = false; + + //set message + message::add($text['message-toggle']); + } + unset($records, $gateways); + } + + } + } + + /** + * copy records + */ + public function copy($records) { + if (permission_exists($this->permission_prefix.'add')) { + + //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; + } + + //copy the checked records + if (is_array($records) && @sizeof($records) != 0) { + + //get checked records + foreach($records as $record) { + if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { + $record_uuids[] = $this->uuid_prefix."uuid = '".$record['uuid']."'"; + } + } + + //create insert array from existing data + if (is_array($record_uuids) && @sizeof($record_uuids) != 0) { + $sql = "select * from v_".$this->table." "; + $sql .= "where (domain_uuid = :domain_uuid ".(permission_exists('gateway_domain') ? " or domain_uuid is null " : null).") "; + $sql .= "and ( ".implode(' or ', $record_uuids)." ) "; + $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $database = new database; + $rows = $database->select($sql, $parameters, 'all'); + if (is_array($rows) && @sizeof($rows) != 0) { + foreach ($rows as $x => $row) { + $primary_uuid = uuid(); + + //copy data + $array[$this->table][$x] = $row; + + //overwrite + $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $primary_uuid; + $array[$this->table][$x]['description'] = trim($row['description'].' ('.$text['label-copy'].')'); + unset($array[$this->table][$x]['channels']); + + //defaults + if (strlen($row['expire_seconds']) == 0) { + $array[$this->table][$x]['expire_seconds'] = '800'; + } + if (strlen($row['retry_seconds']) == 0) { + $array[$this->table][$x]['retry_seconds'] = '30'; + } + + //array of new gateways + if ($row['enabled'] == 'true') { + $gateways[$primary_uuid]['name'] = $row['gateway']; + } + } + } + unset($sql, $parameters, $rows, $row); + } + + //save the changes and set the message + if (is_array($array) && @sizeof($array) != 0) { + + //save the array + $database = new database; + $database->app_name = $this->app_name; + $database->app_uuid = $this->app_uuid; + $database->save($array); + unset($array); + + //add new gateways to session variables + if (is_array($gateways) && @sizeof($gateways) != 0) { + foreach ($gateways as $gateway_uuid -> $gateway) { + $_SESSION['gateways'][$gateway_uuid] = $gateway['name']; + } + } + + //synchronize the xml config + save_gateway_xml(); + + //clear the cache + $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']); + $hostname = trim(event_socket_request($fp, 'api switchname')); + $cache = new cache; + $cache->delete("configuration:sofia.conf:".$hostname); + + //set message + message::add($text['message-copy']); + + } + unset($records, $gateways); + } + + } + } + + } +} + +?> \ No newline at end of file diff --git a/themes/default/app_config.php b/themes/default/app_config.php index 6f6a30b2fa..9d64724a7a 100644 --- a/themes/default/app_config.php +++ b/themes/default/app_config.php @@ -1918,6 +1918,14 @@ $apps[$x]['default_settings'][$y]['default_setting_enabled'] = "true"; $apps[$x]['default_settings'][$y]['default_setting_description'] = ""; $y++; + $apps[$x]['default_settings'][$y]['default_setting_uuid'] = "7e5d0132-a3a8-40b1-9540-f8b7df4cf8ca"; + $apps[$x]['default_settings'][$y]['default_setting_category'] = "theme"; + $apps[$x]['default_settings'][$y]['default_setting_subcategory'] = "button_icon_start"; + $apps[$x]['default_settings'][$y]['default_setting_name'] = "text"; + $apps[$x]['default_settings'][$y]['default_setting_value'] = "fas fa-play"; + $apps[$x]['default_settings'][$y]['default_setting_enabled'] = "true"; + $apps[$x]['default_settings'][$y]['default_setting_description'] = ""; + $y++; $apps[$x]['default_settings'][$y]['default_setting_uuid'] = "ccfc5c6a-4946-496d-b1aa-45dfb35588f7"; $apps[$x]['default_settings'][$y]['default_setting_category'] = "theme"; $apps[$x]['default_settings'][$y]['default_setting_subcategory'] = "button_icon_stop";