Copyright (C) 2008-2013 All Rights Reserved. Contributor(s): Mark J Crane */ 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 require_once "app_languages.php"; foreach($text as $key => $value) { $text[$key] = $value[$_SESSION['domain']['language']['code']]; } //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 http post variables and set them to php variables if (count($_POST) > 0) { //devices $device_mac_address = check_str($_POST["device_mac_address"]); $device_mac_address = strtolower($device_mac_address); $_POST["device_mac_address"] = preg_replace('#[^a-fA-F0-9./]#', '', $device_mac_address); $device_label = check_str($_POST["device_label"]); $device_vendor = check_str($_POST["device_vendor"]); $device_model = check_str($_POST["device_model"]); $device_firmware_version = check_str($_POST["device_firmware_version"]); $device_provision_enable = check_str($_POST["device_provision_enable"]); $device_template = check_str($_POST["device_template"]); $device_username = check_str($_POST["device_username"]); $device_password = check_str($_POST["device_password"]); $device_time_zone = check_str($_POST["device_time_zone"]); $device_description = check_str($_POST["device_description"]); //lines $line_number = check_str($_POST["line_number"]); $server_address = check_str($_POST["server_address"]); $outbound_proxy = check_str($_POST["outbound_proxy"]); $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"]); //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) { $msg = ''; if ($action == "update") { $device_uuid = check_str($_POST["device_uuid"]); } //check for all required data 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_provision_enable) == 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_time_zone) == 0) { $msg .= "Please provide: Time Zone
\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 "
\n"; echo $msg."
"; echo "
\n"; persistformvar($_POST); echo "
\n"; require_once "resources/footer.php"; return; } //add or update the database if ($_POST["persistformvar"] != "true") { /* //remove the invalid characters from the extension name foreach ($_POST as $key => $value) { if ($key == "dialplan_name") { $dialplan_name = str_replace(" ", "_", $value); $dialplan_name = str_replace("/", "", $dialplan_name); $_POST["dialplan_name"] = $dialplan_name; } } */ //add domain_uuid to the array if (!isset($_POST["domain_uuid"])) { $_POST["domain_uuid"] = $_SESSION["domain_uuid"]; } foreach ($_POST as $key => $value) { if (is_array($value)) { $y = 0; foreach ($value as $k => $v) { if (!isset($v["domain_uuid"])) { $_POST[$key][$y]["domain_uuid"] = $_SESSION["domain_uuid"]; } $y++; } } } //array cleanup $x = 0; foreach ($_POST["device_lines"] as $row) { // //unset the empty row if (strlen($row["line_number"]) == 0) { unset($_POST["device_lines"][$x]); } //unset dialplan_detail_uuid if the field has no value if (strlen($row["device_line_uuid"]) == 0) { unset($_POST["device_lines"][$x]["device_line_uuid"]); } //increment the row $x++; } $x = 0; foreach ($_POST["device_keys"] as $row) { //unset the empty row if (strlen($row["device_key_id"]) == 0) { unset($_POST["device_keys"][$x]); } //unset dialplan_detail_uuid if the field has no value if (strlen($row["device_key_uuid"]) == 0) { unset($_POST["device_keys"][$x]["device_key_uuid"]); } //increment the row $x++; } $x = 0; foreach ($_POST["device_settings"] as $row) { //unset the empty row if (strlen($row["device_setting_subcategory"]) == 0) { unset($_POST["device_settings"][$x]); } //unset dialplan_detail_uuid if the field has no value if (strlen($row["device_setting_uuid"]) == 0) { unset($_POST["device_settings"][$x]["device_setting_uuid"]); } //increment the row $x++; } //add or update the database if ($_POST["persistformvar"] != "true") { $orm = new orm; $orm->name('devices'); if (strlen($device_uuid) > 0) { $orm->uuid($device_uuid); } $orm->save($_POST); $message = $orm->message; } //write the provision files // require_once "app/provision/provision_write.php"; //set the message if ($action == "add") { $_SESSION['message'] = $text['message-add']; } if ($action == "update") { $_SESSION['message'] = $text['message-update']; } } //if ($_POST["persistformvar"] != "true") } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) //pre-populate the form if (count($_GET) > 0 && $_POST["persistformvar"] != "true") { $dialplan_uuid = check_str($_GET["id"]); $orm = new orm; $orm->name('devices'); $orm->uuid($dialplan_uuid); $result = $orm->find()->get(); //$message = $orm->message; foreach ($result as &$row) { $device_mac_address = $row["device_mac_address"]; $device_mac_address = substr($device_mac_address, 0,2).'-'.substr($device_mac_address, 2,2).'-'.substr($device_mac_address, 4,2).'-'.substr($device_mac_address, 6,2).'-'.substr($device_mac_address, 8,2).'-'.substr($device_mac_address, 10,2); $device_label = $row["device_label"]; $device_vendor = $row["device_vendor"]; $device_model = $row["device_model"]; $device_firmware_version = $row["device_firmware_version"]; $device_provision_enable = $row["device_provision_enable"]; $device_template = $row["device_template"]; $device_username = $row["device_username"]; $device_password = $row["device_password"]; $device_time_zone = $row["device_time_zone"]; $device_description = $row["device_description"]; } unset ($prep_statement); } //get device lines $sql = "SELECT * FROM v_device_lines "; $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "and device_uuid = '".$device_uuid."' "; $sql .= "order by line_number asc "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $device_lines = $prep_statement->fetchAll(PDO::FETCH_NAMED); //get device keys $sql = "SELECT * FROM v_device_keys "; $sql .= "WHERE domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "AND device_uuid = '".$device_uuid."' "; $sql .= "ORDER by "; $sql .= "CASE device_key_category "; $sql .= "WHEN 'line' THEN 1 "; $sql .= "WHEN 'memort' THEN 2 "; $sql .= "WHEN 'programmable' THEN 3 "; $sql .= "WHEN 'expansion' THEN 4 "; $sql .= "ELSE 100 END, "; $sql .= "device_key_id asc "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $device_keys = $prep_statement->fetchAll(PDO::FETCH_NAMED); //get device settings $sql = "SELECT * FROM v_device_settings "; $sql .= "WHERE domain_uuid = '".$_SESSION['domain_uuid']."' "; $sql .= "AND device_uuid = '".$device_uuid."' "; $sql .= "ORDER by device_setting_subcategory asc "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $device_settings = $prep_statement->fetchAll(PDO::FETCH_NAMED); //use the mac address to get the vendor if (strlen($device_vendor) == 0) { $device_vendor = device::get_vendor($device_mac_address); } //name='dialplan_details[".$x."][dialplan_detail_type]' //show the header require_once "resources/header.php"; //javascript to change select to input and back again ?> "; echo "\n"; echo "\n"; echo " "; echo " "; 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"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo " "; echo " "; echo " "; echo " "; if (permission_exists('device_key_add') || permission_exists('device_key_edit')) { echo " "; echo " "; echo " "; echo " "; } //device settings if (permission_exists('device_setting_add')) { echo " "; echo " "; echo " "; 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"; 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"; echo "\n"; echo " \n"; echo " \n"; echo " "; echo "
".$text['header-device']."\n"; echo " \n"; echo " \n"; echo "
\n"; echo $text['description-device']."

