Example #1
0
 function editModalForm($headingName, $titleName, $infoArray, $infoKey, $modalID, $value)
 {
     parent::setHeadings($headingName);
     parent::setTitles($titleName);
     parent::setData($infoArray);
     parent::setSortable(false);
     parent::setDatabase($infoKey);
     parent::setModalID($modalID);
     parent::setUpdateValue($value);
     return parent::modalForm(10);
 }
Example #2
0
 private function list_secret_data()
 {
     $content = '';
     $modal_forms;
     $tool = new EdittingTools();
     $content .= $tool->createNewFilters();
     $content .= "<a name='modal' href='#Add_privatedata_modal'><img src='icons/Add.png' height=18>Add Private Data</a><br><br>";
     // We need to know all groups this user is in:
     $user = new User($_SESSION['userid']);
     $user_groups = $user->get_groups();
     $data = array();
     // Create modal for adding a new Private data entry
     // This modal should ask for which group to add it as and the password
     // We need to know all groups this user is in:
     $user = new User($_SESSION['userid']);
     $user_groups = $user->get_groups();
     if (sizeof($user_groups) == 1) {
         foreach ($user_groups as $gid => $gname) {
             $group_data = $gname;
         }
     } else {
         $group_data = "";
     }
     $modalForm = new Form("auto", 2);
     $modalForm->setHeadings(array("For which group would you like to add private"));
     $modalForm->setTitles(array("Group", "Group Password.tip.This is the shared secret for the group you selected above.", "Fill in Private Data Details below:", "Description", "Private Data <br><small><i>Stored encrypted</i></small>.tip.This data will be AES encrypted", "Type <br><small><a name='modal' href='#add_pdtype_modal'>Add Private data type</a></small>", "Notes <br><small><i>Stored encrypted</i></small>.tip.This data will be AES encrypted", "device_id"));
     $modalForm->setData(array("{$group_data}", "", "", "", "", "", "", $_GET['ID']));
     $modalForm->setDatabase(array("group_id", "group_pass", "dummy", "private_data_desc", "private_data_password", "private_data_type", "private_data_notes", "device_id"));
     $modalForm->setFieldType(array(0 => 'drop_down', 1 => 'password_autocomplete_off', 2 => 'static', 5 => 'drop_down', 6 => 'text_area', 7 => 'hidden'));
     // Drop down
     // We need to know all groups this user is in:
     $modalForm->setType($user_groups);
     $dataTypes = PrivateDataType::get_private_data_types();
     $modalForm->setType($dataTypes);
     //End Dropdown
     // Change button text
     $modalForm->setUpdateValue("add_private_data_for_group");
     $modalForm->setUpdateValue("add_private_data_for_group");
     $modalForm->setUpdateText("Add");
     $modalForm->setModalID("Add_privatedata_modal");
     $modal_forms .= $modalForm->modalForm();
     unset($modalForm);
     // End modal
     // Create modal forms
     // Add Modal for adding Private data types
     $modalForm = new Form("auto", 2);
     $modalForm->setHeadings(array("<br><br>Add Private Data Type"));
     $modalForm->setTitles(array("Name.tip.Descriptive String for this type", "Description"));
     $modalForm->setData(array("", ""));
     $modalForm->setDatabase(array("pdtype_name", "pdtype_desc"));
     // Change button text
     $modalForm->setUpdateValue("add_private_data_type");
     $modalForm->setUpdateText("Add Private Data Type");
     $modalForm->setModalID("add_pdtype_modal");
     $modal_forms .= $modalForm->modalForm();
     unset($modalForm);
     // End Modal for adding Private data types
     foreach ($user_groups as $gid => $gname) {
         // Create a modal per group, that asks for the group password
         // We only need one per group, as passwords are unqiue per group
         $modalForm = new Form("auto", 2);
         $modalForm->setHeadings(array("Please provide group password for {$gname}"));
         $modalForm->setTitles(array("Password", "group_id"));
         $modalForm->setData(array("", $gid));
         $modalForm->setDatabase(array('group_pass', 'group_id'));
         $modalForm->setFieldType(array(0 => 'password_autocomplete_off', 1 => 'hidden'));
         $myModalID = "modal_group_pass_" . $gid;
         // Change button text
         $modalForm->setUpdateValue("Decrypt_Private_Data");
         $modalForm->setUpdateText("Submit");
         $modalForm->setModalID($myModalID);
         $modal_forms .= $modalForm->modalForm();
         unset($modalForm);
         // End modal
         $group_private_data = PrivateData::get_private_data_by_group($gid);
         if ($group_private_data) {
             foreach ($group_private_data as $id => $pdname) {
                 $privDataObj = new PrivateData($id);
                 if (is_numeric($privDataObj->get_device_id())) {
                     // Means device assocication
                     continue;
                 }
                 // Here we check if the user submitted a group password
                 // Only for the group for which the pasword has been provided
                 $password = "******";
                 $actions = "<a name='modal' href='#modal_group_pass_" . $gid . "'>Unlock Private Data</a>";
                 if (isset($_POST['group_pass']) && $_POST['group_pass'] != '' && $privDataObj->get_group_id() == $_POST['group_id']) {
                     // now get private data (password)
                     $password = $privDataObj->get_private_data($_POST['group_pass']);
                     if ($password != false) {
                         // Decrypted successful!
                         // Get historical data, and create modal
                         $modalForm = new Form("auto", 2);
                         $modalForm->setHeadings(array("Changed (exipred) at:", "Private Data"));
                         // Loop through old data and fill arrays for form
                         $Htitles = array();
                         $Hdata = array();
                         $HfieldType = array();
                         $historical_passwords = $privDataObj->get_history($_POST['group_pass']);
                         if ($historical_passwords) {
                             foreach ($historical_passwords as $old_date => $old_data) {
                                 array_push($Htitles, $old_date);
                                 array_push($Hdata, $old_data);
                                 array_push($HfieldType, "static");
                             }
                         }
                         $modalForm->setTitles($Htitles);
                         $modalForm->setData($Hdata);
                         $modalForm->setFieldType($HfieldType);
                         unset($Htitles);
                         unset($Hdata);
                         unset($HfieldType);
                         $modalForm->setTitleWidth("40%");
                         $modalForm->setDatabase(array('date', 'old_data'));
                         $myHistoryModalID = "modal_old_pass_" . $id;
                         // Change button text
                         $modalForm->setUpdateValue("close");
                         $modalForm->setUpdateText("Press cancel");
                         $modalForm->setModalID($myHistoryModalID);
                         $modal_forms .= $modalForm->modalForm();
                         unset($modalForm);
                         // End modal
                         if ($privDataObj->get_notes($_POST['group_pass']) != '') {
                             $name_tooltip = ".tip.<b>Notes:</b><br>" . nl2br($privDataObj->get_notes($_POST['group_pass']));
                         }
                         // Now create a modal that allows us to update the private data object
                         // Start Update Modal
                         $PdataModal = new Form("auto", 2);
                         $PdataModal->setHeadings(array("Update Private Data"));
                         $PdataModal->setTitles(array("Description", "Private Data <br><small><i>Stored encrypted</i></small>.tip.This data will be AES encrypted", "Type <br><small><a name='modal' href='#add_pdtype_modal'>\n\t\t\t\t\t\t\tAdd Private data type</a></small>", "Notes<br><small><i>Stored encrypted</i></small>.tip.This data will be AES encrypted", "PDid", "", ""));
                         $PdataModal->setData(array($privDataObj->get_name(), $password, $privDataObj->get_type_name(), $privDataObj->get_notes($_POST['group_pass']), $id, $_POST['group_id'], $_POST['group_pass']));
                         $PdataModal->setDatabase(array('private_data_desc', 'private_data_password', 'private_data_type', 'private_data_notes', 'private_data_id', 'group_id', 'group_pass'));
                         $PdataModal->setFieldType(array(2 => 'drop_down', 3 => 'text_area', 4 => 'hidden', 5 => 'hidden', 6 => 'hidden'));
                         // Creat dropdown
                         $dataTypes = PrivateDataType::get_private_data_types();
                         $PdataModal->setType($dataTypes);
                         $PdataModal->setUpdateValue('update_private_data');
                         $PdataModalID = "modal_private_data_id" . $id;
                         // Change button text
                         $PdataModal->setModalID($PdataModalID);
                         $modalForms .= $PdataModal->modalForm();
                         // End Update modal
                         // Now a Modal to Delete an Entry
                         // We'll ask for the password again.
                         $modalFormDelete = new Form("auto", 2);
                         $modalFormDelete->setHeadings(array("Delete " . $privDataObj->get_name() . "<br>Please provide group password for " . $privDataObj->get_group_name()));
                         $modalFormDelete->setTitles(array("Password", "group_id", ""));
                         $modalFormDelete->setData(array("", $privDataObj->get_group_id(), $id));
                         $modalFormDelete->setDatabase(array('group_pass', 'group_id', 'private_data_id'));
                         $modalFormDelete->setFieldType(array(0 => 'password_autocomplete_off', 1 => 'hidden', 2 => 'hidden'));
                         $myDeleteModalID = "modal_delete_pass_" . $id;
                         // Change button text
                         $modalFormDelete->setUpdateValue("delete_private_data");
                         $modalFormDelete->setUpdateText("Delete");
                         $modalFormDelete->setModalID($myDeleteModalID);
                         $modalForms .= $modalFormDelete->modalForm();
                         // End Delete modal
                         if (count($historical_passwords) > 0) {
                             $history_string = "<a name='modal' href='#" . $myHistoryModalID . "'>History</a>";
                         } else {
                             $history_string = "<i>No History</i>";
                         }
                         $actions = "<a name='modal' href='#" . $PdataModalID . "'>Edit</a> &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp\n                                              \t\t<a name='modal' href='#" . $myDeleteModalID . "'>Delete</a> &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp\n\t\t\t\t\t\t\t{$history_string}";
                     } else {
                         $form = new Form();
                         $content .= $form->error("Warning: " . $privDataObj->get_error());
                     }
                 }
                 if (count($historical_passwords) > 0) {
                     $history_string = "<a name='modal' href='#" . $myHistoryModalID . "'>History</a>";
                 } else {
                     $history_string = "<i>No History</i>";
                 }
                 array_push($data, $privDataObj->get_type_desc() . $type_tooltip, $privDataObj->get_name() . $name_tooltip, $password, $privDataObj->get_group_name(), $actions);
             }
         }
     }
     $heading = array("Type", "Description", "Private Data", "Group", "Actions");
     $pdata_form = new Form("auto", 5);
     $pdata_form->setSortable(true);
     $pdata_form->setHeadings($heading);
     $pdata_form->setData($data);
     $pdata_form->setTableWidth("800px");
     $content .= $pdata_form->showForm();
     $content .= $modalForms;
     return "{$content} {$modal_forms} {$private_data_type_modal}";
 }
