Copyright (C) 2008-2016 All Rights Reserved.
*/
//includes
require_once "root.php";
require_once "resources/require.php";
//check permissions
require_once "resources/check_auth.php";
if (permission_exists('device_add') || permission_exists('device_edit')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//check for duplicates
if ($_GET["check"] == 'duplicate') {
//mac address
if ($_GET["mac"] != '' && $_GET["mac"] != "000000000000") {
$sql = "select ";
$sql .= "d2.domain_name ";
$sql .= "from ";
$sql .= "v_devices as d1, ";
$sql .= "v_domains as d2 ";
$sql .= "where ";
$sql .= "d1.domain_uuid = d2.domain_uuid and ";
$sql .= "d1.device_mac_address = '".check_str($_GET["mac"])."' ";
if ($_GET["device_uuid"] != '') {
$sql .= " and d1.device_uuid <> '".check_str($_GET["device_uuid"])."' ";
}
$prep_statement = $db->prepare($sql);
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
if ($row['domain_name'] != '') {
echo $text['message-duplicate'].((if_group("superadmin") && $_SESSION["domain_name"] != $row["domain_name"]) ? ": ".$row["domain_name"] : null);
}
}
unset($prep_statement);
}
//username
if ($_GET['username'] != '') {
$sql = "select ";
$sql .= "d2.domain_name, ";
$sql .= "d1.device_mac_address ";
$sql .= "from ";
$sql .= "v_devices as d1, ";
$sql .= "v_domains as d2 ";
$sql .= "where ";
$sql .= "d1.domain_uuid = d2.domain_uuid and ";
$sql .= "d1.device_username = '".check_str($_GET["username"])."' ";
if ($_GET['domain_uuid'] != '') {
$sql .= "and d2.domain_uuid = '".check_str($_GET['domain_uuid'])."' ";
}
if ($_GET['device_uuid'] != '') {
$sql .= "and d1.device_uuid <> '".check_str($_GET["device_uuid"])."' ";
}
$prep_statement = $db->prepare($sql);
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
if ($row['domain_name'] != '') {
echo $text['message-duplicate_username'].((if_group("superadmin")) ? ": ".format_mac($row['device_mac_address']).(($_SESSION["domain_name"] != $row["domain_name"]) ? " (".$row["domain_name"].")" : null) : null);
}
}
unset($prep_statement);
}
exit;
}
//include the device class
require_once "app/devices/resources/classes/device.php";
//action add or update
if (isset($_REQUEST["id"])) {
$action = "update";
$device_uuid = check_str($_REQUEST["id"]);
}
else {
$action = "add";
}
//get total device count from the database, check limit, if defined
if ($action == 'add') {
if ($_SESSION['limit']['devices']['numeric'] != '') {
$sql = "select count(*) as num_rows from v_devices where domain_uuid = '".$_SESSION['domain_uuid']."' ";
$prep_statement = $db->prepare($sql);
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
$total_devices = $row['num_rows'];
}
unset($prep_statement, $row);
if ($total_devices >= $_SESSION['limit']['devices']['numeric']) {
$_SESSION['message_mood'] = 'negative';
$_SESSION['message'] = $text['message-maximum_devices'].' '.$_SESSION['limit']['devices']['numeric'];
header('Location: devices.php');
return;
}
}
}
//get http post variables and set them to php variables
if (count($_POST) > 0) {
//device mac address
if (permission_exists('device_mac_address')) {
$device_mac_address = check_str($_POST["device_mac_address"]);
$device_mac_address = strtolower(preg_replace('#[^a-fA-F0-9./]#', '', $device_mac_address));
$_POST["device_mac_address"] = $device_mac_address;
}
else {
$sql = "select * from v_devices ";
$sql .= "where device_uuid = '$device_uuid' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach ($result as &$row) {
$device_mac_address = $row["device_mac_address"];
$_POST["device_mac_address"] = $device_mac_address;
}
unset ($prep_statement);
}
//get assigned user
$device_user_uuid = check_str($_POST["device_user_uuid"]);
//devices
$device_label = check_str($_POST["device_label"]);
$device_vendor = check_str($_POST["device_vendor"]);
$device_uuid_alternate = check_str($_POST["device_uuid_alternate"]);
$device_model = check_str($_POST["device_model"]);
$device_firmware_version = check_str($_POST["device_firmware_version"]);
$device_enabled = check_str($_POST["device_enabled"]);
$device_template = check_str($_POST["device_template"]);
$device_description = check_str($_POST["device_description"]);
//lines
$line_number = check_str($_POST["line_number"]);
$server_address = check_str($_POST["server_address"]);
$outbound_proxy_primary = check_str($_POST["outbound_proxy_primary"]);
$outbound_proxy_secondary = check_str($_POST["outbound_proxy_secondary"]);
$display_name = check_str($_POST["display_name"]);
$user_id = check_str($_POST["user_id"]);
$auth_id = check_str($_POST["auth_id"]);
$password = check_str($_POST["password"]);
//profile
$device_profile_uuid = check_str($_POST["device_profile_uuid"]);
//keys
$device_key_category = check_str($_POST["device_key_category"]);
$device_key_id = check_str($_POST["device_key_id"]);
$device_key_type = check_str($_POST["device_key_type"]);
$device_key_line = check_str($_POST["device_key_line"]);
$device_key_value = check_str($_POST["device_key_value"]);
$device_key_extension = check_str($_POST["device_key_extension"]);
$device_key_label = check_str($_POST["device_key_label"]);
//settings
//$device_setting_category = check_str($_POST["device_setting_category"]);
$device_setting_subcategory = check_str($_POST["device_setting_subcategory"]);
//$device_setting_name = check_str($_POST["device_setting_name"]);
$device_setting_value = check_str($_POST["device_setting_value"]);
$device_setting_enabled = check_str($_POST["device_setting_enabled"]);
$device_setting_description = check_str($_POST["device_setting_description"]);
}
//use the mac address to get the vendor
if (strlen($device_vendor) == 0) {
$device_vendor = device::get_vendor($device_mac_address);
}
//add or update the database
if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
//check for all required data
$msg = '';
//if (strlen($device_mac_address) == 0) { $msg .= $text['message-required'].$text['label-extension']."
\n"; }
//if (strlen($device_label) == 0) { $msg .= "Please provide: Label
\n"; }
//if (strlen($device_vendor) == 0) { $msg .= "Please provide: Vendor
\n"; }
//if (strlen($device_model) == 0) { $msg .= "Please provide: Model
\n"; }
//if (strlen($device_firmware_version) == 0) { $msg .= "Please provide: Firmware Version
\n"; }
//if (strlen($device_enabled) == 0) { $msg .= "Please provide: Enabled
\n"; }
//if (strlen($device_template) == 0) { $msg .= "Please provide: Template
\n"; }
//if (strlen($device_username) == 0) { $msg .= "Please provide: Username
\n"; }
//if (strlen($device_password) == 0) { $msg .= "Please provide: Password
\n"; }
//if (strlen($device_description) == 0) { $msg .= "Please provide: Description
\n"; }
if (strlen($msg) > 0) {
require_once "resources/header.php";
require_once "resources/persist_form_var.php";
echo "
| \n";
echo $msg." "; echo " |