Пример #1
0
 public function run_deployment()
 {
     if (!ALLOW_DEPLOYMENT) {
         echo NConf_HTML::limit_space(NConf_HTML::show_error('ERROR', 'Deployment functionality is currently disabled.'));
     } elseif (ALLOW_DEPLOYMENT && (!ALLOW_DIRECT_DEPLOYMENT && empty($_POST["status"]))) {
         echo NConf_HTML::limit_space(NConf_HTML::show_error('ERROR', 'Please first run the "Generate Nagios config".'));
     } elseif (ALLOW_DEPLOYMENT && ALLOW_DIRECT_DEPLOYMENT || ALLOW_DEPLOYMENT && (!ALLOW_DIRECT_DEPLOYMENT && (!empty($_POST["status"]) && $_POST["status"] == "OK"))) {
         echo NConf_HTML::table_begin('class="table_checks"', array(170, 50, ''));
         // DEPLOY
         // First do the local module
         $local_module = $this->modules["local"];
         if ($local_module->configured()) {
             NConf_DEBUG::set('', 'DEBUG', 'Deploying ' . $local_module->name);
             echo NConf_HTML::table_row_text(NConf_HTML::title($local_module->name, '', 'class="content_header"'));
             NConf_DEBUG::set($local_module->destinations, 'DEBUG', $local_module->name);
             $local_module->deploy();
             echo NConf_HTML::table_row_text(NConf_HTML::line(), '', 'colspan=3');
         }
         // Then do all other modules if they are configured
         foreach ($this->modules as $module) {
             // Dont do the "local" module
             // Check also if module is configured
             if ($module->name == "local" or !$module->configured()) {
                 continue;
             }
             NConf_DEBUG::set('', 'DEBUG', 'Deploying ' . $module->name);
             echo NConf_HTML::table_row_text(NConf_HTML::title($module->name, '', 'class="content_header"'));
             NConf_DEBUG::set($module->destinations, 'DEBUG', $module->name);
             // run the deploy
             $module->deploy();
             echo NConf_HTML::table_row_text(NConf_HTML::line(), '', 'colspan=3');
         }
         echo NConf_HTML::table_end();
     } else {
         echo NConf_HTML::text('Deployment is enabled, but your configuration seems to have errors.', TRUE, 'div', 'class="attention"');
     }
 }
