2013-08-28 22:47:04 +02:00
< ? php
2013-10-19 16:20:33 +02:00
2013-08-28 22:47:04 +02:00
/**
* File : userpanel_ao . php .
* Author : Ulrich Block
* 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-19 16:20:33 +02:00
include ( EASYWIDIR . '/stuff/keyphrasefile.php' );
2014-11-15 12:46:01 +01:00
include ( EASYWIDIR . '/stuff/methods/class_ftp.php' );
include ( EASYWIDIR . '/stuff/methods/functions_ssh_exec.php' );
include ( EASYWIDIR . '/stuff/methods/class_app.php' );
2013-10-19 16:20:33 +02:00
2013-10-03 12:49:13 +02:00
if (( ! isset ( $user_id ) or $main != 1 ) or ( isset ( $user_id ) and ! $pa [ 'useraddons' ])) {
2013-08-28 22:47:04 +02:00
header ( 'Location: userpanel.php' );
2015-09-24 09:31:52 +02:00
die ( 'No Access' );
2013-08-28 22:47:04 +02:00
}
2013-10-19 16:20:33 +02:00
2014-11-15 12:46:01 +01:00
$sprache = getlanguagefile ( 'images' , $user_language , $resellerLockupID );
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-19 16:20:33 +02:00
$logusertype = 'user' ;
2013-09-29 15:29:58 +02:00
$logreseller = 0 ;
2013-10-19 16:20:33 +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
} else {
2013-09-29 15:29:58 +02:00
$logsubuser = 0 ;
2013-08-28 22:47:04 +02:00
}
2013-10-19 16:20:33 +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
} else {
2013-09-29 15:29:58 +02:00
$logsubuser = 0 ;
2013-08-28 22:47:04 +02:00
}
2013-10-19 16:20:33 +02:00
2014-10-05 12:13:20 +02:00
if ( $ui -> id ( 'id' , 10 , 'get' ) and $ui -> id ( 'adid' , 10 , 'get' ) and in_array ( $ui -> st ( 'action' , 'get' ), array ( 'ad' , 'dl' )) and ( ! isset ( $_SESSION [ 'sID' ]) or in_array ( $ui -> id ( 'id' , 10 , 'get' ), $substituteAccess [ 'gs' ]))) {
2013-10-19 16:20:33 +02:00
2014-11-15 12:46:01 +01:00
$id = ( int ) $ui -> id ( 'id' , 10 , 'get' );
$addonID = ( int ) $ui -> id ( 'adid' , 10 , 'get' );
2014-10-05 12:13:20 +02:00
2014-11-15 12:46:01 +01:00
$query = $sql -> prepare ( " SELECT `rootID` FROM `gsswitch` WHERE `id`=? AND `userid`=? AND `resellerid`=? LIMIT 1 " );
$query -> execute ( array ( $id , $user_id , $resellerLockupID ));
2013-10-19 16:20:33 +02:00
2014-11-15 12:46:01 +01:00
$appServer = new AppServer ( $query -> fetchColumn ());
2014-10-05 12:13:20 +02:00
2014-11-15 12:46:01 +01:00
$appServer -> getAppServerDetails ( $id );
2014-10-05 12:13:20 +02:00
2014-11-15 12:46:01 +01:00
// Will be false in case no fitting data could be fetched before
if ( $appServer -> appServerDetails ) {
2014-10-05 12:13:20 +02:00
2014-11-15 12:46:01 +01:00
$query2 = $sql -> prepare ( " INSERT INTO `addons_installed` (`userid`,`addonid`,`serverid`,`servertemplate`,`paddon`,`resellerid`) VALUES (?,?,?,?,?,?) " );
2014-10-05 12:13:20 +02:00
2014-11-15 12:46:01 +01:00
$query = $sql -> prepare ( " SELECT `addon`,`paddon` FROM `addons` WHERE `id`=? AND `resellerid`=? AND `active`='Y' LIMIT 1 " );
$query -> execute ( array ( $addonID , $resellerLockupID ));
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2014-10-05 12:13:20 +02:00
2014-11-15 12:46:01 +01:00
$protectedAllowed = $row [ 'paddon' ];
$addonName = $row [ 'addon' ];
2013-10-19 16:20:33 +02:00
2014-11-15 12:46:01 +01:00
if ( $ui -> st ( 'action' , 'get' ) == 'ad' ) {
2014-10-05 12:13:20 +02:00
2014-11-15 12:46:01 +01:00
// Check if the addon is allowed for installing
2014-10-05 12:13:20 +02:00
2014-11-15 12:46:01 +01:00
if ( $appServer -> appServerDetails [ 'protectionModeStarted' ] == 'N' or ( $appServer -> appServerDetails [ 'protectionModeStarted' ] == 'Y' and $protectedAllowed == 'Y' )) {
2014-10-05 12:13:20 +02:00
2014-11-15 12:46:01 +01:00
$query2 -> execute ( array ( $user_id , $addonID , $appServer -> appServerDetails [ 'app' ][ 'id' ], $appServer -> appServerDetails [ 'app' ][ 'servertemplate' ], $appServer -> appServerDetails [ 'protectionModeStarted' ], $resellerLockupID ));
2014-10-05 12:13:20 +02:00
2014-11-15 12:46:01 +01:00
$template_file = $sprache -> addon_inst ;
$actionstatus = 'ok' ;
2014-10-05 12:13:20 +02:00
2014-11-15 12:46:01 +01:00
// Reload addon details in order to have the newly inserted available as well
$appServer -> getAddonDetails ();
$appServer -> addAddon ( $addonID );
2014-10-05 12:13:20 +02:00
2014-11-15 12:46:01 +01:00
// This case becomes true in case the user tries to manipulate the URL
} else {
$template_file = $sprache -> failed ;
$actionstatus = 'fail' ;
2013-08-28 22:47:04 +02:00
}
2014-10-05 12:13:20 +02:00
2014-11-15 12:46:01 +01:00
} else {
2014-10-05 12:13:20 +02:00
2014-11-15 12:46:01 +01:00
// This will load all details for all installed addons into the object
$appServer -> getAddonDetails ();
2014-10-05 12:13:20 +02:00
2014-11-15 12:46:01 +01:00
// Remove the selected addon
$appServer -> removeAddon ( $addonID );
2013-10-19 16:20:33 +02:00
2013-09-29 15:29:58 +02:00
$template_file = $sprache -> addon_del ;
2013-10-19 16:20:33 +02:00
$actionstatus = 'ok' ;
2014-10-05 12:13:20 +02:00
}
2013-08-28 22:47:04 +02:00
}
2013-10-19 16:20:33 +02:00
2014-11-15 12:46:01 +01:00
if ( isset ( $protectedAllowed , $addonName )) {
$appServer -> execute ();
2014-10-05 12:13:20 +02:00
2014-11-15 12:46:01 +01:00
$loguseraction = " % { $ui -> st ( 'action' , 'get' ) } % %addon% { $addonName } { $appServer -> appServerDetails [ 'serverIP' ] } : { $appServer -> appServerDetails [ 'port' ] } % { $actionstatus } % " ;
2013-08-28 22:47:04 +02:00
$insertlog -> execute ();
2014-10-05 12:13:20 +02:00
2014-11-15 12:46:01 +01:00
if ( isset ( $dbConnect [ 'debug' ]) and $dbConnect [ 'debug' ] == 1 ) {
$template_file .= '<br><pre>' . implode ( " \r \n " , $appServer -> debug ()) . '</pre>' ;
}
2013-08-28 22:47:04 +02:00
} else {
2013-09-29 15:29:58 +02:00
$template_file = $sprache -> failed ;
2013-08-28 22:47:04 +02:00
}
2013-10-19 16:20:33 +02:00
2013-08-28 22:47:04 +02:00
} else {
2013-09-29 15:29:58 +02:00
$template_file = $sprache -> failed ;
2013-08-28 22:47:04 +02:00
}
2013-10-19 16:20:33 +02:00
2014-11-16 14:23:20 +01:00
} else if ( $ui -> id ( 'id' , 10 , 'get' ) and ( ! isset ( $_SESSION [ 'sID' ]) or in_array ( $ui -> id ( 'id' , 10 , 'get' ), $substituteAccess [ 'gs' ]))) {
2013-10-19 16:20:33 +02:00
$table = array ();
2014-10-05 12:13:20 +02:00
$i = 0 ;
2013-10-19 16:20:33 +02:00
$username = getusername ( $user_id );
2014-10-05 12:13:20 +02:00
$switchID = $ui -> id ( 'id' , 10 , 'get' );
2013-10-19 16:20:33 +02:00
$query = $sql -> prepare ( " SELECT g.`serverid`,g.`serverip`,g.`port`,g.`protected`,g.`queryName`,s.`servertemplate`,t.`shorten`,t.`id` AS `servertype_id` FROM `gsswitch` g INNER JOIN `serverlist` s ON g.`serverid`=s.`id` INNER JOIN `servertypes` t ON s.`servertype`=t.`id` WHERE g.`userid`=? AND g.`id`=? AND g.`resellerid`=? LIMIT 1 " );
2014-11-15 12:46:01 +01:00
$query -> execute ( array ( $user_id , $switchID , $resellerLockupID ));
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2013-09-29 15:29:58 +02:00
$table2 = array ();
$table3 = array ();
2014-11-15 12:46:01 +01:00
2013-09-29 15:29:58 +02:00
$description = '' ;
2014-11-15 12:46:01 +01:00
2013-10-13 11:42:31 +02:00
$serverip = $row [ 'serverip' ];
$serverport = $row [ 'port' ];
$serverid = $row [ 'serverid' ];
$servershorten = $row [ 'shorten' ];
$servertemplate = $row [ 'servertemplate' ];
$protected = $row [ 'protected' ];
$description = $row [ 'queryName' ];
2013-10-20 12:02:02 +02:00
2014-10-05 12:13:20 +02:00
$currentTemplate = ( $servertemplate > 1 ) ? $servershorten . '-' . $servertemplate : $servershorten ;
2014-11-15 12:46:01 +01:00
$query2 = ( $protected == 'Y' ) ? $sql -> prepare ( " SELECT a.`addon_id`,t.`menudescription`,t.`depending`,t.`type` FROM `addons_allowed` AS a INNER JOIN `addons` t ON a.`addon_id`=t.`id` AND a.`reseller_id`=t.`resellerid` WHERE t.`active`='Y' AND t.`paddon`='Y' AND a.`servertype_id`=? AND a.`reseller_id`=? ORDER BY t.`depending`,t.`menudescription` " ) : $sql -> prepare ( " SELECT a.`addon_id`,t.`menudescription`,t.`depending`,t.`type` FROM `addons_allowed` AS a INNER JOIN `addons` t ON a.`addon_id`=t.`id` AND a.`reseller_id`=t.`resellerid` WHERE t.`active`='Y' AND a.`servertype_id`=? AND a.`reseller_id`=? ORDER BY t.`depending`,t.`menudescription` " );
$query2 -> execute ( array ( $row [ 'servertype_id' ], $resellerLockupID ));
while ( $row2 = $query2 -> fetch ( PDO :: FETCH_ASSOC )) {
2013-10-20 12:02:02 +02:00
2014-08-28 23:42:22 +02:00
$imgAlt = '' ;
2013-10-20 12:02:02 +02:00
$descriptionrow = '' ;
$lang = '' ;
$delete = '' ;
2013-10-19 16:20:33 +02:00
$adid = $row2 [ 'addon_id' ];
2013-10-13 11:42:31 +02:00
$depending = $row2 [ 'depending' ];
$menudescription = $row2 [ 'menudescription' ];
2013-10-20 12:02:02 +02:00
2013-09-29 15:29:58 +02:00
$query3 = $sql -> prepare ( " SELECT `text` FROM `translations` WHERE `type`='ad' AND `transID`=? AND `lang`=? AND `resellerID`=? LIMIT 1 " );
2014-11-15 12:46:01 +01:00
$query3 -> execute ( array ( $adid , $user_language , $resellerLockupID ));
2013-10-13 11:42:31 +02:00
$descriptionrow = $query3 -> fetchColumn ();
2013-10-20 12:02:02 +02:00
2013-10-13 13:11:38 +02:00
if ( empty ( $descriptionrow )) {
2013-09-29 15:29:58 +02:00
$query3 = $sql -> prepare ( " SELECT `text` FROM `translations` WHERE `type`='ad' AND `transID`=? AND `lang`=? AND `resellerID`=? LIMIT 1 " );
2014-11-15 12:46:01 +01:00
$query3 -> execute ( array ( $adid , $rSA [ 'language' ], $resellerLockupID ));
2013-10-13 11:42:31 +02:00
$descriptionrow = $query -> fetchColumn ();
2013-08-28 22:47:04 +02:00
}
2014-08-28 23:42:22 +02:00
2016-05-07 11:46:28 +02:00
$addescription = $descriptionrow ;
2013-10-20 12:02:02 +02:00
$query3 = ( $protected == 'Y' ) ? $sql -> prepare ( " SELECT `id` FROM `addons_installed` WHERE `userid`=? AND `serverid`=? AND `addonid`=? AND `servertemplate`=? AND `paddon`='Y' AND `resellerid`=? LIMIT 1 " ) : $sql -> prepare ( " SELECT `id` FROM `addons_installed` WHERE `userid`=? AND `serverid`=? AND `addonid`=? AND `servertemplate`=? AND `resellerid`=? LIMIT 1 " );
2014-11-15 12:46:01 +01:00
$query3 -> execute ( array ( $user_id , $serverid , $adid , $servertemplate , $resellerLockupID ));
2013-10-13 11:42:31 +02:00
$installedid = $query3 -> fetchColumn ();
2013-10-20 12:02:02 +02:00
2014-11-15 12:46:01 +01:00
if ( isid ( $installedid , 10 )){
2014-08-28 23:42:22 +02:00
2013-10-20 12:02:02 +02:00
$action = 'dl' ;
$delete = '&rid=' . $installedid ;
2013-08-28 22:47:04 +02:00
} else {
2014-08-28 23:42:22 +02:00
$query3 = $sql -> prepare ( " SELECT COUNT(1) AS `amount` FROM `addons_installed` WHERE `userid`=? AND `serverid`=? AND `servertemplate`=? AND `addonid`=? AND `resellerid`=? LIMIT 1 " );
2014-11-15 12:46:01 +01:00
$query3 -> execute ( array ( $user_id , $serverid , $servertemplate , $depending , $resellerLockupID ));
2014-08-28 23:42:22 +02:00
$colcount = $query3 -> fetchColumn ();
2013-10-20 12:02:02 +02:00
if ( $row2 [ 'type' ] == 'map' or $depending == 0 or ( $depending > 0 and $colcount > 0 )) {
$action = 'ad' ;
2013-08-28 22:47:04 +02:00
} else {
2014-08-28 23:42:22 +02:00
2013-10-20 12:02:02 +02:00
$action = 'none' ;
2014-08-28 23:42:22 +02:00
2013-09-29 15:29:58 +02:00
$query3 = $sql -> prepare ( " SELECT `menudescription` FROM `addons` WHERE `id`=? AND `resellerid`=? LIMIT 1 " );
2014-11-15 12:46:01 +01:00
$query3 -> execute ( array ( $depending , $resellerLockupID ));
2013-10-13 11:42:31 +02:00
$imgAlt = $sprache -> requires . ': ' . $query3 -> fetchColumn ();
2013-08-28 22:47:04 +02:00
}
2013-10-20 12:02:02 +02:00
2013-08-28 22:47:04 +02:00
}
2013-10-20 12:02:02 +02:00
2014-08-28 23:42:22 +02:00
$link = ( $action != 'none' ) ? 'userpanel.php?w=ao&id=' . $switchID . '&adid=' . $adid . '&action=' . $action . $delete . '&r=gs' : '#' ;
2013-10-20 12:02:02 +02:00
2013-10-03 12:49:13 +02:00
if ( $row2 [ 'type' ] == 'tool' ) {
2014-08-28 23:42:22 +02:00
$table2 [] = array ( 'adid' => $adid , 'menudescription' => $menudescription , 'addescription' => $addescription , 'installedid' => $installedid , 'alt' => $imgAlt , 'link' => $link , 'action' => $action );
2013-10-03 12:49:13 +02:00
} else if ( $row2 [ 'type' ] == 'map' ) {
2014-08-28 23:42:22 +02:00
$table3 [] = array ( 'adid' => $adid , 'menudescription' => $menudescription , 'addescription' => $addescription , 'installedid' => $installedid , 'alt' => $imgAlt , 'link' => $link , 'action' => $action );
2013-08-28 22:47:04 +02:00
}
2013-10-20 12:02:02 +02:00
2013-08-28 22:47:04 +02:00
}
2013-10-20 12:02:02 +02:00
$table = array ( 'id' => $switchID , 'serverip' => $serverip , 'port' => $serverport , 'tools' => $table2 , 'maps' => $table3 , 'name' => $description );
2014-10-05 12:13:20 +02:00
2013-10-19 16:20:33 +02:00
unset ( $table2 , $table3 );
2014-08-28 23:42:22 +02:00
}
2013-10-19 16:20:33 +02:00
$template_file = 'userpanel_gserver_addon.tpl' ;
2014-10-05 12:13:20 +02:00
2013-08-28 22:47:04 +02:00
} else {
2013-09-29 15:29:58 +02:00
$template_file = 'userpanel_404.tpl' ;
2015-09-07 18:38:07 +02:00
}