2013-08-28 22:47:04 +02:00
< ? php
2013-10-13 11:35:58 +02:00
2013-08-28 22:47:04 +02:00
/**
* File : voice_master . php .
* Author : Ulrich Block
* Date : 23.09 . 12
* Time : 11 : 16
* 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-13 11:35:58 +02:00
include ( EASYWIDIR . '/stuff/keyphrasefile.php' );
2014-02-23 13:13:48 +01:00
include ( EASYWIDIR . '/stuff/methods/class_ts3.php' );
include ( EASYWIDIR . '/stuff/methods/functions_ts3.php' );
include ( EASYWIDIR . '/stuff/methods/functions_ssh_exec.php' );
2013-10-18 18:38:09 +02:00
include ( EASYWIDIR . '/third_party/password_compat/password.php' );
2013-10-13 11:35:58 +02:00
if (( ! isset ( $admin_id ) or $main != 1 ) or ( isset ( $admin_id ) and ! $pa [ 'voicemasterserver' ])) {
header ( 'Location: admin.php' );
2015-12-15 19:21:03 +01:00
die ( 'No access' );
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
$sprache = getlanguagefile ( 'voice' , $user_language , $reseller_id );
$usprache = getlanguagefile ( 'user' , $user_language , $reseller_id );
2013-09-29 15:29:58 +02:00
$loguserid = $admin_id ;
$logusername = getusername ( $admin_id );
$logusertype = 'admin' ;
2013-10-13 11:35:58 +02:00
2013-10-13 13:11:38 +02:00
if ( $reseller_id == 0 ) {
2013-09-29 15:29:58 +02:00
$logreseller = 0 ;
$logsubuser = 0 ;
2013-10-13 11:35:58 +02:00
2013-08-28 22:47:04 +02:00
} else {
2013-10-13 11:35:58 +02:00
$logsubuser = ( isset ( $_SESSION [ 'oldid' ])) ? $_SESSION [ 'oldid' ] : 0 ;
2013-09-29 15:29:58 +02:00
$logreseller = 0 ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
if ( $reseller_id != 0 and $admin_id != $reseller_id ) {
$reseller_id = $admin_id ;
}
if ( $ui -> w ( 'action' , 4 , 'post' ) and ! token ( true )) {
2014-03-08 10:57:48 +01:00
unset ( $header , $text );
$errors = array ( $spracheResponse -> token );
$template_file = ( $ui -> st ( 'd' , 'get' ) == 'md' ) ? 'admin_voicemasterserver_md.tpl' : 'admin_voicemasterserver_add.tpl' ;
2013-10-13 11:35:58 +02:00
} else if ( $ui -> st ( 'd' , 'get' ) == 'ad' or (( $ui -> st ( 'd' , 'get' ) == 'ri' or $ui -> st ( 'd' , 'get' ) == 'md' ) and $ui -> id ( 'id' , 10 , 'get' ))) {
2014-01-05 12:15:02 +01:00
$oldactive = 'Y' ;
2013-10-13 11:35:58 +02:00
$resellerToBeWritten = null ;
$externalDNS = array ();
$dnsarray = array ();
2013-10-22 21:05:24 +02:00
$errors = array ();
2013-10-13 11:35:58 +02:00
$id = $ui -> id ( 'id' , 10 , 'get' );
$autorestart = $ui -> active ( 'autorestart' , 'post' );
$externalDefaultDNS = $ui -> active ( 'externalDefaultDNS' , 'post' );
$ip = $ui -> ip ( 'ip' , 'post' );
$user = $ui -> username ( 'user' , 50 , 'post' );
$externalID = $ui -> escaped ( 'externalID' , 'post' );
$ips = $ui -> ips ( 'ips' , 'post' );
$addtype = 2 ;
$addedby = 2 ;
$keyname = $ui -> startparameter ( 'keyname' , 'post' );
$pass = $ui -> startparameter ( 'pass' , 'post' );
$serverdir = $ui -> folder ( 'serverdir' , 'post' );
2014-11-08 12:56:38 +01:00
$rootid = ( $ui -> id ( 'rootid' , 2 , 'post' )) ? $ui -> id ( 'rootid' , 2 , 'post' ) : null ;
2013-10-13 11:35:58 +02:00
$usedns = $ui -> active ( 'usedns' , 'post' );
$querypassword = $ui -> password ( 'querypassword' , 50 , 'post' );
$type = 'ts3' ;
$defaultdns = strtolower ( $ui -> domain ( 'defaultdns' , 'post' ));
$defaultwelcome = $ui -> description ( 'defaultwelcome' , 'post' );
$defaulthostbanner_url = $ui -> url ( 'defaulthostbanner_url' , 'post' );
$defaulthostbanner_gfx_url = $ui -> url ( 'defaulthostbanner_gfx_url' , 'post' );
$defaulthostbutton_tooltip = $ui -> description ( 'defaulthostbutton_tooltip' , 'post' );
$defaulthostbutton_url = $ui -> url ( 'defaulthostbutton_url' , 'post' );
$defaulthostbutton_gfx_url = $ui -> url ( 'defaulthostbutton_gfx_url' , 'post' );
2014-06-01 17:47:41 +02:00
$description = $ui -> description ( 'description' , 'post' );
2015-12-15 19:21:03 +01:00
$iniConfiguration = $ui -> escaped ( 'iniConfiguration' , 'post' );
2013-10-13 11:35:58 +02:00
2016-06-01 21:35:00 +02:00
$tsdnsServerID = $ui -> id ( 'tsdnsServerID' , 19 , 'post' ) || 1 ;
$defaultFlexSlotsFree = $ui -> id ( 'defaultFlexSlotsFree' , 11 , 'post' ) || 5 ;
$defaultFlexSlotsPercent = $ui -> id ( 'defaultFlexSlotsPercent' , 3 , 'post' ) || 80 ;
2013-10-13 11:35:58 +02:00
$queryport = ( $ui -> port ( 'queryport' , 'post' )) ? $ui -> port ( 'queryport' , 'post' ) : 10011 ;
$filetransferport = ( $ui -> port ( 'filetransferport' , 'post' )) ? $ui -> port ( 'filetransferport' , 'post' ) : 30033 ;
2015-12-15 19:21:03 +01:00
$defaultname = ( $ui -> startparameter ( 'defaultname' , 'post' )) ? $ui -> startparameter ( 'defaultname' , 'post' ) : " My Voiceserver " . $rSA [ 'brandname' ];
2013-10-13 11:35:58 +02:00
$active = ( $ui -> active ( 'active' , 'post' )) ? $ui -> active ( 'active' , 'post' ) : 'Y' ;
2014-01-05 17:12:59 +01:00
$publickey = ( $ui -> w ( 'publickey' , 1 , 'post' )) ? $ui -> w ( 'publickey' , 1 , 'post' ) : 'N' ;
2013-10-13 11:35:58 +02:00
$maxserver = ( $ui -> id ( 'maxserver' , 30 , 'post' )) ? $ui -> id ( 'maxserver' , 30 , 'post' ) : 10 ;
$maxslots = ( $ui -> id ( 'maxslots' , 30 , 'post' )) ? $ui -> id ( 'maxslots' , 30 , 'post' ) : 512 ;
$port = ( $ui -> port ( 'port' , 'post' )) ? $ui -> port ( 'port' , 'post' ) : 22 ;
$bit = ( $ui -> id ( 'bit' , 2 , 'post' )) ? $ui -> id ( 'bit' , 2 , 'post' ) : 64 ;
$managedServer = ( $ui -> active ( 'managedServer' , 'post' )) ? $ui -> active ( 'managedServer' , 'post' ) : 'N' ;
2013-12-19 21:06:02 +01:00
$managedForID = $ui -> id ( 'managedForID' , 10 , 'post' );
2016-02-27 08:22:48 +01:00
$connectIpOnly = ( $ui -> active ( 'connectIpOnly' , 'post' )) ? $ui -> active ( 'connectIpOnly' , 'post' ) : 'N' ;
2013-09-07 13:33:50 +02:00
2015-12-15 19:21:03 +01:00
if ( ! $iniConfiguration or strlen ( $iniConfiguration ) < 2 or !@ parse_ini_string ( $iniConfiguration , true )) {
2015-12-17 21:37:02 +01:00
$iniConfiguration = ' [ Show at Global List ]
virtualserver_weblist_enabled 1 = On
virtualserver_weblist_enabled 0 = Off ' ;
2015-12-15 19:21:03 +01:00
}
2013-09-07 13:33:50 +02:00
// https://github.com/easy-wi/developer/issues/36 managedServer,managedForID added
2013-10-13 11:35:58 +02:00
if ( $ui -> st ( 'd' , 'get' ) == 'ad' or $ui -> st ( 'd' , 'get' ) == 'md' ) {
2013-09-29 15:29:58 +02:00
$resellerIDs = array ();
2013-10-13 11:35:58 +02:00
2013-10-13 13:11:38 +02:00
$or = ( $reseller_id == 0 ) ? 'OR `resellerid`=`id`' : '' ;
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT `id`,`cname`,`vname`,`name` FROM `userdata` WHERE (`resellerid`=? $or ) AND `accounttype`='r' ORDER BY `id` DESC " );
2013-09-07 13:33:50 +02:00
$query -> execute ( array ( $reseller_id ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2013-10-13 11:35:58 +02:00
$resellerIDs [ $row [ 'id' ]] = trim ( $row [ 'cname' ] . ' ' . $row [ 'vname' ] . ' ' . $row [ 'name' ]);
}
2013-09-07 13:33:50 +02:00
}
2013-10-13 11:35:58 +02:00
if ( $ui -> w ( 'action' , 3 , 'post' ) and ( $ui -> st ( 'd' , 'get' ) == 'ad' or $ui -> st ( 'd' , 'get' ) == 'md' ) and $ui -> active ( 'managedServer' , 'post' ) == 'Y' ) {
if ( $reseller_id == 0 ) {
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT 1 FROM `userdata` WHERE `resellerid`=? AND `accounttype`='r' LIMIT 1 " );
2013-10-13 11:35:58 +02:00
$query -> execute ( array ( $ui -> id ( 'managedForID' , 10 , 'post' )));
2013-09-07 13:33:50 +02:00
} else {
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT 1 FROM `userdata` WHERE `id`=? AND `resellerid`=? AND `accounttype`='r' LIMIT 1 " );
2013-10-13 11:35:58 +02:00
$query -> execute ( array ( $ui -> id ( 'managedForID' , 10 , 'post' ), $reseller_id ));
2013-09-07 13:33:50 +02:00
}
2013-10-13 11:35:58 +02:00
2013-11-24 12:12:07 +01:00
$resellerToBeWritten = ( $query -> rowCount () > 0 ) ? $ui -> id ( 'managedForID' , 10 , 'post' ) : null ;
2013-09-07 13:33:50 +02:00
}
2013-10-13 11:35:58 +02:00
$query = $sql -> prepare ( " SELECT `id`,`ssh2ip`,`description` FROM `voice_tsdns` WHERE `active`='Y' AND `resellerid`=? " );
$query -> execute ( array ( $reseller_id ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2013-10-13 11:35:58 +02:00
$externalDNS [ $row [ 'id' ]] = ( $row [ 'description' ] != '' and $row [ 'description' ] != null ) ? $row [ 'ssh2ip' ] . ': ' . $row [ 'description' ] : $row [ 'ssh2ip' ];
}
if ( $ui -> st ( 'd' , 'get' ) == 'ad' ) {
2013-09-29 15:29:58 +02:00
$roots = array ();
2013-10-13 11:35:58 +02:00
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT `id`,`ip` FROM `rserverdata` WHERE `active`='Y' AND `resellerid`=? " );
2013-10-13 11:35:58 +02:00
$query2 = $sql -> prepare ( " SELECT COUNT(`id`) AS `amount` FROM `voice_masterserver` WHERE `rootid`=? AND `resellerid`=? " );
2013-08-28 22:47:04 +02:00
$query -> execute ( array ( $reseller_id ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2013-10-13 11:35:58 +02:00
$query2 -> execute ( array ( $row [ 'id' ], $reseller_id ));
$colcount = $query2 -> fetchColumn ();
2013-09-07 13:33:50 +02:00
2013-10-13 11:35:58 +02:00
if ( $colcount == 0 ) {
$roots [] = '<option value="' . $row [ 'id' ] . '">' . $row [ 'ip' ] . '</option>' ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
}
}
if ( ! $ui -> w ( 'action' , 3 , 'post' ) and $ui -> st ( 'd' , 'get' ) != 'ri' ) {
if ( $ui -> st ( 'd' , 'get' ) == 'ad' ) {
2020-07-26 22:44:21 +02:00
$ssh2keys = array_diff ( scandir ( EASYWIDIR . '/keys/' ), array ( '..' , '.' , " empty.txt " ));
2013-10-13 11:35:58 +02:00
$template_file = 'admin_voicemasterserver_add.tpl' ;
} else if ( $ui -> st ( 'd' , 'get' ) == 'md' and $id ) {
2013-12-19 21:06:02 +01:00
2013-10-13 11:35:58 +02:00
$query = $sql -> prepare ( " SELECT *,AES_DECRYPT(`querypassword`,:aeskey) AS `decryptedquerypassword`,AES_DECRYPT(`ssh2port`,:aeskey) AS `decryptedssh2port`,AES_DECRYPT(`ssh2user`,:aeskey) AS `decryptedssh2user`,AES_DECRYPT(`ssh2password`,:aeskey) AS `decryptedssh2password` FROM `voice_masterserver` WHERE `id`=:id AND `resellerid`=:reseller_id LIMIT 1 " );
$query -> execute ( array ( ':aeskey' => $aeskey , ':id' => $id , ':reseller_id' => $reseller_id ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2013-10-13 11:35:58 +02:00
$active = $row [ 'active' ];
$defaultname = $row [ 'defaultname' ];
2014-06-01 17:47:41 +02:00
$description = $row [ 'description' ];
2013-10-13 11:35:58 +02:00
$addedby = $row [ 'addedby' ];
$autorestart = $row [ 'autorestart' ];
$externalID = $row [ 'externalID' ];
$tsdnsServerID = $row [ 'tsdnsServerID' ];
$externalDefaultDNS = $row [ 'externalDefaultDNS' ];
$defaultFlexSlotsFree = $row [ 'defaultFlexSlotsFree' ];
$defaultFlexSlotsPercent = $row [ 'defaultFlexSlotsPercent' ];
$publickey = $row [ 'publickey' ];
$ip = $row [ 'ssh2ip' ];
2015-02-21 12:30:08 +01:00
$connectIpOnly = $row [ 'connect_ip_only' ];
2013-10-13 11:35:58 +02:00
$ips = $row [ 'ips' ];
$port = $row [ 'decryptedssh2port' ];
$user = $row [ 'decryptedssh2user' ];
$pass = $row [ 'decryptedssh2password' ];
$serverdir = $row [ 'serverdir' ];
$keyname = $row [ 'keyname' ];
$bit = $row [ 'bitversion' ];
2015-12-15 19:21:03 +01:00
$iniConfiguration = $row [ 'iniConfiguration' ];
2013-10-13 11:35:58 +02:00
// https://github.com/easy-wi/developer/issues/36 managedServer,managedForID added
$managedServer = $row [ 'managedServer' ];
$managedForID = $row [ 'managedForID' ];
if ( $row [ 'type' ] == 'ts3' ) {
$type = 'ts3' ;
$usedns = $row [ 'usedns' ];
$defaultdns = $row [ 'defaultdns' ];
$defaultwelcome = $row [ 'defaultwelcome' ];
$defaulthostbanner_url = $row [ 'defaulthostbanner_url' ];
$defaulthostbanner_gfx_url = $row [ 'defaulthostbanner_gfx_url' ];
$defaulthostbutton_tooltip = $row [ 'defaulthostbutton_tooltip' ];
$defaulthostbutton_url = $row [ 'defaulthostbutton_url' ];
$defaulthostbutton_gfx_url = $row [ 'defaulthostbutton_gfx_url' ];
$queryport = $row [ 'queryport' ];
$querypassword = $row [ 'decryptedquerypassword' ];
$filetransferport = $row [ 'filetransferport' ];
$maxserver = $row [ 'maxserver' ];
$maxslots = $row [ 'maxslots' ];
}
if ( $addedby == 1 ) {
$query2 = $sql -> prepare ( " SELECT `ip` FROM `rserverdata` WHERE `id`=? AND `resellerid`=? LIMIT 1 " );
$query2 -> execute ( array ( $row [ 'rootid' ], $reseller_id ));
$root = $query2 -> fetchColumn ();
2013-08-28 22:47:04 +02:00
}
}
2020-07-26 22:44:21 +02:00
$ssh2keys = array_diff ( scandir ( EASYWIDIR . '/keys/' ), array ( '..' , '.' , " empty.txt " ));
2013-10-13 11:35:58 +02:00
$template_file = ( $query -> rowCount () > 0 ) ? 'admin_voicemasterserver_md.tpl' : 'admin_404.tpl' ;
} else {
$template_file = 'admin_404.tpl' ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
} else if ( $ui -> w ( 'action' , 3 , 'post' ) == 'ad' or (( in_array ( $ui -> w ( 'action' , 3 , 'post' ), array ( 'md' , 'ad2' )) or $ui -> st ( 'd' , 'get' ) == 'ri' ) and $id )) {
if ( ! $ui -> active ( 'active' , 'post' )) {
$errors [ 'active' ] = $sprache -> active ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
if ( ! $ui -> active ( 'autorestart' , 'post' )) {
$errors [ 'autorestart' ] = $sprache -> autorestart ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
if ( ! $ui -> id ( 'maxserver' , 30 , 'post' )) {
$errors [ 'maxserver' ] = $sprache -> maxserver ;
}
if ( ! $ui -> id ( 'maxslots' , 30 , 'post' )) {
$errors [ 'maxslots' ] = $sprache -> maxslots ;
}
if ( ! $ui -> w ( 'type' , 3 , 'post' ) == 'ts3' ) {
if ( ! $ui -> active ( 'externalDefaultDNS' , 'post' )) {
$errors [ 'externalDefaultDNS' ] = $sprache -> externalDefaultDNS ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
if ( ! $ui -> active ( 'usedns' , 'post' )) {
$errors [ 'usedns' ] = $sprache -> usedns ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
if ( ! $ui -> password ( 'querypassword' , 50 , 'post' )) {
$errors [ 'querypassword' ] = $sprache -> querypassword ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
if ( ! $ui -> port ( 'queryport' , 'post' )) {
$errors [ 'queryport' ] = $sprache -> queryport ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
if ( ! $ui -> port ( 'filetransferport' , 'post' )) {
$errors [ 'filetransferport' ] = $sprache -> filetransferport ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
}
if (( $ui -> w ( 'action' , 3 , 'post' ) == 'ad' and $ui -> id ( 'addtype' , 1 , 'post' ) == 2 ) or $ui -> w ( 'action' , 3 , 'post' ) == 'md' ) {
2014-01-05 12:15:02 +01:00
2014-01-05 17:12:59 +01:00
if ( ! $ui -> w ( 'publickey' , 1 , 'post' )) {
2013-10-13 11:35:58 +02:00
$errors [ 'publickey' ] = $sprache -> keyuse ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
if ( ! $ui -> ip ( 'ip' , 'post' )) {
$errors [ 'ip' ] = $sprache -> ssh_ip ;
}
if ( ! $ui -> port ( 'port' , 'post' )) {
$errors [ 'port' ] = $sprache -> ssh_port ;
}
if ( ! $ui -> username ( 'user' , 50 , 'post' )) {
$errors [ 'user' ] = $sprache -> ssh_user ;
}
if ( ! $ui -> id ( 'bit' , 2 , 'post' )) {
$errors [ 'bit' ] = $sprache -> os_bit ;
}
if ( count ( $errors ) == 0 and $ui -> st ( 'd' , 'get' ) != 'ri' ) {
2014-01-05 12:15:02 +01:00
if ( $ui -> w ( 'action' , 3 , 'post' ) == 'md' ) {
$query = $sql -> prepare ( " SELECT `active` FROM `voice_masterserver` WHERE `id`=? AND `resellerid`=? LIMIT 1 " );
$query -> execute ( array ( $id , $reseller_id ));
$oldactive = $query -> fetchColumn ();
}
if ( $oldactive != 'N' and $active == 'Y' ) {
$connection = new TS3 ( $ip , $queryport , 'serveradmin' , $querypassword );
2013-10-13 11:35:58 +02:00
2014-01-05 12:15:02 +01:00
if ( $connection -> socketConnected !== true ) {
$errors [ 'ip' ] = $sprache -> ssh_ip ;
$errors [ 'queryport' ] = $sprache -> queryport ;
2013-10-13 11:35:58 +02:00
2014-01-05 12:15:02 +01:00
} else if ( strpos ( $connection -> errorcode , 'error id=0' ) === false ) {
$errors [ 'querypassword' ] = $sprache -> querypassword ;
2013-10-13 11:35:58 +02:00
2014-01-05 12:15:02 +01:00
}
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
}
2014-01-10 12:22:51 +01:00
if ( $publickey != 'N' and ! is_file ( EASYWIDIR . '/keys/' . $keyname )) {
$errors [ 'keyname' ] = $sprache -> keyname ;
}
2016-06-01 21:35:00 +02:00
$ssh2Check = ( count ( $errors ) == 0 and $ui -> st ( 'd' , 'get' ) != 'ri' and $active == 'Y' ) ? ssh_check ( $ui -> ip ( 'ip' , 'post' ), $ui -> port ( 'port' , 'post' ), $ui -> username ( 'user' , 50 , 'post' ), $ui -> w ( 'publickey' , 1 , 'post' ), $ui -> startparameter ( 'keyname' , 'post' ), $ui -> password ( 'pass' , 255 , 'post' )) : true ;
2013-10-13 11:35:58 +02:00
if ( $ssh2Check !== true ) {
if ( $ssh2Check == 'ipport' ) {
2014-02-01 15:08:20 +01:00
2013-10-13 11:35:58 +02:00
$errors [ 'ip' ] = $sprache -> ssh_ip ;
$errors [ 'port' ] = $sprache -> ssh_port ;
} else {
2014-02-01 15:08:20 +01:00
2013-10-13 11:35:58 +02:00
$errors [ 'user' ] = $sprache -> ssh_user ;
2016-11-26 14:09:46 +01:00
if ( $ui -> w ( 'publickey' , 1 , 'post' ) == 'N' ) {
2014-02-01 15:08:20 +01:00
2014-01-05 17:12:59 +01:00
$errors [ 'pass' ] = $sprache -> ssh_pass ;
2014-02-01 15:08:20 +01:00
2016-11-26 14:09:46 +01:00
} else if ( $ui -> w ( 'publickey' , 1 , 'post' ) == 'B' ) {
2014-02-01 15:08:20 +01:00
2014-01-05 17:12:59 +01:00
$errors [ 'pass' ] = $sprache -> ssh_pass ;
2014-02-01 15:08:20 +01:00
$errors [ 'publickey' ] = $sprache -> keyuse ;
2013-10-13 11:35:58 +02:00
$errors [ 'keyname' ] = $sprache -> keyname ;
2014-02-01 15:08:20 +01:00
2013-10-13 11:35:58 +02:00
} else {
2014-02-01 15:08:20 +01:00
$errors [ 'publickey' ] = $sprache -> keyuse ;
2014-01-05 17:12:59 +01:00
$errors [ 'keyname' ] = $sprache -> keyname ;
2013-08-28 22:47:04 +02:00
}
}
}
2013-10-13 11:35:58 +02:00
2013-08-28 22:47:04 +02:00
} else {
2013-10-13 11:35:58 +02:00
$addtype = 1 ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
if ( $ui -> w ( 'action' , 3 , 'post' ) != 'ad2' and (( count ( $errors ) == 0 or ( $ui -> st ( 'd' , 'get' ) == 'ri' and $id )))) {
2014-08-26 20:58:48 +02:00
2013-10-13 11:35:58 +02:00
if ( $ui -> w ( 'action' , 3 , 'post' ) == 'ad' or ( $ui -> st ( 'd' , 'get' ) == 'ri' and ! $ui -> w ( 'action' , 3 , 'post' ) and $id )) {
if ( $ui -> st ( 'd' , 'get' ) == 'ri' ) {
$masterid = $id ;
$query = $sql -> prepare ( " SELECT *,AES_DECRYPT(`querypassword`,:aeskey) AS `decryptedquerypassword`,AES_DECRYPT(`ssh2port`,:aeskey) AS `decryptedssh2port`,AES_DECRYPT(`ssh2user`,:aeskey) AS `decryptedssh2user`,AES_DECRYPT(`ssh2password`,:aeskey) AS `decryptedssh2password` FROM `voice_masterserver` WHERE `id`=:id AND `resellerid`=:reseller_id LIMIT 1 " );
$query -> execute ( array ( ':aeskey' => $aeskey , ':id' => $masterid , ':reseller_id' => $reseller_id ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2015-07-17 19:26:06 +02:00
2013-10-13 11:35:58 +02:00
$active = $row [ 'active' ];
$defaultname = $row [ 'defaultname' ];
$addtype = $row [ 'addedby' ];
$rootid = $row [ 'rootid' ];
$tsdnsServerID = $row [ 'tsdnsServerID' ];
$externalDefaultDNS = $row [ 'externalDefaultDNS' ];
$defaultFlexSlotsFree = $row [ 'defaultFlexSlotsFree' ];
$defaultFlexSlotsPercent = $row [ 'defaultFlexSlotsPercent' ];
2014-06-01 17:47:41 +02:00
$description = $row [ 'description' ];
2015-12-15 19:21:03 +01:00
$iniConfiguration = $row [ 'iniConfiguration' ];
2013-10-13 11:35:58 +02:00
if ( $row [ 'type' ] == 'ts3' ) {
$type = $sprache -> ts3 ;
$usedns = $row [ 'usedns' ];
$defaultdns = $row [ 'defaultdns' ];
$defaultwelcome = $row [ 'defaultwelcome' ];
$defaulthostbanner_url = $row [ 'defaulthostbanner_url' ];
$defaulthostbanner_gfx_url = $row [ 'defaulthostbanner_gfx_url' ];
$defaulthostbutton_tooltip = $row [ 'defaulthostbutton_tooltip' ];
$defaulthostbutton_url = $row [ 'defaulthostbutton_url' ];
$defaulthostbutton_gfx_url = $row [ 'defaulthostbutton_gfx_url' ];
$queryport = $row [ 'queryport' ];
$querypassword = $row [ 'decryptedquerypassword' ];
$filetransferport = $row [ 'filetransferport' ];
$maxserver = $row [ 'maxserver' ];
$maxslots = $row [ 'maxslots' ];
}
if ( $addtype == 2 ) {
$publickey = $row [ 'publickey' ];
$ip = $row [ 'ssh2ip' ];
$ips = $row [ 'ips' ];
$port = $row [ 'decryptedssh2port' ];
$user = $row [ 'decryptedssh2user' ];
$pass = $row [ 'decryptedssh2password' ];
$serverdir = $row [ 'serverdir' ];
$keyname = $row [ 'keyname' ];
$bit = $row [ 'bitversion' ];
} else if ( $addtype == 1 ) {
$query2 = $sql -> prepare ( " SELECT `ip` FROM `rserverdata` WHERE `id`=? AND `resellerid`=? LIMIT 1 " );
$query2 -> execute ( array ( $rootid , $reseller_id ));
$ip = $query2 -> fetchColumn ();
}
}
}
if ( $addtype == 2 ) {
2013-09-29 15:29:58 +02:00
$table = array ();
2013-10-13 11:35:58 +02:00
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT `id`,`cname`,`name`,`vname` FROM `userdata` WHERE `resellerid`=? AND `accounttype`='u' ORDER BY `id` DESC " );
2013-08-28 22:47:04 +02:00
$query -> execute ( array ( $reseller_id ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2015-07-17 19:26:06 +02:00
$table [ $row [ 'id' ]] = ( $row [ 'vname' ] != '' or $row [ 'name' ] != '' ) ? $row [ 'cname' ] . ' (' . $row [ 'vname' ] . ' ' . $row [ 'name' ] . ')' : $row [ 'cname' ];
2013-10-13 11:35:58 +02:00
}
2013-10-03 12:49:13 +02:00
if ( $usedns == 'Y' ) {
2013-10-13 11:35:58 +02:00
if ( isset ( $tsdnsServerID ) and isid ( $tsdnsServerID , 19 )) {
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT *,AES_DECRYPT(`ssh2port`,:aeskey) AS `decryptedssh2port`,AES_DECRYPT(`ssh2user`,:aeskey) AS `decryptedssh2user`,AES_DECRYPT(`ssh2password`,:aeskey) AS `decryptedssh2password` FROM `voice_tsdns` WHERE `active`='Y' AND `id`=:id AND `resellerid`=:reseller_id LIMIT 1 " );
2013-10-05 13:39:56 +02:00
$query -> execute ( array ( ':aeskey' => $aeskey , ':id' => $tsdnsServerID , ':reseller_id' => $reseller_id ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2013-10-13 11:35:58 +02:00
$publickey = $row [ 'publickey' ];
$ip = $row [ 'ssh2ip' ];
$port = $row [ 'decryptedssh2port' ];
$user = $row [ 'decryptedssh2user' ];
$pass = $row [ 'decryptedssh2password' ];
$serverdir = $row [ 'serverdir' ];
$keyname = $row [ 'keyname' ];
$bit = $row [ 'bitversion' ];
if ( $externalDefaultDNS == 'Y' ) {
$defaultdns = $row [ 'defaultdns' ];
2013-08-28 22:47:04 +02:00
}
}
}
2013-10-13 11:35:58 +02:00
2013-10-22 21:05:24 +02:00
$dnsarray = tsdns ( 'li' , $ip , $port , $user , $publickey , $keyname , $pass , 'N' , $serverdir , $bit , array ( '' ), array ( '' ), array ( '' ), $reseller_id );
2013-10-13 11:35:58 +02:00
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
if ( $ui -> st ( 'd' , 'get' ) == 'ri' ) {
$connection = new TS3 ( $ip , $queryport , 'serveradmin' , $querypassword );
}
if ( $connection -> socketConnected === true and strpos ( $connection -> errorcode , 'error id=0' ) !== false ) {
$i = 1 ;
$servers = $connection -> ImportData ( $dnsarray );
$query = $sql -> prepare ( " SELECT `id` FROM `voice_server` WHERE `localserverid`=? AND `ip`=? AND `resellerid`=? LIMIT 1 " );
foreach ( $servers as $virtualserver_id => $values ) {
2015-07-17 19:26:06 +02:00
2013-10-13 11:35:58 +02:00
$query -> execute ( array ( $virtualserver_id , $values [ 'virtualserver_ip' ], $reseller_id ));
$colcount = $query -> rowCount ();
if ( $colcount == 1 or $i > 25 ) {
unset ( $servers [ $virtualserver_id ]);
} else {
$i ++ ;
2013-08-28 22:47:04 +02:00
}
}
2013-10-13 11:35:58 +02:00
2013-08-28 22:47:04 +02:00
$connection -> CloseConnection ();
2013-10-13 11:35:58 +02:00
} else {
$servers = array ();
2013-08-28 22:47:04 +02:00
}
}
2013-09-07 13:33:50 +02:00
2014-05-18 13:48:42 +02:00
$query = $sql -> prepare ( " SELECT `id` FROM `voice_masterserver` WHERE `ssh2ip`=? AND `resellerid`=? LIMIT 1 " );
$query -> execute ( array ( $ip , $reseller_id ));
2016-07-22 16:47:18 +02:00
$masterid = $query -> fetchColumn ();
2013-10-13 11:35:58 +02:00
2016-07-22 16:47:18 +02:00
if ( ! isid ( $masterid , 10 )) {
2013-10-13 11:35:58 +02:00
if ( $ui -> st ( 'd' , 'get' ) != 'ri' ) {
2013-09-07 13:33:50 +02:00
// https://github.com/easy-wi/developer/issues/36 managedServer,managedForID added
2015-12-15 19:21:03 +01:00
$query = $sql -> prepare ( " INSERT INTO `voice_masterserver` (`active`,`iniConfiguration`,`connect_ip_only`,`type`,`description`,`defaultname`,`bitversion`,`queryport`,`querypassword`,`filetransferport`,`maxserver`,`maxslots`,`rootid`,`addedby`,`usedns`,`defaultdns`,`defaultwelcome`,`defaulthostbanner_url`,`defaulthostbanner_gfx_url`,`defaulthostbutton_tooltip`,`defaulthostbutton_url`,`defaulthostbutton_gfx_url`,`defaultFlexSlotsFree`,`defaultFlexSlotsPercent`,`publickey`,`ssh2ip`,`ssh2port`,`ssh2user`,`ssh2password`,`ips`,`serverdir`,`keyname`,`autorestart`,`externalID`,`tsdnsServerID`,`externalDefaultDNS`,`managedServer`,`managedForID`,`resellerid`) VALUES (:active,:iniConfiguration,:connect_ip_only,:type,:description,:defaultname,:bit,:queryport,AES_ENCRYPT(:querypassword,:aeskey),:filetransferport,:maxserver,:maxslots,:rootid,:addedby,:usedns,:defaultdns,:defaultwelcome,:defaulthostbanner_url,:defaulthostbanner_gfx_url,:defaulthostbutton_tooltip,:defaulthostbutton_url,:defaulthostbutton_gfx_url,:defaultFlexSlotsFree,:defaultFlexSlotsPercent,:publickey,:ssh2ip,AES_ENCRYPT(:ssh2port,:aeskey),AES_ENCRYPT(:ssh2user,:aeskey),AES_ENCRYPT(:ssh2password,:aeskey),:ips,:serverdir,:keyname,:autorestart,:externalID,:tsdnsServerID,:externalDefaultDNS,:managedServer,:managedForID,:reseller_id) " );
$query -> execute ( array ( ':aeskey' => $aeskey , ':active' => $active , ':iniConfiguration' => $iniConfiguration , ':connect_ip_only' => $connectIpOnly , ':type' => $type , ':description' => $description , ':defaultname' => $defaultname , ':bit' => $bit , ':queryport' => $queryport , ':querypassword' => $querypassword , ':filetransferport' => $filetransferport , ':maxserver' => $maxserver , ':maxslots' => $maxslots , ':rootid' => $rootid , ':addedby' => $addtype , ':usedns' => $usedns , ':defaultdns' => $defaultdns , ':defaultwelcome' => $defaultwelcome , ':defaulthostbanner_url' => $defaulthostbanner_url , ':defaulthostbanner_gfx_url' => $defaulthostbanner_gfx_url , ':defaulthostbutton_tooltip' => $defaulthostbutton_tooltip , ':defaulthostbutton_url' => $defaulthostbutton_url , ':defaulthostbutton_gfx_url' => $defaulthostbutton_gfx_url , ':defaultFlexSlotsFree' => $defaultFlexSlotsFree , ':defaultFlexSlotsPercent' => $defaultFlexSlotsPercent , ':publickey' => $publickey , ':ssh2ip' => $ip , ':ssh2port' => $port , ':ssh2user' => $user , ':ssh2password' => $pass , ':ips' => $ips , ':serverdir' => $serverdir , ':keyname' => $keyname , ':autorestart' => $autorestart , ':externalID' => $externalID , ':tsdnsServerID' => $tsdnsServerID , ':externalDefaultDNS' => $externalDefaultDNS , ':managedServer' => $managedServer , ':managedForID' => $resellerToBeWritten , ':reseller_id' => $reseller_id ));
2013-10-13 11:35:58 +02:00
$rowCount = $query -> rowCount ();
$masterid = $sql -> lastInsertId ();
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
$loguseraction = '%add% %voserver% %master% ' . $ip ;
$insertlog -> execute ();
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
2014-05-18 13:48:42 +02:00
$template_file = 'admin_voicemasterserver_add2.tpl' ;
2013-10-13 11:35:58 +02:00
} else if ( $ui -> w ( 'action' , 3 , 'post' ) == 'md' ) {
2014-01-05 12:15:02 +01:00
if (( $oldactive == 'Y' and $active == 'N' ) or ( $oldactive == 'N' and $active == 'Y' )) {
2013-09-22 12:00:33 +02:00
2013-10-13 11:35:58 +02:00
2014-01-05 12:15:02 +01:00
$split_config = preg_split ( '/\//' , $serverdir , - 1 , PREG_SPLIT_NO_EMPTY );
$folderfilecount = count ( $split_config ) - 1 ;
2013-09-27 08:22:09 +02:00
2014-01-05 12:15:02 +01:00
$i = 0 ;
while ( $i <= $folderfilecount ) {
if ( isset ( $commandFolders )) {
$commandFolders .= $split_config [ $i ] . '/' ;
2013-08-28 22:47:04 +02:00
} else {
2014-01-05 12:15:02 +01:00
$commandFolders = 'cd ' . $split_config [ $i ] . '/' ;
2013-08-28 22:47:04 +02:00
}
2014-01-05 12:15:02 +01:00
$i ++ ;
}
2013-10-13 11:35:58 +02:00
2014-01-05 12:15:02 +01:00
if ( isset ( $commandFolders )) {
$commandFolders .= ' && ' ;
} else {
$commandFolders = '' ;
}
2013-10-13 11:35:58 +02:00
2014-01-05 12:15:02 +01:00
if ( $bit == '32' ) {
$tsbin = 'ts3server_linux_x86' ;
$tsdnsbin = 'tsdnsserver_linux_x86' ;
2013-10-13 11:35:58 +02:00
2014-01-05 12:15:02 +01:00
} else {
$tsbin = 'ts3server_linux_amd64' ;
$tsdnsbin = 'tsdnsserver_linux_amd64' ;
}
2013-10-13 11:35:58 +02:00
2014-01-05 12:15:02 +01:00
if ( $active == 'N' ) {
$ssh2cmd = " ps fx | grep ' $tsbin ' | grep -v 'grep' | awk ' { print $ 1}' | while read pid; do kill " . '$pid' . " ; done " ;
$ssh2cmd2 = " ps fx | grep ' $tsdnsbin ' | grep -v 'grep' | awk ' { print $ 1}' | while read pid; do kill " . '$pid' . " ; done " ;
2013-10-13 11:35:58 +02:00
2014-01-05 12:15:02 +01:00
} else if ( $active == 'Y' ) {
2016-08-25 04:20:56 +02:00
$ssh2cmd = $commandFolders . 'function restart1 () { if [ "`ps fx | grep ' . $tsbin . ' | grep -v grep`" == "" ]; then ./ts3server_startscript.sh start inifile=ts3server.ini > /dev/null & else ./ts3server_startscript.sh restart inifile=ts3server.ini > /dev/null & fi }; restart1& ' ;
2014-01-05 12:15:02 +01:00
$ssh2cmd2 = $commandFolders . ' cd tsdns && function restart2 () { if [ "`ps fx | grep ' . $tsdnsbin . ' | grep -v grep`" == "" ]; then ./' . $tsdnsbin . ' > /dev/null & else ./' . $tsdnsbin . ' --update > /dev/null & fi }; restart2& ' ;
}
2013-10-13 11:35:58 +02:00
2015-12-15 19:21:03 +01:00
$cmds = ( $usedns == 'Y' ) ? array ( $ssh2cmd , $ssh2cmd2 ) : array ( $ssh2cmd );
2014-01-05 12:15:02 +01:00
ssh2_execute ( 'vm' , $id , $cmds );
2013-08-28 22:47:04 +02:00
}
2013-09-07 13:33:50 +02:00
// https://github.com/easy-wi/developer/issues/36 managedServer,managedForID added
2015-12-15 19:21:03 +01:00
$query = $sql -> prepare ( " UPDATE `voice_masterserver` SET `active`=:active,`iniConfiguration`=:iniConfiguration,`connect_ip_only`=:connect_ip_only,`description`=:description,`managedServer`=:managedServer,`managedForID`=:managedForID,`externalID`=:externalID,`defaultname`=:defaultname,`bitversion`=:bit,`queryport`=:queryport,`querypassword`=AES_ENCRYPT(:querypassword,:aeskey),`filetransferport`=:filetransferport,`maxserver`=:maxserver,`maxslots`=:maxslots,`usedns`=:usedns,`defaultdns`=:defaultdns,`defaultwelcome`=:defaultwelcome,`defaulthostbanner_url`=:defaulthostbanner_url,`defaulthostbanner_gfx_url`=:defaulthostbanner_gfx_url,`defaulthostbutton_tooltip`=:defaulthostbutton_tooltip,`defaulthostbutton_url`=:defaulthostbutton_url,`defaulthostbutton_gfx_url`=:defaulthostbutton_gfx_url,`defaultFlexSlotsFree`=:defaultFlexSlotsFree,`defaultFlexSlotsPercent`=:defaultFlexSlotsPercent,`publickey`=:publickey,`ssh2ip`=:ssh2ip,`ssh2port`=AES_ENCRYPT(:ssh2port,:aeskey),`ssh2user`=AES_ENCRYPT(:ssh2user,:aeskey),`ssh2password`=AES_ENCRYPT(:ssh2password,:aeskey),`ips`=:ips,`serverdir`=:serverdir,`keyname`=:keyname,`autorestart`=:autorestart,`tsdnsServerID`=:tsdnsServerID,`externalDefaultDNS`=:externalDefaultDNS WHERE `id`=:id AND `resellerid`=:reseller_id LIMIT 1 " );
$query -> execute ( array ( ':aeskey' => $aeskey , ':active' => $active , ':iniConfiguration' => $iniConfiguration , ':connect_ip_only' => $connectIpOnly , ':description' => $description , ':managedServer' => $managedServer , ':managedForID' => $resellerToBeWritten , ':externalID' => $externalID , ':defaultname' => $defaultname , ':bit' => $bit , ':queryport' => $queryport , ':querypassword' => $querypassword , ':filetransferport' => $filetransferport , ':maxserver' => $maxserver , ':maxslots' => $maxslots , ':usedns' => $usedns , ':defaultdns' => $defaultdns , ':defaultwelcome' => $defaultwelcome , ':defaulthostbanner_url' => $defaulthostbanner_url , ':defaulthostbanner_gfx_url' => $defaulthostbanner_gfx_url , ':defaulthostbutton_tooltip' => $defaulthostbutton_tooltip , ':defaulthostbutton_url' => $defaulthostbutton_url , ':defaulthostbutton_gfx_url' => $defaulthostbutton_gfx_url , ':defaultFlexSlotsFree' => $defaultFlexSlotsFree , ':defaultFlexSlotsPercent' => $defaultFlexSlotsPercent , ':publickey' => $publickey , ':ssh2ip' => $ip , ':ssh2port' => $port , ':ssh2user' => $user , ':ssh2password' => $pass , ':ips' => $ips , ':serverdir' => $serverdir , ':keyname' => $keyname , ':autorestart' => $autorestart , ':tsdnsServerID' => $tsdnsServerID , ':externalDefaultDNS' => $externalDefaultDNS , ':id' => $id , ':reseller_id' => $reseller_id ));
2013-10-13 11:35:58 +02:00
$rowCount = $query -> rowCount ();
$template_file = $spracheResponse -> table_add ;
$loguseraction = '%mod% %voserver% %master% ' . $ip ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
} else if ( $ui -> w ( 'action' , 3 , 'post' ) == 'ad2' and $ui -> id ( 'id' , 10 , 'get' )) {
# get masterserver data to be able to import existing voice servers
$masterid = $ui -> id ( 'id' , 10 , 'get' );
# Suhoshin has a POST Limit. So we need to limit as well.
$prefix = $rSA [ 'prefix2' ];
$i = 0 ;
$toomuch = 0 ;
$added = '<br />Added:' ;
$ssh2ip = '' ;
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT *,AES_DECRYPT(`querypassword`,:aeskey) AS `decryptedquerypassword`,AES_DECRYPT(`ssh2port`,:aeskey) AS `decryptedssh2port`,AES_DECRYPT(`ssh2user`,:aeskey) AS `decryptedssh2user`,AES_DECRYPT(`ssh2password`,:aeskey) AS `decryptedssh2password` FROM `voice_masterserver` WHERE `id`=:id AND `resellerid`=:reseller_id LIMIT 1 " );
2013-10-05 13:39:56 +02:00
$query -> execute ( array ( ':aeskey' => $aeskey , ':id' => $masterid , ':reseller_id' => $reseller_id ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2013-10-13 11:35:58 +02:00
$defaultdns = $row [ 'defaultdns' ];
$serverdir = $row [ 'serverdir' ];
$addedby = $row [ 'addedby' ];
$usedns = $row [ 'usedns' ];
$defaultdns = $row [ 'defaultdns' ];
$queryport = $row [ 'queryport' ];
$querypassword = $row [ 'decryptedquerypassword' ];
$mnotified = $row [ 'notified' ];
$defaultwelcome = $row [ 'defaultwelcome' ];
$defaulthostbanner_url = $row [ 'defaulthostbanner_url' ];
$defaulthostbanner_gfx_url = $row [ 'defaulthostbanner_gfx_url' ];
$defaulthostbutton_tooltip = $row [ 'defaulthostbutton_tooltip' ];
$defaulthostbutton_url = $row [ 'defaulthostbutton_url' ];
$defaulthostbutton_gfx_url = $row [ 'defaulthostbutton_gfx_url' ];
$tsdnsServerID = $row [ 'tsdnsServerID' ];
$externalDefaultDNS = $row [ 'externalDefaultDNS' ];
$publickey = $row [ 'publickey' ];
$queryip = $row [ 'ssh2ip' ];
$ssh2ip = $row [ 'ssh2ip' ];
$ssh2port = $row [ 'decryptedssh2port' ];
$ssh2user = $row [ 'decryptedssh2user' ];
$ssh2password = $row [ 'decryptedssh2password' ];
$keyname = $row [ 'keyname' ];
$bitversion = $row [ 'bitversion' ];
if ( $addedby == 1 ) {
$query2 = $sql -> prepare ( " SELECT `ip` FROM `rserverdata` WHERE `id`=? AND `resellerid`=? LIMIT 1 " );
$query2 -> execute ( array ( $row [ 'rootid' ], $reseller_id ));
$queryip = $query2 -> fetchColumn ();
2013-08-28 22:47:04 +02:00
}
2015-07-17 19:26:06 +02:00
$TSDNSSsh2ip = ( $row [ 'connect_ip_only' ] == 'Y' ) ? $row [ 'ips' ] : $ssh2ip ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
2014-09-27 12:40:25 +02:00
# will only be an ID in case a master DNS has been chosen
2013-08-28 22:47:04 +02:00
if ( isid ( $tsdnsServerID , 19 )) {
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT *,AES_DECRYPT(`ssh2port`,:aeskey) AS `decryptedssh2port`,AES_DECRYPT(`ssh2user`,:aeskey) AS `decryptedssh2user`,AES_DECRYPT(`ssh2password`,:aeskey) AS `decryptedssh2password` FROM `voice_tsdns` WHERE `active`='Y' AND `id`=:id AND `resellerid`=:reseller_id LIMIT 1 " );
2013-10-05 13:39:56 +02:00
$query -> execute ( array ( ':aeskey' => $aeskey , ':id' => $tsdnsServerID , ':reseller_id' => $reseller_id ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2013-10-13 11:35:58 +02:00
$publickey = $row [ 'publickey' ];
$ssh2port = $row [ 'decryptedssh2port' ];
$ssh2user = $row [ 'decryptedssh2user' ];
$ssh2password = $row [ 'decryptedssh2password' ];
$serverdir = $row [ 'serverdir' ];
$keyname = $row [ 'keyname' ];
$bitversion = $row [ 'bitversion' ];
if ( $externalDefaultDNS == 'Y' ) {
$defaultdns = $row [ 'defaultdns' ];
}
2015-07-17 19:26:06 +02:00
$TSDNSSsh2ip = ( $row [ 'connect_ip_only' ] == 'Y' ) ? $row [ 'external_ip' ] : $row [ 'ssh2ip' ];
2013-08-28 22:47:04 +02:00
}
}
2013-10-13 11:35:58 +02:00
// Connect to TS3 Server. Only if successfull do the import
$connection = new TS3 ( $ssh2ip , $queryport , 'serveradmin' , $querypassword );
if ( $connection -> socketConnected === true and strpos ( $connection -> errorcode , 'error id=0' ) !== false ) {
foreach ( $ui -> id ( 'virtualserver_id' , 19 , 'post' ) as $virtualserver_id ) {
2014-08-26 20:58:48 +02:00
if ( $ui -> active ( " $virtualserver_id -import " , 'post' ) == 'Y' ) {
2013-10-13 11:35:58 +02:00
2013-12-27 17:49:40 +01:00
$customerID = $ui -> id ( " $virtualserver_id -customer " , 10 , 'post' );
2013-10-13 11:35:58 +02:00
2013-12-27 17:49:40 +01:00
if ( $customerID == 0 or $customerID == false or $customerID == null ) {
2013-10-13 11:35:58 +02:00
$usernew = true ;
2013-12-27 17:39:43 +01:00
if ( $ui -> username ( " $virtualserver_id -username " , 50 , 'post' ) and $ui -> ismail ( " $virtualserver_id -email " , 'post' )) {
2013-10-13 11:35:58 +02:00
$query = $sql -> prepare ( " SELECT `id` FROM `userdata` WHERE `cname`=? AND `mail`=? AND `resellerid`=? LIMIT 1 " );
2013-12-27 17:39:43 +01:00
$query -> execute ( array ( $ui -> username ( " $virtualserver_id -username " , 50 , 'post' ), $ui -> ismail ( " $virtualserver_id -email " , 'post' ), $reseller_id ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2013-10-13 11:35:58 +02:00
$usernew = false ;
2013-12-27 17:49:40 +01:00
$customerID = $row [ 'id' ];
2013-12-27 17:39:43 +01:00
$cnamenew = $ui -> username ( " $virtualserver_id -username " , 50 , 'post' );
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
if ( $usernew == true ) {
2013-12-27 17:44:35 +01:00
$initialpassword = passwordgenerate ( 10 );
$newHash = passwordCreate ( $ui -> username ( " $virtualserver_id -username " , 50 , 'post' ), $initialpassword );
2013-10-22 22:24:53 +02:00
if ( is_array ( $newHash )) {
$query = $sql -> prepare ( " INSERT INTO `userdata` (`cname`,`security`,`salt`,`mail`,`accounttype`,`resellerid`) VALUES (?,?,?,?,'u',?) " );
2013-12-27 17:39:43 +01:00
$query -> execute ( array ( $ui -> username ( " $virtualserver_id -username " , 50 , 'post' ), $newHash [ 'hash' ], $newHash [ 'salt' ], $ui -> ismail ( " $virtualserver_id -email " , 'post' ), $reseller_id ));
2013-10-22 22:24:53 +02:00
} else {
$query = $sql -> prepare ( " INSERT INTO `userdata` (`cname`,`security`,`mail`,`accounttype`,`resellerid`) VALUES (?,?,?,'u',?) " );
2013-12-27 17:39:43 +01:00
$query -> execute ( array ( $ui -> username ( " $virtualserver_id -username " , 50 , 'post' ), $newHash , $ui -> ismail ( " $virtualserver_id -email " , 'post' ), $reseller_id ));
2013-10-22 22:24:53 +02:00
}
2013-10-13 11:35:58 +02:00
$query = $sql -> prepare ( " SELECT `id` FROM `userdata` WHERE `cname`=? AND `mail`=? AND `resellerid`=? ORDER BY `id` DESC LIMIT 1 " );
2013-12-27 17:39:43 +01:00
$query -> execute ( array ( $ui -> username ( " $virtualserver_id -username " , 50 , 'post' ), $ui -> ismail ( " $virtualserver_id -email " , 'post' ), $reseller_id ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2013-12-27 17:49:40 +01:00
$customerID = $row [ 'id' ];
2013-12-27 17:39:43 +01:00
$cnamenew = $ui -> username ( " $virtualserver_id -username " , 50 , 'post' );
2013-12-27 17:49:40 +01:00
sendmail ( 'emailuseradd' , $customerID , $cnamenew , $initialpassword );
2013-10-13 11:35:58 +02:00
}
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
} else {
$userlist = '' ;
$cldbid = rand ( 1 , 100 ) . '.' . rand ( 1 , 100 );
$adminList = $connection -> AdminList ( $virtualserver_id );
2020-07-22 19:41:54 +02:00
if ( is_array ( $adminList ) and count ( $adminList ) > 0 ) {
2013-10-13 11:35:58 +02:00
foreach ( $adminList as $cldbid => $client_unique_identifier ) {
$userlist .= $cldbid . ':' . $client_unique_identifier . '|' ;
}
}
$cnamenew = $prefix . $cldbid ;
$query = $sql -> prepare ( " INSERT INTO `userdata` (`cname`,`security`,`mail`,`accounttype`,`resellerid`) VALUES (?,?,?,'u',?) " );
$query -> execute ( array ( $cnamenew , $userlist , 'ts3@import.mail' , $reseller_id ));
$query = $sql -> prepare ( " SELECT `id` FROM `userdata` WHERE `cname`=? AND `mail`='ts3@import.mail' ORDER BY `id` DESC LIMIT 1 " );
$query -> execute ( array ( $cnamenew ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2013-12-27 17:49:40 +01:00
$customerID = $row [ 'id' ];
$cnamenew = $prefix . $customerID ;
2013-10-13 11:35:58 +02:00
}
$query = $sql -> prepare ( " UPDATE `userdata` SET `cname`=? WHERE `id`=? AND `resellerid`=? LIMIT 1 " );
2013-12-27 17:49:40 +01:00
$query -> execute ( array ( $cnamenew , $customerID , $reseller_id ));
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
if ( $usernew == true ) {
$query = $sql -> prepare ( " SELECT `id` FROM `usergroups` WHERE `active`='Y' AND `defaultgroup`='Y' AND `grouptype`='u' AND `resellerid`=? LIMIT 1 " );
$query -> execute ( array ( $reseller_id ));
$groupID = $query -> fetchColumn ();
2013-12-27 17:49:40 +01:00
$query = $sql -> prepare ( " INSERT INTO `userdata_groups` (`userID`,`groupID`,`resellerID`) VALUES (?,?,?) ON DUPLICATE KEY UPDATE `resellerID`=`resellerID` " );
$query -> execute ( array ( $customerID , $groupID , $reseller_id ));
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
$added .= 'User ' . $cnamenew . ' ' ;
} else {
$query = $sql -> prepare ( " SELECT `cname` FROM `userdata` WHERE `id`=? AND `resellerid`=? LIMIT 1 " );
2013-12-27 17:49:40 +01:00
$query -> execute ( array ( $customerID , $reseller_id ));
2013-10-13 11:35:58 +02:00
$cnamenew = $query -> fetchColumn ();
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
$slots = $ui -> id ( " $virtualserver_id -virtualserver_maxclients " , 30 , 'post' );
$port = $ui -> port ( " $virtualserver_id -virtualserver_port " , 'post' );
$forcewelcome = $ui -> active ( " $virtualserver_id -forcewelcome " , 'post' );
$forcebanner = $ui -> active ( " $virtualserver_id -forcebanner " , 'post' );
$forcebutton = $ui -> active ( " $virtualserver_id -forcebutton " , 'post' );
$forceservertag = $ui -> active ( " $virtualserver_id -forceservertag " , 'post' );
$flexSlots = $ui -> active ( " $virtualserver_id -flexSlots " , 'post' );
$flexSlotsFree = $ui -> id ( " $virtualserver_id -flexSlotsFree " , 11 , 'post' );
$flexSlotsPercent = $ui -> id ( " $virtualserver_id -flexSlotsPercent " , 3 , 'post' );
$password = ( $ui -> id ( " $virtualserver_id -password " , 1 , 'post' ) == 1 ) ? 'Y' : 'N' ;
$serverdns = ( $ui -> domain ( " $virtualserver_id -virtualserver_dns " , 'post' ) == '' ) ? $cnamenew . '-' . $virtualserver_id . '.' . $defaultdns : $ui -> domain ( " $virtualserver_id -virtualserver_dns " , 'post' );
2013-10-13 13:11:38 +02:00
if ( $port != null ) {
2015-07-17 19:26:06 +02:00
$serverdns = strtolower ( $serverdns );
2013-10-13 11:35:58 +02:00
unset ( $addlist );
$addlist = array ();
unset ( $removelist );
$removelist = array ();
unset ( $settings );
$settings = array ();
$settings [ 'virtualserver_max_download_total_bandwidth' ] = 65536 ;
$settings [ 'virtualserver_max_upload_total_bandwidth' ] = 65536 ;
if ( $forcebanner == 'Y' ) {
$removelist [] = 'b_virtualserver_modify_hostbanner' ;
$removelist [] = 'i_needed_modify_power_virtualserver_modify_hostbanner' ;
$settings [ 'virtualserver_hostbanner_url' ] = $defaulthostbanner_url ;
$settings [ 'virtualserver_hostbanner_gfx_url' ] = $defaulthostbanner_gfx_url ;
} else if ( $forcebanner == 'N' ) {
$addlist [] = 'b_virtualserver_modify_hostbanner' ;
$addlist [] = 'i_needed_modify_power_virtualserver_modify_hostbanner' ;
}
if ( $forcebutton == 'Y' ) {
$removelist [] = 'b_virtualserver_modify_hostbutton' ;
$removelist [] = 'i_needed_modify_power_virtualserver_modify_hostbutton' ;
$settings [ 'virtualserver_hostbutton_url' ] = $defaulthostbutton_url ;
$settings [ 'virtualserver_hostbutton_gfx_url' ] = $defaulthostbutton_gfx_url ;
$settings [ 'virtualserver_hostbutton_tooltip' ] = $defaulthostbutton_tooltip ;
} else if ( $forcebutton == 'N' ) {
$addlist [] = 'b_virtualserver_modify_hostbutton' ;
$addlist [] = 'i_needed_modify_power_virtualserver_modify_hostbutton' ;
}
if ( $forcewelcome == 'Y' ) {
$removelist [] = 'b_virtualserver_modify_welcomemessage' ;
$removelist [] = 'i_needed_modify_power_virtualserver_modify_welcomemessage' ;
$settings [ 'virtualserver_welcomemessage' ] = $defaultwelcome ;
} else if ( $forcewelcome == 'N' ) {
$addlist [] = 'b_virtualserver_modify_welcomemessage' ;
$addlist [] = 'i_needed_modify_power_virtualserver_modify_welcomemessage' ;
}
if ( isset ( $addlist )) {
$connection -> AdminPermissions ( $virtualserver_id , 'add' , $addlist );
}
if ( isset ( $removelist )) {
$connection -> AdminPermissions ( $virtualserver_id , 'del' , $removelist );
}
2015-07-17 19:26:06 +02:00
$connection -> ImportModServer ( $virtualserver_id , $slots , $TSDNSSsh2ip , $port , $settings );
2013-10-13 11:35:58 +02:00
$added .= 'Server ' . $ssh2ip . ':' . $port . '<br />' ;
$query = $sql -> prepare ( " INSERT INTO `voice_server` (`userid`,`masterserver`,`ip`,`port`,`slots`,`password`,`forcebanner`,`forcebutton`,`forceservertag`,`forcewelcome`,`dns`,`flexSlots`,`flexSlotsFree`,`flexSlotsPercent`,`localserverid`,`resellerid`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) " );
2015-07-17 19:26:06 +02:00
$query -> execute ( array ( $customerID , $masterid , $TSDNSSsh2ip , $port , $slots , $password , $forcebanner , $forcebutton , $forceservertag , $forcewelcome , $serverdns , $flexSlots , $flexSlotsFree , $flexSlotsPercent , $virtualserver_id , $reseller_id ));
2013-08-28 22:47:04 +02:00
}
2015-07-17 19:26:06 +02:00
2013-10-13 11:35:58 +02:00
$i ++ ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
}
2014-08-26 20:58:48 +02:00
$not = '' ;
2013-10-13 11:35:58 +02:00
$connection -> CloseConnection ();
if ( $usedns == 'Y' ) {
2015-07-17 19:26:06 +02:00
2013-10-13 11:35:58 +02:00
$dns = array ();
if ( isid ( $tsdnsServerID , 19 )) {
2015-07-17 19:26:06 +02:00
2013-10-13 11:35:58 +02:00
$query = $sql -> prepare ( " SELECT `id` FROM `voice_masterserver` WHERE `tsdnsServerID`=? AND `resellerid`=? " );
$query2 = $sql -> prepare ( " SELECT `ip`,`port`,`dns` FROM `voice_server` WHERE `masterserver`=? AND `resellerid`=? " );
2015-07-17 19:26:06 +02:00
2013-10-13 11:35:58 +02:00
$query -> execute ( array ( $tsdnsServerID , $reseller_id ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2015-07-17 19:26:06 +02:00
2013-10-13 11:35:58 +02:00
$query2 -> execute ( array ( $row [ 'id' ], $reseller_id ));
2014-11-30 12:55:07 +01:00
while ( $row2 = $query2 -> fetch ( PDO :: FETCH_ASSOC )) {
2013-10-13 11:35:58 +02:00
$dns [] = $row2 [ 'dns' ] . '=' . $row2 [ 'ip' ] . ':' . $row2 [ 'port' ];
}
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
} else {
2015-07-17 19:26:06 +02:00
2013-10-13 11:35:58 +02:00
$query = $sql -> prepare ( " SELECT `ip`,`port`,`dns` FROM `voice_server` WHERE `masterserver`=? AND `resellerid`=? " );
$query -> execute ( array ( $masterid , $reseller_id ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2013-10-13 11:35:58 +02:00
$dns [] = $row [ 'dns' ] . '=' . $row [ 'ip' ] . ':' . $row [ 'port' ];
2013-08-28 22:47:04 +02:00
}
}
2013-10-13 11:35:58 +02:00
$dns = array_unique ( $dns );
2015-07-17 19:26:06 +02:00
2013-10-13 11:35:58 +02:00
if ( $i > 0 ) {
2013-10-22 21:05:24 +02:00
$template_file = tsdns ( 'mw' , $TSDNSSsh2ip , $ssh2port , $ssh2user , $publickey , $keyname , $ssh2password , $mnotified , $serverdir , $bitversion , $dns , '' , '' , $reseller_id );
2013-10-13 11:35:58 +02:00
}
2013-08-28 22:47:04 +02:00
}
}
2013-10-13 11:35:58 +02:00
if ( $added == '<br />Added:' ) {
$template_file = $spracheResponse -> error_table ;
2013-08-28 22:47:04 +02:00
} else {
2013-10-13 11:35:58 +02:00
$template_file = $spracheResponse -> table_add . $not . $added ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
2013-08-28 22:47:04 +02:00
} else {
2013-10-13 11:35:58 +02:00
unset ( $header , $text );
$template_file = ( $ui -> st ( 'd' , 'get' ) == 'md' ) ? 'admin_voicemasterserver_md.tpl' : 'admin_voicemasterserver_add.tpl' ;
2013-08-28 22:47:04 +02:00
}
} else {
2013-10-13 11:35:58 +02:00
$template_file = 'admin_404.tpl' ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
} else if ( $ui -> st ( 'd' , 'get' ) == 'dl' and $ui -> id ( 'id' , 10 , 'get' )) {
$id = $ui -> id ( 'id' , 10 , 'get' );
if ( ! $ui -> w ( 'action' , 3 , 'post' )) {
2015-01-25 10:23:59 +01:00
$query = $sql -> prepare ( " SELECT `ssh2ip`,`description`,`rootid`,`type` FROM `voice_masterserver` WHERE `id`=? AND `resellerid`=? LIMIT 1 " );
2013-10-13 11:35:58 +02:00
$query -> execute ( array ( $id , $reseller_id ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2013-10-13 11:35:58 +02:00
$ip = $row [ 'ssh2ip' ];
2015-01-25 10:23:59 +01:00
$description = $row [ 'description' ];
2013-10-13 11:35:58 +02:00
$type = $row [ 'type' ];
2013-08-28 22:47:04 +02:00
if ( $ip == null ) {
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT `ip` FROM `rserverdata` WHERE `id`=? AND `resellerid`=? LIMIT 1 " );
2013-10-13 11:35:58 +02:00
$query -> execute ( array ( $row [ 'rootid' ], $reseller_id ));
$ip = $query -> fetchColumn ();
2013-08-28 22:47:04 +02:00
}
}
2013-10-13 11:35:58 +02:00
$template_file = ( $query -> rowCount () > 0 ) ? 'admin_voicemasterserver_dl.tpl' : 'admin_404.tpl' ;
} else if ( $ui -> w ( 'action' , 3 , 'post' ) == 'dl' ) {
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT `ssh2ip`,`rootid`,`type` FROM `voice_masterserver` WHERE `id`=? AND `resellerid`=? LIMIT 1 " );
2013-10-13 11:35:58 +02:00
$query -> execute ( array ( $id , $reseller_id ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2013-10-13 11:35:58 +02:00
$ip = $row [ 'ssh2ip' ];
$type = $row [ 'type' ];
if ( $row [ 'ssh2ip' ] == null ) {
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT `ip` FROM `rserverdata` WHERE `id`=? AND `resellerid`=? LIMIT 1 " );
2013-10-13 11:35:58 +02:00
$query -> execute ( array ( $row [ 'rootid' ], $reseller_id ));
$ip = $query -> fetchColumn ();
2013-08-28 22:47:04 +02:00
}
}
2013-11-24 12:12:07 +01:00
if ( $query -> rowCount () > 0 ) {
2015-01-25 10:23:59 +01:00
2013-10-13 11:35:58 +02:00
$query = $sql -> prepare ( " DELETE FROM `voice_masterserver` WHERE `id`=? AND `resellerid`=? LIMIT 1 " );
$query -> execute ( array ( $id , $reseller_id ));
$query = $sql -> prepare ( " DELETE FROM `voice_server` WHERE `masterserver`=? AND `resellerid`=? " );
$query -> execute ( array ( $id , $reseller_id ));
$template_file = $spracheResponse -> table_del ;
$loguseraction = '%del% %voserver% %master% ' . $ip . ' ' . $type ;
$insertlog -> execute ();
} else {
$spracheResponse -> error_table ;
}
2013-08-28 22:47:04 +02:00
} else {
2013-10-13 11:35:58 +02:00
$template_file = 'admin_404.tpl' ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:35:58 +02:00
2013-08-28 22:47:04 +02:00
} else {
2013-10-13 11:35:58 +02:00
2015-01-25 10:23:59 +01:00
configureDateTables ( '-1' , '1, "asc"' , 'ajax.php?w=datatable&d=voicemasterserver' );
2013-09-07 13:33:50 +02:00
2015-01-25 10:23:59 +01:00
$template_file = 'admin_voicemasterserver_list.tpl' ;
2016-08-25 04:20:56 +02:00
}