function CleanLogsDatabases($nopid = false)
{
    include_once dirname(__FILE__) . '/ressources/class.mysql.inc';
    $unix = new unix();
    if ($nopid) {
        $pidpath = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = @file_get_contents($pidpath);
        if ($unix->process_exists($pid)) {
            $pidtime = $unix->PROCCESS_TIME_MIN($pid);
            system_admin_events(basename(__FILE__) . ":: " . __FUNCTION__ . " Already process {$pid} running since {$pidtime} Mn.. Aborting", __FUNCTION__, __FILE__, __LINE__);
            return;
        }
        @file_put_contents($pidpath, getmypid());
    }
    $sock = new sockets();
    $q = new mysql();
    $settings = unserialize(base64_decode($sock->GET_INFO("FcronSchedulesParams")));
    if (!is_numeric($settings["max_events"])) {
        $settings["max_events"] = "10000";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "max_events::{$settings["max_events"]}\n";
    }
    $tables = array();
    $tables["dhcpd_logs"] = true;
    $tables["ps_mem"] = true;
    $tables["update_events"] = true;
    $tables["nmap_events"] = true;
    $tables["backup_events"] = true;
    $tables["computers_available"] = true;
    $tables["auth_events"] = true;
    $tables["events"] = true;
    $ff = $q->LIST_TABLES_EVENTS_SYSTEM();
    while (list($tbl, $ligne) = each($ff)) {
        $tables[$tbl] = true;
    }
    $ff = $q->LIST_TABLES_EVENTS_SQUID();
    while (list($tbl, $ligne) = each($ff)) {
        $tables[$tbl] = true;
    }
    while (list($tbl, $ligne) = each($tables)) {
        _CleanLogsDatabases($tbl, $settings["max_events"]);
    }
}
Exemple #2
0
function page(){
	$page=CurrentPageName();
	$tpl=new templates();	
	$sock=new sockets();
	$purge_catagories_database_explain=$tpl->javascript_parse_text("{purge_catagories_database_explain}");
	$purge_catagories_table_explain=$tpl->javascript_parse_text("{purge_catagories_table_explain}");
	$items=$tpl->_ENGINE_parse_body("{items}");
	$size=$tpl->_ENGINE_parse_body("{size}");
	$SaveToDisk=$tpl->_ENGINE_parse_body("{SaveToDisk}");
	$addCat=$tpl->_ENGINE_parse_body("{add} {category}");
	$description=$tpl->_ENGINE_parse_body("{description}");
	$task=$tpl->_ENGINE_parse_body("{task}");
	$new_schedule=$tpl->_ENGINE_parse_body("{new_schedule}");
	$run=$tpl->_ENGINE_parse_body("{run}");
	$events=$tpl->_ENGINE_parse_body("{events}");
	$run_this_task_now=$tpl->javascript_parse_text("{run_this_task_now} ?");
	$all_events=$tpl->_ENGINE_parse_body("{events}");
	$parameters=$tpl->_ENGINE_parse_body("{parameters}");
	$internal_scheduler=$tpl->_ENGINE_parse_body("{internal_scheduler}");
	$build_config=$tpl->_ENGINE_parse_body("{WIZARD_COMPILE}");
	$ForceTaskType=$_GET["ForceTaskType"];
	if(!is_numeric($ForceTaskType)){$ForceTaskType=0;}
	$CountEvents=0;
	$q=new mysql();
	$tasks=$tpl->_ENGINE_parse_body("{tasks}");
	
	
	

	
	$t=time();
	$bgroup1="{name: '$all_events', bclass: 'Search', onpress : AllEvents$t},
	{name: '$internal_scheduler', bclass: 'Script', onpress : internal_scheduler$t},";
	$bgroup2="{name: '$parameters', bclass: 'Settings', onpress : Parmaeters$t},";
	
	
	$events=$tpl->_ENGINE_parse_body("{events}");
	
	if($ForceTaskType>0){
		$bgroup1=null;
		$bgroup2=null;
		$schedules=new system_tasks();
		$title=$tpl->javascript_parse_text($schedules->tasks_array[$ForceTaskType]);
	}else{
		$LIST_TABLES_EVENTS_SYSTEM=$q->LIST_TABLES_EVENTS_SYSTEM();
		$CountTasks=$q->COUNT_ROWS("system_schedules", "artica_backup");
		while (list ($tablename, $rows) = each ($LIST_TABLES_EVENTS_SYSTEM) ){$CountEvents=$CountEvents +$q->COUNT_ROWS($tablename, "artica_events");}
		$CountEvents=numberFormat($CountEvents, 0 , '.' , ' ');
		$title="$CountTasks $tasks $CountEvents $events";
		
	}
	
	$html="
	<div style='margin-left:-15px'>
		<table class='$t' style='display: none' id='$t' style='width:99%'></table>
	</div>
<script>
var rowSquidTask='';
$(document).ready(function(){
$('#$t').flexigrid({
	url: '$page?search=yes&minisize={$_GET["minisize"]}&ForceTaskType={$_GET["ForceTaskType"]}',
	dataType: 'json',
	colModel : [
		{display: '&nbsp;', name : 'ID', width : 32, sortable : true, align: 'center'},
		{display: '$task', name : 'TaskType', width : 217, sortable : false, align: 'left'},
		{display: '$description', name : 'TimeDescription', width : 410, sortable : false, align: 'left'},
		{display: '$run', name : 'run', width : 32, sortable : false, align: 'left'},
		{display: '$events', name : 'run1', width : 32, sortable : false, align: 'center'},
		{display: '&nbsp;', name : 'enable', width : 32, sortable : true, align: 'center'},
		{display: '&nbsp;', name : 'delete', width : 32, sortable : false, align: 'center'}
	],
buttons : [
	{name: '$new_schedule', bclass: 'add', onpress : AddNewSchedule},
	$bgroup1
	{name: '$build_config', bclass: 'Restore', onpress : build_config$t},
	$bgroup2
	],	
	searchitems : [
		{display: '$description', name : 'TimeDescription'},
		],
		
	sortname: 'ID',
	sortorder: 'asc',
	usepager: true,
	title: '$title',
	useRp: true,
	rp: 15,
	showTableToggleBtn: false,
	width: '99%',
	height: 450,
	singleSelect: true
	
	});   
});	
	function AllEvents$t(){
		Loadjs('squid.update.events.php?table=Taskev0')
	
	}
	
	function Parmaeters$t(){
		Loadjs('$page?schedules-params=yes');
	}
	
	function internal_scheduler$t(){
		Loadjs('artica.internal.cron.php');
	}


	function AddNewSchedule(category){
			Loadjs('$page?AddNewSchedule-js=yes&ID=0&ForceTaskType={$_GET["ForceTaskType"]}');
	}
	
	function SystemCrontaskUpdateTable(){
		$('#$t').flexReload();
	 }
	
	var x_SystemTaskEnable=function (obj) {
		var ID='{$_GET["ID"]}';$array
		var results=obj.responseText;
		if(results.length>0){alert(results);}		
	}

	var x_DisableSquidDefaultScheduleCheck=function (obj) {
		var ID='{$_GET["ID"]}';
		var results=obj.responseText;
		if(results.length>0){alert(results);}
		$('#$t').flexReload();		
	}

	function build_config$t(){
		YahooWinBrowse('650','$page?build-config=yes','$build_config');
	}


	function SystemTaskEnable(md,id){
	  	var XHR = new XHRConnection();
	  	if(document.getElementById(md).checked){XHR.appendData('value',1);}else{XHR.appendData('value',0);}
		XHR.appendData('ID',id);
	  	XHR.appendData('schedule-enable','yes');
	  	XHR.sendAndLoad('$page', 'POST',x_SystemTaskEnable);
	}

	function DisableSquidDefaultScheduleCheck(){
	  	var XHR = new XHRConnection();
	  	if(document.getElementById('DisableSquidDefaultSchedule').checked){XHR.appendData('DisableSquidDefaultSchedule',1);}
	  	else{XHR.appendData('DisableSquidDefaultSchedule',0);}
	  	XHR.sendAndLoad('$page', 'POST',x_DisableSquidDefaultScheduleCheck);	
	}
	
	
	function SystemTaskRun(ID,explain){
		if(confirm('$run_this_task_now `'+explain+'`')){
			var XHR = new XHRConnection();
			XHR.appendData('ID',ID);
	  		XHR.appendData('schedule-run','yes');
	  		XHR.sendAndLoad('$page', 'POST',x_SystemTaskEnable);		
		}
	
	}
	
	
	var x_SquidTaskDelete=function (obj) {
		var results=obj.responseText;
		if(results.length>0){alert(results);return;}
		$('#rowSquidTask'+rowSquidTask).remove();
	}	
	
	function SquidTaskDelete(ID){
		rowSquidTask=ID;
	  	var XHR = new XHRConnection();
		XHR.appendData('ID',ID);
	  	XHR.appendData('schedule-delete','yes');
	  	XHR.sendAndLoad('$page', 'POST',x_SquidTaskDelete);	
	}
	
	
	
</script>";
	
	echo $html;
	
}
function clean_events()
{
    $q = new mysql();
    $unix = new unix();
    $rm = $unix->find_program("rm");
    $nohup = $unix->find_program("nohup");
    $TABLES = $q->LIST_TABLES_EVENTS_SYSTEM();
    while (list($tablename, $line) = each($TABLES)) {
        echo "DROP {$tablename}\n";
        $q->QUERY_SQL("DROP TABLE `{$tablename}`", "artica_events");
    }
    $datadir = $unix->MYSQL_DATA_DIR();
    shell_exec("{$rm} -f {$datadir}/artica_events/*.BAK");
    if (is_dir("{$datadir}/syslogstore")) {
        $q->DELETE_DATABASE("syslogstore");
        shell_exec("{$rm} -f {$datadir}/syslogstore/*.BAK");
    }
    $files = $unix->DirFiles("{$datadir}/artica_events", "TaskSq[0-9]+\\.MYI");
    while (list($file, $line) = each($files)) {
        $file = str_replace(".MYI", "", $file);
        $q->QUERY_SQL("DROP TABLE `{$file}`", "artica_events");
    }
    $q->QUERY_SQL("TRUNCATE TABLE `nmap_events`", "artica_events");
    $q->QUERY_SQL("TRUNCATE TABLE `nmap_events`", "artica_events");
    $q->QUERY_SQL("TRUNCATE TABLE `avgreports`", "artica_events");
    $q->QUERY_SQL("TRUNCATE TABLE `events`", "artica_events");
    $q->QUERY_SQL("TRUNCATE TABLE `dhcpd_logs`", "artica_events");
    $q->QUERY_SQL("TRUNCATE TABLE `update_events`", "artica_events");
    shell_exec("{$nohup} /etc/init.d/mysql restart --framework=" . __FILE__ . " >/dev/null 2>&1 &");
    shell_exec($unix->LOCATE_PHP5_BIN() . " /usr/share/artica-postfix/exec.mysql.start.php --engines --verbose --framework=" . __FILE__ . " 2>&1 &");
}
Exemple #4
0
function table()
{
    $page = CurrentPageName();
    $tpl = new templates();
    $sock = new sockets();
    $purge_catagories_database_explain = $tpl->javascript_parse_text("{purge_catagories_database_explain}");
    $purge_catagories_table_explain = $tpl->javascript_parse_text("{purge_catagories_table_explain}");
    $items = $tpl->_ENGINE_parse_body("{items}");
    $size = $tpl->_ENGINE_parse_body("{size}");
    $SaveToDisk = $tpl->_ENGINE_parse_body("{SaveToDisk}");
    $addCat = $tpl->_ENGINE_parse_body("{add} {category}");
    $description = $tpl->_ENGINE_parse_body("{description}");
    $task = $tpl->_ENGINE_parse_body("{task}");
    $new_schedule = $tpl->_ENGINE_parse_body("{new_schedule}");
    $run = $tpl->_ENGINE_parse_body("{run}");
    $events = $tpl->_ENGINE_parse_body("{events}");
    $run_this_task_now = $tpl->javascript_parse_text("{run_this_task_now} ?");
    $all_events = $tpl->_ENGINE_parse_body("{events}");
    $parameters = $tpl->_ENGINE_parse_body("{parameters}");
    $internal_scheduler = $tpl->_ENGINE_parse_body("{internal_scheduler}");
    $build_config = $tpl->_ENGINE_parse_body("{apply_all_schedules}");
    $ForceTaskType = $_GET["ForceTaskType"];
    if (!is_numeric($ForceTaskType)) {
        $ForceTaskType = 0;
    }
    $CountEvents = 0;
    $q = new mysql();
    $tasks = $tpl->_ENGINE_parse_body("{tasks}");
    $t = time();
    $bgroup1 = "{name: '<strong style=font-size:18px>{$all_events}</strong>', bclass: 'Search', onpress : AllEvents{$t}},\n\t{name: '<strong style=font-size:18px>{$internal_scheduler}</strong>', bclass: 'Script', onpress : internal_scheduler{$t}},";
    $bgroup2 = "{name: '<strong style=font-size:18px>{$parameters}</strong>', bclass: 'Settings', onpress : Parmaeters{$t}},";
    $bgroup0 = null;
    $events = $tpl->_ENGINE_parse_body("{events}");
    if ($ForceTaskType > 0) {
        $bgroup1 = null;
        $bgroup2 = null;
        $schedules = new system_tasks();
        $title = $tpl->javascript_parse_text($schedules->tasks_array[$ForceTaskType]);
        if ($ForceTaskType == 23) {
            $bgroup0 = "{name: '<strong style=font-size:18px>WebCopy {$parameters}</strong>', bclass: 'Restore', onpress : GotoWebCopy},";
        }
    } else {
        $LIST_TABLES_EVENTS_SYSTEM = $q->LIST_TABLES_EVENTS_SYSTEM();
        $CountTasks = $q->COUNT_ROWS("system_schedules", "artica_backup");
        while (list($tablename, $rows) = each($LIST_TABLES_EVENTS_SYSTEM)) {
            $CountEvents = $CountEvents + $q->COUNT_ROWS($tablename, "artica_events");
        }
        $CountEvents = numberFormat($CountEvents, 0, '.', ' ');
        $title = "{$CountTasks} {$tasks} {$CountEvents} {$events}";
    }
    $html = "\n<table class='{$t}' style='display: none' id='{$t}' style='width:99%'></table>\n<script>\nvar rowSquidTask='';\n\$(document).ready(function(){\n\$('#{$t}').flexigrid({\n\turl: '{$page}?search=yes&minisize={$_GET["minisize"]}&ForceTaskType={$_GET["ForceTaskType"]}',\n\tdataType: 'json',\n\tcolModel : [\n\t\t{display: '<span style=font-size:22px>&nbsp;</span>', name : 'ID', width : 32, sortable : true, align: 'center'},\n\t\t{display: '<span style=font-size:22px>{$task}</span>', name : 'TaskType', width : 561, sortable : false, align: 'left'},\n\t\t{display: '<span style=font-size:22px>{$description}</span>', name : 'TimeDescription', width : 561, sortable : false, align: 'left'},\n\t\t{display: '<span style=font-size:22px>{$run}</span>', name : 'run', width : 64, sortable : false, align: 'center'},\n\t\t{display: '<span style=font-size:22px>{$events}</span>', name : 'run1', width : 32, sortable : false, align: 'center'},\n\t\t{display: '&nbsp;', name : 'enable', width : 32, sortable : true, align: 'center'},\n\t\t{display: '&nbsp;', name : 'delete', width : 64, sortable : false, align: 'center'}\n\t],\n\t\nbuttons : [\n\t{$bgroup0}\n\t{name: '<strong style=font-size:18px>{$new_schedule}</strong>', bclass: 'add', onpress : AddNewSchedule},\n\t{$bgroup1}\n\t{name: '<strong style=font-size:18px>{$build_config}</strong>', bclass: 'apply', onpress : build_config{$t}},\n\t{$bgroup2}\n\t],\t\n\tsearchitems : [\n\t\t{display: '{$description}', name : 'TimeDescription'},\n\t\t],\n\t\t\n\tsortname: 'ID',\n\tsortorder: 'asc',\n\tusepager: true,\n\ttitle: '<span style=font-size:30px>{$title}</span>',\n\tuseRp: true,\n\trp: 15,\n\tshowTableToggleBtn: false,\n\twidth: '99%',\n\theight: 550,\n\tsingleSelect: true\n\t\n\t});   \n});\t\n\tfunction AllEvents{$t}(){\n\t\tLoadjs('squid.update.events.php?table=Taskev0')\n\t\n\t}\n\t\n\tfunction Parmaeters{$t}(){\n\t\tLoadjs('{$page}?schedules-params=yes');\n\t}\n\t\n\tfunction internal_scheduler{$t}(){\n\t\tLoadjs('artica.internal.cron.php');\n\t}\n\n\n\tfunction AddNewSchedule(category){\n\t\t\tLoadjs('{$page}?AddNewSchedule-js=yes&ID=0&ForceTaskType={$_GET["ForceTaskType"]}');\n\t}\n\t\n\tfunction SystemCrontaskUpdateTable(){\n\t\t\$('#{$t}').flexReload();\n\t }\n\t\n\tvar x_SystemTaskEnable=function (obj) {\n\t\tvar ID='{$_GET["ID"]}';{$array}\n\t\tvar results=obj.responseText;\n\t\tif(results.length>0){alert(results);}\t\t\n\t}\n\n\tvar x_DisableSquidDefaultScheduleCheck=function (obj) {\n\t\tvar ID='{$_GET["ID"]}';\n\t\tvar results=obj.responseText;\n\t\tif(results.length>0){alert(results);}\n\t\t\$('#{$t}').flexReload();\t\t\n\t}\n\n\tfunction build_config{$t}(){\n\t\tYahooWinBrowse('650','{$page}?build-config=yes','{$build_config}');\n\t}\n\n\n\tfunction SystemTaskEnable(md,id){\n\t  \tvar XHR = new XHRConnection();\n\t  \tif(document.getElementById(md).checked){XHR.appendData('value',1);}else{XHR.appendData('value',0);}\n\t\tXHR.appendData('ID',id);\n\t  \tXHR.appendData('schedule-enable','yes');\n\t  \tXHR.sendAndLoad('{$page}', 'POST',x_SystemTaskEnable);\n\t}\n\n\tfunction DisableSquidDefaultScheduleCheck(){\n\t  \tvar XHR = new XHRConnection();\n\t  \tif(document.getElementById('DisableSquidDefaultSchedule').checked){XHR.appendData('DisableSquidDefaultSchedule',1);}\n\t  \telse{XHR.appendData('DisableSquidDefaultSchedule',0);}\n\t  \tXHR.sendAndLoad('{$page}', 'POST',x_DisableSquidDefaultScheduleCheck);\t\n\t}\n\t\n\t\n\tfunction SystemTaskRun(ID,explain){\n\t\tif(confirm('{$run_this_task_now} `'+explain+'`')){\n\t\t\tvar XHR = new XHRConnection();\n\t\t\tXHR.appendData('ID',ID);\n\t  \t\tXHR.appendData('schedule-run','yes');\n\t  \t\tXHR.sendAndLoad('{$page}', 'POST',x_SystemTaskEnable);\t\t\n\t\t}\n\t\n\t}\n\t\n\t\n\tvar x_SquidTaskDelete=function (obj) {\n\t\tvar results=obj.responseText;\n\t\tif(results.length>0){alert(results);return;}\n\t\t\$('#rowSquidTask'+rowSquidTask).remove();\n\t}\t\n\t\n\tfunction SquidTaskDelete(ID){\n\t\trowSquidTask=ID;\n\t  \tvar XHR = new XHRConnection();\n\t\tXHR.appendData('ID',ID);\n\t  \tXHR.appendData('schedule-delete','yes');\n\t  \tXHR.sendAndLoad('{$page}', 'POST',x_SquidTaskDelete);\t\n\t}\n\t\n\t\n\t\n</script>";
    echo $html;
}