developer/web/stuff/methods/functions_gs.php

201 lines
7.7 KiB
PHP
Raw Normal View History

2014-01-26 11:03:52 +01:00
<?php
/**
* File: functions_gs.php.
* Author: Ulrich Block
* Date: 26.01.14
* Time: 10:46
* Contact: <ulrich.block@easy-wi.com>
*
* This file is part of Easy-WI.
*
* Easy-WI is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Easy-WI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Easy-WI. If not, see <http://www.gnu.org/licenses/>.
*
* Diese Datei ist Teil von Easy-WI.
*
* Easy-WI ist Freie Software: Sie koennen es unter den Bedingungen
* der GNU General Public License, wie von der Free Software Foundation,
* Version 3 der Lizenz oder (nach Ihrer Wahl) jeder spaeteren
* veroeffentlichten Version, weiterverbreiten und/oder modifizieren.
*
* Easy-WI wird in der Hoffnung, dass es nuetzlich sein wird, aber
* OHNE JEDE GEWAEHELEISTUNG, bereitgestellt; sogar ohne die implizite
* Gewaehrleistung der MARKTFAEHIGKEIT oder EIGNUNG FUER EINEN BESTIMMTEN ZWECK.
* Siehe die GNU General Public License fuer weitere Details.
*
* Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
* Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
*/
if (!defined('EASYWIDIR')) {
define('EASYWIDIR', '');
}
if (!function_exists('eacchange')) {
2014-01-26 11:03:52 +01:00
function eacchange($what, $serverid, $rcon, $reseller_id) {
global $sql;
2014-02-01 15:07:29 +01:00
global $dbConnect;
2014-04-23 20:08:59 +02:00
2014-01-26 11:03:52 +01:00
$subfolder = '';
$parameter = '';
2014-02-01 15:07:29 +01:00
$query = $sql->prepare("SELECT `active`,`cfgdir`,`type`,`mysql_server`,`mysql_port`,`mysql_db`,`mysql_table`,`mysql_user`,`mysql_password` FROM `eac` WHERE `resellerid`=? LIMIT 1");
2014-01-26 11:03:52 +01:00
$query->execute(array($reseller_id));
foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $row) {
2014-10-05 12:13:20 +02:00
2014-01-26 11:03:52 +01:00
$cfgdir = $row['cfgdir'];
$active = $row['active'];
2014-02-01 15:07:29 +01:00
$type = $row['type'];
$mysql_server = $row['mysql_server'];
$mysql_port = $row['mysql_port'];
$mysql_db = $row['mysql_db'];
$mysql_table = $row['mysql_table'];
$mysql_user = $row['mysql_user'];
$mysql_password = $row['mysql_password'];
2014-01-26 11:03:52 +01:00
2014-10-05 12:13:20 +02:00
$query2 = $sql->prepare("SELECT g.`serverip`,g.`port`,s.`anticheat`,t.`shorten` FROM `gsswitch` g LEFT JOIN `serverlist` s ON g.`serverid`=s.`id` LEFT JOIN `servertypes` t ON s.`servertype`=t.`id` WHERE g.`id`=? AND g.`resellerid`=? LIMIT 1");
$query2->execute(array($serverid, $reseller_id));
foreach ($query2->fetchAll(PDO::FETCH_ASSOC) as $row2) {
2014-02-01 15:07:29 +01:00
2014-10-05 12:13:20 +02:00
$gsip = $row2['serverip'];
$gsport = $row2['port'];
2014-02-01 15:07:29 +01:00
$sqlParameter = 0;
2014-01-26 11:03:52 +01:00
2014-10-05 12:13:20 +02:00
if ($row2['anticheat'] == 3) {
2014-01-26 11:03:52 +01:00
$parameter = '';
2014-10-05 12:13:20 +02:00
} else if ($row2['anticheat'] == 4) {
2014-01-26 11:03:52 +01:00
$parameter = '-2';
2014-02-01 15:07:29 +01:00
$sqlParameter = 2;
2014-10-05 12:13:20 +02:00
} else if ($row2['anticheat'] == 5) {
2014-01-26 11:03:52 +01:00
$parameter = '-1';
2014-02-01 15:07:29 +01:00
$sqlParameter = 1;
2014-10-05 12:13:20 +02:00
} else if ($row2['anticheat'] == 6) {
2014-01-26 11:03:52 +01:00
$parameter = '-3';
2014-02-01 15:07:29 +01:00
$sqlParameter = 3;
2014-01-26 11:03:52 +01:00
}
2014-02-01 15:07:29 +01:00
$gameID = 0;
2014-10-05 12:13:20 +02:00
if ($row2['shorten'] == 'cstrike' or $row2['shorten'] == 'czero') {
2014-02-01 15:07:29 +01:00
2014-01-26 11:03:52 +01:00
$subfolder = 'hl1';
2014-02-01 15:07:29 +01:00
$gameID = 1;
2014-10-05 12:13:20 +02:00
} else if ($row2['shorten'] == 'css' or $row2['shorten'] == 'tf') {
2014-02-01 15:07:29 +01:00
2014-01-26 11:03:52 +01:00
$subfolder = 'hl2';
2014-02-01 15:07:29 +01:00
$gameID = 2;
2014-10-05 12:13:20 +02:00
} else if ($row2['shorten'] == 'csgo') {
2014-02-01 15:07:29 +01:00
$subfolder = 'csgo';
2014-02-01 15:07:29 +01:00
$gameID = 4;
2014-01-26 11:03:52 +01:00
}
2014-02-01 15:07:29 +01:00
if ($type == 'M') {
2014-01-26 11:03:52 +01:00
2014-02-01 15:07:29 +01:00
$mysql_port = (port($mysql_port)) ? $mysql_port : 3306;
$eacSql = new PDO("mysql:host=${mysql_server};dbname=${mysql_db};port=${mysql_port}", $mysql_user, $mysql_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
2014-01-26 11:03:52 +01:00
2014-02-01 15:07:29 +01:00
if ($dbConnect['debug'] == 1) {
$eacSql->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
2014-01-26 11:03:52 +01:00
}
2014-02-01 15:07:29 +01:00
2014-10-05 12:13:20 +02:00
$query3 = $eacSql->prepare("SELECT 1 FROM `" . $mysql_table . "` WHERE `IP`=? LIMIT 1");
$query3->execute(array($gsip . ':' . $gsport));
$entryExists = $query3->rowCount();
2014-02-01 15:07:29 +01:00
if ($entryExists > 0 and $what == 'change') {
2014-10-05 12:13:20 +02:00
$query3 = $eacSql->prepare("UPDATE `" . $mysql_table . "` SET `GAME`=?,`RCONPWD`=?,`FLAGS`=?,`EAC_ENABLED`=1 WHERE `IP`=? LIMIT 1");
$query3->execute(array($gameID, $rcon, $sqlParameter, $gsip . ':' . $gsport));
2014-02-01 15:07:29 +01:00
} else if ($entryExists == 0 and $what == 'change') {
2014-10-05 12:13:20 +02:00
$query3 = $eacSql->prepare("INSERT INTO `" . $mysql_table . "` (`GAME`,`IP`,`RCONPWD`,`FLAGS`,`EAC_ENABLED`) VALUES (?,?,?,?,1)");
$query3->execute(array($gameID, $gsip . ':' . $gsport, $rcon, $sqlParameter));
2014-02-01 15:07:29 +01:00
} else if ($entryExists > 0 and $what == 'remove') {
2014-10-05 12:13:20 +02:00
$query3 = $eacSql->prepare("DELETE FROM `" . $mysql_table . "` WHERE `IP`=?");
$query3->execute(array($gsip . ':' . $gsport));
2014-02-01 15:07:29 +01:00
}
} else {
$file = $cfgdir . '/' . $subfolder . '/' . $gsip . '-' . $gsport;
$file = preg_replace('/\/\//', '/', $file);
if ($what == 'change') {
$ssh2cmd = 'echo "' . $gsip . ':' . $gsport . '-' . $rcon . $parameter . '" > '.$file;
} else if ($what == 'remove') {
$ssh2cmd = 'rm -f ' . $file;
}
if (isset($ssh2cmd) and $active == 'Y') {
if (!function_exists('ssh2_execute')) {
2014-02-23 13:13:48 +01:00
include(EASYWIDIR . '/stuff/methods/functions_ssh_exec.php');
2014-02-01 15:07:29 +01:00
}
if (isset($ssh2cmd)) {
ssh2_execute('eac', $reseller_id, $ssh2cmd);
}
2014-01-26 11:03:52 +01:00
}
}
}
}
}
function normalizeName ($value) {
// control characters
$value = str_replace(array("\r", "\n"), '', $value);
// COD colors
$value = preg_replace('/\^[0-9]/i', '', $value);
// Unreal Tournament Colors
$value = preg_replace('/\x1B...|\^\d/', '', $value);
// Minecraft Motd Colors
$value = preg_replace('/\\[u]00A7[\w]/i', '', $value);
// Minecraft standard colors
$value = preg_replace('/§[0-9a-f]/i', '', $value);
return $value;
}
2014-09-28 13:47:14 +02:00
function getAppMasterList ($resellerID) {
$table = array();
global $sql;
$query = $sql->prepare("SELECT r.`id`,r.`ip`,r.`description`,(r.`maxserver` - COUNT(DISTINCT s.`id`)) AS `freeserver`,r.`active` AS `hostactive`,r.`resellerid` AS `resellerid` FROM `rserverdata` r LEFT JOIN `gsswitch` s ON s.`rootID` = r.`id` WHERE r.`active`='Y' AND r.`resellerid`=? GROUP BY r.`id` HAVING (`freeserver`>0 OR `freeserver` IS NULL) ORDER BY `freeserver` DESC");
$query->execute(array($resellerID));
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
$table[$row['id']] = ($row['description'] != null and $row['description'] != '') ? $row['ip'] . ' ' . $row['description'] : $row['ip'];
}
return $table;
}
2014-01-26 11:03:52 +01:00
}