示例#1
0
function AddServer($ip, $port, $rcon, $rcon2, $mod, $enabled, $group, $group_name)
{
    $objResponse = new xajaxResponse();
    global $userbank, $username;
    if (!$userbank->HasAccess(ADMIN_OWNER | ADMIN_ADD_SERVER)) {
        $objResponse->redirect("index.php?p=login&m=no_access", 0);
        $log = new CSystemLog("w", "Hacking Attempt", $username . " tried to add a server, but doesnt have access.");
        return $objResponse;
    }
    $ip = RemoveCode($ip);
    $group_name = RemoveCode($group_name);
    $error = 0;
    // ip
    if (empty($ip)) {
        $error++;
        $objResponse->addAssign("address.msg", "innerHTML", "You must type the server address.");
        $objResponse->addScript("\$('address.msg').setStyle('display', 'block');");
    } else {
        $objResponse->addAssign("address.msg", "innerHTML", "");
        if (!validate_ip($ip) && !is_string($ip)) {
            $error++;
            $objResponse->addAssign("address.msg", "innerHTML", "You must type a valid IP.");
            $objResponse->addScript("\$('address.msg').setStyle('display', 'block');");
        } else {
            $objResponse->addAssign("address.msg", "innerHTML", "");
        }
    }
    // Port
    if (empty($port)) {
        $error++;
        $objResponse->addAssign("port.msg", "innerHTML", "You must type the server port.");
        $objResponse->addScript("\$('port.msg').setStyle('display', 'block');");
    } else {
        $objResponse->addAssign("port.msg", "innerHTML", "");
        if (!is_numeric($port)) {
            $error++;
            $objResponse->addAssign("port.msg", "innerHTML", "You must type a valid port <b>number</b>.");
            $objResponse->addScript("\$('port.msg').setStyle('display', 'block');");
        } else {
            $objResponse->addScript("\$('port.msg').setStyle('display', 'none');");
            $objResponse->addAssign("port.msg", "innerHTML", "");
        }
    }
    // rcon
    if (!empty($rcon) && $rcon != $rcon2) {
        $error++;
        $objResponse->addAssign("rcon2.msg", "innerHTML", "The passwords don't match.");
        $objResponse->addScript("\$('rcon2.msg').setStyle('display', 'block');");
    } else {
        $objResponse->addAssign("rcon2.msg", "innerHTML", "");
    }
    // Please Select
    if ($mod == -2) {
        $error++;
        $objResponse->addAssign("mod.msg", "innerHTML", "You must select the mod your server runs.");
        $objResponse->addScript("\$('mod.msg').setStyle('display', 'block');");
    } else {
        $objResponse->addAssign("mod.msg", "innerHTML", "");
    }
    if ($group == -2) {
        $error++;
        $objResponse->addAssign("group.msg", "innerHTML", "You must select an option.");
        $objResponse->addScript("\$('group.msg').setStyle('display', 'block');");
    } else {
        $objResponse->addAssign("group.msg", "innerHTML", "");
    }
    if ($error) {
        return $objResponse;
    }
    // Check for dublicates afterwards
    $chk = $GLOBALS['db']->GetRow('SELECT sid FROM `' . DB_PREFIX . '_servers` WHERE ip = ? AND port = ?;', array($ip, (int) $port));
    if ($chk) {
        $objResponse->addScript("ShowBox('Error', 'There already is a server with that IP:Port combination.', 'red');");
        return $objResponse;
    }
    // ##############################################################
    // ##                     Start adding to DB                   ##
    // ##############################################################
    //they wanna make a new group
    $gid = -1;
    $sid = nextSid();
    $enable = $enabled == "true" ? 1 : 0;
    // Add the server
    $addserver = $GLOBALS['db']->Prepare("INSERT INTO " . DB_PREFIX . "_servers (`sid`, `ip`, `port`, `rcon`, `modid`, `enabled`)\r\n\t\t\t\t\t\t\t\t\t\t  VALUES (?,?,?,?,?,?)");
    $GLOBALS['db']->Execute($addserver, array($sid, $ip, (int) $port, $rcon, $mod, $enable));
    // Add server to each group specified
    $groups = explode(",", $group);
    $addtogrp = $GLOBALS['db']->Prepare("INSERT INTO " . DB_PREFIX . "_servers_groups (`server_id`, `group_id`) VALUES (?,?)");
    foreach ($groups as $g) {
        if ($g) {
            $GLOBALS['db']->Execute($addtogrp, array($sid, $g));
        }
    }
    $objResponse->addScript("ShowBox('Server Added', 'Your server has been successfully created.', 'green', 'index.php?p=admin&c=servers');");
    $objResponse->addScript("TabToReload();");
    $log = new CSystemLog("m", "Server Added", "Server (" . $ip . ":" . $port . ") has been added");
    return $objResponse;
}
function AddServer($ip, $port, $rcon, $rcon2, $mod, $enabled, $group, $group_name)
{
    $objResponse = new xajaxResponse();
    global $userbank, $username;
    if (!$userbank->HasAccess(ADMIN_OWNER | ADMIN_ADD_SERVER)) {
        $objResponse->redirect("index.php?p=login&m=no_access", 0);
        $log = new CSystemLog("w", "Ошибка доступа", $username . " пытался добавить сервер, не имея на это прав.");
        return $objResponse;
    }
    $ip = RemoveCode($ip);
    $group_name = RemoveCode($group_name);
    $error = 0;
    // ip
    if (empty($ip)) {
        $error++;
        $objResponse->addAssign("address.msg", "innerHTML", "Введите адрес сервера.");
        $objResponse->addScript("\$('address.msg').setStyle('display', 'block');");
    } else {
        $objResponse->addAssign("address.msg", "innerHTML", "");
        if (!validate_ip($ip) && !is_string($ip)) {
            $error++;
            $objResponse->addAssign("address.msg", "innerHTML", "Введите действительный IP сервера.");
            $objResponse->addScript("\$('address.msg').setStyle('display', 'block');");
        } else {
            $objResponse->addAssign("address.msg", "innerHTML", "");
        }
    }
    // Port
    if (empty($port)) {
        $error++;
        $objResponse->addAssign("port.msg", "innerHTML", "Введите порт сервера.");
        $objResponse->addScript("\$('port.msg').setStyle('display', 'block');");
    } else {
        $objResponse->addAssign("port.msg", "innerHTML", "");
        if (!is_numeric($port)) {
            $error++;
            $objResponse->addAssign("port.msg", "innerHTML", "Вы должны ввести действительный порт.");
            $objResponse->addScript("\$('port.msg').setStyle('display', 'block');");
        } else {
            $objResponse->addScript("\$('port.msg').setStyle('display', 'none');");
            $objResponse->addAssign("port.msg", "innerHTML", "");
        }
    }
    // rcon
    if (!empty($rcon) && $rcon != $rcon2) {
        $error++;
        $objResponse->addAssign("rcon2.msg", "innerHTML", "Пароли не совпадают.");
        $objResponse->addScript("\$('rcon2.msg').setStyle('display', 'block');");
    } else {
        $objResponse->addAssign("rcon2.msg", "innerHTML", "");
    }
    // Please Select
    if ($mod == -2) {
        $error++;
        $objResponse->addAssign("mod.msg", "innerHTML", "Выберите МОД сервера.");
        $objResponse->addScript("\$('mod.msg').setStyle('display', 'block');");
    } else {
        $objResponse->addAssign("mod.msg", "innerHTML", "");
    }
    if ($group == -2) {
        $error++;
        $objResponse->addAssign("group.msg", "innerHTML", "Вы должны выбрать опцию.");
        $objResponse->addScript("\$('group.msg').setStyle('display', 'block');");
    } else {
        $objResponse->addAssign("group.msg", "innerHTML", "");
    }
    if ($error) {
        return $objResponse;
    }
    // Check for dublicates afterwards
    $chk = $GLOBALS['db']->GetRow('SELECT sid FROM `' . DB_PREFIX . '_servers` WHERE ip = ? AND port = ?;', array($ip, (int) $port));
    if ($chk) {
        $objResponse->addScript("ShowBox('Ошибка', 'Введённый сервер уже существует в базе.', 'red');");
        return $objResponse;
    }
    // ##############################################################
    // ##                     Start adding to DB                   ##
    // ##############################################################
    //they wanna make a new group
    $gid = -1;
    $sid = nextSid();
    $enable = $enabled == "true" ? 1 : 0;
    // Add the server
    $addserver = $GLOBALS['db']->Prepare("INSERT INTO " . DB_PREFIX . "_servers (`sid`, `ip`, `port`, `rcon`, `modid`, `enabled`)\r\n\t\t\t\t\t\t\t\t\t\t  VALUES (?,?,?,?,?,?)");
    $GLOBALS['db']->Execute($addserver, array($sid, $ip, (int) $port, $rcon, $mod, $enable));
    // Add server to each group specified
    $groups = explode(",", $group);
    $addtogrp = $GLOBALS['db']->Prepare("INSERT INTO " . DB_PREFIX . "_servers_groups (`server_id`, `group_id`) VALUES (?,?)");
    foreach ($groups as $g) {
        if ($g) {
            $GLOBALS['db']->Execute($addtogrp, array($sid, $g));
        }
    }
    $objResponse->addScript("ShowBox('Сервер добавлен', 'Сервер добавлен.', 'green', 'index.php?p=admin&c=servers');");
    $objResponse->addScript("TabToReload();");
    $log = new CSystemLog("m", "Сервер добавлен", "Сервер (" . $ip . ":" . $port . ") добавлен");
    return $objResponse;
}