Exemplo n.º 1
0
function rule_save()
{
    $q = new mysql_shorewall();
    if (!is_numeric($_POST["connections"])) {
        $_POST["connections"] = 5;
    }
    if ($_POST["burst"] < 5) {
        $_POST["burst"] = 5;
    }
    $_POST["RATELIMIT"] = "{$_POST["LIMIT_TD"]}:{$_POST["connections"]}/{$_POST["LIMIT_T"]}:{$_POST["burst"]}";
    unset($_POST["LIMIT_TD"]);
    unset($_POST["connections"]);
    unset($_POST["LIMIT_T"]);
    unset($_POST["burst"]);
    $table = "fw_rules";
    if (!$q->TABLE_EXISTS($table)) {
        $q->CheckTables();
    }
    $editF = false;
    $ID = $_POST["rule-save"];
    unset($_POST["rule-save"]);
    while (list($key, $value) = each($_POST)) {
        $value = url_decode_special_tool($value);
        $fields[] = "`{$key}`";
        $values[] = "'" . mysql_escape_string2($value) . "'";
        $edit[] = "`{$key}`='" . mysql_escape_string2($value) . "'";
    }
    $sql_edit = "UPDATE `{$table}` SET " . @implode(",", $edit) . " WHERE ID='{$ID}'";
    $sql = "INSERT IGNORE INTO `{$table}` (" . @implode(",", $fields) . ") VALUES (" . @implode(",", $values) . ")";
    if ($ID > 0) {
        $sql = $sql_edit;
    }
    $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo "Mysql error: `{$q->mysql_error}`";
        return;
    }
    $tpl = new templates();
    $tpl->javascript_parse_text("{success}");
}
Exemplo n.º 2
0
function items()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql_shorewall();
    $t = $_GET["t"];
    $search = '%';
    $table = "fw_objects";
    $page = 1;
    $FORCE_FILTER = null;
    $ruleid = $_GET["ruleid"];
    $total = 0;
    $FORCE_FILTER = null;
    if (!$q->TABLE_EXISTS("fw_objects")) {
        $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS `fw_objects` (\n\t\t\t`ID` INT UNSIGNED AUTO_INCREMENT PRIMARY KEY ,\n\t\t\t`groupname` VARCHAR( 255 ) NOT NULL,\n\t\t\t`grouptype` VARCHAR(20) NOT NULL,\n\t\t\t KEY `groupname` (`groupname`),\n\t\t\t KEY `grouptype` (`grouptype`)\n\t\t\t) ENGINE=MYISAM;");
    }
    if (isset($_POST["sortname"])) {
        if ($_POST["sortname"] != null) {
            $ORDER = "ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";
        }
    }
    if (isset($_POST['page'])) {
        $page = $_POST['page'];
    }
    $searchstring = string_to_flexquery();
    if ($searchstring != null) {
        $sql = "SELECT COUNT(*) as TCOUNT FROM {$table} WHERE 1 {$FORCE_FILTER} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        $total = $ligne["TCOUNT"];
    } else {
        $total = $q->COUNT_ROWS("fw_objects");
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    if (is_numeric($rp)) {
        $limitSql = "LIMIT {$pageStart}, {$rp}";
    }
    $sql = "SELECT *  FROM {$table} WHERE 1 {$searchstring} {$FORCE_FILTER} {$ORDER} {$limitSql}";
    $results = $q->QUERY_SQL($sql);
    $no_rule = $tpl->_ENGINE_parse_body("{no_rule}");
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total;
    $data['rows'] = array();
    if (!$q->ok) {
        json_error_show($q->mysql_error . "<br>{$sql}");
    }
    if (mysql_num_rows($results) == 0) {
        json_error_show("no data {$sql}");
    }
    $fontsize = "16";
    while ($ligne = mysql_fetch_assoc($results)) {
        $color = "black";
        $NICNAME = null;
        $delete = imgsimple("delete-32.png", null, "Loadjs('{$MyPage}?remove-group-js={$ligne["ID"]}&t={$_GET["t"]}&t-rule={$_GET["t-rule"]}&tt={$_GET["tt"]}')");
        $link = imgsimple("arrow-right-32.png", null, "Link{$_GET["tt"]}({$ligne["ID"]})");
        $editjs = "<a href=\"javascript:blur();\" \n\t\tOnClick=\"javascript:Loadjs('shorewall.groups.items.php?js=yes&groupid={$ligne['ID']}&t={$_GET["t"]}',true);\"\n\t\tstyle='font-size:{$fontsize}px;font-weight:bold;color:{$color};text-decoration:underline'>";
        $groupname = utf8_encode($ligne["groupname"]);
        $grouptype = $tpl->_ENGINE_parse_body($q->RULES_POLICIES_GROUP_TYPE[$ligne["grouptype"]]);
        $ligne2 = mysql_fetch_array($q->QUERY_SQL("SELECT COUNT(ID) as tcount FROM fw_items WHERE groupid='{$ligne['ID']}'"));
        $itemsNum = $ligne2["tcount"];
        $data['rows'][] = array('id' => $ligne['ID'], 'cell' => array("<span style='font-size:{$fontsize}px;font-weight:bold;color:{$color}'>{$editjs}{$groupname}</span>", "<span style='font-size:{$fontsize}px;font-weight:bold;color:{$color}'>{$editjs}{$grouptype}</a></span>", "<span style='font-size:{$fontsize}px;font-weight:normal;color:{$color}'>{$itemsNum}</span>", "<span style='font-size:{$fontsize}px;font-weight:normal;color:{$color}'>{$link}</span>", "<span style='font-size:{$fontsize}px;font-weight:normal;color:{$color}'>{$delete}</span>"));
    }
    echo json_encode($data);
}