#!/usr/local/bin/php -c/usr/local/directadmin/plugins/cagefs/php.ini
$value)
// $str .= $key.' - '.$value.PHP_EOL;
// $file = fopen('/usr/local/directadmin/plugins/cagefs/admin/log.txt',"a+");
// fwrite($file,'REQUEST: '.PHP_EOL.$str.PHP_EOL.PHP_EOL);
include_once('sessions_rw.php');
$RequestParams = array();
if ('' != trim($_SERVER['QUERY_STRING'])) {
$tmp = explode('&',trim($_SERVER['QUERY_STRING']));
$RequestParams = array();
foreach ($tmp as $item) {
$tmp2 = explode('=',$item);
$RequestParams[$tmp2[0]] = str_replace('%20',' ',$tmp2[1]);
unset($tmp2);
}
unset($tmp);
}
// if (!empty($RequestParams)) {
// $str = '';
// foreach ($RequestParams as $key=>$value)
// $str .= $key.' - '.$value.PHP_EOL;
// fwrite($file,'OWN REQUEST: '.PHP_EOL.$str.PHP_EOL.PHP_EOL);
// fclose($file);
// }
define ("CAGEFS_SKELETON", "/usr/share/cagefs-skeleton/bin");
define ("CAGEFS_RESULTFILE", "/var/log/cagefs-update.log");
define ("CAGEFS_RESULTFILEUPD", "/var/log/cagefs-update.log");
try {
if (!@include_once('commands.php'))
throw new Exception('CageFS plugin error. Please contact administrator.');
} catch (Exception $e) {
echo $e->getMessage();
exit;
}
if (!$commands->CheckKernel()) {
echo '
Current running kernel is NOT supported.
';
exit();
}
if ('get_update_log' == $RequestParams['action']) {
header("Cache-Control: no-cache, must-revalidate");
header("Content-Type: text/html");
header('Content-Disposition: attachment; filename="cagefs-update.log"');
header("Content-Length: ".filesize(CAGEFS_RESULTFILEUPD));
include_once(CAGEFS_RESULTFILEUPD);
exit();
}
if ('get_init_log' == $RequestParams['action']) {
header("Cache-Control: no-cache, must-revalidate");
header("Content-Type: text/html");
header('Content-Disposition: attachment; filename="cagefs-init.log"');
header("Content-Length: ".filesize(CAGEFS_RESULTFILE));
include_once(CAGEFS_RESULTFILE);
exit();
}
// Session initialize
sess_init ( );
if (!array_key_exists('action', $RequestParams)):
// Generate constant part of security token to avoid CSRF attack
$csrf_token_const = md5 ( microtime ( ) );
$_SESSION [ "csrf_token_const" ] = $csrf_token_const;
// 2. Generate variable part of security token
$token = $csrf_token_const . mt_rand ( 0, mt_getrandmax ( ) ) ;
$_SESSION [ "csrf_token" ] = $token;
// Session data save
sess_data_save ( );
if (!$commands->CheckSkeleteon()) {
@include_once('Start.html');
exit();
}
if ('update' == $commands->CheckCagefsCtlExists()) {
echo '';
exit();
}
if ('init' == $commands->CheckCagefsCtlExists()) {
echo '';
exit();
}
$disabled = $commands->GetCagefsDisabledList();
$enabled = $commands->GetCagefsEnabledList();
if (!$CageFSMode = $commands->CheckCagefsMode()) {
@include_once('index.js');
@include_once('ajax.js');
@include_once('CageFSDisabled.html');
exit();
}
@include_once('index.js');
@include_once('ajax.js');
@include_once('default.html');
else:
// Retrive CSRF protection token from session
if ( !isset ($_SESSION["csrf_token"]) )
{ // No protection token found - exit
// Prints error message and terminates the script
_print_error_and_exit ( 'Illegal call' );
} // if
$csrf_token = $_SESSION["csrf_token"];
// Check CSRF token
if ( !isset($RequestParams['token']) )
{ // Token not found - error
_print_error_and_exit ( 'Illegal call' );
} // if
$token = $RequestParams [ 'token' ];
if ( $token != $csrf_token )
{ // Illegal token
_print_error_and_exit ( 'Illegal call' );
} // if
switch ($RequestParams['action']):
case 'change_users_mode':
$commands->ChangeUserMode($RequestParams['mode'],$RequestParams['users']);
break;
case 'change_cagefs_mode':
$commands->ChangeCageFSMode($RequestParams['mode']);
break;
case 'change_cagefs_status':
$commands->ChangeCageFSStatus($RequestParams['mode']);
break;
case 'Init':
$Progress = $commands->InitCageFS();
@include_once('index.js');
@include_once('ajax.js');
@include_once('CageFSInit.html');
break;
case 'update_cagefs':
$Progress = $commands->UpdateCageFS();
@include_once('index.js');
@include_once('ajax.js');
@include_once('CageFSUpdate.html');
break;
default:
break;
endswitch;
endif;