Example #3
0
function displayDevice($devices)
{
    //global all variables
    global $deviceKey, $deviceForm, $tool, $headings, $titles, $deviceTypes, $location;
    //if this isn't in ajax mode display the Ajax buttons
    if (!isset($_GET['mode'])) {
        if ($_GET['tab'] == 2) {
            $name = array($devices->get_name(), "Interface", "Device Control.first.");
        } else {
            if ($_GET['tab'] == 1) {
                $name = array($devices->get_name(), "Interface.first.", "Device Control");
            } else {
                $name = array($devices->get_name() . ".first.", "Interface", "Device Control");
            }
        }
        $page = array("devices.php?action=showID&ID={$_GET['ID']}&mode=deviceInfo", "devices.php?action=showID&ID={$_GET['ID']}&mode=deviceInterface", "devices.php?action=showID&ID={$_GET['ID']}&mode=deviceControl");
        echo $tool->createNewButtons($name, "devicePart", $page);
    }
    //the division for the interfae, control port, and info page to show
    echo "<div id='devicePart'>";
    //success message for the ajax mode
    switch (success) {
        case $_GET['update']:
            $deviceForm->success("Updated successfully");
            break;
        case $_GET['add']:
            $deviceForm->success("Added new data successfully");
            break;
        case $_GET['delete']:
            $deviceForm->success("Deleted and archived data successfully");
            break;
    }
    //if ajax mod is part of displaying the interface
    if ($_GET['mode'] == deviceInterface || $_GET['tab'] == 1) {
        //set the table attributes
        $deviceForm->setCols(11);
        $deviceForm->setTableWidth("100%");
        $deviceForm->setTitleWidth("10%");
        //create tools for this mode
        /*Taken out for user interface issues
        		$toolNames = array("All Devices", "All Archived Device");
        		$toolIcons = array("devices", "devices");
        		$toolHandlers = array("handleEvent('devices.php')", "handleEvent('devices.php?action=showArchived')");
        		
        		echo $tool->createNewTools($toolNames, $toolIcons, $toolHandlers);*/
        //can be displayed in both percent and bPS mode
        if ($_GET['output'] == percent) {
            $headings = array("Interface name", "Interface alias", "Interface description", "Status", "Discovered interface speed(bps)", "Current throughput in % \n\t\t\t\t\t\t  <a href='#' style='color:yellow;' onclick=\"handleEvent('devices.php?action=showID&ID={$_GET['ID']}&output=bps&tab=1');\">[switch to bps] </a>", "Interface MTU", "IPv4/IPv6 address", "Interface duplex", "Interface type", "Discovered interface index");
        } else {
            $headings = array("Interface name", "Interface alias", "Interface description", "Status", "Discovered interface speed(bps)", "Current throughput in bps\n\t\t\t\t\t\t\t  <a href='#' style='color:yellow;' onclick=\"handleEvent('devices.php?action=showID&ID={$_GET['ID']}&output=percent&tab=1');\">[switch to percent] </a>", "Interface MTU", "IPv4/IPv6 address", "Interface duplex", "Interface type", "Discovered interface index");
        }
        //get all the interfacese
        $interfaces = $devices->get_interfaces();
        $info = array();
        $title = array();
        $handlers = array();
        //put all the interface information into the arrays
        foreach ($interfaces as $id => $value) {
            //array_push($title, "");
            array_push($title, $value->get_name() . '//' . $value->get_interface_id() . '//' . $value->get_device_id());
            array_push($info, $value->get_alias());
            array_push($info, $value->get_descr());
            array_push($info, $value->get_oper_status());
            $speed = $tool->calculator("convertBits", $value->get_speed());
            array_push($info, $speed);
            //calculate the percentage if it's in percent mode, otherwise convert it in to the right bits
            if ($value->get_inbits() > $value->get_outbits()) {
                $highBits = $value->get_inbits();
            } else {
                $highBits = $value->get_outbits();
            }
            if ($_GET['output'] == percent) {
                if ($value->get_speed() > 0) {
                    $percentage = $highBits / $value->get_speed();
                    $percentage = $tool->calculator("convertPercent", $percentage);
                } else {
                    $percentage = "0%";
                }
                array_push($info, $percentage);
            } else {
                $highBits = $tool->calculator("convertBits", $highBits);
                array_push($info, $highBits);
            }
            array_push($info, $value->get_mtu());
            $ipv4 = $value->get_ipv4_addresses();
            $ipv6 = $value->get_ipv6_addresses();
            $ip = "";
            //store both ipv4 and ipv6 addresses
            foreach ($ipv4 as $ipID => $ipValue) {
                $ip .= $ipID . "<br/>";
            }
            foreach ($ipv6 as $ipID => $ipValue) {
                $ip .= $ipID . "<br/>";
            }
            array_push($info, $ip);
            array_push($info, "");
            array_push($info, $value->get_type());
            array_push($info, $value->get_ifindex());
            //prepare strings into html format to display the graph and push it into the handler
            $nameTitle = str_replace(" ", "%20", $value->get_name());
            $name = str_replace(" ", "-", $value->get_name());
            $name = str_replace("/", "-", $name);
            $graphLink = "rrdgraph.php?file=deviceid" . $value->get_device_id() . "_" . $name . ".rrd&title=" . $nameTitle . "---Bits%20Per%20Second&type=traffic";
            array_push($handlers, $graphLink);
        }
        //If there are info, display the interfaces, else give a warniing message
        if (count($info) > 0) {
            echo $deviceForm->showAll($headings, $title, $info, $handlers, 3);
        } else {
            $deviceForm->warning("You have no Interfaces");
        }
    } elseif ($_GET['mode'] == deviceControl || $_GET['tab'] == 2) {
        //set the form attributes
        $deviceForm->setCols(7);
        /*check if the device type is a power or console device
         *if it is a control or console device, the user can add both management and control port
         *Otherwise the user can only add management ports
         */
        //if ($devices->get_device_type()==5 || $devices->get_device_type()==6)
        if ($devices->get_device_class() == 'console_server' || $devices->get_device_class() == 'power_control') {
            $cPorts = array();
            if ($_SESSION['access'] >= 50) {
                $toolNames = array("New management port.tip.Management Ports are ports that help you manage this device using power or console ports.", "New control port.tip.Control ports are ports that help you manage connected devices. Examples are power ports on remote power controls and serial ports on console servers.");
                $toolIcons = array("add", "add");
                $toolHandlers = array("return LoadPage('devices.php?action=add&item=mPort&mode=deviceControl&ID={$_GET['ID']}', 'devicePart');", "return LoadPage('devices.php?action=add&item=cPort&mode=deviceControl&ID={$_GET['ID']}&deviceClass=" . $devices->get_device_class() . "', 'devicePart');");
            }
        } else {
            if ($_SESSION['access'] >= 50) {
                $toolNames = array("New management port.tip.Management Ports are ports that help you manage this device using power or console ports.");
                $toolIcons = array("add");
                $toolHandlers = array("return LoadPage('devices.php?action=add&item=mPort&mode=deviceControl&ID={$_GET['ID']}', 'devicePart');");
            }
        }
        //create the tool
        echo $tool->createNewTools($toolNames, $toolIcons, $toolHandlers);
        //create the headings titles and info emptyy arrays for both management and control ports
        $cHeadings = array("Description", "Physical port", "Port name", "Port type", "Group", "Managed device", "Action");
        $mHeadings = array("Description", "Physical port", "Port name", "Port type", "Group", "Control device", "Action");
        $cTitles = array();
        $mTitles = array();
        $cInfo = array();
        $mInfo = array();
        //get all the control and management ports to store in an array for display
        $management = $devices->get_management_ports();
        $control = $devices->get_control_ports();
        $mPorts = array();
        $index = 0;
        //insert the ports into an array
        foreach ($management as $id => $value) {
            $mPorts[$index] = new ControlPort($id);
            $index++;
        }
        foreach ($control as $id => $value) {
            $cPorts[$index] = new ControlPort($id);
            $index++;
        }
        //push the info of these ports into the table
        foreach ($mPorts as $id => $value) {
            array_push($mTitles, $mPorts[$id]->get_description());
        }
        if (isset($cPorts)) {
            foreach ($cPorts as $id => $value) {
                array_push($cTitles, $cPorts[$id]->get_description());
            }
        }
        foreach ($mPorts as $id => $value) {
            array_push($mInfo, $mPorts[$id]->get_port());
            array_push($mInfo, $mPorts[$id]->get_name());
            array_push($mInfo, $mPorts[$id]->get_type());
            array_push($mInfo, $mPorts[$id]->get_group());
            array_push($mInfo, $mPorts[$id]->get_control_device_name());
            $portID = $mPorts[$id]->get_id();
            if ($_SESSION['access'] >= 50) {
                array_push($mInfo, "<a href='#' onclick=\"return LoadPage('devices.php?action=edit&ID={$_GET['ID']}&mode=deviceControl&mportID={$id}&portID={$portID}', 'devicePart');\">Edit</a> | <a href='#' onclick=\"handleEvent('devices.php?action=remove&ID={$_GET['ID']}&mportID={$id}&portID={$portID}');\">Delete</a>");
            } else {
                array_push($mInfo, 'No Access');
            }
        }
        if (isset($cPorts)) {
            foreach ($cPorts as $id => $value) {
                array_push($cInfo, $cPorts[$id]->get_port());
                array_push($cInfo, $cPorts[$id]->get_name());
                array_push($cInfo, $cPorts[$id]->get_type());
                array_push($cInfo, $cPorts[$id]->get_group());
                array_push($cInfo, $cPorts[$id]->get_managed_device_name());
                $portID = $cPorts[$id]->get_id();
                if ($_SESSION['access'] >= 50) {
                    array_push($cInfo, "<a href='#' onclick=\"return LoadPage('devices.php?action=edit&ID={$_GET['ID']}&mode=deviceControl&cportID={$id}&portID={$portID}', 'devicePart');\">Edit</a> | <a href='#' onclick=\"handleEvent('devices.php?action=remove&ID={$_GET['ID']}&cportID={$id}&portID={$portID}');\">Delete</a>");
                } else {
                    array_push($cInfo, 'No Access');
                }
            }
        }
        //if the user is editting this information, make it all editable
        if ($_GET['action'] == edit) {
            $deviceForm->setCols(2);
            $fieldType = array("hidden", "", "", "", "static", "", "drop_down");
            //checks to see if it's management or control ports to give different forms
            if (isset($_GET['mportID'])) {
                $name = $devices->get_name();
                $headings = array("Port Information for " . $name);
                $titles = array("pType", "Description.tip.A descriptive name for this connection, i.e. \"console connection for router1, routing engine 2\" or \"Remote power cycle group for router1\"", "Physical port.tip.Which port is this device physically connected to", "Port name.tip.Name of port. This will also be the name used for scripts", "Port type", "Group", "Control device");
                $group = $mPorts[$_GET['mportID']]->get_group();
                if ($group == '') {
                    $fieldType = array("hidden", "", "", "", "static", "static", "drop_down");
                    $group = "NOT APPLICABLE";
                }
                $info = array("mport", $mPorts[$_GET['mportID']]->get_description(), $mPorts[$_GET['mportID']]->get_port(), $mPorts[$_GET['mportID']]->get_name(), $mPorts[$_GET['mportID']]->get_type(), $group, $mPorts[$_GET['mportID']]->get_control_device_name());
                if ($mPorts[$_GET['mportID']]->get_type() == "console") {
                    $portTypeName = "console_server";
                } else {
                    $portTypeName = "power_control";
                }
                $types = $devices->get_devices_by_class($portTypeName);
                $deviceKey = array("pType", "description", "physicalPort", "portName", "portType", "group", "controlledDevice");
            } else {
                if (isset($_GET['cportID'])) {
                    $name = $devices->get_name();
                    $headings = array("Port Information for " . $name);
                    $titles = array("pType", "Description.tip.A descriptive name for this connection, i.e. \"console connection for router1, routing engine 2\" or \"Remote power cycle group for router1\"", "Physical port.tip.Which port is this device physically connected to", "Port name.tip.Name of port. This will also be the name used for scripts", "Port type", "Group", "Managed device.tip.Select a device or select \"Other Device\" if you want to manage a device that is not in the database. If you select \"Other Device\" please make sure to have a good port description.");
                    $group = $cPorts[$_GET['cportID']]->get_group();
                    if ($group == '') {
                        $fieldType = array("hidden", "", "", "", "static", "static", "drop_down");
                        $group = "NOT APPLICABLE";
                    }
                    $info = array("cport", $cPorts[$_GET['cportID']]->get_description(), $cPorts[$_GET['cportID']]->get_port(), $cPorts[$_GET['cportID']]->get_name(), $cPorts[$_GET['cportID']]->get_type(), $group, $cPorts[$_GET['cportID']]->get_managed_device_name());
                    $types = $devices->get_devices();
                    array_push($types, "Other devices");
                    $deviceKey = array("pType", "description", "physicalPort", "portName", "portType", "group", "managedDevice");
                }
            }
            $deviceForm->setFieldType($fieldType);
            echo $deviceForm->editPortForm($headings, $titles, $info, $deviceKey, $types);
        } else {
            if ($_GET['action'] == showID) {
                //show the ports
                if (isset($cPorts)) {
                    echo "<div style='clear:both;'></div><h2>Control Ports</h2>";
                    echo $deviceForm->showAll($cHeadings, $cTitles, $cInfo);
                }
                if (isset($mPorts)) {
                    echo "<div style='clear:both;'></div><h2>Management  Ports</h2>";
                    echo $deviceForm->showAll($mHeadings, $mTitles, $mInfo);
                }
                if (!isset($mPorts) && !isset($cPorts)) {
                    $deviceForm->warning("You have no Ports");
                }
            }
        }
    } else {
        $deviceForm->setCols(2);
        //make the tool bar for this page
        if ($_SESSION['access'] >= 50) {
            $toolNames = array("Edit Device", "Delete Device");
            $toolIcons = array("edit", "delete");
            $toolHandlers = array("handleEvent('devices.php?action=edit&ID={$_GET['ID']}');", "handleEvent('devices.php?action=remove&ID={$_GET['ID']}')");
        }
        echo $tool->createNewTools($toolNames, $toolIcons, $toolHandlers);
        //make the headings
        $headings = array("Device Information");
        //store all the device information values into an array
        $info = array($devices->get_name(), $devices->get_device_fqdn(), $devices->get_location_name(), $devices->get_type_name(), $devices->get_snmp_ro(), $devices->get_device_oob(), $devices->get_notes());
        //if the user is editting this information, make it all editable
        if ($_GET['action'] == edit) {
            $deviceKey = array("name", "device_fqdn", "location", "device_type", "SNMP Community String.tip.Read only SNMP community used for SNMP data collection", "device_oob", "notes");
            $fieldType = array("", "", "drop_down", "drop_down", "", "", "text_area");
            $deviceForm->setFieldType($fieldType);
            $type = array($location, $deviceTypes);
            echo $deviceForm->editDeviceForm($headings, $titles, $info, $deviceKey, $type);
        } elseif ($_GET['action'] == showID) {
            //store all the device information values into an array
            $info = array($devices->get_name(), $devices->get_device_fqdn(), $devices->get_location_name(), $devices->get_type_name(), $devices->get_snmp_ro(), $devices->get_device_oob(), nl2br($devices->get_notes()));
            echo $deviceForm->showDeviceForm($headings, $titles, $info);
            // Everything below is for viewing & edditing Private Data for this device.
            $modalForms = "";
            echo "<div style='clear:both;'></div>";
            echo "<h2>Private Data</h2>";
            // Here we check if we just deleted a private data entry
            if (isset($_POST['delete_private_data'])) {
                $form = new Form();
                // Yes update
                $privDataObj = new PrivateData($_POST['private_data_id']);
                if ($privDataObj->delete($_POST['group_pass'])) {
                    $form->success("Private entry Deleted");
                    $_SESSION['action'] = "Removed private data for: " . $devices->get_name();
                } else {
                    $form->error("Warning: Failed to delete Private data Reason: " . $privDataObj->get_error(), $_GET['ID']);
                    unset($_POST['group_pass']);
                }
            }
            // Check if we just added a private data Type
            if (isset($_POST['add_private_data_type'])) {
                $form = new Form();
                $no_error = true;
                // Check mandotry fields
                if ($_POST['pdtype_name'] == '') {
                    $form->error("Error: Private DataType name is empty");
                    $no_error = false;
                } elseif ($_POST['pdtype_desc'] == '') {
                    $form->error("Error: Private DataType Description is empty");
                    $no_error = false;
                }
                if ($no_error) {
                    $privDataTypeObj = new PrivateDataType();
                    $privDataTypeObj->set_name($_POST['pdtype_name']);
                    $privDataTypeObj->set_desc($_POST['pdtype_desc']);
                    if ($privDataTypeObj->insert()) {
                        $form->success("Private data type '" . $_POST['pdtype_name'] . "' Added");
                        $_SESSION['action'] = "Added private data Type";
                    } else {
                        $form->error("Warning: Failed to Add Private data Reason: " . $privDataTypeObj->get_error());
                    }
                }
            }
            // Check if we just added a private data entry
            if (isset($_POST['add_private_data_for_group'])) {
                $form = new Form();
                $no_error = true;
                // Check mandotry fields
                if (!is_numeric($_POST['device_id'])) {
                    $form->error("Error: Invalid device id");
                    $no_error = false;
                } elseif (!is_numeric($_POST['group_id'])) {
                    $form->error("Error: No Group Specified");
                    $no_error = false;
                } elseif (!is_numeric($_POST['private_data_type'])) {
                    $form->error("Error: No Private Data type specified");
                    $no_error = false;
                } elseif ($_POST['private_data_password'] == '') {
                    $form->error("Warning: Private Data string was empty");
                    //$no_error = false;
                }
                if ($no_error) {
                    $privDataObj = new PrivateData();
                    $privDataObj->set_group_id($_POST['group_id']);
                    $privDataObj->set_type_id($_POST['private_data_type']);
                    $privDataObj->set_device_id($_POST['device_id']);
                    $privDataObj->set_notes($_POST['private_data_notes']);
                    $privDataObj->set_name($_POST['private_data_desc']);
                    $privDataObj->set_private_data($_POST['private_data_password']);
                    if ($privDataObj->insert($_POST['group_pass'])) {
                        $form->success("Private data entry Added");
                        $_SESSION['action'] = "Added private data for: " . $devices->get_name();
                    } else {
                        $form->error("Warning: Failed to Add Private data Reason: " . $privDataObj->get_error(), $_GET['ID']);
                        unset($_POST['group_pass']);
                    }
                }
            }
            echo "<a name='modal' href='#Add_privatedata_modal'><img src='icons/Add.png' height=18>Add Private Data</a><br>";
            // Add Modal for adding Private data types
            $modalForm = new Form("auto", 2);
            $modalForm->setHeadings(array("<br><br>Add Private Data Type"));
            $modalForm->setTitles(array("Name.tip.Descriptive String for this type", "Description"));
            $modalForm->setData(array("", ""));
            $modalForm->setDatabase(array("pdtype_name", "pdtype_desc"));
            // Change button text
            $modalForm->setUpdateValue("add_private_data_type");
            $modalForm->setUpdateText("Add Private Data Type");
            $modalForm->setModalID("add_pdtype_modal");
            $private_data_type_modal = $modalForm->modalForm();
            unset($modalForm);
            // End Modal for adding Private data types
            // Create modal for adding a new Private data entry
            // This modal should ask for which group to add it as and the password
            // We need to know all groups this user is in:
            $user = new User($_SESSION['userid']);
            $user_groups = $user->get_groups();
            if (sizeof($user_groups) == 1) {
                foreach ($user_groups as $gid => $gname) {
                    $group_data = $gname;
                }
            } else {
                $group_data = "";
            }
            $modalForm = new Form("auto", 2);
            $modalForm->setHeadings(array("For which group would you like to add private"));
            $modalForm->setTitles(array("Group", "Group Password.tip.This is the shared secret for the group you selected above.", "Fill in Private Data Details below:", "Description", "Private Data<br><small>Stored encrypted</small>.tip.This is the data that will be encrypted", "Type <br><small><a name='modal' href='#add_pdtype_modal'>Add Private data type</a></small>", "Notes <br><small><i>Stored encrypted</i></small>.tip.This data will be AES encrypted", "device_id"));
            $modalForm->setData(array("{$group_data}", "", "", "", "", "", "", $_GET['ID']));
            $modalForm->setDatabase(array("group_id", "group_pass", "dummy", "private_data_desc", "private_data_password", "private_data_type", "private_data_notes", "device_id"));
            $modalForm->setFieldType(array(0 => 'drop_down', 1 => 'password_autocomplete_off', 2 => 'static', 5 => 'drop_down', 6 => 'text_area', 7 => 'hidden'));
            // Drop down
            // We need to know all groups this user is in:
            $modalForm->setType($user_groups);
            $dataTypes = PrivateDataType::get_private_data_types();
            $modalForm->setType($dataTypes);
            //End Dropdown
            // Change button text
            $modalForm->setUpdateValue("add_private_data_for_group");
            $modalForm->setUpdateText("Add");
            $modalForm->setModalID("Add_privatedata_modal");
            echo $modalForm->modalForm();
            unset($modalForm);
            // End modal
            // Also create a table with PrivateData
            // 1st get all entries for this device
            $all_private_data = PrivateData::get_private_data_by_device($_GET['ID']);
            // Only if there is any private data for this device
            if ($all_private_data && $_GET['action'] == showID) {
                $i++;
                // Check if we just updated the info,
                // If so we need to update Private data
                if (isset($_POST['update_private_data'])) {
                    // Yes update
                    $tmpform = new Form();
                    $privDataObj = new PrivateData($_POST['private_data_id']);
                    $privDataObj->set_name($_POST['private_data_desc']);
                    $privDataObj->set_notes($_POST['private_data_notes']);
                    $privDataObj->set_type_id($_POST['private_data_type']);
                    $privDataObj->set_private_data($_POST['private_data_password']);
                    if ($privDataObj->update($_POST['group_pass'])) {
                        $tmpform->success("Private data updated Succesfully");
                        unset($tmpform);
                        $_SESSION['action'] = "Updated private data for: " . $devices->get_name();
                    } else {
                        print "NOK " . $privDataObj->get_error();
                        $tmpform->error("Warning: Failed to Update Private data Reason: " . $privDataObj->get_error(), $_GET['ID']);
                    }
                }
                // Placeholder for modal forms
                $heading = array("Type", "Description", "Private Data", "Group", "Actions");
                $data = array();
                foreach ($all_private_data as $id => $group_id) {
                    $privDataObj = new PrivateData($id);
                    // Only show tooltip when data is available
                    // This is for type description
                    if ($privDataObj->get_type_desc() != '') {
                        $type_tooltip = ".tip.Private Data Type keyword:<br> " . $privDataObj->get_type_name();
                    } else {
                        $type_tooltip = "";
                    }
                    // This is for type name + Notes
                    //if ($privDataObj->get_notes() != '') {
                    //	$name_tooltip = ".tip.<b>Notes:</b><br>".nl2br($privDataObj->get_notes());
                    //} else {
                    //	$name_tooltip = "";
                    //}
                    // We also need to create a modal that will Ask the user for a password
                    // We only need one per group, as passwords are unqiue per group
                    $modalForm = new Form("auto", 2);
                    $modalForm->setHeadings(array("Please provide group password for " . $privDataObj->get_group_name()));
                    $modalForm->setTitles(array("Password", "group_id"));
                    $modalForm->setData(array("", $privDataObj->get_group_id()));
                    $modalForm->setDatabase(array('group_pass', 'group_id'));
                    $modalForm->setFieldType(array(0 => 'password_autocomplete_off', 1 => 'hidden'));
                    $myModalID = "modal_group_pass_" . $privDataObj->get_group_id();
                    // Change button text
                    $modalForm->setUpdateValue("Decrypt_Private_Data");
                    $modalForm->setUpdateText("Submit");
                    $modalForm->setModalID($myModalID);
                    $modalForms .= $modalForm->modalForm();
                    unset($modalForm);
                    // End modal
                    $name_tooltip = "";
                    // Here we check if the user submitted a group password
                    // Only for the group for which the pasword has been provided
                    if (isset($_POST['group_pass']) && $_POST['group_pass'] != '' && $privDataObj->get_group_id() == $_POST['group_id']) {
                        // now get private data (password)
                        $password = $privDataObj->get_private_data($_POST['group_pass']);
                        if ($password != false) {
                            // Decrypted successful!
                            // This is for type name + Notes
                            if ($privDataObj->get_notes($_POST['group_pass']) != '') {
                                $name_tooltip = ".tip.<b>Notes:</b><br>" . nl2br($privDataObj->get_notes($_POST['group_pass']));
                            }
                            // Get historical data, and create modal
                            $modalForm = new Form("auto", 2);
                            $modalForm->setHeadings(array("Changed (exipred) at:", "Private Data"));
                            // Loop through old data and fill arrays for form
                            $Htitles = array();
                            $Hdata = array();
                            $HfieldType = array();
                            $historical_passwords = $privDataObj->get_history($_POST['group_pass']);
                            if ($historical_passwords) {
                                foreach ($historical_passwords as $old_date => $old_data) {
                                    array_push($Htitles, $old_date);
                                    array_push($Hdata, $old_data);
                                    array_push($HfieldType, "static");
                                }
                            }
                            $modalForm->setTitles($Htitles);
                            $modalForm->setData($Hdata);
                            $modalForm->setFieldType($HfieldType);
                            unset($Htitles);
                            unset($Hdata);
                            unset($HfieldType);
                            $modalForm->setTitleWidth("40%");
                            $modalForm->setDatabase(array('date', 'old_data'));
                            $myHistoryModalID = "modal_old_pass_" . $id;
                            // Change button text
                            $modalForm->setUpdateValue("close");
                            $modalForm->setUpdateText("Press cancel");
                            $modalForm->setModalID($myHistoryModalID);
                            $modalForms .= $modalForm->modalForm();
                            unset($modalForm);
                            // End modal
                            // Now create a modal that allows us to update the private data object
                            // Start Update Modal
                            $PdataModal = new Form("auto", 2);
                            $PdataModal->setHeadings(array("Update Private Data"));
                            $PdataModal->setTitles(array("Description", "Private Data <br><small><i>Stored encrypted</i></small>.tip.This data will be AES encrypted", "Type <br><small><a name='modal' href='#add_pdtype_modal'>Add Private data type</a></small>", "Notes<br><small><i>Stored encrypted</i></small>.tip.This data will be AES encrypted", "PDid", "", ""));
                            $PdataModal->setData(array($privDataObj->get_name(), $password, $privDataObj->get_type_name(), $privDataObj->get_notes($_POST['group_pass']), $id, $_POST['group_id'], $_POST['group_pass']));
                            $PdataModal->setDatabase(array('private_data_desc', 'private_data_password', 'private_data_type', 'private_data_notes', 'private_data_id', 'group_id', 'group_pass'));
                            $PdataModal->setFieldType(array(2 => 'drop_down', 3 => 'text_area', 4 => 'hidden', 5 => 'hidden', 6 => 'hidden'));
                            // Creat dropdown
                            $dataTypes = PrivateDataType::get_private_data_types();
                            $PdataModal->setType($dataTypes);
                            $PdataModal->setUpdateValue('update_private_data');
                            $PdataModalID = "modal_private_data_id" . $id;
                            // Change button text
                            $PdataModal->setModalID($PdataModalID);
                            $modalForms .= $PdataModal->modalForm();
                            // End Update modal
                            // Now a Modal to Delete an Entry
                            // We'll ask for the password again.
                            $modalFormDelete = new Form("auto", 2);
                            $modalFormDelete->setHeadings(array("Delete " . $privDataObj->get_name() . "<br>Please provide group password for " . $privDataObj->get_group_name()));
                            $modalFormDelete->setTitles(array("Password", "group_id", ""));
                            $modalFormDelete->setData(array("", $privDataObj->get_group_id(), $id));
                            $modalFormDelete->setDatabase(array('group_pass', 'group_id', 'private_data_id'));
                            $modalFormDelete->setFieldType(array(0 => 'password_autocomplete_off', 1 => 'hidden', 2 => 'hidden'));
                            $myDeleteModalID = "modal_delete_pass_" . $id;
                            // Change button text
                            $modalFormDelete->setUpdateValue("delete_private_data");
                            $modalFormDelete->setUpdateText("Delete");
                            $modalFormDelete->setModalID($myDeleteModalID);
                            $modalForms .= $modalFormDelete->modalForm();
                            // End Delete modal
                            if (count($historical_passwords) > 0) {
                                $history_string = "<a name='modal' href='#" . $myHistoryModalID . "'>History</a>";
                            } else {
                                $history_string = "<i>No History</i>";
                            }
                            array_push($data, $privDataObj->get_type_desc() . $type_tooltip, $privDataObj->get_name() . "{$name_tooltip}", $password, $privDataObj->get_group_name(), "<a name='modal' href='#" . $PdataModalID . "'>Edit</a> &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp\n\t\t\t\t\t\t\t\t<a name='modal' href='#" . $myDeleteModalID . "'>Delete</a> &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp\n\t\t\t\t\t\t\t\t{$history_string}");
                            // Replace Heading of original Form, where used to be Group,
                            // we now make the Edit / Delete fields
                        } else {
                            array_push($data, $privDataObj->get_type_desc() . $type_tooltip, $privDataObj->get_name(), "*********", $privDataObj->get_group_name(), "<b>Could not retrieve Private Data. Reason: " . $privDataObj->get_error() . "</b><br><a name='modal' href='#" . $myModalID . "'>Unlock Private Data</a>");
                        }
                    } else {
                        array_push($data, $privDataObj->get_type_desc() . $type_tooltip, $privDataObj->get_name() . $name_tooltip, "*********", $privDataObj->get_group_name(), "<a name='modal' href='#" . $myModalID . "'>Unlock Private Data</a>");
                    }
                }
                $pdata_form = new Form("auto", 5);
                $pdata_form->setSortable(true);
                $pdata_form->setHeadings($heading);
                $pdata_form->setData($data);
                $pdata_form->setTableWidth("777px");
                echo $pdata_form->showForm();
                echo $modalForms;
            } else {
                //echo "No Private data for this Device";
            }
            echo $private_data_type_modal;
        }
    }
    echo "</div>";
}
Example #4
0
 function modalForm($headingName, $titleName, $infoArray, $infoKey, $type = '', $location = '', $modalID = '')
 {
     parent::setHeadings($headingName);
     parent::setTitles($titleName);
     parent::setData($infoArray);
     parent::setSortable(false);
     parent::setDatabase($infoKey);
     foreach ($type as $id => $value) {
         if (is_array($value)) {
             parent::setType($value);
         } else {
             parent::setType($type);
             break;
         }
     }
     parent::setModalID($modalID);
     return parent::modalForm(10);
 }
