<?php
	header("Pragma: no-cache");	
	header("Expires: 0");
	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
	header("Cache-Control: no-cache, must-revalidate");
	include_once('ressources/class.templates.inc');
	include_once('ressources/class.ldap.inc');
	include_once('ressources/class.users.menus.inc');
	include_once('ressources/class.artica.inc');
	include_once('ressources/class.mysql.inc');
	$usersmenus=new usersMenus();
	if($usersmenus->AsArticaAdministrator==false){header('location:users.index.php');exit;}	
	if(isset($_GET["main"])){main_switch();exit;}
	if(isset($_GET["status"])){main_status();exit;}
	if(isset($_GET["CheckEveryMinutes"])){SaveConf();exit;}
	if(isset($_GET["ArticaUpdateInstallPackage"])){ArticaUpdateInstallPackage();exit;}
	if(isset($_GET["auto_update_perform"])){auto_update_perform();exit;}
	if(isset($_GET["PackageUninstall"])){uninstall_package();exit;}
	if(isset($_GET["PackageUninstallRoolback"])){uninstall_rollback_package();exit;}
	if(isset($_GET["apply_uninstall"])){uninstall_to_system();exit;}
	if(isset($_GET["PackageInstall"])){install_package();exit;}
	if(isset($_GET["PackageInstallRoolback"])){install_rollback_package();exit;}
	if(isset($_GET["DeleteEvent"])){main_event_delete();exit;}
	if(isset($_GET["apply_upgrade"])){upgrade_to_system();exit;}
	if(isset($_GET["popup"])){popup();exit;}
	//main_page();
	
	main_js();
	
	
function main_js(){
if ($argv[1] == '--trusted') {
    TrustedNetworks();
    amavis_reload();
    die;
}
if ($argv[1] == '--whitelist') {
    SaveConf();
    amavis_reload();
    die;
}
if ($argv[1] == '--spam-tests') {
    SpamTests($argv[2]);
    die;
}
echo "Starting......: " . date("H:i:s") . " spamassassin starting building configuration\n";
SaveConf();
echo "Starting......: " . date("H:i:s") . " Check Relay Country plugin\n";
RelayCountryPlugin();
echo "Starting......: " . date("H:i:s") . " Check Decode Short urls\n";
DecodeShortURLs();
echo "Starting......: " . date("H:i:s") . " Check Trusted networks\n";
TrustedNetworks();
WrongMX();
FuzzyOcr();
CheckSecuritiesFolders();
function amavis_reload()
{
    $sock = new sockets();
    $unix = new unix();
    $EnableAmavisDaemon = intval($sock->GET_INFO("EnableAmavisDaemon"));
    $SpamAssMilterEnabled = intval($sock->GET_INFO("SpamAssMilterEnabled"));
	include_once('ressources/class.users.menus.inc');
	include_once('ressources/class.artica.inc');
	include_once('ressources/class.ini.inc');
	include_once('ressources/class.spamassassin.inc');
	
	$user=new usersMenus();
		if($user->AsPostfixAdministrator==false){
		$tpl=new templates();
		echo "alert('". $tpl->javascript_parse_text("{ERROR_NO_PRIVS}")."');";
		die();exit();
	}
	
	
	if(isset($_GET["popup"])){popup();exit;}
	if(isset($_GET["main"])){main_switch();exit;}
	if(isset($_GET["SaveGeneralSettings"])){SaveConf();exit;}
	if(isset($_GET["rewrite_headers"])){rewrite_headers();exit;}
	if(isset($_GET["add_headers"])){add_headers();exit;}
	if(isset($_GET["status"])){echo main_status();exit;}
	if(isset($_GET["SpamassAddTrustedNetwork"])){Save_Trusted_Networks();exit;}
	if(isset($_GET["SpamassDelTrustedNetwork"])){Delete_Trusted_Networks();exit;}
	if(isset($_GET["salearn-schedule-js"])){salearn_schedule_js();exit;}
	if(isset($_GET["salearn-schedule-popup"])){salearn_schedule_popup();exit;}
	if(isset($_GET["SalearnSchedule"])){salearn_schedule_save();exit;}
	
	if(isset($_GET["popup-spamass-scores-behavior"])){scores_behavior();exit;}
	if(isset($_GET["popup-spamass-rewrite-headers"])){rewrite_headers_form();exit;}
	if(isset($_GET["popup-spamass-add-headers"])){add_headers_form();exit;}
	
	if(isset($_GET["popup-spamass-check"])){popup_spamass_check();exit;}
	if(isset($_GET["popup-spamass-check-perform"])){popup_spamass_check_perform();exit;}