Пример #2
0
 public static function show_debug($LEVEL = '', $IN_CONTENT = FALSE, $BACK_BUTTON = FALSE)
 {
     if (self::status($LEVEL)) {
         $output = '';
         $after_titel = TRUE;
         $group_open = FALSE;
         $group_level = 0;
         foreach (self::$debug as $entry) {
             if (empty($LEVEL) || $LEVEL == $entry["LEVEL"]) {
                 //if ( !empty($entry["GROUP"]) ){
                 if (is_int($entry["GROUP"]) and $entry["GROUP"] > 0) {
                     # Handle groups
                     if ($entry["GROUP"] == $group_level and $group_open) {
                         $output .= '</fieldset><fieldset';
                     } elseif ($entry["GROUP"] == $group_level and !$group_open) {
                         $output .= '<fieldset';
                     } elseif ($entry["GROUP"] > $group_level) {
                         $output .= '<fieldset';
                         $group_level++;
                         $group_open = TRUE;
                     } elseif ($entry["GROUP"] < $group_level) {
                         for ($level = $group_level; $level >= $entry["GROUP"]; $level--) {
                             $output .= '</fieldset>';
                         }
                         $output .= '<fieldset';
                         $group_level = $entry["GROUP"];
                     }
                     # define the background
                     if ((1 & $entry["GROUP"]) == 1) {
                         $bgcolor = "even";
                     } else {
                         $bgcolor = "odd";
                     }
                     $output .= ' class="' . $bgcolor . '">';
                     // put title in FIELDSET - LEGEND
                     if (!empty($entry["TITLE"])) {
                         $output .= '<legend><b>' . $entry["TITLE"] . '</b></legend>';
                     }
                 } elseif ($entry["GROUP"] === FALSE) {
                     for ($level = $group_level; $level > 0; $level--) {
                         $output .= '</fieldset>';
                     }
                     $group_open = FALSE;
                 } elseif (is_int($entry["GROUP"]) and $entry["GROUP"] < 0) {
                     for ($level = (int) -$group_level; $level <= $entry["GROUP"]; $level++) {
                         $output .= '</fieldset>';
                     }
                     $group_open = FALSE;
                 } elseif (is_array($entry["MESSAGE"])) {
                     if ($after_titel) {
                         $output .= NConf_HTML::swap_content($entry["MESSAGE"], $entry["TITLE"]);
                     } else {
                         $output .= NConf_HTML::swap_content($entry["MESSAGE"], $entry["TITLE"], FALSE, FALSE);
                     }
                 } else {
                     if ($IN_CONTENT) {
                         if (!empty($entry["TITLE"])) {
                             if (!empty($entry["MESSAGE"])) {
                                 if ($after_titel) {
                                     $output .= NConf_HTML::text('<b>' . $entry["TITLE"] . '</b>: ' . $entry["MESSAGE"], FALSE);
                                 } else {
                                     $output .= NConf_HTML::text('<b>' . $entry["TITLE"] . '</b>: ' . $entry["MESSAGE"]);
                                 }
                                 // info about new line for next message
                                 $after_titel = FALSE;
                             } else {
                                 $output .= NConf_HTML::title($entry["TITLE"]);
                                 // info about new line for next message
                                 $after_titel = TRUE;
                             }
                         } else {
                             if ($after_titel) {
                                 $output .= NConf_HTML::text($entry["MESSAGE"], FALSE);
                                 $after_titel = FALSE;
                             } else {
                                 $output .= NConf_HTML::text($entry["MESSAGE"]);
                             }
                         }
                     } else {
                         if (!empty($entry["TITLE"])) {
                             $output .= NConf_HTML::text('<b>' . $entry["TITLE"] . '</b>: ' . $entry["MESSAGE"]);
                         } else {
                             // mostly for fieldset not making a first line
                             //if ($after_titel){
                             //    $output .= NConf_HTML::text($entry["MESSAGE"], FALSE);
                             //    $after_titel = FALSE;
                             //}else{
                             $output .= NConf_HTML::text($entry["MESSAGE"]);
                             //}
                         }
                     }
                 }
             }
         }
         # print back button if wanted
         if ($BACK_BUTTON) {
             $output .= '<br><br>';
             $output .= '<div id=buttons>';
             $output .= '<input type=button onClick="window.location.href=\'' . $BACK_BUTTON . '\'" value="Back">';
             $output .= '</div>';
         }
         return $output;
     } else {
         return '';
     }
 }
