2013-08-28 22:47:04 +02:00
< ? php
/**
* File : root_pxe . php .
* Author : Ulrich Block
* Date : 03.10 . 12
* Time : 11 : 36
* 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 ( $admin_id ) or $main != 1 or $reseller_id != 0 or ! $pa [ 'vserversettings' ]){
2013-08-28 22:47:04 +02:00
header ( 'Location: admin.php' );
die ;
}
2013-09-27 08:22:09 +02:00
include ( EASYWIDIR . '/stuff/keyphrasefile.php' );
2013-09-29 15:29:58 +02:00
$sprache = getlanguagefile ( 'reseller' , $user_language , $reseller_id );
$loguserid = $admin_id ;
$logusername = getusername ( $admin_id );
$logusertype = 'admin' ;
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-08-28 22:47:04 +02:00
} else {
$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-03 16:48:54 +02:00
if ( $ui -> w ( 'action' , 4 , 'post' ) and ! token ( true )) {
2013-09-29 15:29:58 +02:00
$template_file = $spracheResponse -> token ;
2013-10-13 11:42:31 +02:00
} else if ( in_array ( $ui -> st ( 'd' , 'get' ), array ( 'md' , 'ad' ))){
if ( ! in_array ( $ui -> smallletters ( 'action' , 2 , 'post' ), array ( 'md' , 'ad' )) and $ui -> st ( 'd' , 'get' ) == 'md' ) {
$id = $ui -> id ( 'id' , 19 , 'get' );
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT *,AES_DECRYPT(`port`,:aeskey) AS `decryptedport`,AES_DECRYPT(`user`,:aeskey) AS `decrypteduser`,AES_DECRYPT(`pass`,:aeskey) AS `decryptedpass` FROM `rootsPXE` WHERE `resellerid`=:reseller_id LIMIT 1 " );
2013-10-05 13:39:56 +02:00
$query -> execute ( array ( ':aeskey' => $aeskey , ':reseller_id' => $reseller_id ));
2014-11-30 12:55:07 +01:00
while ( $row = $query -> fetch ( PDO :: FETCH_ASSOC )) {
2013-10-13 11:42:31 +02:00
$active = $row [ 'active' ];
$ip = $row [ 'ip' ];
$port = $row [ 'decryptedport' ];
$user = $row [ 'decrypteduser' ];
$pass = $row [ 'decryptedpass' ];
$publickey = $row [ 'publickey' ];
$keyname = $row [ 'keyname' ];
$PXEFolder = $row [ 'PXEFolder' ];
$description = $row [ 'description' ];
2013-08-28 22:47:04 +02:00
}
2013-09-29 15:29:58 +02:00
$template_file = ( isset ( $PXEFolder )) ? 'admin_root_pxe_md.tpl' : 'admin_404.tpl' ;
2013-10-13 11:42:31 +02:00
} else if ( ! in_array ( $ui -> smallletters ( 'action' , 2 , 'post' ), array ( 'md' , 'ad' )) and $ui -> st ( 'd' , 'get' ) == 'ad' ) {
2013-09-29 15:29:58 +02:00
$template_file = 'admin_root_pxe_ad.tpl' ;
2013-10-13 11:42:31 +02:00
} else if ( in_array ( $ui -> smallletters ( 'action' , 2 , 'post' ), array ( 'md' , 'ad' ))) {
2013-09-29 15:29:58 +02:00
$error = array ();
2014-01-05 17:12:59 +01:00
if ( ! $ui -> w ( 'publickey' , 1 , 'post' )) {
2013-10-03 12:49:13 +02:00
$error [] = 'Publickey' ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:42:31 +02:00
if ( ! $ui -> active ( 'active' , 'post' )) {
2013-10-03 12:49:13 +02:00
$error [] = 'Active' ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:42:31 +02:00
if ( ! $ui -> ip ( 'ip' , 'post' )) {
2013-10-03 12:49:13 +02:00
$error [] = 'IP' ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:42:31 +02:00
if ( ! $ui -> port ( 'port' , 'post' )) {
2013-10-03 12:49:13 +02:00
$error [] = 'Port' ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:42:31 +02:00
if ( ! $ui -> password ( 'pass' , 255 , 'post' )) {
2013-10-03 12:49:13 +02:00
$error [] = 'Password' ;
2013-08-28 22:47:04 +02:00
}
2013-10-13 11:42:31 +02:00
if ( ! $ui -> username ( 'user' , 255 , 'post' )) {
2013-10-03 12:49:13 +02:00
$error [] = 'Username' ;
2013-08-28 22:47:04 +02:00
}
if ( count ( $error ) > 0 ) {
2013-09-29 15:29:58 +02:00
$template_file = 'Error: ' . implode ( '<br />' , $error );
2013-08-28 22:47:04 +02:00
} else {
2014-01-05 17:12:59 +01:00
$publickey = $ui -> w ( 'publickey' , 1 , 'post' );
2013-10-13 11:42:31 +02:00
$keyname = $ui -> startparameter ( 'keyname' , 'post' );
$active = $ui -> active ( 'active' , 'post' );
$ip = $ui -> ip ( 'ip' , 'post' );
$ips = $ui -> ips ( 'ips' , 'post' );
$netmask = $ui -> ips ( 'netmask' , 'post' );
$port = $ui -> port ( 'port' , 'post' );
$user = $ui -> username ( 'user' , 255 , 'post' );
$pass = $ui -> password ( 'pass' , 255 , 'post' );
$PXEFolder = $ui -> startparameter ( 'PXEFolder' , 'post' );
$description = $ui -> escaped ( 'description' , 'post' );
if ( $ui -> st ( 'd' , 'get' ) == 'md' and $ui -> id ( 'id' , 19 , 'get' )) {
$id = $ui -> id ( 'id' , 19 , 'get' );
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " UPDATE `rootsPXE` SET `active`=:active,`ip`=:ip,`port`=AES_ENCRYPT(:port,:aeskey),`user`=AES_ENCRYPT(:user,:aeskey),`pass`=AES_ENCRYPT(:pass,:aeskey),`publickey`=:publickey,`keyname`=:keyname,`PXEFolder`=:PXEFolder,`description`=:description WHERE `id`=:id AND `resellerid`=:reseller_id " );
2013-10-05 13:39:56 +02:00
$query -> execute ( array ( ':active' => $active , ':ip' => $ip , ':port' => $port , ':aeskey' => $aeskey , ':user' => $user , ':pass' => $pass , ':publickey' => $publickey , ':keyname' => $keyname , ':PXEFolder' => $PXEFolder , ':description' => $description , ':id' => $id , ':reseller_id' => $reseller_id ));
2013-08-28 22:47:04 +02:00
$loguseraction = " %mod% PXE " ;
2013-10-13 11:42:31 +02:00
} else if ( $ui -> st ( 'd' , 'get' ) == 'ad' ) {
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " INSERT INTO `rootsPXE` (`active`,`ip`,`port`,`user`,`pass`,`publickey`,`keyname`,`PXEFolder`,`description`,`resellerid`) VALUES (:active,:ip,AES_ENCRYPT(:port,:aeskey),AES_ENCRYPT(:user,:aeskey),AES_ENCRYPT(:pass,:aeskey),:publickey,:keyname,:PXEFolder,:description,:reseller_id) " );
2013-10-05 13:39:56 +02:00
$query -> execute ( array ( ':active' => $active , ':ip' => $ip , ':port' => $port , ':aeskey' => $aeskey , ':user' => $user , ':pass' => $pass , ':publickey' => $publickey , ':keyname' => $keyname , ':PXEFolder' => $PXEFolder , ':description' => $description , ':reseller_id' => $reseller_id ));
2013-08-28 22:47:04 +02:00
$loguseraction = " %add% PXE " ;
} else {
2013-09-29 15:29:58 +02:00
$template_file = 'admin_404.tpl' ;
2013-08-28 22:47:04 +02:00
}
2013-11-24 12:12:07 +01:00
if ( ! isset ( $template_file ) and $query -> rowCount () > 0 ) {
2013-08-28 22:47:04 +02:00
$insertlog -> execute ();
2013-09-29 15:29:58 +02:00
$template_file = $spracheResponse -> table_add ;
2013-08-28 22:47:04 +02:00
} else if ( ! isset ( $template_file )) {
2013-09-29 15:29:58 +02:00
$template_file = $spracheResponse -> error_table ;
2013-08-28 22:47:04 +02:00
}
}
}
2013-10-13 11:42:31 +02:00
} else if ( $ui -> st ( 'd' , 'get' ) == 'dl' and $ui -> id ( 'id' , 19 , 'get' )) {
$id = $ui -> id ( 'id' , 19 , 'get' );
if ( ! $ui -> smallletters ( 'action' , 2 , 'post' )) {
$id = $ui -> id ( 'id' , 19 , 'get' );
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " SELECT `ip`,`description` FROM `rootsPXE` WHERE `id`=? AND `resellerid`=? LIMIT 1 " );
2013-08-28 22:47:04 +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:42:31 +02:00
$ip = $row [ 'ip' ];
$description = $row [ 'description' ];
2013-08-28 22:47:04 +02:00
}
2013-09-29 15:29:58 +02:00
$template_file = ( isset ( $ip )) ? 'admin_root_pxe_dl.tpl' : 'admin_404.tpl' ;
2013-10-13 11:42:31 +02:00
} else if ( $ui -> smallletters ( 'action' , 2 , 'post' ) == 'dl' ) {
2013-09-29 15:29:58 +02:00
$query = $sql -> prepare ( " DELETE FROM `rootsPXE` WHERE `id`=? AND `resellerid`=? LIMIT 1 " );
2013-08-28 22:47:04 +02:00
$query -> execute ( array ( $id , $reseller_id ));
2013-11-24 12:12:07 +01:00
if ( $query -> rowCount () > 0 ) {
2013-08-28 22:47:04 +02:00
$loguseraction = " %del% PXE " ;
$insertlog -> execute ();
2013-09-29 15:29:58 +02:00
$template_file = $spracheResponse -> table_del ;
2013-08-28 22:47:04 +02:00
} else {
2013-09-29 15:29:58 +02:00
$template_file = $spracheResponse -> error_table ;
2013-08-28 22:47:04 +02:00
}
} else {
2013-09-29 15:29:58 +02:00
$template_file = 'admin_404.tpl' ;
2013-08-28 22:47:04 +02:00
}
} else {
2013-10-13 11:42:31 +02:00
$o = $ui -> st ( 'o' , 'get' );
if ( $ui -> st ( 'o' , 'get' ) == 'dd' ) {
2013-10-05 18:39:30 +02:00
$orderby = '`description` DESC' ;
2013-10-13 11:42:31 +02:00
} else if ( $ui -> st ( 'o' , 'get' ) == 'ad' ) {
2013-10-05 18:39:30 +02:00
$orderby = '`description` ASC' ;
2013-10-13 11:42:31 +02:00
} else if ( $ui -> st ( 'o' , 'get' ) == 'dp' ) {
2013-10-05 18:39:30 +02:00
$orderby = '`ip` DESC' ;
2013-10-13 11:42:31 +02:00
} else if ( $ui -> st ( 'o' , 'get' ) == 'ap' ) {
2013-10-05 18:39:30 +02:00
$orderby = '`ip` ASC' ;
2013-10-13 11:42:31 +02:00
} else if ( $ui -> st ( 'o' , 'get' ) == 'ds' ) {
2013-10-05 18:39:30 +02:00
$orderby = '`active` DESC,`notified` DESC' ;
2013-10-13 11:42:31 +02:00
} else if ( $ui -> st ( 'o' , 'get' ) == 'as' ) {
2013-10-05 18:39:30 +02:00
$orderby = '`active` ASC,`notified` ASC' ;
2013-10-13 11:42:31 +02:00
} else if ( $ui -> st ( 'o' , 'get' ) == 'di' ) {
2013-10-05 18:39:30 +02:00
$orderby = '`id` DESC' ;
2013-08-28 22:47:04 +02:00
} else {
2013-10-05 18:39:30 +02:00
$orderby = '`id` ASC' ;
$o = 'ai' ;
2013-08-28 22:47:04 +02:00
}
2013-09-29 15:29:58 +02:00
$table = array ();
$query = $sql -> prepare ( " SELECT `active`,`id`,`ip`,`description`,`notified` FROM `rootsPXE` WHERE `resellerid`=? ORDER BY $orderby " );
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-03 12:49:13 +02:00
if ( $row [ 'active' ] == 'Y' and $row [ 'notified' ] > 0 ) {
2013-10-13 17:12:44 +02:00
$imgName = '16_error' ;
$imgAlt = 'Crashed' ;
2013-10-03 12:49:13 +02:00
} else if ( $row [ 'active' ] == 'Y' ) {
2013-10-13 17:12:44 +02:00
$imgName = '16_ok' ;
$imgAlt = 'Active' ;
2013-08-28 22:47:04 +02:00
} else {
2013-10-13 17:12:44 +02:00
$imgName = '16_bad' ;
$imgAlt = 'Inactive' ;
2013-08-28 22:47:04 +02:00
}
2013-10-10 08:06:37 +02:00
$table [] = array ( 'id' => $row [ 'id' ], 'ip' => $row [ 'ip' ], 'description' => $row [ 'description' ], 'img' => $imgName , 'alt' => $imgAlt , 'active' => $row [ 'active' ]);
2013-08-28 22:47:04 +02:00
}
2013-09-29 15:29:58 +02:00
$template_file = 'admin_root_pxe_list.tpl' ;
2013-08-28 22:47:04 +02:00
}