Ejemplo n.º 1
0
/**
 * Confirm and then actually create a rule
 */
function createRule($confirm, $msg = '')
{
    global $data, $misc;
    global $lang;
    if (!isset($_POST['name'])) {
        $_POST['name'] = '';
    }
    if (!isset($_POST['event'])) {
        $_POST['event'] = '';
    }
    if (!isset($_POST['where'])) {
        $_POST['where'] = '';
    }
    if (!isset($_POST['type'])) {
        $_POST['type'] = 'SOMETHING';
    }
    if (!isset($_POST['raction'])) {
        $_POST['raction'] = '';
    }
    if ($confirm) {
        $misc->printTrail($_REQUEST['subject']);
        $misc->printTitle($lang['strcreaterule'], 'pg.rule.create');
        $misc->printMsg($msg);
        echo "<form action=\"rules.php\" method=\"post\">\n";
        echo "<table>\n";
        echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n";
        echo "<td class=\"data1\"><input name=\"name\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"", htmlspecialchars($_POST['name']), "\" /></td></tr>\n";
        echo "<tr><th class=\"data left required\">{$lang['strevent']}</th>\n";
        echo "<td class=\"data1\"><select name=\"event\">\n";
        foreach ($data->rule_events as $v) {
            echo "<option value=\"{$v}\"", $v == $_POST['event'] ? ' selected="selected"' : '', ">{$v}</option>\n";
        }
        echo "</select></td></tr>\n";
        echo "<tr><th class=\"data left\">{$lang['strwhere']}</th>\n";
        echo "<td class=\"data1\"><input name=\"where\" size=\"32\" value=\"", htmlspecialchars($_POST['where']), "\" /></td></tr>\n";
        echo "<tr><th class=\"data left\"><label for=\"instead\">{$lang['strinstead']}</label></th>\n";
        echo "<td class=\"data1\">";
        echo "<input type=\"checkbox\" id=\"instead\" name=\"instead\" ", isset($_POST['instead']) ? ' checked="checked"' : '', " />\n";
        echo "</td></tr>\n";
        echo "<tr><th class=\"data left required\">{$lang['straction']}</th>\n";
        echo "<td class=\"data1\">";
        echo "<input type=\"radio\" id=\"type1\" name=\"type\" value=\"NOTHING\"", $_POST['type'] == 'NOTHING' ? ' checked="checked"' : '', " /> <label for=\"type1\">NOTHING</label><br />\n";
        echo "<input type=\"radio\" name=\"type\" value=\"SOMETHING\"", $_POST['type'] == 'SOMETHING' ? ' checked="checked"' : '', " />\n";
        echo "(<input name=\"raction\" size=\"32\" value=\"", htmlspecialchars($_POST['raction']), "\" />)</td></tr>\n";
        echo "</table>\n";
        echo "<input type=\"hidden\" name=\"action\" value=\"save_create_rule\" />\n";
        echo "<input type=\"hidden\" name=\"subject\" value=\"", htmlspecialchars($_REQUEST['subject']), "\" />\n";
        echo "<input type=\"hidden\" name=\"", htmlspecialchars($_REQUEST['subject']), "\" value=\"", htmlspecialchars($_REQUEST[$_REQUEST['subject']]), "\" />\n";
        echo $misc->form;
        echo "<p><input type=\"submit\" name=\"ok\" value=\"{$lang['strcreate']}\" />\n";
        echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
        echo "</form>\n";
    } else {
        if (trim($_POST['name']) == '') {
            createRule(true, $lang['strruleneedsname']);
        } else {
            $status = $data->createRule($_POST['name'], $_POST['event'], $_POST[$_POST['subject']], $_POST['where'], isset($_POST['instead']), $_POST['type'], $_POST['raction']);
            if ($status == 0) {
                doDefault($lang['strrulecreated']);
            } else {
                createRule(true, $lang['strrulecreatedbad']);
            }
        }
    }
}
Ejemplo n.º 2
0
            // add rules to [category program]
            if (preg_match('/^\\[([^\\]]+)\\]/', $line, $matchRules)) {
                // [*...] will be translated to (...)
                if (substr($matchRules[1], 0, 1) === '*') {
                    $out .= createRule('(' . $rules . ' ' . substr($matchRules[1], 1) . ')', $comment);
                } else {
                    $out .= createRule('[' . $rules . ' ' . $matchRules[1] . ']', $comment);
                }
            } else {
                if (preg_match('/^([0-8]\\.)([0-9][0-9]+)(\\.[0-9\\-]+( |$).*)/', $line, $matchRules)) {
                    // check match "[0-9].xx[x].y[y] ". This is old OLAN family code
                    $mid = substr($matchRules[2], 0, 1) . '.' . substr($matchRules[2], 1);
                    $out .= createRule($matchRules[1] . $mid . $matchRules[3], $comment);
                } else {
                    if (preg_match('/^more[ ]*=[ ]*(.*)/', $line, $matchRules)) {
                        // prepend $rules to more=xxx rules
                        $out .= createRule('more=' . $rules . ' ' . $matchRules[1], $comment);
                    } else {
                        // no changes, just create rule
                        $out .= createRule($line, $comment);
                    }
                }
            }
            //}
        }
    } else {
        // add newline
        $out .= "\n";
    }
}
file_put_contents($outfile, $out);