2013-08-28 22:47:04 +02:00
< ? php
2014-03-22 10:12:53 +01:00
2013-08-28 22:47:04 +02:00
/**
* File : userpanel_mysql . 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 />.
*/
2014-03-22 10:12:53 +01:00
2013-10-27 00:16:43 +02:00
if (( ! isset ( $user_id ) or $main != 1 ) or ( isset ( $user_id ) and ! $pa [ 'mysql' ])) {
2013-08-28 22:47:04 +02:00
header ( 'Location: userpanel.php' );
die ;
}
2013-09-27 08:22:09 +02:00
2014-04-18 13:48:31 +02:00
include ( EASYWIDIR . '/stuff/methods/class_mysql.php' );
2013-09-27 08:22:09 +02:00
include ( EASYWIDIR . '/stuff/keyphrasefile.php' );
2014-03-22 10:12:53 +01:00
$sprache = getlanguagefile ( 'mysql' , $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 ;
2014-03-22 10:12:53 +01: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
}
2014-03-22 10:12:53 +01:00
2013-10-03 16:48:54 +02:00
if ( $ui -> w ( 'action' , 4 , 'post' ) and ! token ( true )) {
2014-03-22 10:12:53 +01:00
2013-09-29 15:29:58 +02:00
$template_file = $spracheResponse -> token ;
2014-03-22 10:12:53 +01:00
} else if ( $ui -> id ( 'id' , 10 , 'get' ) and ( ! isset ( $_SESSION [ 'sID' ]) or in_array ( $ui -> id ( 'id' , 10 , 'get' ), $substituteAccess [ 'db' ]))) {
2013-10-13 11:42:31 +02:00
$id = $ui -> id ( 'id' , 10 , 'get' );
2014-03-22 10:12:53 +01:00
2013-10-13 11:42:31 +02:00
if ( ! $ui -> smallletters ( 'action' , 2 , 'post' )) {
2013-09-01 17:07:11 +02:00
#https://github.com/easy-wi/developer/issues/42 column description added
2015-02-22 14:31:36 +01:00
$query = $sql -> prepare ( " SELECT e.`dbname`,e.`description`,e.`manage_host_table`,AES_DECRYPT(e.`password`,?) AS `decryptedpassword`,e.`ips`,s.`port`,s.`interface`,u.`cname`,CASE WHEN s.`connect_ip_only`='Y' THEN s.`external_address` ELSE s.`ip` END AS `address` FROM `mysql_external_dbs` e LEFT JOIN `mysql_external_servers` s ON e.`sid`=s.`id` LEFT JOIN `userdata` u ON e.`uid`=u.`id` WHERE e.`id`=? AND e.`active`='Y' AND s.`active` AND e.`resellerid`=? LIMIT 1 " );
2014-03-22 10:12:53 +01:00
$query -> execute ( array ( $aeskey , $id , $reseller_id ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2015-02-22 14:31:36 +01:00
$address = $row [ 'address' ];
2014-04-18 14:28:36 +02:00
$manage_host_table = $row [ 'manage_host_table' ];
2013-10-13 11:42:31 +02:00
$ips = $row [ 'ips' ];
$port = $row [ 'port' ];
2014-04-18 14:28:36 +02:00
$interface = trim ( $row [ 'interface' ]);
2013-10-13 11:42:31 +02:00
$dbname = $row [ 'dbname' ];
$cname = $row [ 'cname' ];
2014-04-18 13:48:31 +02:00
$description = trim ( $row [ 'description' ]);
2013-10-13 11:42:31 +02:00
$password = $row [ 'decryptedpassword' ];
2013-08-28 22:47:04 +02:00
}
2014-03-22 10:12:53 +01:00
2014-04-18 13:48:31 +02:00
$queryCount = $query -> rowCount ();
2014-03-22 10:12:53 +01:00
2014-04-18 13:48:31 +02:00
if ( $queryCount > 0 and $ui -> st ( 'd' , 'get' ) == 'ri' ) {
$template_file = 'userpanel_mysql_db_ri.tpl' ;
} else if ( $queryCount > 0 and $ui -> st ( 'd' , 'get' ) != 'ri' ) {
$template_file = 'userpanel_mysql_db_md.tpl' ;
} else {
$template_file = 'userpanel_404.tpl' ;
}
2014-03-22 10:12:53 +01:00
2014-04-18 13:48:31 +02:00
} else if ( $ui -> smallletters ( 'action' , 2 , 'post' ) == 'ri' and $ui -> st ( 'd' , 'get' ) == 'ri' ){
2015-06-06 19:55:18 +02:00
$query = $sql -> prepare ( " SELECT e.`dbname`,e.`description`,e.`ips`,e.`max_queries_per_hour`,e.`max_connections_per_hour`,e.`max_updates_per_hour`,e.`max_userconnections_per_hour`,AES_DECRYPT(e.`password`,?) AS `decryptedpassword`,s.`ip`,AES_DECRYPT(s.`password`,?) AS `decryptedpassword2`,s.`port`,s.`user`,CASE WHEN s.`connect_ip_only`='Y' THEN s.`external_address` ELSE s.`ip` END AS `address` FROM `mysql_external_dbs` e INNER JOIN `mysql_external_servers` s ON e.`sid`=s.`id` WHERE e.`id`=? AND e.`active`='Y' AND s.`active`='Y' AND e.`uid`=? AND e.`resellerid`=? LIMIT 1 " );
2014-04-18 13:48:31 +02:00
$query -> execute ( array ( $aeskey , $aeskey , $id , $user_id , $reseller_id ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2014-04-18 13:48:31 +02:00
$remotesql = new ExternalSQL ( $row [ 'ip' ], $row [ 'port' ], $row [ 'user' ], $row [ 'decryptedpassword2' ]);
if ( $remotesql -> error == 'ok' ) {
$remotesql -> DelDB ( $row [ 'dbname' ]);
$remotesql -> DelUser ( $row [ 'dbname' ]);
2015-06-06 19:55:18 +02:00
$mailData = array (
'userId' => $user_id ,
'name' => ( strlen ( $row [ 'description' ]) > 0 ) ? $row [ 'description' ] : $row [ 'dbname' ],
'mailConnectInfo' => array (
'ip' => $row [ 'address' ],
'port' => $row [ 'port' ]
)
);
$remotesql -> AddDB ( $mailData , $row [ 'dbname' ], $row [ 'decryptedpassword' ], $row [ 'ips' ], $row [ 'max_queries_per_hour' ], $row [ 'max_connections_per_hour' ], $row [ 'max_updates_per_hour' ], $row [ 'max_userconnections_per_hour' ]);
2014-04-18 13:48:31 +02:00
2015-02-22 14:31:36 +01:00
$loguseraction = '%ri% MYSQL DB ' . $row [ 'dbname' ] . ' (' . $row [ 'address' ] . ')' ;
2014-04-18 13:48:31 +02:00
$insertlog -> execute ();
2014-03-22 10:12:53 +01:00
2014-04-18 13:48:31 +02:00
$template_file = $spracheResponse -> reinstall_success ;
} else {
$template_file = $remotesql -> error ;
}
}
if ( ! isset ( $remotesql )) {
$template_file = 'userpanel_404.tpl' ;
}
} else if ( $ui -> smallletters ( 'action' , 2 , 'post' ) == 'md' and $ui -> st ( 'd' , 'get' ) != 'ri' ){
if ( $ui -> password ( 'password' , 255 , 'post' )) {
2014-03-22 10:12:53 +01:00
2015-02-22 14:31:36 +01:00
$query = $sql -> prepare ( " SELECT e.`dbname`,e.`manage_host_table`,e.`ips`,e.`max_queries_per_hour`,e.`max_connections_per_hour`,e.`max_updates_per_hour`,e.`max_userconnections_per_hour`,s.`ip`,AES_DECRYPT(s.`password`,?) AS `decryptedpassword2`,s.`port`,s.`user`,CASE WHEN s.`connect_ip_only`='Y' THEN s.`external_address` ELSE s.`ip` END AS `address` FROM `mysql_external_dbs` e INNER JOIN `mysql_external_servers` s ON e.`sid`=s.`id` WHERE e.`id`=? AND e.`active`='Y' AND s.`active`='Y' AND e.`uid`=? AND e.`resellerid`=? LIMIT 1 " );
2014-03-30 14:04:11 +02:00
$query -> execute ( array ( $aeskey , $id , $user_id , $reseller_id ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2014-03-22 10:12:53 +01:00
2014-04-18 14:28:36 +02:00
$ips = ( $row [ 'manage_host_table' ] == 'Y' ) ? $ui -> ips ( 'ips' , 'post' ) : $row [ 'ips' ];
2014-03-30 14:04:11 +02:00
$remotesql = new ExternalSQL ( $row [ 'ip' ], $row [ 'port' ], $row [ 'user' ], $row [ 'decryptedpassword2' ]);
2014-03-22 10:12:53 +01:00
2014-03-30 14:04:11 +02:00
if ( $remotesql -> error == 'ok' ) {
2014-03-22 10:12:53 +01:00
2014-03-30 14:04:11 +02:00
#https://github.com/easy-wi/developer/issues/42 column description added
2015-02-22 14:31:36 +01:00
$query2 = $sql -> prepare ( " UPDATE `mysql_external_dbs` SET `description`=?,`password`=AES_ENCRYPT(?,?),`ips`=? WHERE `id`=? AND `uid`=? AND `resellerid`=? LIMIT 1 " );
$query2 -> execute ( array ( trim ( $ui -> startparameter ( 'description' , 'post' )), $ui -> password ( 'password' , 255 , 'post' ), $aeskey , $ips , $id , $user_id , $reseller_id ));
2013-09-01 17:07:11 +02:00
2015-02-22 14:31:36 +01:00
if ( $query2 -> rowCount () > 0 ) {
2014-03-22 10:12:53 +01:00
2015-07-17 21:08:04 +02:00
$template_file = $spracheResponse -> table_add ;
$dbReturn = $remotesql -> ModDB ( $row [ 'dbname' ], $ui -> password ( 'password' , 255 , 'post' ), $ips , $row [ 'max_queries_per_hour' ], $row [ 'max_connections_per_hour' ], $row [ 'max_updates_per_hour' ], $row [ 'max_userconnections_per_hour' ]);
if ( isset ( $dbConnect [ 'debug' ]) and $dbConnect [ 'debug' ] == 1 ) {
$template_file .= '<br>' . $dbReturn ;
}
2014-03-22 10:12:53 +01:00
2015-02-22 14:31:36 +01:00
$loguseraction = '%mod% MYSQL DB ' . $row [ 'dbname' ] . ' (' . $row [ 'address' ] . ')' ;
2013-08-28 22:47:04 +02:00
$insertlog -> execute ();
2014-03-22 10:12:53 +01:00
2013-08-28 22:47:04 +02:00
} else {
2014-03-30 14:04:11 +02:00
$template_file = $spracheResponse -> error_table ;
2013-08-28 22:47:04 +02:00
}
2014-03-22 10:12:53 +01:00
2013-08-28 22:47:04 +02:00
} else {
2014-03-30 14:04:11 +02:00
$template_file = $remotesql -> error ;
2013-08-28 22:47:04 +02:00
}
}
2014-03-22 10:12:53 +01:00
2014-04-18 13:48:31 +02:00
if ( ! isset ( $remotesql )) {
$template_file = 'userpanel_404.tpl' ;
}
2013-08-28 22:47:04 +02:00
} else {
2014-03-22 10:12:53 +01:00
$template_file = 'Error: ' . $sprache -> password ;
2013-08-28 22:47:04 +02:00
}
2014-03-22 10:12:53 +01:00
2013-08-28 22:47:04 +02:00
} else {
2013-09-29 15:29:58 +02:00
$template_file = 'userpanel_404.tpl' ;
2013-08-28 22:47:04 +02:00
}
2014-03-22 10:12:53 +01:00
2013-08-28 22:47:04 +02:00
} else {
2014-03-22 10:12:53 +01:00
2013-09-29 15:29:58 +02:00
$table = array ();
2014-03-22 10:12:53 +01:00
2015-02-22 14:31:36 +01:00
$query = $sql -> prepare ( " SELECT e.`id`,e.`dbname`,e.`description`,e.`dbSize`,s.`port`,s.`interface`,CASE WHEN s.`connect_ip_only`='Y' THEN s.`external_address` ELSE s.`ip` END AS `address` FROM `mysql_external_dbs` e INNER JOIN `mysql_external_servers` s ON e.`sid`=s.`id` WHERE e.`active`='Y' AND s.`active`='Y' AND e.`uid`=? AND e.`resellerid`=? " );
2014-03-22 10:12:53 +01:00
$query -> execute ( array ( $user_id , $reseller_id ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2014-03-22 10:12:53 +01:00
if ( ! isset ( $_SESSION [ 'sID' ]) or in_array ( $row [ 'id' ], $substituteAccess [ 'db' ])) {
2015-02-22 14:31:36 +01:00
$table [] = array ( 'id' => $row [ 'id' ], 'dbname' => $row [ 'dbname' ], 'dbSize' => $row [ 'dbSize' ], 'address' => $row [ 'address' ], 'port' => $row [ 'port' ], 'description' => trim ( $row [ 'description' ]), 'interface' => $row [ 'interface' ]);
2013-08-28 22:47:04 +02:00
}
}
2014-03-22 10:12:53 +01:00
$template_file = 'userpanel_mysql_db_list.tpl' ;
2013-08-28 22:47:04 +02:00
}