fusionpbx/app/access_controls/access_controls.php

262 lines
10 KiB
PHP
Raw Permalink Normal View History

<?php
2018-06-04 01:59:16 +02:00
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2018-2024
2018-06-04 01:59:16 +02:00
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
2016-06-22 02:00:38 +02:00
2022-10-11 00:35:14 +02:00
//includes files
Use magic constant dir (#6711) * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ to load only functions.php * replace spaces with tab character * update dirname command to use levels instead of nesting * use magic constant __DIR__ * update dirname command to use levels instead of nesting * Update access_control_edit.php * Update access_control_import.php * Update access_controls.php * Update dnd.php * Update access_controls_reload.php * Update call_center_agents.php * Update call_center_agents.php * Update fax_queue.php * Update login.php * Update pdo.php * Update pdo_vm.php * Update switch.php * Update index.php * Update css.php * Update v_mailto.php * Update fax_to_email.php --------- Co-authored-by: FusionPBX <markjcrane@gmail.com>
2023-06-15 19:28:23 +02:00
require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php";
2016-06-22 02:00:38 +02:00
//check permissions
2020-07-23 21:31:43 +02:00
if (permission_exists('access_control_view')) {
//access granted
}
else {
echo "access denied";
exit;
2016-06-22 02:00:38 +02:00
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//define variable
$search = '';
2024-05-02 14:58:58 +02:00
//add the settings object
$settings = new settings(["domain_uuid" => $_SESSION['domain_uuid'], "user_uuid" => $_SESSION['user_uuid']]);
//set from session variables
2024-05-02 14:58:58 +02:00
$list_row_edit_button = $settings->get('theme', 'list_row_edit_button', 'false');
2020-07-23 21:31:43 +02:00
//get the http post data
if (!empty($_POST['access_controls'])) {
$action = $_POST['action'] ?? '';
$search = $_POST['search'] ?? '';
2019-10-20 00:59:17 +02:00
$access_controls = $_POST['access_controls'];
}
2019-11-30 22:18:00 +01:00
//process the http post data by action
if (!empty($action) && !empty($access_controls) && count($access_controls) > 0) {
2020-07-23 21:31:43 +02:00
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: access_controls.php');
exit;
}
//prepare the array
2023-06-09 21:40:20 +02:00
$x = 0;
foreach ($access_controls as $row) {
$array['access_controls'][$x]['checked'] = $row['checked'] ?? null;
2020-07-23 21:31:43 +02:00
$array['access_controls'][$x]['access_control_uuid'] = $row['access_control_uuid'];
$x++;
}
//prepare the database object
$database = new database;
$database->app_name = 'access_controls';
$database->app_uuid = '1416a250-f6e1-4edc-91a6-5c9b883638fd';
//send the array to the database class
2019-11-30 19:12:41 +01:00
switch ($action) {
case 'copy':
if (permission_exists('access_control_add')) {
2020-07-23 21:31:43 +02:00
$database->copy($array);
}
break;
case 'toggle':
if (permission_exists('access_control_edit')) {
$database->toggle($array);
2019-11-30 19:12:41 +01:00
}
break;
case 'delete':
if (permission_exists('access_control_delete')) {
2020-07-23 21:31:43 +02:00
$database->delete($array);
2019-11-30 19:12:41 +01:00
}
break;
2019-10-20 00:59:17 +02:00
}
2019-11-30 19:12:41 +01:00
2020-07-23 21:31:43 +02:00
//redirect the user
header('Location: access_controls.php'.(!empty($search) ? '?search='.urlencode($search) : null));
2019-11-30 19:12:41 +01:00
exit;
2019-10-20 00:59:17 +02:00
}
2020-07-23 21:31:43 +02:00
//get order and order by
$order_by = $_GET["order_by"] ?? '';
$order = $_GET["order"] ?? '';
2020-07-23 21:31:43 +02:00
//add the search
if (isset($_GET["search"])) {
$search = strtolower($_GET["search"]);
2019-10-20 00:59:17 +02:00
$parameters['search'] = '%'.$search.'%';
}
2020-07-23 21:31:43 +02:00
//get the count
$sql = "select count(access_control_uuid) ";
$sql .= "from v_access_controls ";
if (!empty($search)) {
2020-07-23 21:31:43 +02:00
$sql .= "where (";
$sql .= " lower(access_control_name) like :search ";
$sql .= " or lower(access_control_default) like :search ";
$sql .= " or lower(access_control_description) like :search ";
$sql .= ") ";
2019-10-20 00:59:17 +02:00
}
2019-05-28 04:00:19 +02:00
$database = new database;
$num_rows = $database->select($sql, $parameters ?? null, 'column');
2016-06-22 02:00:38 +02:00
//get the list
2020-07-23 21:31:43 +02:00
$sql = "select ";
$sql .= "access_control_uuid, ";
$sql .= "access_control_name, ";
$sql .= "access_control_default, ";
$sql .= "access_control_description ";
$sql .= "from v_access_controls ";
if (!empty($search)) {
2020-07-23 21:31:43 +02:00
$sql .= "where (";
$sql .= " lower(access_control_name) like :search ";
$sql .= " or lower(access_control_default) like :search ";
$sql .= " or lower(access_control_description) like :search ";
$sql .= ") ";
}
$sql .= order_by($order_by, $order, 'access_control_name', 'asc');
2019-05-28 04:00:19 +02:00
$database = new database;
$access_controls = $database->select($sql, $parameters ?? null, 'all');
2019-10-20 00:59:17 +02:00
unset($sql, $parameters);
2016-06-22 02:00:38 +02:00
2019-10-20 00:59:17 +02:00
//create token
$object = new token;
$token = $object->create($_SERVER['PHP_SELF']);
2020-07-23 21:31:43 +02:00
//additional includes
2020-01-06 20:11:08 +01:00
$document['title'] = $text['title-access_controls'];
2019-10-20 00:59:17 +02:00
require_once "resources/header.php";
2016-06-22 02:00:38 +02:00
//show the content
2019-10-20 00:59:17 +02:00
echo "<div class='action_bar' id='action_bar'>\n";
2024-09-07 00:43:42 +02:00
echo " <div class='heading'><b>".$text['title-access_controls']."</b><div class='count'>".number_format($num_rows)."</div></div>\n";
2019-10-25 00:31:14 +02:00
echo " <div class='actions'>\n";
echo button::create(['label'=>$text['button-reload'],'icon'=>$_SESSION['theme']['button_icon_reload'],'type'=>'button','id'=>'button_reload','link'=>'access_controls_reload.php'.(!empty($search) ? '?search='.urlencode($search) : null),'style'=>'margin-right: 15px;']);
2019-10-20 00:59:17 +02:00
if (permission_exists('access_control_add')) {
2020-07-23 21:31:43 +02:00
echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','name'=>'btn_add','link'=>'access_control_edit.php']);
2019-10-20 00:59:17 +02:00
}
if (permission_exists('access_control_add') && $access_controls) {
2020-07-23 21:31:43 +02:00
echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'id'=>'btn_copy','name'=>'btn_copy','style'=>'display:none;','onclick'=>"modal_open('modal-copy','btn_copy');"]);
2019-10-20 00:59:17 +02:00
}
if (permission_exists('access_control_delete') && $access_controls) {
2020-07-23 21:31:43 +02:00
echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'btn_delete','style'=>'display:none;','onclick'=>"modal_open('modal-delete','btn_delete');"]);
2019-10-20 00:59:17 +02:00
}
echo "<form id='form_search' class='inline' method='get'>\n";
echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown=''>";
echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search']);
//echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'access_controls.php','style'=>($search == '' ? 'display: none;' : null)]);
2019-10-25 00:28:09 +02:00
echo " </form>\n";
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
2019-10-20 00:59:17 +02:00
echo "</div>\n";
2020-03-26 02:26:34 +01:00
if (permission_exists('access_control_add') && $access_controls) {
echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('copy'); list_form_submit('form_list');"])]);
}
if (permission_exists('access_control_delete') && $access_controls) {
echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); list_form_submit('form_list');"])]);
}
2020-07-26 02:25:05 +02:00
echo $text['title_description-access_controls']."\n";
echo "<br /><br />\n";
2019-10-20 00:59:17 +02:00
echo "<form id='form_list' method='post'>\n";
echo "<input type='hidden' id='action' name='action' value=''>\n";
echo "<input type='hidden' name='search' value=\"".escape($search)."\">\n";
echo "<div class='card'>\n";
2019-10-20 00:59:17 +02:00
echo "<table class='list'>\n";
echo "<tr class='list-header'>\n";
2020-07-23 21:31:43 +02:00
if (permission_exists('access_control_add') || permission_exists('access_control_edit') || permission_exists('access_control_delete')) {
echo " <th class='checkbox'>\n";
echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle(); checkbox_on_change(this);' ".(!empty($access_controls) ?: "style='visibility: hidden;'").">\n";
echo " </th>\n";
}
echo th_order_by('access_control_name', $text['label-access_control_name'], $order_by, $order);
echo th_order_by('access_control_default', $text['label-access_control_default'], $order_by, $order);
2020-07-23 21:31:43 +02:00
echo " <th class='hide-sm-dn'>".$text['label-access_control_description']."</th>\n";
if (permission_exists('access_control_edit') && $list_row_edit_button == 'true') {
2019-10-20 00:59:17 +02:00
echo " <td class='action-button'>&nbsp;</td>\n";
}
2019-10-20 00:59:17 +02:00
echo "</tr>\n";
if (!empty($access_controls) && count($access_controls) > 0) {
2019-10-20 03:12:37 +02:00
$x = 0;
2020-07-23 21:31:43 +02:00
foreach ($access_controls as $row) {
$list_row_url = '';
if (permission_exists('access_control_edit')) {
$list_row_url = "access_control_edit.php?id=".urlencode($row['access_control_uuid']);
if ($row['domain_uuid'] != $_SESSION['domain_uuid'] && permission_exists('domain_select')) {
$list_row_url .= '&domain_uuid='.urlencode($row['domain_uuid']).'&domain_change=true';
}
}
2019-10-20 00:59:17 +02:00
echo "<tr class='list-row' href='".$list_row_url."'>\n";
2020-07-23 21:31:43 +02:00
if (permission_exists('access_control_add') || permission_exists('access_control_edit') || permission_exists('access_control_delete')) {
echo " <td class='checkbox'>\n";
2020-07-23 21:31:43 +02:00
echo " <input type='checkbox' name='access_controls[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"checkbox_on_change(this); if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
echo " <input type='hidden' name='access_controls[$x][access_control_uuid]' value='".escape($row['access_control_uuid'])."' />\n";
echo " </td>\n";
}
2020-07-23 21:31:43 +02:00
echo " <td>\n";
if (permission_exists('access_control_edit')) {
echo " <a href='".$list_row_url."' title=\"".$text['button-edit']."\">".escape($row['access_control_name'])."</a>\n";
}
else {
echo " ".escape($row['access_control_name']);
}
echo " </td>\n";
2019-10-20 00:59:17 +02:00
echo " <td>".escape($row['access_control_default'])."</td>\n";
2020-07-23 21:31:43 +02:00
echo " <td class='description overflow hide-sm-dn'>".escape($row['access_control_description'])."</td>\n";
if (permission_exists('access_control_edit') && $list_row_edit_button == 'true') {
2020-07-23 21:31:43 +02:00
echo " <td class='action-button'>\n";
2019-10-20 00:59:17 +02:00
echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
echo " </td>\n";
}
echo "</tr>\n";
2019-10-20 00:59:17 +02:00
$x++;
}
unset($access_controls);
}
echo "</table>\n";
echo "</div>\n";
echo "<br />\n";
2019-10-20 00:59:17 +02:00
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
echo "</form>\n";
//include the footer
require_once "resources/footer.php";
2016-06-22 02:00:38 +02:00
2020-07-26 02:25:05 +02:00
?>