Пример #3
0
function db_handler($query, $output = "result", $debug_title = "query")
{
    # Remove beginning spaces
    $query = trim($query);
    if (DB_NO_WRITES == 1 and !preg_match("/^SELECT/i", $query)) {
        message('INFO', "DB_NO_WRITES activated, no deletions or modifications will be performed");
    } else {
        $result = mysql_query($query);
        // new DEBUG output
        $debug_query = NConf_HTML::text_converter("sql_uppercase", $query);
        $debug_query_output = NConf_HTML::swap_content($debug_query, 'Query', FALSE, FALSE);
        $debug_data_result = '<br>(Result output not yet defined)';
        if ($result) {
            # Output related stuff
            # not already implemented, or replaced functions:
            //if ($output == "getOne") $output = "1st_field_data";
            switch ($output) {
                case "affected":
                case "insert":
                case "update":
                case "delete":
                    $affected = mysql_affected_rows();
                    if ($affected > 0) {
                        //message('DEBUG', "# affected rows: $affected", "ok");
                        $return = $affected;
                    } else {
                        // needed for inserts ??:
                        //message('DEBUG', "# affected rows: $affected", "nomatch");
                        $return = "yes";
                    }
                    # DEBUG output with new API module:
                    $debug_data_result = NConf_HTML::swap_content($return, 'Result: affected rows: ' . $affected . ')', FALSE, TRUE);
                    break;
                case "getOne":
                    $first_row = mysql_fetch_row($result);
                    $return = $first_row[0];
                    # DEBUG output with new API module:
                    $debug_data_result = NConf_HTML::text('<b>Result: getOne:</b>' . $return);
                    break;
                case "result":
                    $return = $result;
                    # DEBUG output with new API module:
                    $debug_data_result = NConf_HTML::text('<b>Result:</b>' . $return);
                    break;
                case "query":
                    $return = $query;
                    # DEBUG output with new API module:
                    $debug_data_result = NConf_HTML::text('<b>Result: see query above</b>');
                    break;
                case "insert_id":
                    $new_id = mysql_insert_id();
                    $return = $new_id;
                    # DEBUG output with new API module:
                    $debug_data_result = NConf_HTML::text('<b>Result: last query generated ID:</b>' . $return);
                    break;
                case "num_rows":
                    $result = mysql_num_rows($result);
                    $return = $result;
                    # DEBUG output with new API module:
                    $debug_data_result = NConf_HTML::text('<b>Result: number of rows:</b>' . $return);
                    break;
                case "assoc":
                    $result = mysql_fetch_assoc($result);
                    $return = $result;
                    # DEBUG output with new API module:
                    $debug_data_result = NConf_HTML::swap_content($return, 'Result: assoc array:', FALSE, TRUE);
                    break;
                case "array":
                    $i = 0;
                    $rows = array();
                    while ($row = mysql_fetch_assoc($result)) {
                        $rows[$i] = $row;
                        $i++;
                    }
                    $count = count($rows);
                    $return = $rows;
                    # DEBUG output with new API module:
                    $debug_data_result = NConf_HTML::swap_content($return, 'Result array (rows: ' . $count . ')', FALSE, TRUE);
                    break;
                case "array_direct":
                    $i = 0;
                    $rows = array();
                    while ($row = mysql_fetch_row($result)) {
                        $rows[$i] = $row[0];
                        $i++;
                    }
                    $count = count($rows);
                    $return = $rows;
                    # DEBUG output with new API module:
                    $debug_data_result = NConf_HTML::swap_content($return, 'Result array_direct (rows: ' . $count . ')', FALSE, TRUE);
                    break;
                case "array_2fieldsTOassoc":
                    $rows = array();
                    while ($row = mysql_fetch_row($result)) {
                        $rows[$row[0]] = $row[1];
                    }
                    $count = count($rows);
                    $return = $rows;
                    # DEBUG output with new API module:
                    $debug_data_result = NConf_HTML::swap_content($return, 'Result array_2fieldsTOassoc (rows: ' . $count . ')', FALSE, TRUE);
                    break;
                    # Failed on output case
                # Failed on output case
                default:
                    message('ERROR', "db_handler failed on output case");
                    return FALSE;
            }
            // Debug and result return
            $debug_entry = NConf_HTML::swap_content($debug_query_output . $debug_data_result, "<b>SQL</b> " . $debug_title, FALSE, FALSE, 'debbug_query');
            message('DEBUG', $debug_entry);
            return $return;
        } else {
            // makes an open debug entry with mysql_error info
            $debug_entry = NConf_HTML::swap_content($debug_query_output . '<br><b>mysql error:</b>' . mysql_error(), '<b class="attention" >SQL</b> ' . $debug_title, TRUE, FALSE, 'debbug_query color_warning');
            NConf_DEBUG::set($debug_entry, 'DEBUG');
        }
    }
}
Пример #4
0
 //     link_as_child = '$link_as_child',
 //     link_bidirectional = '$link_bidirectional',
 //     fk_show_class_items = $fk_show_class_items,
 //     fk_id_class = '$fk_id_class'
 // WHERE
 //     id_attr = $attr_id
 // ");
 # get old ordering number
 $old_ordering = db_handler("SELECT ordering FROM ConfigAttrs WHERE id_attr={$attr_id}", "getOne", "GET old ordering number of attr");
 // UPDATE ConfigAttrs
 $query = "UPDATE ConfigAttrs\n                SET\n                attr_name = '{$attr_name}',\n                friendly_name = '{$friendly_name}',\n                description = '{$description}',\n                max_length = '{$max_length}',\n                poss_values = '{$poss_values}',\n                predef_value = '{$predef_value}',\n                mandatory = '{$mandatory}',\n                ordering = '{$ordering}',\n                visible = '{$visible}',\n                write_to_conf = '{$write2conf}'\n                WHERE\n                id_attr = {$attr_id}";
 $result = db_handler($query, "update", "Modify attribute parameters");
 if ($result) {
     # handle the ordering of the other items
     set_attr_order($attr_id, $ordering, $fk_id_class, $old_ordering);
     echo NConf_HTML::text("Successfully modified attribute &quot;{$attr_name}&quot;", FALSE);
     if ($naming_attr_message == "&naming_attr=last") {
         echo TXT_NAMING_ATTR_LAST;
     }
     // 2009-03-04 A. Gargiulo: disabled this code because we don't want users to be able to
     // modify all of the attr params, especially the naming attr (could cause data inconsistency)!
     // When succesfully set new entry including new naming attribute, delete the old one
     //if($naming_attr == "yes"){
     //    if ( (count($old_naming_attr_array) != "0") AND $naming_attr == "yes" ){
     //        foreach ($old_naming_attr_array as $attribute){
     //            $update_query = 'UPDATE `ConfigAttrs` SET `naming_attr` = "no" WHERE `id_attr` = '.$attribute["id_attr"];
     //            db_handler($update_query, "insert", "set old naming attr to 'no'");
     //        }
     //        $naming_attr_message = "&naming_attr=changed";
     //    }
     //}
 public function setURL($URL, $REGEX_OPEN_END = TRUE, $GROUPS = array(), $REQUEST = array())
 {
     # do not check if already allowed
     if ($this->url_check_status == TRUE) {
         return;
     }
     # check URL for passed attributes (should only be the scriptname)
     # the navigation links will need this handler
     # search for query part in URL
     # TODO: check if ampersand can be optimized on xmode views:
     # Array(
     #	[class] => contact
     #	[amp;xmode] => pikett
     # )
     # perhaps using $_SERVER['QUERY_STRING'] ?
     if (strpos($URL, "?") !== FALSE) {
         $url_parsed = parse_url($URL);
         $this->debug .= NConf_HTML::swap_content($url_parsed, "ACL - Found query in URL : Parsing URL", FALSE, TRUE);
         # get request items
         parse_str($url_parsed["query"], $REQUEST);
         $this->debug .= NConf_HTML::swap_content($REQUEST, "ACL - fetched query and converted to REQUEST array", FALSE, TRUE);
         # override URL with correct scriptname
         $URL = $url_parsed["path"];
     }
     # check group permission
     if (empty($GROUPS) or in_array($this->group, $GROUPS)) {
         if ($REGEX_OPEN_END) {
             if (!preg_match('/^' . preg_quote($URL) . '\\w*/', $this->current_script)) {
                 return;
             }
         } else {
             if (!preg_match('/^' . preg_quote($URL) . '$/', $this->current_script)) {
                 return;
             }
         }
         $this->debug .= NConf_HTML::text("URL matched: {$URL}", TRUE);
         # check for request limitations
         if (!empty($REQUEST)) {
             # check if needed request items match
             $diff = array_diff($REQUEST, $_REQUEST);
             if (!empty($diff)) {
                 # for debugging these could be grouped together
                 $this->debug .= NConf_HTML::swap_content($REQUEST, "REQUEST items do not match", FALSE, TRUE);
                 return;
             } else {
                 $this->debug .= NConf_HTML::swap_content($REQUEST, "REQUEST items matched", FALSE, TRUE);
             }
             //NConf_DEBUG::set($REQUEST, 'DEBUG', "REQUEST matched");
         }
         # all checks passed, URL is fine
         $this->url_check_status = TRUE;
         return;
     }
 }
Пример #6
0
###
require_once NCONFDIR . '/include/access_rules.php';
# Show page or EXIT the script ? (based on above auth-checks)
if ($NConf_PERMISSIONS->checkPageAccess() === TRUE and $NConf_PERMISSIONS->checkIdAuthorization() !== FALSE) {
    NConf_DEBUG::set("Access granted", 'DEBUG', "ACL");
    # go ahead in file
} elseif (!isset($_SESSION["group"]) and empty($_GET["goto"])) {
    # not logged in
    # Go to login page, and redirect it to called page
    $url = 'index.php?goto=' . urlencode($_SERVER['REQUEST_URI']);
    # Redirect to login page with url as goto
    echo '<meta http-equiv="refresh" content="0; url=' . $url . '">';
    message($info, '<b>redirecting to:</b> <a href="' . $url . '"> [ this page ] </a>');
    require_once NCONFDIR . '/include/foot.php';
    exit;
} elseif (!isset($_SESSION["group"]) and !empty($_GET["goto"])) {
    # do nothing, login page will be displayed
    message($debug, "display login page");
} else {
    $message = $NConf_PERMISSIONS->message;
    NConf_DEBUG::set($message, 'INFO');
    NConf_DEBUG::set("Access denied", 'DEBUG', "ACL");
    //echo $message;
    echo NConf_HTML::limit_space(NConf_HTML::show_error('Error', $message));
    require_once NCONFDIR . '/include/foot.php';
    # EXIT because of no access
    exit;
}
# close header-part in DEBUG section
$debug_entry = NConf_HTML::line() . NConf_HTML::text("Page specific debugging:", FALSE, 'b');
NConf_DEBUG::set($debug_entry);