2015-08-13 07:09:07 +02:00
|
|
|
<?php
|
2018-06-04 02:01:10 +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
|
|
|
|
|
the Initial Developer. All Rights Reserved.
|
|
|
|
|
Contributor(s):
|
|
|
|
|
Mark J Crane <markjcrane@fusionpbx.com>
|
|
|
|
|
*/
|
2016-06-22 02:00:38 +02:00
|
|
|
|
|
|
|
|
//includes
|
|
|
|
|
require_once "root.php";
|
|
|
|
|
require_once "resources/require.php";
|
2019-07-02 01:30:03 +02:00
|
|
|
require_once "resources/check_auth.php";
|
2016-06-22 02:00:38 +02:00
|
|
|
|
|
|
|
|
//check permissions
|
2019-07-02 01:30:03 +02:00
|
|
|
if (!permission_exists('access_control_add') && !permission_exists('access_control_edit')) {
|
|
|
|
|
echo "access denied"; exit;
|
2016-06-22 02:00:38 +02:00
|
|
|
}
|
2015-08-13 07:09:07 +02:00
|
|
|
|
|
|
|
|
//add multi-lingual support
|
2015-12-21 08:52:40 +01:00
|
|
|
$language = new text;
|
|
|
|
|
$text = $language->get();
|
2015-08-13 07:09:07 +02:00
|
|
|
|
|
|
|
|
//action add or update
|
2019-07-02 01:30:03 +02:00
|
|
|
if (is_uuid($_REQUEST["id"])) {
|
2015-08-13 07:09:07 +02:00
|
|
|
$action = "update";
|
2019-07-02 01:30:03 +02:00
|
|
|
$access_control_uuid = $_REQUEST["id"];
|
2015-08-13 07:09:07 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$action = "add";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//get http post variables and set them to php variables
|
|
|
|
|
if (count($_POST)>0) {
|
2019-07-03 00:57:04 +02:00
|
|
|
$access_control_name = $_POST["access_control_name"];
|
|
|
|
|
$access_control_default = $_POST["access_control_default"];
|
|
|
|
|
$access_control_description = $_POST["access_control_description"];
|
2015-08-13 07:09:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
|
|
|
|
|
|
2019-10-22 01:03:59 +02:00
|
|
|
//delete the access control
|
|
|
|
|
if (permission_exists('access_control_delete')) {
|
|
|
|
|
if ($_POST['action'] == 'delete' && is_uuid($access_control_uuid)) {
|
|
|
|
|
//prepare
|
|
|
|
|
$array[0]['checked'] = 'true';
|
|
|
|
|
$array[0]['uuid'] = $access_control_uuid;
|
|
|
|
|
//delete
|
|
|
|
|
$obj = new access_controls;
|
|
|
|
|
$obj->delete($array);
|
|
|
|
|
//redirect
|
|
|
|
|
header('Location: access_controls.php');
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-04 19:34:41 +02:00
|
|
|
//get the primary key
|
|
|
|
|
if ($action == "update") {
|
2019-07-03 00:57:04 +02:00
|
|
|
$access_control_uuid = $_POST["access_control_uuid"];
|
2017-07-04 19:34:41 +02:00
|
|
|
}
|
2015-08-13 07:09:07 +02:00
|
|
|
|
2019-09-18 05:32:33 +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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-13 07:09:07 +02:00
|
|
|
//check for all required data
|
2017-07-04 19:34:41 +02:00
|
|
|
$msg = '';
|
2015-08-13 07:09:07 +02:00
|
|
|
if (strlen($access_control_name) == 0) { $msg .= $text['message-required']." ".$text['label-access_control_name']."<br>\n"; }
|
|
|
|
|
if (strlen($access_control_default) == 0) { $msg .= $text['message-required']." ".$text['label-access_control_default']."<br>\n"; }
|
2015-08-14 02:50:00 +02:00
|
|
|
//if (strlen($access_control_description) == 0) { $msg .= $text['message-required']." ".$text['label-access_control_description']."<br>\n"; }
|
2015-08-13 07:09:07 +02:00
|
|
|
if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
|
|
|
|
|
require_once "resources/header.php";
|
|
|
|
|
require_once "resources/persist_form_var.php";
|
|
|
|
|
echo "<div align='center'>\n";
|
|
|
|
|
echo "<table><tr><td>\n";
|
|
|
|
|
echo $msg."<br />";
|
|
|
|
|
echo "</td></tr></table>\n";
|
|
|
|
|
persistformvar($_POST);
|
|
|
|
|
echo "</div>\n";
|
|
|
|
|
require_once "resources/footer.php";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//add or update the database
|
|
|
|
|
if ($_POST["persistformvar"] != "true") {
|
2019-07-02 01:30:03 +02:00
|
|
|
$execute = false;
|
2015-08-13 07:09:07 +02:00
|
|
|
|
2019-07-02 01:30:03 +02:00
|
|
|
if ($action == "add" && permission_exists('access_control_add')) {
|
|
|
|
|
$execute = true;
|
|
|
|
|
$access_control_uuid = uuid();
|
2017-07-04 19:34:41 +02:00
|
|
|
|
2019-10-22 01:03:59 +02:00
|
|
|
//set the message
|
2018-08-31 05:09:01 +02:00
|
|
|
message::add($text['message-add']);
|
2019-10-22 01:03:59 +02:00
|
|
|
|
|
|
|
|
//set redirect url
|
|
|
|
|
$redirect_url = 'access_control_edit.php?id='.$access_control_uuid;
|
2019-07-02 01:30:03 +02:00
|
|
|
}
|
2015-08-13 07:09:07 +02:00
|
|
|
|
|
|
|
|
if ($action == "update" && permission_exists('access_control_edit')) {
|
2019-07-02 01:30:03 +02:00
|
|
|
$execute = true;
|
|
|
|
|
|
2019-10-22 01:03:59 +02:00
|
|
|
//set the message
|
2019-07-02 01:30:03 +02:00
|
|
|
message::add($text['message-update']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($execute) {
|
|
|
|
|
$array['access_controls'][0]['access_control_uuid'] = $access_control_uuid;
|
|
|
|
|
$array['access_controls'][0]['access_control_name'] = $access_control_name;
|
|
|
|
|
$array['access_controls'][0]['access_control_default'] = $access_control_default;
|
|
|
|
|
$array['access_controls'][0]['access_control_description'] = $access_control_description;
|
|
|
|
|
$database = new database;
|
|
|
|
|
$database->app_name = 'access_control';
|
|
|
|
|
$database->app_uuid = '1416a250-f6e1-4edc-91a6-5c9b883638fd';
|
|
|
|
|
$database->save($array);
|
|
|
|
|
unset($array);
|
2015-08-13 07:09:07 +02:00
|
|
|
|
2017-07-04 19:15:47 +02:00
|
|
|
//clear the cache
|
|
|
|
|
$cache = new cache;
|
|
|
|
|
$cache->delete("configuration:acl.conf");
|
|
|
|
|
|
2017-07-04 19:34:41 +02:00
|
|
|
//create the event socket connection
|
|
|
|
|
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
|
2017-07-04 19:35:55 +02:00
|
|
|
if ($fp) { event_socket_request($fp, "api reloadacl"); }
|
2019-07-02 01:30:03 +02:00
|
|
|
}
|
2017-07-04 19:34:41 +02:00
|
|
|
|
2019-07-02 01:30:03 +02:00
|
|
|
//redirect the user
|
2019-10-22 01:03:59 +02:00
|
|
|
header('Location: '.($redirect_url ? $redirect_url : 'access_controls.php'));
|
|
|
|
|
exit;
|
|
|
|
|
}
|
2015-08-13 07:09:07 +02:00
|
|
|
|
2019-10-22 01:03:59 +02:00
|
|
|
}
|
2015-08-13 07:09:07 +02:00
|
|
|
|
|
|
|
|
//pre-populate the form
|
2019-07-02 01:30:03 +02:00
|
|
|
if (count($_GET) > 0 && $_POST["persistformvar"] != "true" && is_uuid($_GET["id"])) {
|
|
|
|
|
$access_control_uuid = $_GET["id"];
|
2015-08-13 07:09:07 +02:00
|
|
|
$sql = "select * from v_access_controls ";
|
2019-07-02 01:30:03 +02:00
|
|
|
$sql .= "where access_control_uuid = :access_control_uuid ";
|
|
|
|
|
$parameters['access_control_uuid'] = $access_control_uuid;
|
|
|
|
|
$database = new database;
|
|
|
|
|
$row = $database->select($sql, $parameters, 'row');
|
|
|
|
|
if (is_array($row) && sizeof($row)) {
|
2015-08-13 07:09:07 +02:00
|
|
|
$access_control_name = $row["access_control_name"];
|
|
|
|
|
$access_control_default = $row["access_control_default"];
|
|
|
|
|
$access_control_description = $row["access_control_description"];
|
|
|
|
|
}
|
2019-07-02 01:30:03 +02:00
|
|
|
unset ($sql, $parameters, $row);
|
2015-08-13 07:09:07 +02:00
|
|
|
}
|
|
|
|
|
|
2019-09-18 05:32:33 +02:00
|
|
|
//create token
|
|
|
|
|
$object = new token;
|
|
|
|
|
$token = $object->create($_SERVER['PHP_SELF']);
|
|
|
|
|
|
2015-08-13 07:09:07 +02:00
|
|
|
//show the header
|
2020-01-06 20:11:08 +01:00
|
|
|
$document['title'] = $text['title-access_control'];
|
2015-08-13 07:09:07 +02:00
|
|
|
require_once "resources/header.php";
|
|
|
|
|
|
|
|
|
|
//show the content
|
2020-02-07 19:13:34 +01:00
|
|
|
echo "<form name='frm' id='frm' method='post'>\n";
|
|
|
|
|
|
|
|
|
|
echo "<div class='action_bar' id='action_bar'>\n";
|
|
|
|
|
echo " <div class='heading'><b>".$text['title-access_control']."</b></div>\n";
|
|
|
|
|
echo " <div class='actions'>\n";
|
2020-03-05 08:05:45 +01:00
|
|
|
echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','collapse'=>'hide-xs','link'=>'access_controls.php']);
|
2020-02-07 19:13:34 +01:00
|
|
|
if ($action == 'update' && permission_exists('access_control_delete')) {
|
2020-03-05 17:46:38 +01:00
|
|
|
echo button::create(['type'=>'submit','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'name'=>'action','value'=>'delete','collapse'=>'hide-xs','onclick'=>"if (confirm('".$text['confirm-delete']."')) { document.getElementById('frm').submit(); } else { this.blur(); return false; }",'style'=>'margin-right: 15px;']);
|
2019-10-22 01:03:59 +02:00
|
|
|
}
|
2020-03-05 08:05:45 +01:00
|
|
|
echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','collapse'=>'hide-xs']);
|
2020-02-07 19:13:34 +01:00
|
|
|
echo " </div>\n";
|
|
|
|
|
echo " <div style='clear: both;'></div>\n";
|
|
|
|
|
echo "</div>\n";
|
|
|
|
|
|
|
|
|
|
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
|
2015-08-13 07:09:07 +02:00
|
|
|
|
|
|
|
|
echo "<tr>\n";
|
2020-02-07 19:13:34 +01:00
|
|
|
echo "<td width='30%' class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
|
2015-08-13 07:09:07 +02:00
|
|
|
echo " ".$text['label-access_control_name']."\n";
|
|
|
|
|
echo "</td>\n";
|
2020-02-07 19:13:34 +01:00
|
|
|
echo "<td width='70%' class='vtable' align='left'>\n";
|
2018-06-30 02:28:09 +02:00
|
|
|
echo " <input class='formfld' type='text' name='access_control_name' maxlength='255' value=\"".escape($access_control_name)."\">\n";
|
2015-08-13 07:09:07 +02:00
|
|
|
echo "<br />\n";
|
|
|
|
|
echo $text['description-access_control_name']."\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "</tr>\n";
|
|
|
|
|
|
|
|
|
|
echo "<tr>\n";
|
2019-10-20 00:59:17 +02:00
|
|
|
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
|
2015-08-13 07:09:07 +02:00
|
|
|
echo " ".$text['label-access_control_default']."\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "<td class='vtable' align='left'>\n";
|
|
|
|
|
echo " <select class='formfld' name='access_control_default'>\n";
|
2016-03-11 12:47:28 +01:00
|
|
|
if ($access_control_default == "allow") {
|
2015-08-13 07:09:07 +02:00
|
|
|
echo " <option value='allow' selected='selected'>".$text['label-allow']."</option>\n";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo " <option value='allow'>".$text['label-allow']."</option>\n";
|
|
|
|
|
}
|
2016-03-11 12:47:28 +01:00
|
|
|
if ($access_control_default == "deny") {
|
2015-08-13 07:09:07 +02:00
|
|
|
echo " <option value='deny' selected='selected'>".$text['label-deny']."</option>\n";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
echo " <option value='deny'>".$text['label-deny']."</option>\n";
|
|
|
|
|
}
|
|
|
|
|
echo " </select>\n";
|
|
|
|
|
echo "<br />\n";
|
|
|
|
|
echo $text['description-access_control_default']."\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "</tr>\n";
|
|
|
|
|
|
|
|
|
|
echo "<tr>\n";
|
2015-08-14 02:50:00 +02:00
|
|
|
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
|
2015-08-13 07:09:07 +02:00
|
|
|
echo " ".$text['label-access_control_description']."\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "<td class='vtable' align='left'>\n";
|
2018-06-30 02:28:09 +02:00
|
|
|
echo " <input class='formfld' type='text' name='access_control_description' maxlength='255' value=\"".escape($access_control_description)."\">\n";
|
2015-08-13 07:09:07 +02:00
|
|
|
echo "<br />\n";
|
|
|
|
|
echo $text['description-access_control_description']."\n";
|
|
|
|
|
echo "</td>\n";
|
|
|
|
|
echo "</tr>\n";
|
2020-02-07 19:13:34 +01:00
|
|
|
|
|
|
|
|
echo "</table>";
|
|
|
|
|
echo "<br /><br />";
|
|
|
|
|
|
2015-08-13 07:09:07 +02:00
|
|
|
if ($action == "update") {
|
2020-02-07 19:13:34 +01:00
|
|
|
echo "<input type='hidden' name='access_control_uuid' value='".escape($access_control_uuid)."'>\n";
|
2015-08-13 07:09:07 +02:00
|
|
|
}
|
2020-02-07 19:13:34 +01:00
|
|
|
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
|
|
|
|
|
|
2015-08-13 07:09:07 +02:00
|
|
|
echo "</form>";
|
|
|
|
|
|
|
|
|
|
if ($action == "update") {
|
|
|
|
|
require "access_control_nodes.php";
|
2016-03-28 16:41:55 +02:00
|
|
|
echo "<br><br>";
|
2015-08-13 07:09:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//include the footer
|
|
|
|
|
require_once "resources/footer.php";
|
2018-06-30 02:28:09 +02:00
|
|
|
|
2019-10-22 01:03:59 +02:00
|
|
|
?>
|