\n"; echo "
\n"; echo " ".$text['label-device_mac_address'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-device_mac_address']."\n"; echo "
\n"; echo " ".$text['label-device_label'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-device_label']."\n"; echo "
\n"; echo " ".$text['label-device_template'].":\n"; echo "\n"; echo "\n"; echo "
\n"; echo $text['description-device_template']."\n"; echo "
".$text['label-lines'].":"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; $x = 0; foreach($device_lines as $row) { //if (strlen($row['line_number']) == 0) { $row['line_number'] = "1"; } echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; $x++; } //device lines $x = 0; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
".$text['label-line']."".$text['label-server_address']."".$text['label-outbound_proxy']."".$text['label-display_name']."".$text['label-user_id']."".$text['label-auth_id']."".$text['label-password']." 
\n"; echo " ".$row['line_number']." \n"; echo " \n"; echo " ".$row['server_address']." \n"; echo " \n"; echo " ".$row['outbound_proxy']." \n"; echo " \n"; echo " ".$row['display_name']." \n"; echo " \n"; echo " ".$row['user_id']." \n"; echo " \n"; echo " ".$row['auth_id']." \n"; echo " \n"; echo " ********  \n"; //$row['password'] echo " \n"; if (permission_exists('device_edit')) { echo " $v_link_label_edit\n"; } if (permission_exists('device_delete')) { echo " $v_link_label_delete\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"; if (strlen($text['description-lines']) > 0) { echo "
".$text['description-lines']."\n"; } echo "
".$text['label-keys'].":"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; $x = 0; foreach($device_keys as $row) { echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; $x++; } $x = 0; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "
".$text['label-device_key_category']."".$text['label-device_key_id']."".$text['label-device_key_type']."".$text['label-device_key_line']."".$text['label-device_key_value']."".$text['label-device_key_extension']."".$text['label-device_key_label']." 
\n"; echo " ".$row['device_key_category']." \n"; echo " \n"; echo " ".$row['device_key_id']." \n"; echo " \n"; echo " ".$row['device_key_type']." \n"; echo " \n"; echo " ".$row['device_key_line']." \n"; echo " \n"; echo " ".$row['device_key_value']." \n"; echo " \n"; echo " ".$row['device_key_extension']." \n"; echo " \n"; echo " ".$row['device_key_label']." \n"; echo " \n"; if (permission_exists('device_key_edit')) { echo " $v_link_label_edit\n"; } if (permission_exists('device_key_delete')) { echo " $v_link_label_delete\n"; } echo "
\n"; echo " \n"; echo "\n"; echo " \n"; echo "\n"; //echo " \n"; ?> \n"; echo "\n"; echo " \n"; echo "\n"; echo " \n"; echo "\n"; echo " \n"; echo "\n"; echo " \n"; echo "\n"; echo " \n"; echo "
\n"; if (strlen($text['description-keys']) > 0) { echo "
".$text['description-keys']."\n"; } echo "
".$text['label-settings'].":"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; $x = 0; foreach($device_settings as $row) { //if (strlen($row['line_number']) == 0) { $row['line_number'] = "1"; } echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; $x++; } $x = 0; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "
".$text['label-device_setting_name']."".$text['label-device_setting_value']."".$text['label-enabled']."".$text['label-device_setting_description']." 
\n"; echo " ".$row['device_setting_subcategory']." \n"; echo " \n"; echo " ".$row['device_setting_value']." \n"; echo " \n"; echo " ".$row['device_setting_enabled']." \n"; echo " \n"; echo " ".$row['device_setting_description']." \n"; echo " \n"; if (permission_exists('device_edit')) { echo " $v_link_label_edit\n"; } if (permission_exists('device_delete')) { echo " $v_link_label_delete\n"; } echo "
\n"; echo " \n"; echo "\n"; echo " \n"; echo "\n"; echo " \n"; echo "\n"; echo " \n"; echo "\n"; echo " \n"; echo "
\n"; if (strlen($text['description-settings']) > 0) { echo "
".$text['description-settings']."\n"; } echo "
\n"; echo " ".$text['label-device_vendor'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-device_vendor']."\n"; echo "
\n"; echo " ".$text['label-device_model'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-device_model']."\n"; echo "
\n"; echo " ".$text['label-device_firmware_version'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-device_firmware_version']."\n"; echo "
\n"; echo " ".$text['label-device_username'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-device_username']."\n"; echo "
\n"; echo " ".$text['label-device_password'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-device_password']."\n"; echo "
\n"; echo " ".$text['label-device_provision_enable'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-device_provision_enable']."\n"; echo "
\n"; echo " ".$text['label-device_time_zone'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-device_time_zone']."\n"; echo "
\n"; echo " ".$text['label-device_description'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-device_description']."\n"; echo "
\n"; if ($action == "update") { echo " \n"; } echo " \n"; echo "
"; echo ""; echo "
"; echo ""; //show the footer require_once "resources/footer.php"; ?>