if (empty($_SESSION['token'])) {
     $sessions = new dbSession();
 }
 //define the template and cache directories
 $tpl->strTemplateDir = $defined['virpath'] . 'templates';
 $tpl->strCacheDir = '/tmp';
 if (!empty($_GET) || !empty($_POST)) {
     $flag = "TRUE";
 } else {
     $flag = "FALSE";
 }
 // setup our template style data
 if ($val->ValidateString($_GET['skin']) === -1 || empty($_GET['skin'])) {
     $style = $defined['templates'] . "/black";
     if (!empty($_GET['skin'])) {
         $skin_err = $err->GenerateErrorLink("help/help.php", "#val_xss", $defined['error_small'], $errors['val_xss'], NULL, NULL);
     }
 } else {
     $style = $skin->SelectSkin($defined['templates'], $_GET['skin'], $_COOKIE['skin']);
 }
 // call our header file and pass it some variables
 $tpl->assign('TITLE', $defined['title'], NULL, NULL);
 $tpl->assign('DESCRIPTION', "Manage Master/Peer Failover Options", NULL, NULL);
 $tpl->assign('STYLE', $style, NULL, NULL);
 // authentication template
 $FILE = "auth.tpl";
 // default is no error just diplay login form
 if ($auth->AuthUser($_POST['user'], $_POST['pass'], $_SESSION['token']) === -1) {
     // well looks like at least one login attempt has been processed, show empty field error
     if ($_SESSION['x']++ >= 1) {
         $ERROR = $err->GenerateErrorLink("help/help.html", "#missing", $defined['error'], $errors['auth_e'], NULL, NULL);
 if (empty($_SESSION['token'])) {
     $sessions = new dbSession();
 }
 //define the template and cache directories
 $tpl->strTemplateDir = $defined['virpath'] . 'templates';
 $tpl->strCacheDir = '/tmp';
 if (!empty($_GET) || !empty($_POST)) {
     $flag = "TRUE";
 } else {
     $flag = "FALSE";
 }
 // setup our template style data
 if ($val->ValidateString($_GET['skin']) === -1 || empty($_GET['skin'])) {
     $style = $defined['templates'] . "/black";
     if (!empty($_GET['skin'])) {
         $skin_err = $err->GenerateErrorLink("help/help.php", "#val_xss", $defined['error_small'], $errors['val_xss'], NULL, NULL);
     }
 } else {
     $style = $skin->SelectSkin($defined['templates'], $_GET['skin'], $_COOKIE['skin']);
 }
 // call our header file and pass it some variables
 $tpl->assign('TITLE', $defined['title'], NULL, NULL);
 $tpl->assign('DESCRIPTION', "Manage Pools", NULL, NULL);
 $tpl->assign('STYLE', $style, NULL, NULL);
 // authentication template
 $FILE = "auth.tpl";
 // default is no error just diplay login form
 if ($auth->AuthUser($_POST['user'], $_POST['pass'], $_SESSION['token']) === -1) {
     // well looks like at least one login attempt has been processed, show empty field error
     if ($_SESSION['x']++ >= 1) {
         $ERROR = $err->GenerateErrorLink("help/help.html", "#missing", $defined['error'], $errors['auth_e'], NULL, NULL);
 if (empty($_SESSION['token'])) {
     $sessions = new dbSession();
 }
 //define the template and cache directories
 $tpl->strTemplateDir = $defined['virpath'] . 'templates';
 $tpl->strCacheDir = '/tmp';
 if (!empty($_GET) || !empty($_POST)) {
     $flag = "TRUE";
 } else {
     $flag = "FALSE";
 }
 // setup our template style data
 if ($val->ValidateString($_GET['skin']) === -1 || empty($_GET['skin'])) {
     $style = $defined['templates'] . "/black";
     if (!empty($_GET['skin'])) {
         $skin_err = $err->GenerateErrorLink("help/help.php", "#val_xss", $defined['error_small'], $errors['val_xss'], NULL, NULL);
     }
 } else {
     $style = $skin->SelectSkin($defined['templates'], $_GET['skin'], $_COOKIE['skin']);
 }
 // call our header file and pass it some variables
 $tpl->assign('TITLE', $defined['title'], NULL, NULL);
 $tpl->assign('DESCRIPTION', "Manage Leases", NULL, NULL);
 $tpl->assign('STYLE', $style, NULL, NULL);
 // authentication template
 $FILE = "auth.tpl";
 // default is no error just diplay login form
 if ($auth->AuthUser($_POST['user'], $_POST['pass'], $_SESSION['token']) === -1) {
     // well looks like at least one login attempt has been processed, show empty field error
     if ($_SESSION['x']++ >= 1) {
         $ERROR = $err->GenerateErrorLink("help/help.html", "#missing", $defined['error'], $errors['auth_e'], NULL, NULL);
 if (empty($_SESSION['token'])) {
     $sessions = new dbSession();
 }
 //define the template and cache directories
 $tpl->strTemplateDir = $defined['virpath'] . 'templates';
 $tpl->strCacheDir = '/tmp';
 if (!empty($_GET) || !empty($_POST)) {
     $flag = "TRUE";
 } else {
     $flag = "FALSE";
 }
 // setup our template style data
 if ($val->ValidateString($_GET['skin']) === -1 || empty($_GET['skin'])) {
     $style = $defined['templates'] . "/black";
     if (!empty($_GET['skin'])) {
         $skin_err = $err->GenerateErrorLink("help/help.php", "#val_xss", $defined['error_small'], $errors['val_xss'], NULL, NULL);
     }
 } else {
     $style = $skin->SelectSkin($defined['templates'], $_GET['skin'], $_COOKIE['skin']);
 }
 // call our header file and pass it some variables
 $tpl->assign('TITLE', $defined['title'], NULL, NULL);
 $tpl->assign('DESCRIPTION', "Manage Backups of dhcpd.conf", NULL, NULL);
 $tpl->assign('STYLE', $style, NULL, NULL);
 // authentication template
 $FILE = "auth.tpl";
 // default is no error just diplay login form
 if ($auth->AuthUser($_POST['user'], $_POST['pass'], $_SESSION['token']) === -1) {
     // well looks like at least one login attempt has been processed, show empty field error
     if ($_SESSION['x']++ >= 1) {
         $ERROR = $err->GenerateErrorLink("help/help.html", "#missing", $defined['error'], $errors['auth_e'], NULL, NULL);
 if (empty($_SESSION['token'])) {
     $sessions = new dbSession();
 }
 //define the template and cache directories
 $tpl->strTemplateDir = '../../../../templates';
 $tpl->strCacheDir = '/tmp';
 if (!empty($_GET) || !empty($_POST)) {
     $flag = "TRUE";
 } else {
     $flag = "FALSE";
 }
 // setup our template style data
 if ($val->ValidateString($_GET['skin']) === -1 || empty($_GET['skin'])) {
     $style = $defined['templates'] . "/black";
     if (!empty($_GET['skin'])) {
         $skin_err = $err->GenerateErrorLink("help/help.php", "#val_xss", $defined['error_small'], $errors['val_xss'], NULL, NULL);
     }
 } else {
     $style = $skin->SelectSkin($defined['templates'], $_GET['skin'], $_COOKIE['skin']);
 }
 // call our header file and pass it some variables
 $tpl->assign('TITLE', $defined['title'], NULL, NULL);
 $tpl->assign('DESCRIPTION', $defined['description'], NULL, NULL);
 $tpl->assign('STYLE', $style, NULL, NULL);
 // javascript to set focus on login form
 $JS = " document.login.user.focus();";
 // authentication template
 $FILE = "auth.tpl";
 // default is no error just diplay login form
 if ($auth->AuthUser($_POST['user'], $_POST['pass'], $_SESSION['token']) === -1) {
     // well looks like at least one login attempt has been processed, show empty field error
$STYLE = "../templates/black";
$DESCRIPTION = "I am here to help you import the database structure and setup the application defaults";
$DISCLAIMER = "All rights reserved 2009 ® 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 {
                        $query = "FLUSH PRIVILEGES";
                        if (($value = $db->dbQuery($val->ValidateSQL($query, $dbconn), $dbconn)) === -1) {
 if (empty($_SESSION['token'])) {
     $sessions = new dbSession();
 }
 //define the template and cache directories
 $tpl->strTemplateDir = $defined['virpath'] . 'templates';
 $tpl->strCacheDir = '/tmp';
 if (!empty($_GET) || !empty($_POST)) {
     $flag = "TRUE";
 } else {
     $flag = "FALSE";
 }
 // setup our template style data
 if ($val->ValidateString($_GET['skin']) === -1 || empty($_GET['skin'])) {
     $style = $defined['templates'] . "/black";
     if (!empty($_GET['skin'])) {
         $skin_err = $err->GenerateErrorLink("help/help.php", "#val_xss", $defined['error_small'], $errors['val_xss'], NULL, NULL);
     }
 } else {
     $style = $skin->SelectSkin($defined['templates'], $_GET['skin'], $_COOKIE['skin']);
 }
 // call our header file and pass it some variables
 $tpl->assign('TITLE', $defined['title'], NULL, NULL);
 $tpl->assign('DESCRIPTION', "Manage Groups", NULL, NULL);
 $tpl->assign('STYLE', $style, NULL, NULL);
 // authentication template
 $FILE = "auth.tpl";
 // default is no error just diplay login form
 if ($auth->AuthUser($_POST['user'], $_POST['pass'], $_SESSION['token']) === -1) {
     // well looks like at least one login attempt has been processed, show empty field error
     if ($_SESSION['x']++ >= 1) {
         $ERROR = $err->GenerateErrorLink("help/help.html", "#missing", $defined['error'], $errors['auth_e'], NULL, NULL);
 if (empty($_SESSION['token'])) {
     $sessions = new dbSession();
 }
 //define the template and cache directories
 $tpl->strTemplateDir = $defined['virpath'] . 'templates';
 $tpl->strCacheDir = '/tmp';
 if (!empty($_GET) || !empty($_POST)) {
     $flag = "TRUE";
 } else {
     $flag = "FALSE";
 }
 // setup our template style data
 if ($val->ValidateString($_GET['skin']) === -1 || empty($_GET['skin'])) {
     $style = $defined['templates'] . "/black";
     if (!empty($_GET['skin'])) {
         $skin_err = $err->GenerateErrorLink("help/help.php", "#val_xss", $defined['error_small'], $errors['val_xss'], NULL, NULL);
     }
 } else {
     $style = $skin->SelectSkin($defined['templates'], $_GET['skin'], $_COOKIE['skin']);
 }
 // call our header file and pass it some variables
 $tpl->assign('TITLE', $defined['title'], NULL, NULL);
 $tpl->assign('DESCRIPTION', "Manage Subnets", NULL, NULL);
 $tpl->assign('STYLE', $style, NULL, NULL);
 // authentication template
 $FILE = "auth.tpl";
 // default is no error just diplay login form
 if ($auth->AuthUser($_POST['user'], $_POST['pass'], $_SESSION['token']) === -1) {
     // well looks like at least one login attempt has been processed, show empty field error
     if ($_SESSION['x']++ >= 1) {
         $ERROR = $err->GenerateErrorLink("help/help.html", "#missing", $defined['error'], $errors['auth_e'], NULL, NULL);
 if (empty($_SESSION['token'])) {
     $sessions = new dbSession();
 }
 //define the template and cache directories
 $tpl->strTemplateDir = $defined['virpath'] . 'templates';
 $tpl->strCacheDir = '/tmp';
 if (!empty($_GET) || !empty($_POST)) {
     $flag = "TRUE";
 } else {
     $flag = "FALSE";
 }
 // setup our template style data
 if ($val->ValidateString($_GET['skin']) === -1 || empty($_GET['skin'])) {
     $style = $defined['templates'] . "/black";
     if (!empty($_GET['skin'])) {
         $skin_err = $err->GenerateErrorLink("help/help.php", "#val_xss", $defined['error_small'], $errors['val_xss'], NULL, NULL);
     }
 } else {
     $style = $skin->SelectSkin($defined['templates'], $_GET['skin'], $_COOKIE['skin']);
 }
 // call our header file and pass it some variables
 $tpl->assign('TITLE', $defined['title'], NULL, NULL);
 $tpl->assign('DESCRIPTION', "Output new dhcpd.conf and restart ISC DHCPD service", NULL, NULL);
 $tpl->assign('STYLE', $style, NULL, NULL);
 // authentication template
 $FILE = "auth.tpl";
 // default is no error just diplay login form
 if ($auth->AuthUser($_POST['user'], $_POST['pass'], $_SESSION['token']) === -1) {
     // well looks like at least one login attempt has been processed, show empty field error
     if ($_SESSION['x']++ >= 1) {
         $ERROR = $err->GenerateErrorLink("help/help.html", "#missing", $defined['error'], $errors['auth_e'], NULL, NULL);
 if (empty($_SESSION['token'])) {
     $sessions = new dbSession();
 }
 //define the template and cache directories
 $tpl->strTemplateDir = $defined['virpath'] . 'templates';
 $tpl->strCacheDir = '/tmp';
 if (!empty($_GET) || !empty($_POST)) {
     $flag = "TRUE";
 } else {
     $flag = "FALSE";
 }
 // setup our template style data
 if ($val->ValidateString($_GET['skin']) === -1 || empty($_GET['skin'])) {
     $style = $defined['templates'] . "/black";
     if (!empty($_GET['skin'])) {
         $skin_err = $err->GenerateErrorLink("help/help.php", "#val_xss", $defined['error_small'], $errors['val_xss'], NULL, NULL);
     }
 } else {
     $style = $skin->SelectSkin($defined['templates'], $_GET['skin'], $_COOKIE['skin']);
 }
 // call our header file and pass it some variables
 $tpl->assign('TITLE', $defined['title'], NULL, NULL);
 $tpl->assign('DESCRIPTION', "Manage Static Hosts", NULL, NULL);
 $tpl->assign('STYLE', $style, NULL, NULL);
 // authentication template
 $FILE = "auth.tpl";
 // default is no error just diplay login form
 if ($auth->AuthUser($_POST['user'], $_POST['pass'], $_SESSION['token']) === -1) {
     // well looks like at least one login attempt has been processed, show empty field error
     if ($_SESSION['x']++ >= 1) {
         $ERROR = $err->GenerateErrorLink("help/help.html", "#missing", $defined['error'], $errors['auth_e'], NULL, NULL);
 if (empty($_SESSION['token'])) {
     $sessions = new dbSession();
 }
 //define the template and cache directories
 $tpl->strTemplateDir = $defined['virpath'] . 'templates';
 $tpl->strCacheDir = '/tmp';
 if (!empty($_GET) || !empty($_POST)) {
     $flag = "TRUE";
 } else {
     $flag = "FALSE";
 }
 // setup our template style data
 if ($val->ValidateString($_GET['skin']) === -1 || empty($_GET['skin'])) {
     $style = $defined['templates'] . "/black";
     if (!empty($_GET['skin'])) {
         $skin_err = $err->GenerateErrorLink("help/help.php", "#val_xss", $defined['error_small'], $errors['val_xss'], NULL, NULL);
     }
 } else {
     $style = $skin->SelectSkin($defined['templates'], $_GET['skin'], $_COOKIE['skin']);
 }
 // call our header file and pass it some variables
 $tpl->assign('TITLE', $defined['title'] . " >> Main Page", NULL, NULL);
 $tpl->assign('DESCRIPTION', $defined['description'], NULL, NULL);
 $tpl->assign('STYLE', $style, NULL, NULL);
 // javascript to set focus on login form
 $JS = " document.login.user.focus();";
 // authentication template
 $FILE = "auth.tpl";
 // initialize a db connection handle
 $dbconn = $db->dbConnect($defined['dbhost'], $defined['username'], $defined['password'], $defined['dbname']);
 // provide count of online users