2013-08-28 22:47:04 +02:00
< ? php
2014-01-26 13:04:36 +01:00
2013-08-28 22:47:04 +02:00
/**
* File : api_gserver . php .
* Author : Ulrich Block
* Date : 05.08 . 12
* Time : 18 : 27
* 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 />.
*/
2014-01-26 13:04:36 +01:00
$minimumArray = array ( 'action' , 'identify_server_by' , 'server_local_id' , 'server_external_id' );
$editArray = array ( 'active' , 'private' , 'slots' , 'shorten' , 'identify_user_by' , 'user_localid' , 'user_externalid' , 'username' );
2013-08-28 22:47:04 +02:00
foreach ( $minimumArray as $key ) {
2014-01-26 13:04:36 +01:00
if ( ! array_key_exists ( $key , $data )) {
$success [ 'false' ][] = 'Data key does not exist: ' . $key ;
2013-08-28 22:47:04 +02:00
}
}
2014-01-26 13:04:36 +01:00
if ( array_key_exists ( 'action' , $data ) and $data [ 'action' ] != 'gs' ) {
2013-08-28 22:47:04 +02:00
foreach ( $editArray as $key ) {
2014-01-26 13:04:36 +01:00
if ( ! array_key_exists ( $key , $data )) {
$success [ 'false' ][] = 'Data key does not exist: ' . $key ;
2013-08-28 22:47:04 +02:00
}
}
}
2014-01-26 13:04:36 +01:00
2013-09-29 15:29:58 +02:00
$active = '' ;
$private = '' ;
$shorten = '' ;
$slots = '' ;
$identifyUserBy = '' ;
$localUserID = '' ;
$externalUserID = '' ;
$username = '' ;
$identifyServerBy = '' ;
$localServerID = '' ;
$externalServerID = '' ;
$taskset = '' ;
$eacallowed = '' ;
$brandname = '' ;
$tvenable = '' ;
$pallowed = '' ;
2014-07-05 10:39:33 +02:00
$name = '' ;
2014-10-05 15:51:03 +02:00
$homeDirLabel = '' ;
2014-10-18 15:42:23 +02:00
$hdd = '' ;
2014-08-09 13:27:50 +02:00
$ip = '' ;
2013-09-29 15:29:58 +02:00
$port = '' ;
$port2 = '' ;
$port3 = '' ;
$port4 = '' ;
$port5 = '' ;
$minram = '' ;
$maxram = '' ;
$hostID = '' ;
$cores = '' ;
2014-06-08 10:02:46 +02:00
$coreCount = '' ;
2013-09-29 15:29:58 +02:00
$customID = 0 ;
$hostExternalID = '' ;
$initialpassword = '' ;
2014-01-26 13:04:36 +01:00
$installGames = 'A' ;
2013-09-29 15:29:58 +02:00
$autoRestart = '' ;
2014-06-09 11:39:37 +02:00
$ftpUser = '' ;
2014-01-26 13:04:36 +01:00
if ( ! isset ( $success [ 'false' ]) and array_value_exists ( 'action' , 'add' , $data ) and 1 > $licenceDetails [ 'lG' ]) {
2014-03-20 21:59:15 +01:00
2013-10-03 12:49:13 +02:00
$success [ 'false' ][] = 'licence limit reached' ;
2014-01-26 13:04:36 +01:00
} else if ( ! isset ( $success [ 'false' ]) and array_value_exists ( 'action' , 'add' , $data ) and $licenceDetails [ 'lG' ] > 0 ) {
if ( dataExist ( 'identify_user_by' , $data ) and isid ( $data [ 'slots' ], 11 )) {
2013-08-28 22:47:04 +02:00
if ( is_array ( $data [ 'shorten' ]) or is_object ( $data [ 'shorten' ])) {
2013-10-13 11:42:31 +02:00
$shorten = $data [ 'shorten' ];
2013-08-28 22:47:04 +02:00
} else {
2014-01-26 13:04:36 +01:00
$shorten = array ( $data [ 'shorten' ]);
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
if ( count ( $shorten ) == 0 ) {
2013-10-03 12:49:13 +02:00
$success [ 'false' ][] = 'No gameshorten(s) has been send' ;
2014-01-26 13:04:36 +01:00
2013-08-28 22:47:04 +02:00
} else {
2014-01-26 13:04:36 +01:00
$typeIDs = array ();
$typeIDList = array ();
$shortenToID = array ();
$from = array ( 'user_localid' => 'id' , 'username' => 'cname' , 'user_externalid' => 'externalID' , 'email' => 'mail' );
$active = active_check ( $data [ 'active' ]);
$private = active_check ( $data [ 'private' ]);
$slots = isid ( $data [ 'slots' ], 11 );
2013-10-13 11:42:31 +02:00
$identifyUserBy = $data [ 'identify_user_by' ];
2014-01-26 13:04:36 +01:00
$localUserID = isid ( $data [ 'user_localid' ], 21 );
2014-07-05 11:34:58 +02:00
$externalUserID = isExternalID ( $data [ 'user_externalid' ]);
2013-10-13 11:42:31 +02:00
$username = $data [ 'username' ];
$identifyServerBy = $data [ 'identify_server_by' ];
2014-01-26 13:04:36 +01:00
$localServerID = isid ( $data [ 'server_local_id' ], 19 );
2014-07-05 11:34:58 +02:00
$externalServerID = isExternalID ( $data [ 'server_external_id' ]);
2014-01-26 13:04:36 +01:00
2016-02-15 20:26:56 +01:00
$initialpassword = ( isset ( $data [ 'initialpassword' ]) and wpreg_check ( $data [ 'initialpassword' ], 50 ) and strlen ( $data [ 'initialpassword' ]) > 1 ) ? $data [ 'initialpassword' ] : passwordgenerate ( 10 );
$taskset = ( isset ( $data [ 'taskset' ]) and active_check ( $data [ 'taskset' ])) ? $data [ 'taskset' ] : 'N' ;
$eacallowed = ( isset ( $data [ 'eacallowed' ]) and active_check ( $data [ 'eacallowed' ])) ? $data [ 'eacallowed' ] : 'N' ;
$brandname = ( isset ( $data [ 'brandname' ]) and active_check ( $data [ 'brandname' ])) ? $data [ 'brandname' ] : 'N' ;
$tvenable = ( isset ( $data [ 'tvenable' ]) and active_check ( $data [ 'tvenable' ])) ? $data [ 'tvenable' ] : 'N' ;
$pallowed = ( isset ( $data [ 'pallowed' ]) and active_check ( $data [ 'pallowed' ])) ? $data [ 'pallowed' ] : 'N' ;
$autoRestart = ( isset ( $data [ 'autoRestart' ]) and active_check ( $data [ 'autoRestart' ])) ? $data [ 'autoRestart' ] : 'Y' ;
$minram = ( isset ( $data [ 'minram' ]) and isid ( $data [ 'minram' ], 10 )) ? $data [ 'minram' ] : 256 ;
$maxram = ( isset ( $data [ 'maxram' ]) and isid ( $data [ 'maxram' ], 10 )) ? $data [ 'maxram' ] : 512 ;
2016-02-15 21:45:18 +01:00
$hdd = ( isset ( $data [ 'hdd' ]) and isid ( $data [ 'hdd' ], 10 )) ? $data [ 'hdd' ] : 0 ;
2016-02-15 20:26:56 +01:00
2014-01-26 13:04:36 +01:00
$query = $sql -> prepare ( " SELECT `id`,`cname` FROM `userdata` WHERE ` " . $from [ $data [ 'identify_user_by' ]] . " `=? AND `resellerid`=? LIMIT 1 " );
$query -> execute ( array ( $data [ $data [ 'identify_user_by' ]], $resellerID ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2014-06-09 11:50:24 +02:00
2014-06-09 11:39:37 +02:00
$localUserLookupID = $row [ 'id' ];
2014-06-09 11:45:45 +02:00
$ftpUser = $row [ 'cname' ];
2014-06-09 11:50:24 +02:00
if ( $username != $row [ 'cname' ]) {
$username = $row [ 'cname' ];
}
2014-06-09 11:39:37 +02:00
}
2014-01-26 13:04:36 +01:00
2014-06-09 11:39:37 +02:00
if ( ! isset ( $localUserLookupID ) or ! isid ( $localUserLookupID , 11 )) {
2013-10-03 12:49:13 +02:00
$success [ 'false' ][] = 'user does not exist' ;
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT * FROM `servertypes` WHERE `shorten`=? AND `resellerid`=? LIMIT 1 " );
2014-01-26 13:04:36 +01:00
2013-08-28 22:47:04 +02:00
foreach ( $shorten as $singleShorten ) {
2014-01-26 13:04:36 +01:00
$query -> execute ( array ( $singleShorten , $resellerID ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2014-01-26 13:04:36 +01:00
if ( ! isset ( $portMax ) or $row [ 'portMax' ] > $portMax or ( isset ( $data [ 'primary' ]) and gamestring ( $data [ 'primary' ]) and $row [ 'portMax' ] <= $portMax and $singleShorten == $data [ 'primary' ])) {
2013-10-13 11:42:31 +02:00
$portStep = $row [ 'portStep' ];
$portMax = $row [ 'portMax' ];
$port = $row [ 'portOne' ];
$port2 = $row [ 'portTwo' ];
$port3 = $row [ 'portThree' ];
$port4 = $row [ 'portFour' ];
$port5 = $row [ 'portFive' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2013-10-05 13:39:56 +02:00
$typeIDList [] = $row [ 'id' ];
$shortenToID [ $row [ 'id' ]] = $singleShorten ;
2014-01-29 19:55:33 +01:00
$typeIDs [ $singleShorten ] = array ( 'id' => $row [ 'id' ], 'map' => $row [ 'map' ], 'mapGroup' => $row [ 'mapGroup' ], 'tic' => $row [ 'tic' ], 'fps' => $row [ 'fps' ], 'cmd' => $row [ 'cmd' ], 'gamemod' => $row [ 'gamemod' ], 'gamemod2' => $row [ 'gamemod2' ], 'modcmds' => $row [ 'modcmds' ]);
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2013-09-08 17:21:34 +02:00
if ( ! isset ( $typeIDs [ $singleShorten ])) {
2014-01-29 19:55:33 +01:00
$success [ 'false' ][] = 'image with the shorten ' . $singleShorten . ' does not exists' ;
2013-08-28 22:47:04 +02:00
}
}
2014-01-26 13:04:36 +01:00
if ( ! isset ( $success [ 'false' ]) and ! in_array ( $externalServerID , $bad )) {
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT COUNT(`id`) AS `amount` FROM `gsswitch` WHERE `externalID`=? LIMIT 1 " );
2013-08-28 22:47:04 +02:00
$query -> execute ( array ( $externalServerID ));
2014-01-26 13:04:36 +01:00
if ( $query -> fetchColumn () > 0 ) {
2013-10-03 12:49:13 +02:00
$success [ 'false' ][] = 'server with external ID already exists' ;
2013-08-28 22:47:04 +02:00
}
}
2014-01-26 13:04:36 +01:00
2013-08-28 22:47:04 +02:00
if ( ! isset ( $success [ 'false' ])) {
2014-01-26 13:04:36 +01:00
$masterServerCount = count ( $typeIDList );
if ( $masterServerCount == 1 ) {
$implodedQuery = 'm.`servertypeid`=' . $typeIDList [ 0 ];
2013-08-28 22:47:04 +02:00
} else {
2014-01-26 13:04:36 +01:00
$implodedQuery = '(m.`servertypeid`=' . implode ( ' OR m.`servertypeid`=' , $typeIDList ) . ')' ;
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2014-06-08 10:02:46 +02:00
if ( isset ( $data [ 'master_server_id' ])) {
$masterIDsArray = ( isid ( $data [ 'master_server_id' ], 19 )) ? array ( $data [ 'master_server_id' ]) : ( array ) $data [ 'master_server_id' ];
}
2014-01-26 13:04:36 +01:00
2014-06-08 10:02:46 +02:00
if ( isset ( $data [ 'master_server_external_id' ])) {
2014-07-16 20:07:20 +02:00
$externalMasterIDsArray = ( isExternalID ( $data [ 'master_server_external_id' ]) != '' ) ? array ( $data [ 'master_server_external_id' ]) : ( array ) $data [ 'master_server_external_id' ];
2014-06-08 10:02:46 +02:00
}
2014-01-26 13:04:36 +01:00
2014-06-08 10:02:46 +02:00
$inSQLArray = '' ;
2014-01-26 13:04:36 +01:00
2014-06-08 10:02:46 +02:00
if ( isset ( $masterIDsArray ) and count ( $masterIDsArray ) > 0 ) {
2014-01-26 13:04:36 +01:00
2014-06-08 10:02:46 +02:00
$inSQLArray = 'r.`id` IN (' . implode ( ',' , $masterIDsArray ) . ') AND' ;
2014-01-26 13:04:36 +01:00
2014-06-08 10:02:46 +02:00
} else if ( isset ( $externalMasterIDsArray ) and count ( $externalMasterIDsArray ) > 0 ) {
2014-01-26 13:04:36 +01:00
2017-12-27 22:42:10 +01:00
$inSQLArray = 'r.`externalID` IN (\'' . implode ( '\', \'' , $externalMasterIDsArray ) . '\') AND' ;
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2016-02-15 20:26:56 +01:00
$query = $sql -> prepare ( " SELECT r.`id`,r.`quota_active`,r.`install_paths`,r.`hyperthreading`,r.`cores`,r.`externalID`,r.`connect_ip_only`,r.`ip`,r.`altips`,r.`maxslots`,r.`maxserver`,r.`active` AS `hostactive`,r.`resellerid` AS `resellerid`,(r.`maxserver`-(SELECT COUNT(`id`) FROM `gsswitch` AS g WHERE g.`rootID`=r.`id` )) AS `freeserver`,(r.`maxslots`-(SELECT SUM(g.`slots`) FROM `gsswitch` AS g WHERE g.`rootID`=r.`id`)) AS `leftslots`,(r.`ram`-(SELECT SUM(g.`maxram`) FROM `gsswitch` AS g WHERE g.`rootID`=r.`id`)) AS `free_ram`,(SELECT COUNT(m.`id`) FROM `rservermasterg` AS m WHERE m.`serverid`=r.`id` AND $implodedQuery ) `mastercount` FROM `rserverdata` AS r GROUP BY r.`id` HAVING ( $inSQLArray `hostactive`='Y' AND r.`resellerid`=? AND (`freeserver`>0 OR `freeserver` IS NULL) AND (`leftslots`>? OR `leftslots` IS NULL) AND (`free_ram`>? OR `free_ram` IS NULL) AND `mastercount`=?) ORDER BY `freeserver` DESC LIMIT 1 " );
$query -> execute ( array ( $resellerID , $slots , $maxram , $masterServerCount ));
2014-06-08 10:02:46 +02:00
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2014-09-14 11:05:11 +02:00
$ips = array ();
2014-10-05 15:51:03 +02:00
$defaultHomeDir = 'home' ;
$iniVars = parse_ini_string ( $row [ 'install_paths' ], true );
if ( $iniVars ) {
foreach ( $iniVars as $key => $values ) {
if ( isset ( $values [ 'default' ]) and $values [ 'default' ] == 1 ) {
$defaultHomeDir = $key ;
}
}
}
$homeLabelGiven = ( isset ( $data [ 'home_label' ]) and strlen ( $data [ 'home_label' ]) > 0 ) ? $data [ 'home_label' ] : $defaultHomeDir ;
$homeDirLabel = ( $iniVars and isset ( $iniVars [ $homeLabelGiven ][ 'path' ])) ? $homeLabelGiven : $defaultHomeDir ;
2014-10-18 15:42:23 +02:00
$quotaActive = $row [ 'quota_active' ];
2014-10-05 15:51:03 +02:00
2013-10-13 11:42:31 +02:00
$hostID = $row [ 'id' ];
$hostExternalID = $row [ 'externalID' ];
2014-09-14 11:05:11 +02:00
if ( $row [ 'connect_ip_only' ] != 'Y' ) {
$ips [] = $row [ 'ip' ];
}
2014-01-26 13:04:36 +01:00
2014-06-08 10:02:46 +02:00
if ( isset ( $data [ 'coreCount' ]) and $data [ 'coreCount' ] > 0 ) {
2014-01-26 13:04:36 +01:00
2014-06-08 10:02:46 +02:00
$coreCount = ( $row [ 'hyperthreading' ] == 'Y' ) ? 2 * $row [ 'cores' ] : $row [ 'cores' ];
2014-01-26 13:04:36 +01:00
2014-06-08 10:02:46 +02:00
$c = 0 ;
$cores = array ();
2014-01-26 13:04:36 +01:00
2014-06-08 10:02:46 +02:00
while ( $c < $coreCount ) {
$cores [ $c ] = 0 ;
$c ++ ;
}
2014-01-26 13:04:36 +01:00
2014-06-08 10:02:46 +02:00
$query2 = $sql -> prepare ( " SELECT `taskset`,`cores` FROM `gsswitch` WHERE `rootID`=? AND `resellerid`=? " );
$query2 -> execute ( array ( $hostID , $resellerID ));
2014-11-30 12:55:07 +01:00
while ( $row2 = $query2 -> fetch ( PDO :: FETCH_ASSOC )) {
2014-01-26 13:04:36 +01:00
2014-06-08 10:02:46 +02:00
$coreExploded = explode ( ',' , $row2 [ 'cores' ]);
$coreCounted = count ( $coreExploded );
if ( $row2 [ 'taskset' ] == 'Y' and $coreCounted > 0 ) {
foreach ( $coreExploded as $usedCore ) {
$cores [ $usedCore ] = $cores [ $usedCore ] + round ( 1 / $coreCounted , 2 );
}
}
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2014-06-08 10:02:46 +02:00
asort ( $cores );
$i = 0 ;
$calculatedCores = array ();
foreach ( $cores as $core => $usage ) {
$calculatedCores [] = $core ;
2014-01-26 13:04:36 +01:00
2014-06-08 10:02:46 +02:00
$i ++ ;
2014-01-26 13:04:36 +01:00
2014-06-08 10:02:46 +02:00
if ( $i == $coreCount or $i == $data [ 'coreCount' ]) {
break ;
}
2013-08-28 22:47:04 +02:00
}
2014-06-08 10:02:46 +02:00
$calculatedCores = implode ( ',' , $calculatedCores );
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2014-09-27 16:58:58 +02:00
foreach ( preg_split ( '/\r\n/' , $row [ 'altips' ], - 1 , PREG_SPLIT_NO_EMPTY ) as $ip ) {
2014-06-08 10:02:46 +02:00
$ips [] = $ip ;
}
$used = usedPorts ( $ips );
$ip = $used [ 'ip' ];
$ports = $used [ 'ports' ];
2013-08-28 22:47:04 +02:00
}
}
2014-01-26 13:04:36 +01:00
if ( ! isset ( $success [ 'false' ]) and isip ( $ip , 'ip4' )) {
2014-10-05 15:51:03 +02:00
if ( $portMax > 0 ) {
2014-01-26 13:04:36 +01:00
if ( isset ( $data [ 'port' ]) and checkPorts ( array ( $data [ 'port' ]), $ports ) === true ) {
2013-10-13 11:42:31 +02:00
$port = $data [ 'port' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
while ( in_array ( $port , $ports )) {
$port += $portStep ;
2013-08-28 22:47:04 +02:00
}
2014-10-05 15:51:03 +02:00
}
2014-01-26 13:04:36 +01:00
2014-10-05 15:51:03 +02:00
if ( $portMax > 1 ) {
2014-01-26 13:04:36 +01:00
2014-10-05 15:51:03 +02:00
if ( isset ( $data [ 'port2' ]) and checkPorts ( array ( $data [ 'port2' ]), $ports ) === true ) {
2013-10-13 11:42:31 +02:00
$port = $data [ 'port' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2014-10-05 15:51:03 +02:00
while ( in_array ( $port2 , $ports )) {
2014-01-26 13:04:36 +01:00
$port2 += $portStep ;
2013-08-28 22:47:04 +02:00
}
2014-10-05 15:51:03 +02:00
}
2014-01-26 13:04:36 +01:00
2014-10-05 15:51:03 +02:00
if ( $portMax > 2 ) {
2014-01-26 13:04:36 +01:00
2014-10-05 15:51:03 +02:00
if ( isset ( $data [ 'port3' ]) and checkPorts ( array ( $data [ 'port3' ]), $ports ) === true ) {
2013-10-13 11:42:31 +02:00
$port = $data [ 'port' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2014-10-05 15:51:03 +02:00
while ( in_array ( $port3 , $ports )) {
2014-01-26 13:04:36 +01:00
$port3 += $portStep ;
2013-08-28 22:47:04 +02:00
}
2014-10-05 15:51:03 +02:00
}
2014-01-26 13:04:36 +01:00
2014-10-05 15:51:03 +02:00
if ( $portMax > 3 ) {
2014-01-26 13:04:36 +01:00
2014-10-05 15:51:03 +02:00
if ( isset ( $data [ 'port4' ]) and checkPorts ( array ( $data [ 'port4' ]), $ports ) === true ) {
2013-10-13 11:42:31 +02:00
$port = $data [ 'port' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2014-10-05 15:51:03 +02:00
while ( in_array ( $port4 , $ports )) {
2014-01-26 13:04:36 +01:00
$port4 += $portStep ;
2013-08-28 22:47:04 +02:00
}
2014-10-05 15:51:03 +02:00
}
2014-01-26 13:04:36 +01:00
2014-10-05 15:51:03 +02:00
if ( $portMax > 4 ) {
2014-01-26 13:04:36 +01:00
2014-10-05 15:51:03 +02:00
if ( isset ( $data [ 'port5' ]) and checkPorts ( array ( $data [ 'port5' ]), $ports ) === true ) {
2013-10-13 11:42:31 +02:00
$port = $data [ 'port' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2014-10-05 15:51:03 +02:00
while ( in_array ( $port5 , $ports )) {
2014-01-26 13:04:36 +01:00
$port5 += $portStep ;
2013-08-28 22:47:04 +02:00
}
}
2014-01-26 13:04:36 +01:00
2014-06-08 10:02:46 +02:00
if ( isset ( $data [ 'coreCount' ]) and $data [ 'coreCount' ] > 0 and isset ( $calculatedCores )) {
$cores = $calculatedCores ;
} else {
$cores = ( isset ( $data [ 'cores' ]) and cores ( $data [ 'cores' ])) ? $data [ 'cores' ] : '' ;
}
2014-01-26 13:04:36 +01:00
if ( isset ( $data [ 'installGames' ]) and wpreg_check ( $data [ 'installGames' ], 1 )) {
2013-10-13 11:42:31 +02:00
$installGames = $data [ 'installGames' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
$json = json_encode ( array ( 'installGames' => $installGames ));
2014-10-18 15:42:23 +02:00
$query = $sql -> prepare ( " INSERT INTO `gsswitch` (`active`,`homeLabel`,`hdd`,`taskset`,`cores`,`userid`,`pallowed`,`eacallowed`,`serverip`,`rootID`,`tvenable`,`port`,`port2`,`port3`,`port4`,`port5`,`minram`,`maxram`,`slots`,`war`,`brandname`,`autoRestart`,`ftppassword`,`resellerid`,`externalID`,`serverid`,`stopped`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,AES_ENCRYPT(?,?),?,?,1,'Y') " );
$query -> execute ( array ( $active , $homeDirLabel , $hdd , $taskset , $cores , $localUserLookupID , $pallowed , $eacallowed , $ip , $hostID , $tvenable , $port , $port2 , $port3 , $port4 , $port5 , $minram , $maxram , $slots , $private , $brandname , $autoRestart , $initialpassword , $aeskey , $resellerID , $externalServerID ));
2014-01-26 13:04:36 +01:00
2013-10-13 11:42:31 +02:00
$localServerID = $sql -> lastInsertId ();
$customID = $localServerID ;
2014-06-09 11:45:45 +02:00
$ftpUser .= '-' . $localServerID ;
2014-01-26 13:04:36 +01:00
customColumns ( 'G' , $localServerID , 'save' , $data );
if ( isid ( $localServerID , 19 )) {
2014-01-29 19:55:33 +01:00
$query = $sql -> prepare ( " INSERT INTO `serverlist` (`servertype`,`switchID`,`map`,`mapGroup`,`cmd`,`modcmd`,`tic`,`fps`,`gamemod`,`gamemod2`,`resellerid`) VALUES (?,?,?,?,?,?,?,?,?,?,?) " );
foreach ( $typeIDs as $shorten => $array ) {
$modcmd = '' ;
foreach ( explode ( " \r \n " , $array [ 'modcmds' ]) as $line ) {
if ( preg_match ( '/^(\[[\w\/\.\-\_\= ]{1,}\])$/' , $line )) {
$name = trim ( $line , '[]' );
$ex = preg_split ( " / \ =/ " , $name , - 1 , PREG_SPLIT_NO_EMPTY );
if ( isset ( $ex [ 1 ]) and trim ( $ex [ 1 ]) == 'default' ) {
$modcmd = trim ( $ex [ 0 ]);
break ;
}
}
}
$query -> execute ( array ( $array [ 'id' ], $localServerID , $array [ 'map' ], $array [ 'mapGroup' ], $array [ 'cmd' ], $modcmd , $array [ 'tic' ], $array [ 'fps' ], $array [ 'gamemod' ], $array [ 'gamemod2' ], $resellerID ));
2014-01-26 13:04:36 +01:00
if ( ! isset ( $lastServerID ) or ( isset ( $data [ 'primary' ]) and gamestring ( $data [ 'primary' ]) and $shorten == $data [ 'primary' ])) {
2013-10-13 11:42:31 +02:00
$lastServerID = $sql -> lastInsertId ();
2013-08-28 22:47:04 +02:00
}
}
2014-01-26 13:04:36 +01:00
if ( ! isset ( $lastServerID ) or ! isid ( $lastServerID , 19 ) ) {
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT `id` FROM `serverlist` WHERE `switchID`=? AND `resellerid`=? ORDER BY `id` DESC LIMIT 1 " );
2014-01-26 13:04:36 +01:00
$query -> execute ( array ( $localServerID , $resellerID ));
2013-10-13 11:42:31 +02:00
$lastServerID = $query -> fetchColumn ();
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2014-08-09 13:27:50 +02:00
$name = $ip . ':' . $port ;
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " UPDATE `gsswitch` SET `serverid`=? WHERE `id`=? AND `resellerid`=? LIMIT 1 " );
2014-01-26 13:04:36 +01:00
$query -> execute ( array ( $lastServerID , $localServerID , $resellerID ));
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " UPDATE `jobs` SET `status`='2' WHERE `type`='gs' AND (`status` IS NULL OR `status`='1') AND `affectedID`=? and `resellerID`=? " );
2014-01-26 13:04:36 +01:00
$query -> execute ( array ( $localServerID , $resellerID ));
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " INSERT INTO `jobs` (`api`,`type`,`hostID`,`invoicedByID`,`affectedID`,`userID`,`name`,`status`,`date`,`action`,`extraData`,`resellerid`) VALUES ('A','gs',?,?,?,?,?,NULL,NOW(),'ad',?,?) " );
2014-08-09 13:27:50 +02:00
$query -> execute ( array ( $hostID , $resellerID , $localServerID , $localUserLookupID , $name , $json , $resellerID ));
2014-01-26 13:04:36 +01:00
2013-08-28 22:47:04 +02:00
} else {
2013-10-03 12:49:13 +02:00
$success [ 'false' ][] = 'Could not write game server to database' ;
2013-08-28 22:47:04 +02:00
}
2014-06-08 10:02:46 +02:00
} else {
$success [ 'false' ][] = 'Cannot find free root server with given shorten' ;
2013-08-28 22:47:04 +02:00
}
}
2014-01-26 13:04:36 +01:00
2013-08-28 22:47:04 +02:00
} else if ( ! isset ( $success [ 'false' ])) {
2014-01-26 13:04:36 +01:00
$active = active_check ( $data [ 'active' ]);
$private = active_check ( $data [ 'private' ]);
2013-10-13 11:42:31 +02:00
$shorten = $data [ 'shorten' ];
2014-01-26 13:04:36 +01:00
$slots = isid ( $data [ 'slots' ], 11 );
2013-10-13 11:42:31 +02:00
$identifyUserBy = $data [ 'identify_user_by' ];
2014-01-26 13:04:36 +01:00
$localUserID = isid ( $data [ 'user_localid' ], 21 );
2014-07-05 11:34:58 +02:00
$externalUserID = isExternalID ( $data [ 'user_externalid' ]);
2013-10-13 11:42:31 +02:00
$username = $data [ 'username' ];
$identifyServerBy = $data [ 'identify_server_by' ];
2014-01-26 13:04:36 +01:00
$localServerID = isid ( $data [ 'server_local_id' ], 21 );
2014-07-05 11:34:58 +02:00
$externalServerID = isExternalID ( $data [ 'server_external_id' ]);
2014-01-26 13:04:36 +01:00
$success [ 'false' ][] = ( ! dataExist ( 'identify_user_by' , $data )) ? 'Can not identify user or bad email' : 'Slot amount needs to be specified' ;
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
} else if ( ! isset ( $success [ 'false' ]) and array_value_exists ( 'action' , 'mod' , $data )) {
2013-10-13 11:42:31 +02:00
$identifyUserBy = $data [ 'identify_user_by' ];
2014-01-26 13:04:36 +01:00
$localUserID = isid ( $data [ 'user_localid' ], 21 );
2014-07-05 11:34:58 +02:00
$externalUserID = isExternalID ( $data [ 'user_externalid' ]);
2013-10-13 11:42:31 +02:00
$username = $data [ 'username' ];
$identifyServerBy = $data [ 'identify_server_by' ];
2014-01-26 13:04:36 +01:00
$localServerID = isid ( $data [ 'server_local_id' ], 21 );
2014-07-05 11:34:58 +02:00
$externalServerID = isExternalID ( $data [ 'server_external_id' ]);
2013-10-13 11:42:31 +02:00
$shorten = $data [ 'shorten' ];
2014-01-26 13:04:36 +01:00
$from = array ( 'server_local_id' => 'id' , 'server_external_id' => 'externalID' );
2014-06-09 11:39:37 +02:00
$initialpassword = ( isset ( $data [ 'initialpassword' ]) and wpreg_check ( $data [ 'initialpassword' ], 50 )) ? $data [ 'initialpassword' ] : '' ;
2014-01-26 13:04:36 +01:00
2014-10-10 12:26:09 +02:00
if ( is_array ( $data [ 'shorten' ]) or is_object ( $data [ 'shorten' ])) {
$shorten = $data [ 'shorten' ];
} else if ( isset ( $data [ 'shorten' ])) {
$shorten = array ( $data [ 'shorten' ]);
}
2014-01-26 13:04:36 +01:00
if ( dataExist ( 'identify_server_by' , $data )) {
2014-10-18 15:42:23 +02:00
$query = $sql -> prepare ( " SELECT r.`install_paths`,r.`quota_active`,r.`externalID`,r.`hyperthreading`,r.`cores` AS `coresAvailable`,g.*,u.`cname` FROM `gsswitch` g INNER JOIN `rserverdata` r ON g.`rootID`=r.`id` INNER JOIN `userdata` u ON u.`id`=g.`userid` WHERE g.` " . $from [ $data [ 'identify_server_by' ]] . " `=? AND g.`resellerid`=? LIMIT 1 " );
2014-01-26 13:04:36 +01:00
$query -> execute ( array ( $data [ $data [ 'identify_server_by' ]], $resellerID ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2014-01-26 13:04:36 +01:00
2013-10-13 11:42:31 +02:00
$localID = $row [ 'id' ];
$userID = $row [ 'userid' ];
2014-06-09 11:45:45 +02:00
$ftpUser = $row [ 'cname' ] . '-' . $row [ 'id' ];
2013-10-13 11:42:31 +02:00
$hostID = $row [ 'rootID' ];
2014-10-18 15:42:23 +02:00
$quotaActive = $row [ 'quota_active' ];
2014-06-08 10:02:46 +02:00
2014-06-09 11:50:24 +02:00
if ( $username != $row [ 'cname' ]) {
$username = $row [ 'cname' ];
}
2014-06-08 10:02:46 +02:00
if ( isset ( $data [ 'coreCount' ]) and $data [ 'coreCount' ] > 0 and $data [ 'coreCount' ] != count ( preg_split ( '/,/' , $row [ 'cores' ], - 1 , PREG_SPLIT_NO_EMPTY ))) {
$coreCount = ( $row [ 'hyperthreading' ] == 'Y' ) ? 2 * $row [ 'coresAvailable' ] : $row [ 'coresAvailable' ];
$c = 0 ;
$cores = array ();
while ( $c < $coreCount ) {
$cores [ $c ] = 0 ;
$c ++ ;
}
$query2 = $sql -> prepare ( " SELECT `taskset`,`cores` FROM `gsswitch` WHERE `rootID`=? AND `resellerid`=? " );
$query2 -> execute ( array ( $hostID , $resellerID ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2014-06-08 10:02:46 +02:00
$coreExploded = explode ( ',' , $row2 [ 'cores' ]);
$coreCounted = count ( $coreExploded );
if ( $row2 [ 'taskset' ] == 'Y' and $coreCounted > 0 ) {
foreach ( $coreExploded as $usedCore ) {
$cores [ $usedCore ] = $cores [ $usedCore ] + round ( 1 / $coreCounted , 2 );
}
}
}
asort ( $cores );
$i = 0 ;
$calculatedCores = array ();
foreach ( $cores as $core => $usage ) {
$calculatedCores [] = $core ;
$i ++ ;
if ( $i == $coreCount or $i == $data [ 'coreCount' ]) {
break ;
}
}
$calculatedCores = implode ( ',' , $calculatedCores );
}
2013-10-13 11:42:31 +02:00
$hostExternalID = $row [ 'externalID' ];
$oldSlots = $row [ 'slots' ];
$name = $row [ 'serverip' ] . ':' . $row [ 'port' ];
$oldActive = $row [ 'active' ];
2014-10-10 12:26:09 +02:00
$oldIP = $row [ 'serverip' ];
2013-10-13 11:42:31 +02:00
$oldPort = $row [ 'port' ];
2014-10-05 15:51:03 +02:00
$oldHomeDirLabel = $row [ 'homeLabel' ];
2014-10-18 15:42:23 +02:00
$oldHdd = $row [ 'hdd' ];
2014-10-05 15:51:03 +02:00
$oldProtected = $row [ 'pallowed' ];
2014-01-26 13:04:36 +01:00
$usedPorts = usedPorts ( array ( $row [ 'serverip' ]));
2014-09-13 12:20:43 +02:00
$active = $row [ 'active' ];
$ip = $row [ 'serverip' ];
$port = $row [ 'port' ];
$port2 = $row [ 'port2' ];
$port3 = $row [ 'port3' ];
$port4 = $row [ 'port4' ];
$port5 = $row [ 'port5' ];
$cores = $row [ 'cores' ];
$minram = $row [ 'minram' ];
$maxram = $row [ 'maxram' ];
2014-10-10 12:26:09 +02:00
$pallowed = $row [ 'pallowed' ];
2014-09-13 12:20:43 +02:00
$autoRestart = $row [ 'autoRestart' ];
2014-10-05 15:51:03 +02:00
$homeDirLabel = $row [ 'homeLabel' ];
2014-10-18 15:42:23 +02:00
$hdd = $row [ 'hdd' ];
2014-09-13 12:20:43 +02:00
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT COUNT(`jobID`) AS `amount` FROM `jobs` WHERE `affectedID`=? AND `resellerID`=? AND `action`='dl' AND (`status` IS NULL OR `status`='1') LIMIT 1 " );
2014-01-26 13:04:36 +01:00
$query -> execute ( array ( $localID , $resellerID ));
if ( $query -> fetchColumn () > 0 ) {
$success [ 'false' ][] = 'Server is marked for deletion' ;
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2013-09-29 15:29:58 +02:00
$updateArray = array ();
$eventualUpdate = '' ;
2014-01-26 13:04:36 +01:00
2014-10-05 15:51:03 +02:00
$iniVars = parse_ini_string ( $row [ 'install_paths' ], true );
2014-01-29 19:55:33 +01:00
if ( isset ( $data [ 'private' ]) and active_check ( $data [ 'private' ]) and $data [ 'private' ] != $row [ 'war' ]) {
2013-10-05 13:39:56 +02:00
$updateArray [] = $data [ 'private' ];
2013-10-13 11:42:31 +02:00
$eventualUpdate .= ',`war`=?' ;
$private = $data [ 'private' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2014-10-05 15:51:03 +02:00
if ( isset ( $data [ 'home_label' ]) and $data [ 'home_label' ] != $row [ 'homeLabel' ] and isset ( $iniVars [ $data [ 'home_label' ]][ 'path' ])) {
$updateArray [] = $data [ 'home_label' ];
$eventualUpdate .= ',`homeLabel`=?' ;
$homeDirLabel = $data [ 'home_label' ];
}
2016-10-03 19:23:47 +02:00
if ( $quotaActive == 'Y' and isset ( $data [ 'hdd' ]) and strlen ( $data [ 'hdd' ]) > 0 and $data [ 'hdd' ] != $row [ 'hdd' ]) {
2014-10-18 15:42:23 +02:00
$updateArray [] = $data [ 'hdd' ];
$eventualUpdate .= ',`hdd`=?' ;
$hdd = $data [ 'hdd' ];
}
2014-01-29 19:55:33 +01:00
if ( isset ( $data [ 'slots' ]) and isid ( $data [ 'slots' ], 11 ) and $data [ 'slots' ] != $row [ 'slots' ]) {
2013-10-05 13:39:56 +02:00
$updateArray [] = $data [ 'slots' ];
2013-10-13 11:42:31 +02:00
$eventualUpdate .= ',`slots`=?' ;
$slots = $data [ 'slots' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2014-01-29 19:55:33 +01:00
if ( isset ( $data [ 'taskset' ]) and active_check ( $data [ 'taskset' ]) and $data [ 'taskset' ] != $row [ 'taskset' ]) {
2013-10-05 13:39:56 +02:00
$updateArray [] = $data [ 'taskset' ];
2013-10-13 11:42:31 +02:00
$eventualUpdate .= ',`taskset`=?' ;
$taskset = $data [ 'taskset' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2014-01-29 19:55:33 +01:00
if ( isset ( $data [ 'eacallowed' ]) and active_check ( $data [ 'eacallowed' ]) and $data [ 'eacallowed' ] != $row [ 'eacallowed' ]) {
2013-10-05 13:39:56 +02:00
$updateArray [] = $data [ 'eacallowed' ];
2013-10-13 11:42:31 +02:00
$eventualUpdate .= ',`eacallowed`=?' ;
$eacallowed = $data [ 'eacallowed' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2014-01-29 19:55:33 +01:00
if ( isset ( $data [ 'brandname' ]) and active_check ( $data [ 'brandname' ]) and $data [ 'brandname' ] != $row [ 'brandname' ]) {
2013-10-05 13:39:56 +02:00
$updateArray [] = $data [ 'brandname' ];
2013-10-13 11:42:31 +02:00
$eventualUpdate .= ',`brandname`=?' ;
$brandname = $data [ 'brandname' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2014-01-29 19:55:33 +01:00
if ( isset ( $data [ 'tvenable' ]) and active_check ( $data [ 'tvenable' ]) and $data [ 'tvenable' ] != $row [ 'tvenable' ]) {
2013-10-05 13:39:56 +02:00
$updateArray [] = $data [ 'tvenable' ];
2013-10-13 11:42:31 +02:00
$eventualUpdate .= ',`tvenable`=?' ;
$tvenable = $data [ 'tvenable' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2014-01-29 19:55:33 +01:00
if ( isset ( $data [ 'pallowed' ]) and active_check ( $data [ 'pallowed' ]) and $data [ 'pallowed' ] != $row [ 'pallowed' ]) {
2013-10-05 13:39:56 +02:00
$updateArray [] = $data [ 'pallowed' ];
2013-10-13 11:42:31 +02:00
$eventualUpdate .= ',`pallowed`=?' ;
$pallowed = $data [ 'pallowed' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2014-01-29 19:55:33 +01:00
if ( isset ( $data [ 'autoRestart' ]) and active_check ( $data [ 'autoRestart' ]) and $data [ 'autoRestart' ] != $row [ 'autoRestart' ]) {
2013-10-05 13:39:56 +02:00
$updateArray [] = $data [ 'autoRestart' ];
2013-10-13 11:42:31 +02:00
$eventualUpdate .= ',`autoRestart`=?' ;
$autoRestart = $data [ 'autoRestart' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2014-01-29 19:55:33 +01:00
if ( isset ( $data [ 'minram' ]) and isid ( $data [ 'minram' ], 10 ) and $data [ 'minram' ] != $row [ 'minram' ]) {
2013-10-05 13:39:56 +02:00
$updateArray [] = $data [ 'minram' ];
2013-10-13 11:42:31 +02:00
$eventualUpdate .= ',`minram`=?' ;
$minram = $data [ 'minram' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2014-01-29 19:55:33 +01:00
if ( isset ( $data [ 'maxram' ]) and isid ( $data [ 'maxram' ], 10 ) and $data [ 'maxram' ] != $row [ 'maxram' ]) {
2013-10-05 13:39:56 +02:00
$updateArray [] = $data [ 'maxram' ];
2013-10-13 11:42:31 +02:00
$eventualUpdate .= ',`maxram`=?' ;
$maxram = $data [ 'maxram' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2014-06-08 10:02:46 +02:00
if ( isset ( $calculatedCores ) or ( isset ( $data [ 'cores' ]) and cores ( $data [ 'cores' ]) and $data [ 'cores' ] != $row [ 'cores' ])) {
$updateArray [] = ( isset ( $calculatedCores )) ? $calculatedCores : $data [ 'cores' ];
2013-10-13 11:42:31 +02:00
$eventualUpdate .= ',`cores`=?' ;
2014-06-08 10:02:46 +02:00
$cores = ( isset ( $calculatedCores )) ? $calculatedCores : $data [ 'cores' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2014-01-29 19:55:33 +01:00
if ( isset ( $data [ 'active' ]) and active_check ( $data [ 'active' ]) and $data [ 'active' ] != $row [ 'active' ]) {
2014-11-09 12:06:25 +01:00
$updateArray [] = $data [ 'active' ];
$eventualUpdate .= ',`active`=?' ;
2014-01-29 19:55:33 +01:00
$active = $data [ 'active' ];
}
if ( isset ( $data [ 'port' ]) and port ( $data [ 'port' ]) and $data [ 'port' ] != $row [ 'port' ] and ! in_array ( $data [ 'port' ], $usedPorts )) {
2013-10-13 11:42:31 +02:00
$port = $data [ 'port' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2014-01-29 19:55:33 +01:00
if ( isset ( $data [ 'port2' ]) and port ( $data [ 'port2' ]) and $data [ 'port2' ] != $row [ 'port2' ] and ! in_array ( $data [ 'port' ], $usedPorts )) {
2013-10-05 13:39:56 +02:00
$updateArray [] = $data [ 'port2' ];
2013-10-13 11:42:31 +02:00
$eventualUpdate .= ',`port2`=?' ;
$port2 = $data [ 'port2' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2014-01-29 19:55:33 +01:00
if ( isset ( $data [ 'port3' ]) and port ( $data [ 'port3' ]) and $data [ 'port3' ] != $row [ 'port3' ] and ! in_array ( $data [ 'port' ], $usedPorts )) {
2013-10-05 13:39:56 +02:00
$updateArray [] = $data [ 'port3' ];
2013-10-13 11:42:31 +02:00
$eventualUpdate .= ',`port3`=?' ;
$port3 = $data [ 'port3' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2014-01-29 19:55:33 +01:00
if ( isset ( $data [ 'port4' ]) and port ( $data [ 'port4' ]) and $data [ 'port4' ] != $row [ 'port4' ] and ! in_array ( $data [ 'port' ], $usedPorts )) {
2013-10-05 13:39:56 +02:00
$updateArray [] = $data [ 'port4' ];
2013-10-13 11:42:31 +02:00
$eventualUpdate .= ',`port4`=?' ;
$port4 = $data [ 'port4' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2014-01-29 19:55:33 +01:00
if ( isset ( $data [ 'port5' ]) and port ( $data [ 'port5' ]) and $data [ 'port5' ] != $row [ 'port5' ] and ! in_array ( $data [ 'port' ], $usedPorts )) {
2013-10-05 13:39:56 +02:00
$updateArray [] = $data [ 'port5' ];
2013-10-13 11:42:31 +02:00
$eventualUpdate .= ',`port5`=?' ;
$port5 = $data [ 'port5' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2014-08-09 13:27:50 +02:00
if ( isExternalID ( $data [ 'server_external_id' ]) and $data [ 'identify_server_by' ] == 'server_local_id' ) {
$updateArray [] = $data [ 'server_external_id' ];
$eventualUpdate .= ',`externalID`=?' ;
}
2013-08-28 22:47:04 +02:00
if ( count ( $updateArray ) > 0 ) {
2013-09-29 15:29:58 +02:00
$eventualUpdate = trim ( $eventualUpdate , ',' );
2013-10-13 11:42:31 +02:00
$eventualUpdate .= ',' ;
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2013-10-05 13:39:56 +02:00
$updateArray [] = $localID ;
$updateArray [] = $resellerID ;
2014-01-26 13:04:36 +01:00
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " UPDATE `gsswitch` SET $eventualUpdate `jobPending`='Y' WHERE `id`=? AND `resellerid`=? LIMIT 1 " );
2013-08-28 22:47:04 +02:00
$query -> execute ( $updateArray );
2014-01-26 13:04:36 +01:00
2014-06-09 11:39:37 +02:00
if ( strlen ( $initialpassword ) > 1 ) {
$query = $sql -> prepare ( " UPDATE `gsswitch` SET `ftppassword`=AES_ENCRYPT(?,?) WHERE `id`=? AND `resellerid`=? LIMIT 1 " );
$query -> execute ( array ( $initialpassword , $aeskey , $localID , $resellerID ));
}
2014-01-26 13:04:36 +01:00
customColumns ( 'G' , $localID , 'save' , $data );
2014-10-10 12:26:09 +02:00
// Updating the gameswitch list. If the currently active game is removed we to update the server type at gsswitch.
// In any remove case we need to add a job entry to remove the game from the app root
2014-10-18 14:03:24 +02:00
$gamesToBeRemoved = array ();
2014-10-10 12:26:09 +02:00
2014-10-18 14:03:24 +02:00
if ( isset ( $shorten )) {
2014-10-10 12:26:09 +02:00
2014-10-18 14:03:24 +02:00
$installedGameList = array ();
2014-10-10 12:26:09 +02:00
2014-10-18 14:03:24 +02:00
// First get the current list
$query = $sql -> prepare ( " SELECT l.`id`,t.`shorten` FROM `serverlist` AS l LEFT JOIN `servertypes` AS t ON t.`id`=l.`servertype` WHERE l.`switchID`=? AND l.`resellerid`=? " );
$query -> execute ( array ( $localID , $resellerID ));
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
$installedGameList [ $row [ 'id' ]] = $row [ 'shorten' ];
}
2014-10-10 12:26:09 +02:00
2014-10-18 14:03:24 +02:00
// This section will add missing games, if the according masterserver is installed
$query = $sql -> prepare ( " SELECT t.*,l.`id` AS `list_id` FROM `servertypes` AS t INNER JOIN `rservermasterg` AS m ON m.`servertypeid`=t.`id` LEFT JOIN `serverlist` AS l ON l.`servertype`=t.`id` AND l.`switchID`=? WHERE t.`shorten`=? AND t.`resellerid`=? LIMIT 1 " );
$query2 = $sql -> prepare ( " INSERT INTO `serverlist` (`servertype`,`switchID`,`map`,`mapGroup`,`cmd`,`modcmd`,`tic`,`fps`,`gamemod`,`gamemod2`,`resellerid`) VALUES (?,?,?,?,?,?,?,?,?,?,?) " );
2014-10-10 12:26:09 +02:00
2014-10-18 14:03:24 +02:00
foreach ( $shorten as $singleShorten ) {
2014-10-10 12:26:09 +02:00
2014-10-18 14:03:24 +02:00
$query -> execute ( array ( $localID , $singleShorten , $resellerID ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2014-10-10 12:26:09 +02:00
2014-10-18 14:03:24 +02:00
if ( $row [ 'list_id' ] === null ) {
2014-10-10 12:26:09 +02:00
2014-10-18 14:03:24 +02:00
$modcmd = '' ;
2014-10-10 12:26:09 +02:00
2014-10-18 14:03:24 +02:00
foreach ( explode ( " \r \n " , $row [ 'modcmds' ]) as $line ) {
2014-10-10 12:26:09 +02:00
2014-10-18 14:03:24 +02:00
if ( preg_match ( '/^(\[[\w\/\.\-\_\= ]{1,}\])$/' , $line )) {
$cmdName = trim ( $line , '[]' );
$ex = preg_split ( " / \ =/ " , $cmdName , - 1 , PREG_SPLIT_NO_EMPTY );
if ( isset ( $ex [ 1 ]) and trim ( $ex [ 1 ]) == 'default' ) {
$modcmd = trim ( $ex [ 0 ]);
break ;
}
2014-10-10 12:26:09 +02:00
}
}
2014-10-18 14:03:24 +02:00
$query2 -> execute ( array ( $row [ 'id' ], $localID , $row [ 'map' ], $row [ 'mapGroup' ], $row [ 'cmd' ], $modcmd , $row [ 'tic' ], $row [ 'fps' ], $row [ 'gamemod' ], $row [ 'gamemod2' ], $resellerID ));
2014-10-10 12:26:09 +02:00
2014-10-18 14:03:24 +02:00
if ( ! isset ( $lastServerID ) or ( isset ( $data [ 'primary' ]) and gamestring ( $data [ 'primary' ]) and $shorten == $data [ 'primary' ])) {
$lastServerID = $sql -> lastInsertId ();
}
2014-10-10 12:26:09 +02:00
2014-10-18 14:03:24 +02:00
} else {
unset ( $installedGameList [ $row [ 'list_id' ]]);
}
2014-10-10 12:26:09 +02:00
}
}
2014-10-18 14:03:24 +02:00
// Remove games that no longer exists
$query = $sql -> prepare ( " DELETE FROM `serverlist` WHERE `id`=? AND `switchID`=? AND `resellerid`=? LIMIT 1 " );
2014-10-10 12:26:09 +02:00
2014-10-18 14:03:24 +02:00
foreach ( $installedGameList as $removeID => $shorten ) {
2014-10-10 12:26:09 +02:00
2014-10-18 14:03:24 +02:00
$query -> execute ( array ( $removeID , $localID , $resellerID ));
2014-10-10 12:26:09 +02:00
2014-10-18 14:03:24 +02:00
$gamesToBeRemoved [] = $shorten ;
}
2014-10-10 12:26:09 +02:00
}
2013-10-13 11:42:31 +02:00
$customID = $localID ;
2014-01-26 13:04:36 +01:00
2016-06-27 15:18:41 +02:00
if ( $active != $oldActive or $port != $oldPort or $homeDirLabel != $oldHomeDirLabel or $hdd != $oldHdd or $pallowed != $oldProtected or count ( $gamesToBeRemoved ) > 0 or strlen ( $initialpassword ) > 1 ) {
2014-01-26 13:04:36 +01:00
$query = $sql -> prepare ( " UPDATE `jobs` SET `status`='2' WHERE `type`='gs' AND (`status` IS NULL OR `status`='1') AND `action`!='ad' AND `affectedID`=? and `resellerID`=? " );
$query -> execute ( array ( $localID , $resellerID ));
$query = $sql -> prepare ( " INSERT INTO `jobs` (`api`,`type`,`hostID`,`invoicedByID`,`affectedID`,`userID`,`name`,`status`,`date`,`action`,`extraData`,`resellerID`) VALUES ('A','gs',?,?,?,?,?,NULL,NOW(),'md',?,?) " );
2014-11-09 12:06:25 +01:00
$query -> execute ( array ( $hostID , $resellerID , $localID , $userID , $name , json_encode ( array ( 'newPort' => $port , 'oldProtected' => $oldProtected , 'installGames' => 'N' , 'gamesRemoveArray' => $gamesToBeRemoved )), $resellerID ));
2013-08-28 22:47:04 +02:00
}
}
2014-01-26 13:04:36 +01:00
2013-10-13 13:11:38 +02:00
if ( ! isset ( $oldSlots )) {
2013-10-03 12:49:13 +02:00
$success [ 'false' ][] = 'No server can be found to edit' ;
2013-08-28 22:47:04 +02:00
}
2014-01-29 19:55:33 +01:00
2013-08-28 22:47:04 +02:00
} else {
2014-01-26 13:04:36 +01:00
$success [ 'false' ][] = 'No data for this method: ' . $data [ 'action' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
} else if ( ! isset ( $success [ 'false' ]) and array_value_exists ( 'action' , 'del' , $data )) {
2013-10-13 11:42:31 +02:00
$identifyServerBy = $data [ 'identify_server_by' ];
2014-01-26 13:04:36 +01:00
$localServerID = isid ( $data [ 'server_local_id' ], 21 );
2014-07-05 11:34:58 +02:00
$externalServerID = isExternalID ( $data [ 'server_external_id' ]);
2014-01-26 13:04:36 +01:00
$from = array ( 'server_local_id' => 'id' , 'server_external_id' => 'externalID' );
if ( dataExist ( 'identify_server_by' , $data )) {
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT r.`externalID`,g.`id`,g.`serverip`,g.`port`,g.`userid`,g.`rootID` FROM `gsswitch` g LEFT JOIN `rserverdata` r ON g.`rootID`=r.`id` WHERE g.` " . $from [ $data [ 'identify_server_by' ]] . " `=? AND g.`resellerid`=? " );
2014-01-26 13:04:36 +01:00
$query -> execute ( array ( $data [ $data [ 'identify_server_by' ]], $resellerID ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2013-10-13 11:42:31 +02:00
$localID = $row [ 'id' ];
$userID = $row [ 'userid' ];
$name = $row [ 'serverip' ] . ':' . $row [ 'port' ];
$hostID = $row [ 'rootID' ];
$hostExternalID = $row [ 'rootID' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2013-10-13 13:11:38 +02:00
if ( isset ( $localID ) and isset ( $name )) {
2014-01-26 13:04:36 +01:00
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " UPDATE `gsswitch` SET `jobPending`='Y' WHERE `id`=? AND `resellerid`=? LIMIT 1 " );
2014-01-26 13:04:36 +01:00
$query -> execute ( array ( $localID , $resellerID ));
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " UPDATE `jobs` SET `status`='2' WHERE `type`='gs' AND (`status` IS NULL OR `status`='1') AND `affectedID`=? and `resellerID`=? " );
2014-01-26 13:04:36 +01:00
$query -> execute ( array ( $localID , $resellerID ));
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " INSERT INTO `jobs` (`api`,`type`,`hostID`,`invoicedByID`,`affectedID`,`userID`,`name`,`status`,`date`,`action`,`resellerid`) VALUES ('A','gs',?,?,?,?,?,NULL,NOW(),'dl',?) " );
2014-01-26 13:04:36 +01:00
$query -> execute ( array ( $hostID , $resellerID , $localID , $userID , $name , $resellerID ));
2013-08-28 22:47:04 +02:00
} else {
2013-10-03 12:49:13 +02:00
$success [ 'false' ][] = 'No server can be found to delete' ;
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2013-08-28 22:47:04 +02:00
} else {
2013-10-03 12:49:13 +02:00
$success [ 'false' ][] = 'No data for this method: ' . $data [ 'action' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
} else if ( array_value_exists ( 'action' , 'ls' , $data )) {
$list = true ;
2014-06-01 17:48:11 +02:00
$query = $sql -> prepare ( " SELECT r.`id`,r.`ip`,r.`description`,r.`altips`,r.`maxslots`,r.`maxserver`,r.`maxserver`-COUNT(g.`id`) AS `freeserver`,COUNT(g.`id`) AS `installedserver`,r.`active` AS `hostactive`,r.`resellerid` AS `resellerid`,(r.`maxslots`-SUM(g.`slots`)) AS `leftslots`,SUM(g.`slots`) AS `installedslots` FROM `rserverdata` r LEFT JOIN `gsswitch` g ON g.`rootID`=r.`id` GROUP BY r.`id` HAVING ((`freeserver` > 0 OR `freeserver` IS NULL) AND (`leftslots`>0 OR `leftslots` IS NULL) AND `hostactive`='Y' AND `resellerid`=?) ORDER BY `freeserver` DESC " );
$query2 = $sql -> prepare ( " SELECT t.`shorten`,t.`description` FROM `rservermasterg` AS r INNER JOIN `servertypes` AS t ON r.`servertypeid` = t.`id` WHERE r.`serverid`=? " );
2013-08-28 22:47:04 +02:00
$query -> execute ( array ( $resellerID ));
2014-01-26 13:04:36 +01:00
2013-10-03 12:49:13 +02:00
if ( $apiType == 'xml' ) {
2014-01-26 13:04:36 +01:00
header ( " Content-type: text/xml; charset=UTF-8 " );
$responsexml = new DOMDocument ( '1.0' , 'utf-8' );
$element = $responsexml -> createElement ( 'gserver' );
2014-07-16 20:01:43 +02:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2014-01-26 13:04:36 +01:00
$key = $responsexml -> createElement ( 'server' );
$listServerXML = $responsexml -> createElement ( 'id' , $row [ 'id' ]);
$key -> appendChild ( $listServerXML );
$listServerXML = $responsexml -> createElement ( 'ip' , $row [ 'ip' ]);
$key -> appendChild ( $listServerXML );
2014-06-01 17:48:11 +02:00
$listServerXML = $responsexml -> createElement ( 'description' , $row [ 'description' ]);
$key -> appendChild ( $listServerXML );
2014-01-26 13:04:36 +01:00
$listServerXML = $responsexml -> createElement ( 'altips' , $row [ 'altips' ]);
$key -> appendChild ( $listServerXML );
$listServerXML = $responsexml -> createElement ( 'maxslots' , $row [ 'maxslots' ]);
$key -> appendChild ( $listServerXML );
$listServerXML = $responsexml -> createElement ( 'maxserver' , $row [ 'maxserver' ]);
$key -> appendChild ( $listServerXML );
$listServerXML = $responsexml -> createElement ( 'freeserver' , $row [ 'freeserver' ]);
$key -> appendChild ( $listServerXML );
$listServerXML = $responsexml -> createElement ( 'installedserver' , $row [ 'installedserver' ]);
$key -> appendChild ( $listServerXML );
$listServerXML = $responsexml -> createElement ( 'leftslots' , $row [ 'leftslots' ]);
$key -> appendChild ( $listServerXML );
$listServerXML = $responsexml -> createElement ( 'installedslots' , $row [ 'installedslots' ]);
$key -> appendChild ( $listServerXML );
2014-06-01 17:48:11 +02:00
$listServerXML = $responsexml -> createElement ( 'gamesavailable' );
$query2 -> execute ( array ( $row [ 'id' ]));
2014-11-30 12:55:07 +01:00
while ( $row2 = $query2 -> fetch ( PDO :: FETCH_ASSOC )) {
2014-06-01 17:48:11 +02:00
$listShortenXML = $responsexml -> createElement ( $row2 [ 'shorten' ], $row2 [ 'description' ]);
$listServerXML -> appendChild ( $listShortenXML );
}
$key -> appendChild ( $listServerXML );
2014-01-26 13:04:36 +01:00
$element -> appendChild ( $key );
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
$responsexml -> appendChild ( $element );
$responsexml -> formatOutput = true ;
echo $responsexml -> saveXML ();
2013-10-03 12:49:13 +02:00
} else if ( $apiType == 'json' ) {
2014-01-26 13:04:36 +01:00
2013-08-28 22:47:04 +02:00
header ( " Content-type: application/json; charset=UTF-8 " );
2014-01-26 13:04:36 +01:00
2013-08-28 22:47:04 +02:00
echo json_encode ( $query -> fetchAll ( PDO :: FETCH_ASSOC ));
2014-01-26 13:04:36 +01:00
2013-08-28 22:47:04 +02:00
} else {
header ( 'HTTP/1.1 403 Forbidden' );
die ( '403 Forbidden' );
}
2014-01-26 13:04:36 +01:00
} else if ( ! isset ( $success [ 'false' ]) and array_value_exists ( 'action' , 'gs' , $data )) {
2013-10-13 11:42:31 +02:00
$identifyServerBy = $data [ 'identify_server_by' ];
2014-07-05 11:34:58 +02:00
$localServerID = isid ( $data [ 'server_local_id' ], 10 );
$externalServerID = isExternalID ( $data [ 'server_external_id' ]);
2014-01-26 13:04:36 +01:00
2013-10-03 12:49:13 +02:00
if ( isset ( $data [ 'restart' ]) and ( $data [ 'restart' ] == 're' or $data [ 'restart' ] == 'st' )) {
2014-01-26 13:04:36 +01:00
$from = array ( 'server_local_id' => 'id' , 'server_external_id' => 'externalID' );
2013-10-13 11:42:31 +02:00
$gsRestart = $data [ 'restart' ];
2014-01-26 13:04:36 +01:00
if ( dataExist ( 'identify_server_by' , $data )) {
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT `id`,`userid`,`rootID`,`serverip`,`port` FROM `gsswitch` WHERE ` " . $from [ $data [ 'identify_server_by' ]] . " `=? AND `resellerid`=? LIMIT 1 " );
2014-01-26 13:04:36 +01:00
$query -> execute ( array ( $data [ $data [ 'identify_server_by' ]], $resellerID ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2013-10-13 11:42:31 +02:00
$hostID = $row [ 'rootID' ];
$userID = $row [ 'userid' ];
$localID = $row [ 'id' ];
$name = $row [ 'serverip' ] . ':' . $row [ 'port' ];
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2013-10-13 13:11:38 +02:00
if ( isset ( $localID ) and isset ( $userID )) {
2014-01-26 13:04:36 +01:00
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " UPDATE `gsswitch` SET `jobPending`='Y' WHERE `id`=? AND `resellerid`=? LIMIT 1 " );
2014-01-26 13:04:36 +01:00
$query -> execute ( array ( $localID , $resellerID ));
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " UPDATE `jobs` SET `status`='2' WHERE `type`='gs' AND (`status` IS NULL OR `status`='1') AND (`action`='re' OR `action`='st') AND `affectedID`=? and `resellerID`=? " );
2014-01-26 13:04:36 +01:00
$query -> execute ( array ( $localID , $resellerID ));
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " INSERT INTO `jobs` (`api`,`type`,`hostID`,`invoicedByID`,`affectedID`,`userID`,`name`,`status`,`date`,`action`,`resellerid`) VALUES ('A','gs',?,?,?,?,?,NULL,NOW(),?,?) " );
2014-01-26 13:04:36 +01:00
$query -> execute ( array ( $hostID , $resellerID , $localID , $userID , $name , $gsRestart , $resellerID ));
2013-08-28 22:47:04 +02:00
} else {
2013-10-03 12:49:13 +02:00
$success [ 'false' ][] = 'No server can be found to edit' ;
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2013-08-28 22:47:04 +02:00
} else {
2013-10-03 12:49:13 +02:00
$success [ 'false' ][] = 'Server cannot be identified' ;
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2013-08-28 22:47:04 +02:00
} else {
2013-10-03 12:49:13 +02:00
$success [ 'false' ][] = '(Re)start or Stop not defined' ;
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
2013-08-28 22:47:04 +02:00
} else {
2013-10-03 12:49:13 +02:00
$success [ 'false' ][] = 'Not supported method or incomplete data' ;
2013-08-28 22:47:04 +02:00
}
2013-10-03 12:49:13 +02:00
if ( $apiType == 'xml' and ! isset ( $list )) {
2014-01-26 13:04:36 +01:00
2013-08-28 22:47:04 +02:00
if ( isset ( $success [ 'false' ])) {
2014-01-26 13:04:36 +01:00
$errors = implode ( ', ' , $success [ 'false' ]);
$action = 'fail' ;
2013-08-28 22:47:04 +02:00
} else {
2013-09-29 15:29:58 +02:00
$errors = '' ;
2014-01-26 13:04:36 +01:00
$action = 'success' ;
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
header ( " Content-type: text/xml; charset=UTF-8 " );
$responsexml = new DOMDocument ( '1.0' , 'utf-8' );
$element = $responsexml -> createElement ( 'gserver' );
$key = $responsexml -> createElement ( 'action' , $action );
$element -> appendChild ( $key );
2014-06-08 10:02:46 +02:00
$key = $responsexml -> createElement ( 'actionSend' , ( isset ( $data [ 'action' ]) ? $data [ 'action' ] : '' ));
$element -> appendChild ( $key );
2014-01-26 13:04:36 +01:00
$key = $responsexml -> createElement ( 'private' , $private );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'active' , $active );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'identify_server_by' , $identifyServerBy );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'slots' , $slots );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'server_external_id' , $externalServerID );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'server_local_id' , $localServerID );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'identify_user_by' , $identifyUserBy );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'user_localid' , $localUserID );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'user_externalid' , $externalUserID );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'username' , $username );
$element -> appendChild ( $key );
2014-10-05 15:51:03 +02:00
$key = $responsexml -> createElement ( 'home_label' , $homeDirLabel );
$element -> appendChild ( $key );
2014-10-18 15:42:23 +02:00
$key = $responsexml -> createElement ( 'hdd' , $hdd );
$element -> appendChild ( $key );
2014-01-26 13:04:36 +01:00
$key = $responsexml -> createElement ( 'taskset' , $taskset );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'cores' , $cores );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'eacallowed' , $eacallowed );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'brandname' , $brandname );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'tvenable' , $tvenable );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'pallowed' , $pallowed );
$element -> appendChild ( $key );
2014-07-05 10:39:33 +02:00
$key = $responsexml -> createElement ( 'serverName' , $name );
$element -> appendChild ( $key );
2014-08-09 13:27:50 +02:00
$key = $responsexml -> createElement ( 'ip' , $ip );
$element -> appendChild ( $key );
2014-01-26 13:04:36 +01:00
$key = $responsexml -> createElement ( 'port' , $port );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'port2' , $port2 );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'port3' , $port3 );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'port4' , $port4 );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'port5' , $port5 );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'minram' , $minram );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'maxram' , $maxram );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'master_server_id' , $hostID );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'master_server_external_id' , $hostExternalID );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'initialpassword' , $initialpassword );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'installGames' , $installGames );
$element -> appendChild ( $key );
$key = $responsexml -> createElement ( 'autoRestart' , $autoRestart );
$element -> appendChild ( $key );
2014-06-09 11:39:37 +02:00
$key = $responsexml -> createElement ( 'ftpUser' , $ftpUser );
$element -> appendChild ( $key );
2014-01-26 13:04:36 +01:00
$key = $responsexml -> createElement ( 'errors' , $errors );
$element -> appendChild ( $key );
2013-08-28 22:47:04 +02:00
if ( isset ( $shorten ) and is_array ( $shorten )) {
foreach ( $shorten as $short ) {
2014-01-26 13:04:36 +01:00
$key = $responsexml -> createElement ( 'shorten' , $short );
$element -> appendChild ( $key );
2013-08-28 22:47:04 +02:00
}
}
2014-01-26 13:04:36 +01:00
foreach ( customColumns ( 'G' , $customID ) as $row ) {
$key = $responsexml -> createElement ( $row [ 'name' ], $row [ 'value' ]);
$element -> appendChild ( $key );
2013-08-28 22:47:04 +02:00
}
2014-01-26 13:04:36 +01:00
$responsexml -> appendChild ( $element );
$responsexml -> formatOutput = true ;
echo $responsexml -> saveXML ();
2013-10-03 12:49:13 +02:00
} else if ( $apiType == 'json' and ! isset ( $list )) {
2014-01-26 13:04:36 +01:00
2013-08-28 22:47:04 +02:00
header ( " Content-type: application/json; charset=UTF-8 " );
2014-01-26 13:04:36 +01:00
2013-10-05 13:39:56 +02:00
echo json_encode ( array ( 'action' => $action , 'private' => $private , 'active' => $active , 'identify_server_by' => $identifyServerBy , 'shorten' => $shorten , 'slots' => $slots , 'server_external_id' => $externalServerID , 'server_local_id' => $localServerID , 'identify_user_by' => $identifyUserBy , 'user_localid' => $localUserID , 'user_externalid' => $externalUserID , 'username' => $username , 'errors' => $errors ));
2014-01-26 13:04:36 +01:00
2013-08-28 22:47:04 +02:00
} else if ( ! isset ( $list )) {
header ( 'HTTP/1.1 403 Forbidden' );
die ( '403 Forbidden' );
}