Example #5
0
function displayGroupManagement()
{
    global $tool, $propertyForm;
    $groups = Group::get_groups();
    echo "<style>";
    foreach ($groups as $id => $value) {
        echo "#modalBox #allUserDialog" . $id;
        echo "{\n\t\t\twidth:auto;\n\t\t\tmax-width: 80%;\n\t\t\tmin-width:40%;\n\t\t\theight:auto;\n\t\t\tpadding:10px;\n\t\t\tpadding-top:10px;\n\t\t\toverflow:auto;\n\t\t}";
    }
    echo "</style>";
    $toolNames = array("Add Group");
    $toolIcons = array("add");
    $formType = array("newDialog");
    echo $tool->createNewModal($toolNames, $toolIcons, $formType);
    foreach ($groups as $id => $value) {
        $curGroup = new Group($id);
        $groupID = $id;
        $access = $curGroup->get_access_level();
        switch ($access) {
            case 0:
                $access = "No Access";
                break;
            case 25:
                $access = "Read Only";
                break;
            case 50:
                $access = "Read Write Only";
                break;
            case 100:
                $access = "Admin";
                break;
        }
        echo "<form method='post' action='' style='width:1024px;'><input type='hidden' name='groupID' value='" . $curGroup->get_group_id() . "' />\n\t\t<table id=\"sortDataTable\" class='sortable' cellspacing=\"0\" cellpadding=\"0\" border=\"1\" style='width:100%; clear:left;'>\n\t\t<thead>\n\t\t<tr>\n\t\t<th style='text-align:left;'>" . $curGroup->get_name() . "</th>\n\t\t<th colspan='10'><a name='modal' href='#dialog" . $id . "' style='float:right; margin-bottom:5px; margin-right: 5px;'>Edit</a></th>\n\t\t</tr>\n\t\t</thead>\n\t\t<tbody>";
        if ($curGroup->get_group_pass() == true) {
            $myModalID = "modalPass" . $curGroup->get_group_id();
            // Check if it already has a password or not.
            if ($curGroup->has_password() == 1) {
                // Already has a password
                // this is to update existing pass
                // Create custom input field for password
                // as type password is not defined in class...
                $group_pass = "******" . $myModalID . "'>Update Group Password</a>";
                $heading = array("Update Group Password");
                $title = array("Old Password", "New Password", "New Password", "group_id", "action");
                $keys = array("old_pass", "new_pass1", "new_pass2", "group_id", "update_group_key");
                $data = array("", "", "", $curGroup->get_group_id(), "update_group_key");
                $fieldType = array(0 => "password", 1 => "password", 2 => "password", 3 => "hidden", 4 => "hidden");
            } elseif ($curGroup->has_password() == 0) {
                // Group does not yet have a pass
                // Inital password will be set below
                $group_pass = "******" . $myModalID . "'>Set Group Password</a>";
                $heading = array("Configure Group Password");
                $title = array("Old Password", "New Password", "New Password", "group_id", "action");
                $keys = array("old_pass", "new_pass1", "new_pass2", "group_id", "update_group_key");
                $data = array("dummy", "", "", $curGroup->get_group_id(), "update_group_key");
                $fieldType = array(0 => 'hidden', 1 => 'password', 2 => 'password', 3 => "hidden", 4 => "hidden");
            }
            // Modal for password update
            $form = new Form("auto", 2);
            $form->setHeadings($heading);
            $form->setTitles($title);
            $form->setData($data);
            $form->setDatabase($keys);
            $form->setFieldType($fieldType);
            $form->setModalID($myModalID);
            //set the table size
            $form->setTableWidth("1024px");
            $form->setTitleWidth("20%");
            $modal_group_pass .= $form->modalForm();
            // End Modal for group pass
        } else {
            $group_pass = "******";
        }
        echo "\n\t\t<tr class='form'><td style='text-align:left; width:200px;'><h3>Description</h3>" . $curGroup->get_description() . "</td>\n\t\t<td style='text-align:left; width:200px;'><h3>LDAP Group Name</h3>" . $curGroup->get_ldap_group_name() . "</td>\n\t\t<td style='text-align:left; width:100px;'><h3>Access Level</h3>" . $access . "</td>\n\t\t<td style='text-align:left; width:100px;'><h3>Access To Private Data</h3>" . $group_pass . "</td></tr>";
        echo "<tr class='form'><td colspan='4'>";
        $groupUsers = $curGroup->get_users();
        foreach ($groupUsers as $id => $value) {
            echo "<input type='checkbox' name='userList[]' value='" . $id . "'>" . $value . " | ";
        }
        echo "<a name=modal href='#allUserDialog" . $groupID . "'>Add User...</a>\n\t\t</td></tr>";
        echo "</tbody>\n\t\t</table>";
        echo "<input type='submit' name='delUserFromGroup' value='Delete Users From Group' style='float:right; margin-bottom:5px; margin-right: 5px;' />";
        echo "<input type='submit' name='delGroup' value='Delete Group' style='float:left; clear:left; margin-bottom:20px;' />\n\t\t</form>";
        echo "<div id='modalBox'>";
        $users = User::get_users();
        echo "<div id='allUserDialog" . $groupID . "' class='window'>\n\t\t\t <a href='#'class='close' /><img src='icons/close.png'></a>\n\t\t\t <form method='post' action=''>\n\t\t\t <input type='hidden' name='groups2' value='" . $curGroup->get_group_id() . "' />";
        foreach ($users as $id => $value) {
            $isIn = false;
            foreach ($groupUsers as $gid => $gvalue) {
                if ($value == $gvalue) {
                    $isIn = true;
                }
            }
            if (!$isIn) {
                echo "<input type='checkbox' name='list[]' value='" . $id . "'>" . $value . " | ";
            }
        }
        echo "<input type='submit' name='userToGroup' value='Add Users to Group' />";
        echo "</form>\n\t\t\t </div>";
        echo "<div id='mask'></div>\n\t\t\t </div>";
    }
    $heading = array("Group Information");
    $title = array("Group Name", "Group Description", "Access Level");
    $key = array("name", "desc", "access");
    foreach ($groups as $id => $value) {
        $curGroup = new Group($id);
        switch ($curGroup->get_access_level()) {
            case 0:
                $value = "No Access";
                break;
            case 25:
                $value = "Read Only";
                break;
            case 50:
                $value = "Read Write Only";
                break;
            case 100:
                $value = "Admin";
                break;
        }
        if ($curGroup->get_group_pass() == true) {
            $group_pass = "******";
        } else {
            $group_pass = "******";
        }
        $info = array($id, $curGroup->get_name(), $curGroup->get_description(), $value, $curGroup->get_ldap_group_name(), $group_pass);
        // Only render group pass if it's
        $heading2 = array("Group Information");
        $title2 = array("ID", "Group Name", "Group Description", "Access Level", "LDAP Group", "Enable Private Data access");
        $key2 = array("id", "name", "desc", "access", "ldap", "group_pass");
        //create a new modal form for a new interface ports
        $fieldType = array(0 => "static", 3 => "drop_down", 5 => "drop_down");
        $propertyForm->setFieldType($fieldType);
        $accessLevel = array(0 => "No Access", 25 => "Read Only", 50 => "Read Write Only", 100 => "Admin");
        $group_pass = array(0 => "Disabled", 1 => "Enabled");
        $propertyForm->setType($accessLevel);
        $propertyForm->setType($group_pass);
        echo $propertyForm->editModalForm($heading2, $title2, $info, $key2, "dialog" . $id, "updateGroup");
    }
    //create a new modal form for a new interface ports
    $fieldType = array(2 => "drop_down");
    $propertyForm->setFieldType($fieldType);
    $accessLevel = array(0 => "No Access", 25 => "Read Only", 50 => "Read Write Only", 100 => "Admin");
    $propertyForm->setType($accessLevel);
    echo $propertyForm->newModalForm($heading, $title, $key, "addGroup");
    echo $modal_group_pass;
}