Ejemplo n.º 1
0
function Show_Form($status_msg)
{
    // displays the form
    //
    // inputs:
    //		status_msg		if there's anything in the status_msg variable,
    //						it'll be printed below the header when the form
    //						is displayed
    //
    // ouput:
    //		displays the form
    //
    include "msre_function_global_vars.php";
    // display top of page stuff
    echo "<table border=\"0\" class=\"mailwatch\" align=\"center\">\n";
    echo "<form method=\"post\" name=\"MSRE_edit\" action=\"msre_edit.php?file={$short_filename}\">\n";
    echo "<input type=\"hidden\" name=\"submitted\" value=\"1\">\n";
    // check for status message, and append it to the end of the header
    $my_header = '';
    if ($status_msg) {
        $my_header .= "<br>\n" . $status_msg;
    }
    // show page header
    if ($my_header) {
        TR_Single($my_header, "colspan=\"" . MSRE_COLUMNS . "\" class=\"header\"");
    }
    // write out the table header(s)
    TRH_Single("Current contents of <b>{$short_filename}</b>:", "colspan=\"" . MSRE_COLUMNS . "\"");
    // display the file contents
    TR_Single("<pre>{$file_contents}</pre>", "colspan=\"" . MSRE_COLUMNS . "\"");
    // now grab any lines in the file that aren't comments.
    $ruleset = array();
    $previous_line = "";
    foreach (preg_split("/\n/", $file_contents) as $line) {
        //echo "$i: $line<br>\n";
        //$i++;
        // this should find lines w/out comments, or lines that
        // start with #DISABLED#.
        // Treat empty lines as comments
        if ($line == "") {
            $line = "#";
        }
        if (substr($line, 0, 1) != "#" or preg_match("/^#DISABLED#/", $line)) {
            // check for a description on the previous line
            if (substr($previous_line, 0, 1) == "#") {
                $desc = $previous_line;
            } else {
                $desc = "";
            }
            $ruleset[] = array($desc, $line);
        }
        $previous_line = $line;
    }
    // okay, now display it again, but in a format that the user can edit
    TRH_Single("Edit Ruleset:", "colspan=\"" . MSRE_COLUMNS . "\"");
    $colorpicker = 0;
    $rule_count = 0;
    foreach ($ruleset as $ruleanddesc) {
        $desc = $ruleanddesc[0];
        $rule = $ruleanddesc[1];
        // get rid of the # on the front of desc
        $desc = substr($desc, 1);
        // need to split the rule on tabs and spaces...
        $rule_part = preg_split("/[\t\\s]/", $rule);
        // now I have to get rid of any blank elements, which would be
        // created if there are multiple tabs or spaces in the line
        $old_rule_part = $rule_part;
        $rule_part = array();
        foreach ($old_rule_part as $current_part) {
            if ($current_part != "") {
                $rule_part[] = $current_part;
            }
        }
        // The format for the rules is (pretty much) known, so I should
        // be able to pull something out of it...
        // First of all, the last element will always be the action
        // that is to be taken.  We need to get that right away, since
        // different rules can have different parts....
        $old_rule_part = $rule_part;
        $rule_part = array();
        $rule_part["99action"] = array_pop($old_rule_part);
        // now I should be able to assign the other parts names as well
        // if fewer than 5 parts to rule, fill other parts with NULL
        // too many don't matter, so push 4 NULLs anyway
        if (count($old_rule_part) < 5) {
            array_push($old_rule_part, null, null, null, null);
        }
        list($rule_part["0direction"], $rule_part["1target"], $rule_part["2and"], $rule_part["3and_direction"], $rule_part["4and_target"]) = $old_rule_part;
        // clean out whitespace from the rule parts
        foreach ($rule_part as &$a_part) {
            trim($a_part);
        }
        // I need to check
        // for "missing pieces" of the rule, that may
        // exist in the old_rule_part array in between
        // 4and_target and 99action...
        // if there are missing pieces, the last element
        // of old_rule_part won't match 4and_target.  In that
        // case, we need to tack them onto the front of 99action
        // until we find the matching 4and_target.. I think.
        // Hmm, also need to stop if it matches 1target...
        // I think the only time this "situation" will occur
        // is if there isn't an "and", and there are multiple actions.
        // Not positive, but I'll know more as I test...
        $last_old_rule_part = array_pop($old_rule_part);
        // need two differnt while loops I think, based on
        // if there was an and or not..
        if (strtolower($rule_part["2and"]) == "and") {
            // if there's an and, grab up to the 4and_target
            $grab_to_field = "4and_target";
        } else {
            // if it's not an and, that means it's either blank, or
            // improperly parsed... in both cases, we should then
            // grab up to the 1target field
            $grab_to_field = "1target";
        }
        // now grab shit.
        while ($last_old_rule_part != $rule_part[$grab_to_field]) {
            //echo "lorp$rule_count: $last_old_rule_part<br>\n";
            if ($last_old_rule_part != null) {
                $rule_part["99action"] = $last_old_rule_part . " " . $rule_part["99action"];
            }
            $last_old_rule_part = array_pop($old_rule_part);
        }
        // ok, now that we've taken care of any "missing pieces",
        // we need to clear out the bogus data that was in the fields
        // leading up to the action... but only if the rule
        // isn't supposed to have an "and".  w/an "and", it already
        // has the proper data thx to the above code
        if (strtolower($rule_part["2and"]) != "and" and $rule_part["2and"]) {
            // clean shit out
            $rule_part["2and"] = null;
            $rule_part["3and_direction"] = null;
            $rule_part["4and_target"] = null;
        }
        // now create the rule text
        // sort by keys first
        ksort($rule_part);
        $rule_text = array();
        // description line (and action select box)
        $rule_action_select = "rule" . $rule_count . "_rule_action";
        // need to create the select box now too, but the options
        // that are available to us depend on if the rule is
        // disabled or not
        // To find out if the rule is disabled, we look @ the
        // direction field for #DISABLED# on the beginning
        $desc_value = htmlentities($desc, ENT_QUOTES);
        if (preg_match("/#DISABLED#/", $rule_part["0direction"])) {
            $rule_disabled = 1;
            $rule_action_select_options = "<option value=\"Enable\">Enable</option>\n";
            $disable_desc_text = " disabled ";
            $desc_field = "rule" . $rule_count . "_description_disabled";
            $hidden_field_code = "<input type=\"hidden\" name=\"" . preg_replace("/_disabled\$/", "", $desc_field) . "\" value=\"{$desc_value}\">";
        } else {
            $rule_disabled = 0;
            $rule_action_select_options = "<option value=\"Disable\">Disable</option>\n";
            $disable_desc_text = "";
            $desc_field = "rule" . $rule_count . "_description";
            $hidden_field_code = "";
        }
        $rule_action_select_html = "<select name=\"{$rule_action_select}\"";
        // if this is the default rule, the select box is disabled,
        // because you can't delete, disable, or enable the default
        // rule, only change it.  Originally I had it not there at
        // all, but w/the new way i'm writing the rules (w/the border),
        // each one is in a seperate table, and they don't line up
        // w/out the select box...
        if (strtolower($rule_part["1target"] == "default")) {
            $rule_action_select_html .= " disabled";
        }
        // now continue on..
        $rule_action_select_html .= ">\n" . "  <option value=\"\" selected>----</option>\n" . "  <option value=\"Delete\">Delete</option>\n" . $rule_action_select_options . "</select>\n";
        $desc_text = array($rule_action_select_html => "rowspan=\"3\"", "<b>Description:</b>&nbsp;&nbsp;<input type=\"text\" " . "name=\"{$desc_field}\" size=\"95\" value=\"" . $desc_value . "\"" . $disable_desc_text . ">" . $hidden_field_code => "colspan=\"" . (MSRE_COLUMNS - 1) . "\"");
        foreach ($rule_part as $key => $value) {
            $part_name = "rule" . $rule_count . "_" . preg_replace("/\\d/", "", $key);
            // depending on what part it is, we may need to do something
            // special, like create a select or checkbox
            switch (strtolower($key)) {
                case "2and":
                    // and gets a checkbox
                    $field_name = $part_name;
                    if ($rule_disabled) {
                        $field_name .= "_disabled";
                    }
                    $checkbox_html = "<input type=\"checkbox\" name=\"{$field_name}\" value=\"";
                    $checkbox_html .= "and";
                    $checkbox_html .= "\"";
                    if ($value) {
                        $checkbox_html .= " checked";
                    }
                    if ($rule_disabled) {
                        $checkbox_html .= " disabled ";
                    }
                    $checkbox_html .= ">and";
                    if ($rule_disabled) {
                        $checkbox_html .= "\n<input type=\"hidden\" name=\"{$part_name}\" value=\"";
                        if ($value) {
                            $checkbox_html .= "and";
                        }
                        $checkbox_html .= "\">\n";
                    }
                    $rule_text[] = $checkbox_html;
                    break;
                case "0direction":
                case "3and_direction":
                    // these get select boxen
                    $field_name = $part_name;
                    if ($rule_disabled) {
                        $field_name .= "_disabled";
                    }
                    $select_html = "<select name=\"{$field_name}\"";
                    if ($rule_disabled) {
                        $select_html .= " disabled ";
                    }
                    $select_html .= ">\n" . "<option value=\"\"></option>";
                    foreach ($CONF_ruleset_keyword as $current_kw) {
                        $select_html .= "<option value=\"{$current_kw}\"";
                        $match = strtolower(preg_replace("/#DISABLED#/", "", $value));
                        $kw = "";
                        // Use MailScanner's direction-matching rules
                        if (preg_match("/and/", $match)) {
                            $kw = "fromandto:";
                        } elseif (preg_match("/from/", $match) and preg_match("/to/", $match)) {
                            $kw = "fromorto:";
                        } elseif (preg_match("/from/", $match)) {
                            $kw = "from:";
                        } elseif (preg_match("/to/", $match)) {
                            $kw = "to:";
                        } elseif (preg_match("/virus/", $match)) {
                            $kw = "virus:";
                        }
                        if (strtolower($current_kw) == $kw) {
                            $select_html .= " selected";
                        }
                        $select_html .= ">{$current_kw}</option>";
                    }
                    // need to close my select tag..
                    $select_html .= "</select>";
                    if ($rule_disabled) {
                        $select_html .= "\n<input type=\"hidden\" name=\"{$part_name}\" value=\"{$value}\">\n";
                    }
                    $rule_text[] = $select_html;
                    break;
                default:
                    // others get regular text boxen
                    $field_name = $part_name;
                    if ($rule_disabled) {
                        $field_name .= "_disabled";
                    }
                    if (strtolower($key) == "99action") {
                        $temp_text = "</td></tr><tr><td colspan=\"" . (MSRE_COLUMNS - 1) . "\"><b>Action:</b>&nbsp;&nbsp;<input type=\"text\" name=\"{$field_name}\" value=\"{$value}\" size=\"100\"";
                    } else {
                        $temp_text = "<input type=\"text\" name=\"{$field_name}\" value=\"{$value}\"";
                    }
                    if ($rule_disabled || strtolower($key) == "1target" && strtolower($value) == "default") {
                        $temp_text .= " disabled ";
                    }
                    $temp_text .= ">";
                    if ($rule_disabled) {
                        $temp_text .= "\n<input type=\"hidden\" name=\"{$part_name}\" value=\"{$value}\">\n";
                    }
                    $rule_text[] = $temp_text;
                    break;
            }
        }
        if ($colorpicker) {
            //echo "colorpicker 1<br>\n";
            $tr_param = " class=\"alt\"";
            $colorpicker = 0;
            $boxclass = "dashblackbox";
        } else {
            //echo "colorpicker 0<br>\n";
            $tr_param = "";
            $colorpicker = 1;
            $boxclass = "dashgreybox";
        }
        // something new for v0.2.1 ... I'm going to try to put a box
        // around each ruleset, so it's easier to pick them out from
        // each other in the list...
        echo "<tr>\n" . "<td class=\"{$boxclass}\" colspan=\"" . MSRE_COLUMNS . "\">\n" . "<table border=\"0\">\n";
        TR_Extended($desc_text, $tr_param);
        TR($rule_text, $tr_param);
        echo "</table>\n" . "</td>\n" . "</tr>\n";
        // and a blank space too to break them up a li'l more
        //echo "<tr><td colspan=\"" . MSRE_COLUMNS . "\" bgcolor=\"white\">&nbsp;</td></tr>\n";
        $rule_count++;
    }
    // write the rule count as a hidden field, so that I have it
    // for submit procesing
    echo "<input type=\"hidden\" name=\"rule_count\" value=\"{$rule_count}\">\n";
    // now put a blank one on the bottom, so the user can add a new one
    $add_rule_text = array();
    $add_prefix = "rule" . $rule_count . "_";
    // description
    $desc_text = array("" => "rowspan=\"3\"", "<b>Description:</b>&nbsp;&nbsp;<input type=\"text\" name=\"" . $add_prefix . "description\" value=\"\" size=\"95\">" => "colspan=\"" . (MSRE_COLUMNS - 1) . "\"");
    // direction
    $temp_html = "<b>Condition:</b>&nbsp;&nbsp;<select name=\"" . $add_prefix . "direction\"><option value=\"\"></option>";
    foreach ($CONF_ruleset_keyword as $kw) {
        $temp_html .= "<option value=\"{$kw}\">{$kw}</option>";
    }
    $temp_html .= "</select>\n";
    $add_rule_text[] = $temp_html;
    // target
    $add_rule_text[] = "<input type=\"text\" name=\"" . $add_prefix . "target\" value=\"\">";
    // and
    $add_rule_text[] = "<input type=\"checkbox\" name=\"" . $add_prefix . "and\" value=\"and\">and";
    // and direction
    $temp_html = "<select name=\"" . $add_prefix . "and_direction\"><option value=\"\"></option>";
    foreach ($CONF_ruleset_keyword as $kw) {
        $temp_html .= "<option value=\"{$kw}\">{$kw}</option>";
    }
    $temp_html .= "</select>\n";
    $add_rule_text[] = $temp_html;
    // and target
    $add_rule_text[] = "<input type=\"text\" name=\"" . $add_prefix . "and_target\" value=\"\">";
    // action
    $add_rule_text[] = "</td></tr><tr><td colspan=\"" . (MSRE_COLUMNS - 1) . "\"><b>Action:</b>&nbsp;&nbsp;<input type=\"text\" name=\"" . $add_prefix . "action\" value=\"\" size=\"100\">";
    // now write it
    TRH_Single("Add New Rule:", "colspan=\"" . MSRE_COLUMNS . "\"");
    TR_Extended($desc_text, "");
    TR($add_rule_text);
    // need to put a submit button on the bottom
    TRH_Single("<input type=\"submit\" name=\"submit\" value=\"Save Changes\">", "colspan=\"" . MSRE_COLUMNS . "\"");
    // finally, display page footer
    TR_Single("<a href=\"msre_index.php\">Back to MSRE ruleset index</a><br>\n<a href=\"/mailscanner/other.php\">Back to MailWatch</a><br>\n", "colspan=\"" . MSRE_COLUMNS . "\" class=\"footer\"");
    // that's it
    return;
}
Ejemplo n.º 2
0
    // ############
    // start a table
    echo "<table border=\"0\" class=\"mailwatch\" align=\"center\">\n";
    TRH(array("Choose a ruleset to edit:"));
    $ruleset_file = array();
    // open directory and read its contents
    if (is_dir(MSRE_RULESET_DIR)) {
        if ($dh = opendir(MSRE_RULESET_DIR)) {
            while ($file = readdir($dh)) {
                // if it's a ruleset (*.rules), add it to the array
                if (preg_match("/.+\\.rules\$/", $file)) {
                    array_push($ruleset_file, $file);
                }
            }
            closedir($dh);
        }
    }
    if (empty($ruleset_file)) {
        TR(array('No rules found'));
    } else {
        // display it in a sorted table with links
        asort($ruleset_file);
        foreach ($ruleset_file as $this_ruleset_file) {
            TR(array("<a href=\"msre_edit.php?file={$this_ruleset_file}\">{$this_ruleset_file}</a>"));
        }
        // put a blank header line on the bottom... it just looks nicer that way to me
        TRH(array(""));
    }
    echo "</table><tr><td>\n";
    html_end();
}
Ejemplo n.º 3
0
#!/usr/bin/env php
<?php 
error_reporting(E_ALL);
require_once '../KvzHTML.php';
// These are the default options, so might
// as well have initialized KvzHTML with an
// empty first argument
$H = new KvzHTML(array('xhtml' => true, 'track_toc' => false, 'link_toc' => true, 'indentation' => 4, 'newlines' => true, 'echo' => false, 'buffer' => false, 'xml' => false, 'tidy' => false));
$tags = "html,head,title,body,h1,p,h2,table,th,tr,td";
foreach (explode(',', $tags) as $tag) {
    $TAG = strtoupper($tag);
    $evalMe = "function {$TAG}(\$a) { global \$H; return \$H->{$tag}(\$a); };";
    eval($evalMe);
}
$output = HTML(HEAD(TITLE('My page')) . BODY(H1('Important website', array('bye' => 'ciao')) . P('Welcome to our website.') . H2('Users') . P('Here\'s a list of current users:') . TABLE(TR(TH('id') . TH('name') . TH('age')) . TR(TD('#1') . TD('Kevin van Zonneveld') . TD('26')) . TR(TD('#2') . TD('Foo Bar') . TD('28')))));
echo $output;