<?php
/*
* (с) 2009, Russia, Moscow
* Serge Obookhoff AKA Hong Lee
* www.data-stream.ru && www.veterinars.ru
* Last Revision at 01/2009
* Written for ispCP Team (www.isp-control.net) ONLY.
* Written using the old, dead blanks VHCS.
* All Functions rewritten.
*
* Notice: If you use this script you have own risks.
*
*/
//bypass ispCP HTML input control
$min = implode ("," , $_POST['min']);
$hour = implode ("," , $_POST['hour']);
$day_of_month = implode ("," , $_POST['day_of_month']);
$month = implode ("," , $_POST['month']);
$day_of_week = implode ("," , $_POST['day_of_week']);
unset($_POST['month'], $_POST['day_of_week'], $_POST['min'], $_POST['hour'], $_POST['day_of_month']);
require '../include/ispcp-lib.php';
check_login(__FILE__);
$tpl = new pTemplate();
$tpl->define_dynamic('page', Config::get('CLIENT_TEMPLATE_PATH') . '/cronjobs_edit.tpl');
$tpl->define_dynamic('page_message', 'page');
$tpl->define_dynamic('logged_from', 'page');
$theme_color = Config::get('USER_INITIAL_THEME');
$tpl->assign(
array('TR_CLIENT_CRONJOBS_TITLE' => tr('ispCP - Client/Cronjob Manager'),
'THEME_COLOR_PATH' => "../themes/$theme_color",
'THEME_CHARSET' => tr('encoding'),
'ISP_LOGO' => get_logo($_SESSION['user_id'])
)
);
if (!isset($_GET['cron_id']) && !isset($_POST['Submit'])) {
set_page_message(tr('Nothing to do!'));
user_goto('cronjobs_overview.php');
}
if (isset($_GET['cron_id']) && $_GET['cron_id'] !== '') {
$cron_id = $_GET['cron_id'];}
function update_cron_job(&$tpl, &$sql, $cron_id, $user_id, &$min, &$hour, &$day_of_month, &$month, &$day_of_week, &$file_type) {
/* if ((empty($min) | empty($hour) | empty($day_of_month) | empty($month) | empty($day_of_week) | empty($_POST['name']) | empty($_POST['description']) | empty($_POST['command_line'])) && isset($_POST['Submit'])) {
*
* set_page_message(tr('Please type All Fields and choise all Values!'));
* return;
* }
*/
foreach($_POST as $key => $value)
{
$a = $key;
$$a = $value;
}
//do all checks of command_line
/* Start (c) Vladimir Sinitsyn*/
// Vladimir Sinitsyn aka SenatoR
// Russia, Yekaterinburg
// Русские, привет! =)
// $command_line mey be "perl /var/www/virtual/hackers.ru/htdocs/cgi-bin/decoder.pl?file=/etc/passwd-"
// We must use security check!
# $stop_word = array('/etc/','password','passwd','groups'); //STOP Words!
$stop_word = Config::get('CUSTOM_CRON_STOP_WORD'); //STOP Words!
$stop_word = explode(",", $stop_word);
//Let`s start our work!
$temp = explode(" ", $command_line); //We`ve divided line two parts - command (php) and values.
$command = $temp[0];
$stream = $temp[1];
unset($temp);
//We have commands, so, make it without "cool" things, use simle code..
$cron_allowed_commands = Config::get('CUSTOM_CRON_ALLOWED_CMD');
$cron_allowed_commands = explode(",", $cron_allowed_commands);
$flag = 0;
foreach($cron_allowed_commands as $k=>$v)
{
if(strpos($command,$v) === 0)
{
$flag++;
break; //Stop
}
}
unset ($cron_allowed_commands);
if ($flag == 0) {
set_page_message(tr('Comand not Allowed!'));
return;
}
foreach($stop_word as $k=>$v)
{
if(strpos($stream,$v) == true) {
set_page_message(tr('Are you a cunning Hacker ?! But I am not only stupid machine!!! I will write delation to Admin!'));
write_log("WARNING: Perhaps hacking! ". $_SESSION['user_logged'] . ": add Cron Job: " . $name . " with comnd: " . $command_line);
user_goto('cronjobs_edit.php');
return 0;
} //Hackers ALLERT... `stop word'
}
$flag = 0; //Use one thing!
foreach($file_type as $k=>$v) //Start
{
if(strpos($stream,$v) == true) //Works fast!!! (its important)
{
$flag++; //Yeah! Its good!
$file = preg_replace("/(\\".".".$v.").*/i","\\1",$stream); //CUT ALL!!! Only filename in $file!
break; //Stop
}
}
if($flag == 0) {
set_page_message(tr('File type wrong!'));
return;
}//File type wrong!
//Check files and permission
if(!file_exists($file)) {
set_page_message(tr('File not found!'));
return;
} //No file!
if(!is_readable($file)) {
set_page_message(tr('File not readable!'));
return;
}; //Wrong permissions!
if(strpos("cgi",$file) || strpos("pl",$file)) // only for cgi and pl and so..
{
if(!is_executable($file)) {
set_page_message(tr('Wrong permissions!'));
return;
}; //Wrong permissions!
}
/* End (c) */
$query = "
UPDATE
hcrondtab
SET
name = ?, coment = ?, min = ?, hour = ?, day = ?, mon = ?, dow = ?, cmd = ?, activ = ?, runonce = ?, lastrun = ?
WHERE
id = ?
";
$rs = exec_query($sql, $query, array($name, $description, $min, $hour, $day_of_month, $month, $day_of_week, $command_line, $activ, $runonce, $lastrun =0, $cron_id));
write_log($_SESSION['user_logged'] . ": updeted Cron Job: " . $name);
set_page_message(tr('Cron Job successfully updated!'));
user_goto('cronjobs_overview.php');
} // End of update_cron_job();
function gen_cron_job(&$tpl, &$sql, $cron_id, $user_id, &$new_value) {
$query = "
SELECT
`id`, `domain`, `name`, `coment`, `min`, `hour`, `day`, `mon`, `dow`, `cmd`, `runonce`,`lastrun`, `activ`
FROM
`hcrondtab`
WHERE
domain = $user_id
AND
id = $cron_id
";
$rs = exec_query($sql, $query, $cron_id);
if ($rs->RecordCount() == 0) {
set_page_message(tr('No CronJob with this ID!'));
header('Location: cronjobs_overview.php');
exit(0);
}
if ($rs->fields['activ'] == 1) {$active_yes = 'selected'; $active_no = '';}
else {$active_no = 'selected'; $active_yes = '';}
if ($rs->fields['runonce'] == 1) {$runonce_yes = 'selected'; $runonce_no = '';}
else {$runonce_no = 'selected'; $runonce_yes = '';}
$tpl->assign(
array('NAME' => $rs->fields['name'],
'DESCRIPTION' => $rs->fields['coment'],
'COMMAND_LINE' => $rs->fields['cmd'],
'ACTIVE' => $rs->fields['activ'],
'ACTIVE_YES' => $active_yes,
'ACTIVE_NO' => $active_no,
'ID' => $rs->fields['id'],
'ALLOWED' => 'php, perl, python',
'FILETYPE' => $new_value,
'RUNONCE_YES' => $runonce_yes,
'RUNONCE_NO' => $runonce_no,
)
);
//Highlite time selection
$cron_time = explode(",",$rs->fields['min']);
foreach($cron_time as $k=>$v)
{
$selected_time[$k] = "TR_SELECTED_MIN_".$v;
$tpl->assign(array($selected_time[$k] => tr('selected') ));
}
$cron_time = explode(",",$rs->fields['hour']);
foreach($cron_time as $k=>$v)
{
$selected_time[$k] = "TR_SELECTED_HOUR_".$v;
$tpl->assign(array($selected_time[$k] => tr('selected') ));
}
$cron_time = explode(",",$rs->fields['day']);
foreach($cron_time as $k=>$v)
{
$selected_time[$k] = "TR_SELECTED_DOM_".$v;
$tpl->assign(array($selected_time[$k] => tr('selected') ));
}
$cron_time = explode(",",$rs->fields['mon']);
foreach($cron_time as $k=>$v)
{
$selected_time[$k] = "TR_SELECTED_MONTH_".$v;
$tpl->assign(array($selected_time[$k] => tr('selected') ));
}
$cron_time = explode(",",$rs->fields['dow']);
foreach($cron_time as $k=>$v)
{
$selected_time[$k] = "TR_SELECTED_DOW_".$v;
$tpl->assign(array($selected_time[$k] => tr('selected') ));
}
} // End of gen_cron_job();
/*
*
* static page messages.
*
*/
gen_client_mainmenu($tpl, Config::get('CLIENT_TEMPLATE_PATH') . '/main_menu_webtools.tpl');
gen_client_menu($tpl, Config::get('CLIENT_TEMPLATE_PATH') . '/menu_webtools.tpl');
gen_logged_from($tpl);
check_permissions($tpl);
# $file_type = array('.php','.php4','.php5','.cgi','.pl','.py'); //List of GOOD files ;-)
$file_type = Config::get('CUSTOM_CRON_ALLOWED_EXT'); //List of GOOD files ;-)
$file_type = explode (",", $file_type);
$new_value = implode (",", $file_type);
if (isset($_GET['cron_id']) && is_numeric($_GET['cron_id']) && isset($_POST['Submit'])) update_cron_job($tpl, $sql, $_GET['cron_id'], $_SESSION['user_id'], $min, $hour, $day_of_month, $month, $day_of_week, $file_type);
gen_cron_job($tpl, $sql, $cron_id, $_SESSION['user_id'], $new_value);
$tpl->assign(
array('TR_CRON_MANAGER' => tr('Cronjob Manager'),
'TR_EDIT_CRONJOB' => tr('Edit Cronjob'),
'TR_NAME' => tr('Name'),
'TR_DESCRIPTION' => tr('Description'),
'TR_ACTIVE' => tr('Active'),
'YES' => tr('Yes'),
'NO' => tr('No'),
'TR_CRONJOB' => tr('Cronjob'),
'TR_COMMAND' => tr('Command to run:'),
'TR_MIN' => tr('Minute(s):'),
'TR_HOUR' => tr('Hour(s):'),
'TR_DAY' => tr('Day(s):'),
'TR_MONTHS' => tr('Month(s):'),
'TR_WEEKDAYS' => tr('Weekday(s):'),
'TR_UPDATE' => tr('Update'),
'TR_CANCEL' => tr('Cancel')
)
);
gen_page_message($tpl);
$tpl->parse('PAGE', 'page');
$tpl->prnt();
if (Config::get('DUMP_GUI_DEBUG'))
dump_gui_debug();
unset_messages();
?>