2013-08-28 22:47:04 +02:00
< ? php
/**
* File : userpanel_migration . php .
* Author : Ulrich Block
* Date : 01.02 . 13
* Time : 17 : 13
* 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 />.
*/
2013-10-27 00:16:43 +02:00
if (( ! isset ( $main ) or $main != 1 ) or ( ! isset ( $user_id ) or ( isset ( $user_id ) and ! $pa [ 'restart' ]))) {
2013-08-28 22:47:04 +02:00
header ( 'Location: userpanel.php' );
die ;
}
2013-09-27 08:22:09 +02:00
include ( EASYWIDIR . '/stuff/keyphrasefile.php' );
2014-02-23 13:13:48 +01:00
include ( EASYWIDIR . '/stuff/methods/class_ftp.php' );
2014-11-16 14:23:20 +01:00
include ( EASYWIDIR . '/stuff/methods/functions_gs.php' );
include ( EASYWIDIR . '/stuff/methods/class_app.php' );
2013-09-27 08:22:09 +02:00
2016-06-04 17:12:46 +02:00
$sprache = getlanguagefile ( 'gserver' , $user_language , $reseller_id );
2013-10-13 11:42:31 +02:00
$loguserid = $user_id ;
2013-10-26 11:59:03 +02:00
$logusername = getusername ( $user_id );
2013-10-26 11:35:51 +02:00
$logusertype = 'user' ;
2013-09-29 15:29:58 +02:00
$logreseller = 0 ;
$logsubuser = 0 ;
2016-06-04 17:12:46 +02:00
2013-08-28 22:47:04 +02:00
if ( isset ( $admin_id )) {
2013-10-13 11:42:31 +02:00
$logsubuser = $admin_id ;
2013-08-28 22:47:04 +02:00
} else if ( isset ( $subuser_id )) {
2013-10-13 11:42:31 +02:00
$logsubuser = $subuser_id ;
2013-08-28 22:47:04 +02:00
}
2016-06-04 17:12:46 +02:00
2013-10-03 12:49:13 +02:00
if ( isset ( $admin_id ) and $reseller_id != 0 ) {
2013-10-05 18:39:30 +02:00
$reseller_id = $admin_id ;
2013-08-28 22:47:04 +02:00
}
2016-06-04 17:12:46 +02:00
2013-09-29 15:29:58 +02:00
$ftpAddress = '' ;
2016-06-04 17:12:46 +02:00
$ftpPort = 21 ;
2013-09-29 15:29:58 +02:00
$ftpUser = '' ;
$ftpPassword = '' ;
$ftpPath = '' ;
$thisID = 0 ;
$thisTemplate = '' ;
2016-06-04 17:12:46 +02:00
$ssl = ( $ui -> active ( 'ssl' , 'post' )) ? $ui -> active ( 'ssl' , 'post' ) : 'N' ;
2013-09-29 15:29:58 +02:00
$error = array ();
$table = array ();
2013-12-14 20:32:15 +01:00
2014-11-16 14:23:20 +01:00
$query = $sql -> prepare ( " SELECT AES_DECRYPT(g.`ftppassword`,?) AS `cftppass`,g.`id`,g.`newlayout`,g.`rootID`,g.`serverip`,g.`port`,g.`pallowed`,g.`protected`,u.`cname` FROM `gsswitch` g INNER JOIN `userdata` u ON g.`userid`=u.`id` WHERE g.`userid`=? AND g.`resellerid`=? AND g.`active`='Y' " );
2013-09-29 15:29:58 +02:00
$query2 = $sql -> prepare ( " SELECT s.`id`,t.`description`,t.`shorten`,t.`gamebinary`,t.`binarydir`,t.`modfolder`,t.`appID` FROM `serverlist` s INNER JOIN `servertypes` t ON s.`servertype`=t.`id` WHERE s.`switchID`=? GROUP BY t.`shorten` ORDER BY t.`shorten` " );
2013-12-14 20:32:15 +01:00
$query -> execute ( array ( $aeskey , $user_id , $reseller_id ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2016-06-04 17:12:46 +02:00
2013-12-14 20:32:15 +01:00
if ( ! isset ( $_SESSION [ 'sID' ]) or in_array ( $row [ 'id' ], $substituteAccess [ 'gs' ])) {
2014-10-05 13:23:17 +02:00
2013-09-29 15:29:58 +02:00
$temp = array ();
2013-12-14 20:32:15 +01:00
$search = '' ;
$customer = $row [ 'cname' ];
if ( $row [ 'newlayout' ] == 'Y' ) {
$customer = $row [ 'cname' ] . '-' . $row [ 'id' ];
}
2013-08-28 22:47:04 +02:00
$query2 -> execute ( array ( $row [ 'id' ]));
2014-11-30 12:55:07 +01:00
while ( $row2 = $query2 -> fetch ( PDO :: FETCH_ASSOC )) {
2013-12-14 20:32:15 +01:00
if ( $row2 [ 'gamebinary' ] == 'hlds_run' or ( $row2 [ 'gamebinary' ] == 'srcds_run' and ( $row2 [ 'appID' ] == 740 or $row2 [ 'appID' ] == 730 ))) {
$search = '/' . $row2 [ 'modfolder' ];
} else if ( $row2 [ 'gamebinary' ] == 'srcds_run' or $row2 [ 'gamebinary' ] == 'hlds_run' ) {
$search = '/' . $row2 [ 'binarydir' ] . '/' . $row2 [ 'modfolder' ];
$search = str_replace ( array ( '//' , '///' ), '' , $search );
2013-08-28 22:47:04 +02:00
}
2013-12-14 20:32:15 +01:00
2014-03-01 21:21:00 +01:00
$temp [ $row2 [ 'shorten' ]] = array ( 'shorten' => $row2 [ 'shorten' ], 'description' => $row2 [ 'description' ], 'searchFor' => $search , 'modfolder' => $row2 [ 'modfolder' ]);
2013-08-28 22:47:04 +02:00
}
2013-12-14 20:32:15 +01:00
2013-10-10 08:06:37 +02:00
$table [ $row [ 'id' ]] = array ( 'id' => $row [ 'id' ], 'address' => $row [ 'serverip' ] . ':' . $row [ 'port' ], 'games' => $temp , 'rootID' => $row [ 'rootID' ], 'gsfolder' => $row [ 'serverip' ] . '_' . $row [ 'port' ], 'customer' => $customer , 'cftppass' => $row [ 'cftppass' ]);
2013-08-28 22:47:04 +02:00
}
}
2013-12-14 20:32:15 +01:00
2013-10-03 16:48:54 +02:00
if ( $ui -> w ( 'action' , 4 , 'post' ) and ! token ( true )) {
2013-12-14 20:32:15 +01:00
2013-09-29 15:29:58 +02:00
$template_file = $spracheResponse -> token ;
2013-12-14 20:32:15 +01:00
2013-10-13 11:42:31 +02:00
} else if ( $ui -> smallletters ( 'action' , 2 , 'post' ) == 'ms' ) {
2013-12-14 20:32:15 +01:00
2013-10-13 11:42:31 +02:00
if ( ! $ui -> domain ( 'ftpAddress' , 'post' ) and ! $ui -> ip ( 'ftpAddress' , 'post' )) {
2013-10-05 13:39:56 +02:00
$error [] = $sprache -> ftp_adresse ;
2013-08-28 22:47:04 +02:00
} else {
2013-10-13 11:42:31 +02:00
$ftpAddress = $ui -> post [ 'ftpAddress' ];
2013-08-28 22:47:04 +02:00
}
2013-12-22 14:07:23 +01:00
2013-10-13 11:42:31 +02:00
if ( ! $ui -> port ( 'ftpPort' , 'post' )) {
2013-10-05 13:39:56 +02:00
$error [] = $sprache -> ftp_port ;
2013-08-28 22:47:04 +02:00
} else {
2013-10-13 11:42:31 +02:00
$ftpPort = $ui -> port ( 'ftpPort' , 'post' );
2013-08-28 22:47:04 +02:00
}
2013-12-22 14:07:23 +01:00
2013-10-13 11:42:31 +02:00
if ( ! $ui -> config ( 'ftpUser' , 'post' )) {
2013-10-05 13:39:56 +02:00
$error [] = $sprache -> ftp_user ;
2013-08-28 22:47:04 +02:00
} else {
2013-10-13 11:42:31 +02:00
$ftpUser = $ui -> config ( 'ftpUser' , 'post' );
2013-08-28 22:47:04 +02:00
}
2013-12-22 14:07:23 +01:00
2013-10-13 11:42:31 +02:00
if ( ! $ui -> config ( 'ftpPassword' , 'post' )) {
2013-10-05 13:39:56 +02:00
$error [] = $sprache -> ftp_password ;
2013-08-28 22:47:04 +02:00
} else {
2013-10-13 11:42:31 +02:00
$ftpPassword = $ui -> config ( 'ftpPassword' , 'post' );
2013-08-28 22:47:04 +02:00
}
2013-12-22 14:07:23 +01:00
2013-12-14 20:32:15 +01:00
if ( ! $ui -> id ( 'switchID' , 10 , 'post' ) or ! isset ( $table [ $ui -> id ( 'switchID' , 10 , 'post' )])) {
2014-03-01 21:21:00 +01:00
2013-10-05 13:39:56 +02:00
$error [] = $sprache -> server ;
2014-03-01 21:21:00 +01:00
2013-08-28 22:47:04 +02:00
} else {
2013-12-14 20:32:15 +01:00
$thisID = $ui -> id ( 'switchID' , 10 , 'post' );
$address = $table [ $ui -> id ( 'switchID' , 10 , 'post' )][ 'address' ];
$rootID = $table [ $ui -> id ( 'switchID' , 10 , 'post' )][ 'rootID' ];
$gsfolder = $table [ $ui -> id ( 'switchID' , 10 , 'post' )][ 'gsfolder' ];
$customer = $table [ $ui -> id ( 'switchID' , 10 , 'post' )][ 'customer' ];
$cftppass = $table [ $ui -> id ( 'switchID' , 10 , 'post' )][ 'cftppass' ];
2013-08-28 22:47:04 +02:00
}
2013-12-22 14:07:23 +01:00
2013-12-14 20:32:15 +01:00
if ( ! $ui -> config ( 'template' , 'post' , $thisID ) or ! isset ( $table [ $ui -> id ( 'switchID' , 10 , 'post' )][ 'games' ])) {
2014-03-01 21:21:00 +01:00
2013-10-05 13:39:56 +02:00
$error [] = $gsprache -> template ;
2014-03-01 21:21:00 +01:00
2013-12-14 20:32:15 +01:00
} else if ( isset ( $table [ $ui -> id ( 'switchID' , 10 , 'post' )][ 'games' ])) {
foreach ( $table [ $ui -> id ( 'switchID' , 10 , 'post' )][ 'games' ] as $game ) {
2013-08-28 22:47:04 +02:00
unset ( $temp );
2013-12-14 20:32:15 +01:00
2014-03-01 21:21:00 +01:00
if ( $ui -> config ( 'template' , 'post' , $thisID ) == $game [ 'shorten' ]) {
2013-09-29 15:29:58 +02:00
$temp = 1 ;
2014-03-01 21:21:00 +01:00
} else if ( $ui -> config ( 'template' , 'post' , $thisID ) == $game [ 'shorten' ] . '-2' ) {
2013-09-29 15:29:58 +02:00
$temp = 2 ;
2014-03-01 21:21:00 +01:00
} else if ( $ui -> config ( 'template' , 'post' , $thisID ) == $game [ 'shorten' ] . '-3' ) {
2013-09-29 15:29:58 +02:00
$temp = 3 ;
2013-08-28 22:47:04 +02:00
}
2013-12-14 20:32:15 +01:00
2013-08-28 22:47:04 +02:00
if ( isset ( $temp )) {
2014-11-16 14:23:20 +01:00
$gameSwitchTemplate = ( $temp == 1 ) ? $game [ 'shorten' ] : $game [ 'shorten' ] . '-' . $temp ;
2013-12-14 20:32:15 +01:00
$searchFor = str_replace ( '/' , '' , $game [ 'searchFor' ]);
2014-11-16 14:23:20 +01:00
$modFolder = $game [ 'modfolder' ];
2013-08-28 22:47:04 +02:00
}
}
2013-12-14 20:32:15 +01:00
2014-11-16 14:23:20 +01:00
if ( isset ( $gameSwitchTemplate )) {
$thisTemplate = $ui -> config ( 'template' , 'post' , $thisID );
2013-12-14 20:32:15 +01:00
} else if ( ! in_array ( $gsprache -> template , $error )) {
2013-10-05 13:39:56 +02:00
$error [] = $gsprache -> template ;
2013-08-28 22:47:04 +02:00
}
}
2013-12-14 20:32:15 +01:00
if ( $ui -> anyPath ( 'ftpPath' , 'post' )) {
$ftpPath = $ui -> anyPath ( 'ftpPath' , 'post' );
}
$ftp = new EasyWiFTP ( $ftpAddress , $ftpPort , $ftpUser , $ftpPassword , $ssl );
if ( $ftp -> ftpConnection and $ftp -> loggedIn ) {
if ( isset ( $searchFor )) {
2014-03-01 21:21:00 +01:00
$ftpPath = $ftp -> checkPath ( $ftpPath , $searchFor );
2013-12-14 20:32:15 +01:00
if ( ! $ftpPath ) {
2013-12-22 18:56:33 +01:00
$foundPath = $ftp -> checkFolders ( $ui -> anyPath ( 'ftpPath' , 'post' ), $searchFor , 5 );
2013-12-14 20:32:15 +01:00
2014-10-05 13:23:17 +02:00
$ftpPath = ( is_array ( $foundPath )) ? '' : str_replace ( '//' , '/' , $foundPath );
2013-12-22 18:56:33 +01:00
if ( strlen ( $searchFor ) > 0 or strlen ( $ftpPath ) == 0 ) {
$error [] = $sprache -> ftp_path . '. ' . $sprache -> import_corrected ;
}
2013-08-28 22:47:04 +02:00
}
}
2013-12-14 20:32:15 +01:00
} else if ( $ftp -> ftpConnection and ! $ftp -> loggedIn ) {
$error [] = $sprache -> ftp_user ;
$error [] = $sprache -> ftp_password ;
2013-08-28 22:47:04 +02:00
} else {
2013-12-14 20:32:15 +01:00
if ( ! in_array ( $sprache -> ftp_adresse , $error )) {
$error [] = $sprache -> ftp_adresse ;
}
if ( ! in_array ( $sprache -> ftp_port , $error )) {
$error [] = $sprache -> ftp_port ;
}
2013-08-28 22:47:04 +02:00
}
2013-12-14 20:32:15 +01:00
2014-11-16 14:23:20 +01:00
if ( count ( $error ) == 0 and isset ( $rootID )) {
2013-12-22 18:56:33 +01:00
2014-11-16 14:23:20 +01:00
$ftpConnectString = ( $ssl == 'N' ) ? 'ftp://' : 'ftps://' ;
$ftpConnectString .= $ftpAddress . ':' . $ftpPort . str_replace ( array ( '//' , '///' ), '/' , '/' . $ftpPath );
2013-12-22 18:56:33 +01:00
2014-11-16 14:23:20 +01:00
$appServer = new AppServer ( $rootID );
$appServer -> getAppServerDetails ( $thisID );
2016-06-04 17:12:46 +02:00
$appServer -> stopAppHard ();
2014-11-16 14:23:20 +01:00
$appServer -> migrateToEasyWi ( array ( 'user' => $ftpUser , 'password' => $ftpPassword , 'path' => $ftpPath , 'connectString' => $ftpConnectString ), $gameSwitchTemplate , $modFolder );
$appServer -> execute ();
2014-03-01 21:21:00 +01:00
2014-10-05 13:23:17 +02:00
$template_file = $sprache -> import_start ;
if ( isset ( $dbConnect [ 'debug' ]) and $dbConnect [ 'debug' ] == 1 ) {
2014-11-16 14:23:20 +01:00
$template_file .= '<br><pre>' . implode ( " \r \n " , $appServer -> debug ()) . '</pre>' ;
2014-10-05 13:23:17 +02:00
}
2014-11-16 14:23:20 +01:00
$loguseraction = '%import% %gserver% ' . $address ;
$insertlog -> execute ();
2013-08-28 22:47:04 +02:00
}
}
2014-03-01 21:21:00 +01:00
2013-08-28 22:47:04 +02:00
if ( ! isset ( $template_file ) and isset ( $customer )) {
2014-03-01 21:21:00 +01:00
$template_file = 'userpanel_gserver_migration.tpl' ;
}
if ( ! isset ( $template_file )) {
2013-09-29 15:29:58 +02:00
$template_file = 'userpanel_404.tpl' ;
2013-08-28 22:47:04 +02:00
}