}
     if (!empty($_POST['EditPool'])) {
         $query = $update;
         $db_msg_good = $errors['db_edit'];
         $db_msg_err = $errors['db_edit_err'];
     }
     if (!empty($_POST['DelPool'])) {
         $query = $delete;
         $db_msg_good = $errors['db_del'];
         $db_msg_err = $errors['db_del_err'];
     }
     // process our query
     if (($value = $db->dbQuery($val->ValidateSQL($query, $dbconn), $dbconn)) === -1) {
         $error = $err->GenerateErrorLink("help/help.html", "#config_pool", $defined['error'], $db_msg_err, NULL, NULL);
         // attempt to update if record exists
         if (eregi("duplicate", $db->dbCatchError()) || !empty($id)) {
             if (($value = $db->dbQuery($val->ValidateSQL($update, $dbconn), $dbconn)) === -1) {
                 $error = $err->GenerateErrorLink("help/help.html", "#config_pool", $defined['error'], $errors['db_edit_err'], NULL, NULL);
             } else {
                 $error = $err->GenerateErrorLink("help/help.html", "#config_pool", $defined['good'], $errors['db_edit'], NULL, NULL);
             }
         }
     } else {
         $error = $err->GenerateErrorLink("help/help.html", "#config_pool", $defined['good'], $db_msg_good, NULL, NULL);
     }
 } else {
     // find validation errors
     $e = $err->GenerateErrorImg($defined['error'], "help/help.html#config_pool", '800', '800');
     $list .= "<ol>";
     if ($val->ValidateString($pool_name) === -1) {
         $list .= "<li>Pool field is invalid</li>";
 if (eregi(".*\\.[xml]", $upload_path)) {
 }
 // loop over our array and assign data to our template
 for ($x = 1; $x <= count($tmp); $x++) {
     // open an ordered list
     $list .= "<ol>";
     // check each post element
     if (!empty($tmp[$x]['hostname']) && !empty($tmp[$x]['mac_address']) && !empty($tmp[$x]['ip_address'])) {
         // begin validation of file contents
         if ($val->ValidateParagraph($tmp[$x]['hostname']) !== -1 && $val->ValidateMACFormats($tmp[$x]['mac_address']) !== -1 && $val->ValidateIPv4($tmp[$x]['ip_address']) !== -1 && $val->ValidateParagraph($tmp[$x]['subnet']) !== -1 && $val->ValidateParagraph($tmp[$x]['pxe_group']) !== -1) {
             // generate our sql command
             $insert = "INSERT INTO `conf_hosts` ( `hostname`, `mac-address`, `ip-address`, `subnet-name`, `pxe-group` ) VALUES ( \"" . $tmp[$x]['hostname'] . "\",\"" . $tmp[$x]['mac_address'] . "\", \"" . $tmp[$x]['ip_address'] . "\", \"" . $tmp[$x]['subnet'] . "\", \"" . $tmp[$x]['pxe_group'] . "\" )";
             // insert records or prompt for duplicate errors
             if (($value = $db->dbQuery($val->ValidateSQL($insert, $dbconn), $dbconn)) === -1) {
                 // found an existing record?
                 if (eregi("duplicate", $db->dbCatchError())) {
                     // assign an error message
                     $error = $err->GenerateErrorLink("help/help.html", "#import_host", $defined['error'], "Duplicate records found during import, please review and modify the data below accordingly.", NULL, NULL);
                     // since we have a duplicate and not an invalid record give them the correct template
                     $error_template = "admin.import.hosts.errors.tpl";
                     // find the duplicate record so the user can edit it
                     $find = "SELECT * FROM `conf_hosts` WHERE `hostname` = \"" . $tmp[$x]['hostname'] . "\" OR `mac-address` = \"" . $tmp[$x]['mac_address'] . "\" OR `ip-address` = \"" . $tmp[$x]['mac_address'] . "\" LIMIT 1";
                     if (($value = $db->dbQuery($val->ValidateSQL($find, $dbconn), $dbconn)) === -1) {
                         $error = $err->GenerateErrorLink("help/help.html", "#import_host", $defined['error'], "An error occured when attempting to lookup the duplicate record in which '" . $tmp[$x]['hostname'] . "' conflicts with.", NULL, NULL);
                     } else {
                         $found = $db->dbArrayResultsAssoc($value);
                     }
                     // populate our subnets list for our imported record
                     $sub = "SELECT `subnet-name` FROM `conf_subnets` ORDER BY `subnet-name` ASC";
                     if (($return = $db->dbQuery($val->ValidateSQL($sub, $dbconn), $dbconn)) !== -1) {
                         $subs = $db->dbArrayResultsAssoc($return);
 }
 if (!empty($_POST['EditHosts'])) {
     $query = $update;
     $db_msg_good = $errors['db_edit'];
     $db_msg_err = $errors['db_edit_err'];
 }
 if (!empty($_POST['DelHosts'])) {
     $query = $delete;
     $db_msg_good = $errors['db_del'];
     $db_msg_err = $errors['db_del_err'];
 }
 // process our query
 if (($value = $db->dbQuery($val->ValidateSQL($query, $dbconn), $dbconn)) === -1) {
     $error = $err->GenerateErrorLink("help/help.html", "#host_search", $defined['error'], $db_msg_err, NULL, NULL);
     // does the record exist? a duplicate mac, ip or hostname is not allowed
     if (eregi("duplicate", $db->dbCatchError()) && !empty($id) || !empty($modify) && $modify === "modify") {
         // look at error and grab the existing record
         @preg_match('/.*\'(.*)\'.*/', $db->dbCatchError(), $dup);
         // make sure users can't edit other group records
         if ($group !== "admin") {
             $sql = "SELECT `id` FROM `conf_hosts` WHERE `ip-address` LIKE \"" . $dup[1] . "\" OR `hostname` LIKE \"" . $dup[1] . "\" OR `mac-address` LIKE \"" . $dup[1] . "\" HAVING `group` = \"" . $group . "\"";
         } else {
             $sql = "SELECT `id` FROM `conf_hosts` WHERE `ip-address` LIKE \"" . $dup[1] . "\" OR `hostname` LIKE \"" . $dup[1] . "\" OR `mac-address` LIKE \"" . $dup[1] . "\"";
         }
         // execute the database query for our matching record
         if (($value = $db->dbQuery($val->ValidateSQL($sql, $dbconn), $dbconn)) !== -1) {
             $ids = $db->dbArrayResults($value);
         }
         // create new `update` sql statement with matching id to overwrite record as per requested
         if ($group === "admin") {
             $update = "UPDATE `conf_hosts` SET `hostname` = \"" . $hostname . "\", `mac-address` = \"" . $mac_address . "\", `ip-address` = \"" . $ip_address . "\", `subnet-name` = \"" . $subnet_name . "\", `pxe-group` = \"" . $pxe_group . "\", `group` = \"" . $group . "\" WHERE `id` = \"" . $ids[0]['id'] . "\" LIMIT 1";
Esempio n. 4
0
// Assign some defaults since nothing is configured
$TITLE = "phpDHCPAdmin-0.9.5-beta Setup Wizard";
$STYLE = "../templates/black";
$DESCRIPTION = "I am here to help you import the database structure and setup the application defaults";
$DISCLAIMER = "All rights reserved 2009 &reg; Jason Gerfen";
$TABLES = array('admin_backup_conf', 'admin_config_algorithm', 'admin_logs', 'admin_sessions', 'auth_groups', 'auth_levels', 'auth_users', 'conf_adapters', 'conf_classes', 'conf_classes_options', 'conf_classes_opts', 'conf_dnssec_opts', 'conf_dns_opts', 'conf_failover', 'conf_global_opts', 'conf_hosts', 'conf_leases', 'conf_leases_properties', 'conf_pools', 'conf_pxe_groups', 'conf_pxe_opts', 'conf_shared_networks', 'conf_subnets', 'conf_traffic');
$REGEX = array('/\\$defined[\'hostname\']\\s\\s\\s\\s=\\s\\"\\";/', '/\\$defined[\'dbhost\']\\s\\s\\s\\s\\s\\s=\\s\\"localhost\\";/', '/\\$defined[\'username\']\\s\\s\\s\\s=\\s\\"\\";/', '/\\$defined[\'password\']\\s\\s\\s\\s=\\s\\"\\";/', '/\\$defined[\'mail\']\\s\\s\\s\\s\\s\\s\\s\\s=\\s\\"\\";/', '/\\$defined[\'virpath\']\\s\\s\\s\\s\\s=\\s\\"\\";/');
// lets process the form
if (!empty($_POST)) {
    // make sure we have a complete form submission
    if (!empty($_POST['mysql_root_user']) && !empty($_POST['mysql_root_passwd']) && !empty($_POST['defined_hostname']) && !empty($_POST['mysql_server_address']) && !empty($_POST['mysql_server_username']) && !empty($_POST['mysql_server_password']) && !empty($_POST['configuration_path']) && !empty($_POST['admin_email'])) {
        // ensure nothing screwy is going on in regards to input
        if ($val->ValidateString($_POST['mysql_root_user']) !== -1 && $val->ValidateParagraph($_POST['mysql_root_passwd']) !== -1 && $val->ValidateDomain($_POST['defined_hostname']) !== -1 && $val->ValidateDomain($_POST['mysql_server_address']) !== -1 && $val->ValidateParagraph($_POST['mysql_server_username']) !== -1 && $val->ValidateParagraph($_POST['mysql_server_password']) !== -1 && $val->ValidateParagraph($_POST['configuration_path']) !== -1 && $val->ValidateEmail($_POST['admin_email']) !== -1) {
            // ensure our root username & password is correct
            $dbconn = $db->dbConnectOnly($_POST['mysql_server_address'], $_POST['mysql_root_user'], $_POST['mysql_root_passwd']);
            echo $db->dbCatchError();
            if ($dbconn === -1) {
                $error = $err->GenerateErrorLink("../help/help.html", "#app_setup", '../templates/images/error.jpg', "Error connecting to the database during initial connection. Wrong username/password combination", NULL, NULL);
            } else {
                // perform our .sql file import (this fails if it exists already)
                $cmd = "mysql -u " . $_POST['mysql_root_user'] . " --password="******" < phpDHCPAdmin.sql";
                `{$cmd}`;
                // create a default user based on the form input
                $dbconn = $db->dbConnect($_POST['mysql_server_address'], $_POST['mysql_root_user'], $_POST['mysql_root_passwd'], 'phpDHCPAdmin');
                if ($dbconn === -1) {
                    $error = $err->GenerateErrorLink("../help/help.html", "#app_setup", '../templates/images/error.jpg', "Error connecting to the database. Wrong username/password combination", NULL, NULL);
                } else {
                    $query = "GRANT SELECT,INSERT,UPDATE,DELETE,INDEX,REFERENCES ON phpDHCPAdmin.* TO '" . $_POST['mysql_server_username'] . "'@'" . $_POST['mysql_server_address'] . "' IDENTIFIED BY '" . $_POST['mysql_server_password'] . "'";
                    if (($value = $db->dbQuery($val->ValidateSQL($query, $dbconn), $dbconn)) === -1) {
                        $error = $err->GenerateErrorLink("../help/help.html", "#create_admin_user", '../templates/images/error.jpg', "There was a problem when creating the default user that the phpDHCPAdmin application will use to keep persistant connections to the database", NULL, NULL);
                    } else {
 function ProcessAdapterDetails($array)
 {
     global $defined;
     $db = new dbConn();
     $val = new ValidateStrings();
     $lib = new MiscFunctions();
     $insert = '';
     $update = '';
     $key = '';
     $value = array();
     // initialize a db connection handle
     $dbconn = $db->dbConnect($defined['dbhost'], $defined['username'], $defined['password'], $defined['dbname']);
     // begin loop
     foreach ($array as $key => $value) {
         // sql statements
         $insert = "INSERT INTO `conf_adapters` ( `name`, `encap`, `hwaddr`, `ipv4`, `broadcast`, `mask`, `ipv6`, `flags`, `rx_packets`, `rx_errors`, `rx_dropped`, `rx_overruns`, `rx_frame`, `tx_packets`, `tx_errors`, `tx_dropped`, `tx_overruns`, `tx_carrier`, `rx_bytes`, `tx_bytes` ) VALUES ( \"" . $key . "\", \"" . $value['encap'] . "\", \"" . $value['hwaddr'] . "\", \"" . $value['ipv4'] . "\", \"" . $value['broadcast'] . "\", \"" . $value['mask'] . "\", \"" . $value['ipv6'] . "\", \"" . $value['flags'] . "\", \"" . $value['RX_packets'] . "\", \"" . $value['RX_errors'] . "\", \"" . $value['RX_dropped'] . "\", \"" . $value['RX_overruns'] . "\", \"" . $value['RX_frame'] . "\", \"" . $value['TX_packets'] . "\", \"" . $value['TX_errors'] . "\", \"" . $value['TX_dropped'] . "\", \"" . $value['TX_overruns'] . "\", \"" . $value['TX_carrier'] . "\", \"" . $value['RX_total'] . "\", \"" . $value['TX_total'] . "\" )";
         $update = "UPDATE `conf_adapters_details` SET `name` = \"" . $key . "\", `encap` = \"" . $value['encap'] . "\", `hwaddr` = \"" . $value['hwaddr'] . "\", `ipv4` = \"" . $value['ipv4'] . "\", `broadcast` = \"" . $value['broadcast'] . "\", `mask` = \"" . $value['mask'] . "\", `ipv6` = \"" . $value['ipv6'] . "\", `flags` = \"" . $value['flags'] . "\", `rx_packets` = \"" . $value['RX_packets'] . "\", `rx_errors` = \"" . $value['RX_errors'] . "\", `rx_dropped` = \"" . $value['RX_dropped'] . "\", `rx_overruns` = \"" . $value['RX_overruns'] . "\", `rx_frame` = \"" . $value['RX_frame'] . "\", `tx_packets` = \"" . $value['TX_packets'] . "\", `tx_errors` = \"" . $value['TX_errors'] . "\", `tx_dropped` = \"" . $value['TX_dropped'] . "\", `tx_overruns` = \"" . $value['TX_overruns'] . "\", `tx_carrier` = \"" . $value['TX_carrier'] . "\", `rx_bytes` = \"" . $value['RX_total'] . "\", `tx_bytes` = \"" . $value['TX_total'] . "\" WHERE `name` = \"" . $key . "\" LIMIT 1";
         // determine if an traffic table update should occur
         if ($value['RX_total'] !== 0) {
             // time machine calcs
             // (only run once an hour)
             $now = $this->GenTime();
             // grab some current traffic data
             $res = $db->dbQuery($val->ValidateSQL("SELECT `time` FROM `conf_traffic` WHERE `time` < \"" . $now . "\" AND `bytes` > 0 AND `interface` = \"" . $key . "\" LIMIT 1", $dbconn), $dbconn);
             $times = $db->dbArrayResults($res);
             // get a value we can compare against an hour
             $test = abs($now - $times[0]['time']);
             // insert some data
             if ($test > 3600 && !empty($value['RX_total'])) {
                 $traffic = "INSERT INTO `conf_traffic` ( `interface`, `bytes`, `time` ) VALUES ( \"" . $key . "\", \"" . $value['RX_total'] . "\", UNIX_TIMESTAMP() )";
                 $db->dbQuery($val->ValidateSQL($traffic, $dbconn), $dbconn);
             }
         }
         // do the db stuff for our adapters
         if ($db->dbQuery($val->ValidateSQL($insert, $dbconn), $dbconn) !== 0) {
             if (eregi("duplicate", $db->dbCatchError())) {
                 $db->dbQuery($val->ValidateSQL($update, $dbconn), $dbconn);
             }
         }
     }
 }