Current File : //root/panel/modules/apachespamassassin/code/controller.ext.php
<?php

/**
 * @copyright 2014-2015 Sentora Project (http://www.sentora.org/) 
 * Sentora is a GPL fork of the ZPanel Project whose original header follows:
 *
 * ZPanel - A Cross-Platform Open-Source Web Hosting Control panel.
 *
 * @package ZPanel
 * @version $Id$
 * @author Bobby Allen - ballen@bobbyallen.me
 * @copyright (c) 2008-2014 ZPanel Group - http://www.zpanelcp.com/
 * @license http://opensource.org/licenses/gpl-3.0.html GNU Public License v3
 *
 * This program (ZPanel) 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.
 *
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
class module_controller extends ctrl_module
{

    static $error;
    static $alreadyexists;
    static $badname;
    static $v_blank;
    static $ok;
    static $edit;
    static $samepackage;
	static $v_interval;
	static $v_threshold;
	static $v_window;
	static $v_timeout;
	static $okupdate;
	static $v_thresholdwindow;
	
		static function getInitialize()
	{
        global $controller;
        $line = '<link rel="stylesheet" type="text/css" href="modules/' . $controller->GetControllerRequest('URL', 'module') . '/assets/user_defined.css">';
		$line .= '<script type="text/javascript" src="modules/' . $controller->GetControllerRequest('URL', 'module') . '/assets/jquery.validate.js"></script>';  
 	    $line .= '<script type="text/javascript" src="modules/' . $controller->GetControllerRequest('URL', 'module') . '/assets/user_defined.js"></script>';		
		return $line;
	}
	static function getshowspamscore()
	{
		global $zdbh;
        global $controller;
		$sql = "SELECT  * FROM x_apachespam_settings";
		$sql = $zdbh->prepare($sql);
		$sql->execute();
		$res = $sql->fetch();
		
		// return $res['x_threshold'] ;
			
		$line='';
		$line='<select Id="spam_score" name="spam_score" class="vm_selbx">';
		for($i=1; $i<=10; $i++)
		{
		$selected='';
		if($i==$res['x_score'])
		$selected='Selected';
		
		$line.='<option value="'.$i.'" '.$selected.' >'.$i.'</option>';	
		}
		$line.='</select>';
		return $line;
	}
	
	static function getshowspamenable()
	{
		global $zdbh;
        global $controller;
		$sql = "SELECT  * FROM x_apachespam_settings";
		$sql = $zdbh->prepare($sql);
		$sql->execute();
		$res = $sql->fetch();
		
			
		$line='';
		if ($res['x_spam_enable'] == "0") {
			$line='<input type="radio" name="spam_enable" value="1" class="vm_txtbx"> Enable <input type="radio" name="spam_enable" value="0" class="vm_txtbx" checked> Discard';
        }
        else{
			$line='<input type="radio" name="spam_enable" value="1" checked> Enable <input type="radio" name="spam_enable" value="0" > Discard';
            }
		return $line;
	}
 static function gethelpicon()
{
    global $zdbh;
    global $controller;
    $temp=$controller->GetControllerRequest('URL','module') ;
    $val = '/assets/one.txt';
    $val1 = '/modules/';
   $name=file_get_contents("modules/$temp/assets/helpicon.txt");
   return $name;
}

	
	static function getshowblacklist()
	{
		# flag 0 -> for blacklist 1 -> whitelist 	
		global $zdbh;
        global $controller;
		$currentuser = ctrl_users::GetUserDetail();
		$sql = "SELECT  * FROM x_apachesapm_filters WHERE x_user_id=:userid And x_flag='0'";
        $numrows = $zdbh->prepare($sql);
        $numrows->bindParam(':userid', $currentuser['userid']);
        $numrows->execute();
        if ($numrows->fetchColumn() <> 0) {
			$sql = $zdbh->prepare($sql);
			$sql->bindParam(':userid', $currentuser['userid']);
			$sql->execute();
			$res = $sql->fetch();
			$blacklist_from_array=explode("|",$res['x_domain_list']);
				$line='';
				for($i=1; $i<=5; $i++)
				{
				$line.='<tr>';
				$line.='<td>';
				$line.='<b>blacklist_from</b>';
				$line.='</td>';
				$line.='<td>';
				$line.='<input type="text"  name="blacklist_from[]"  value="'.$blacklist_from_array[$i-1].'" class="vm_txtbx" />';
				$line.='</td>';
				$line.='</tr>';
				}
		}else
		{
				$line='';
				for($i=1; $i<=5; $i++)
				{
				$line.='<tr>';
				$line.='<td>';
				$line.='<b>blacklist_from</b>';
				$line.='</td>';
				$line.='<td>';
				$line.='<input type="text"  name="blacklist_from[]"  class="vm_txtbx" />';
				$line.='</td>';
				$line.='</tr>';
				}
			
		}
				return $line;
	}
	
	static function getshowwhitelist()
	{
		global $zdbh;
        global $controller;
		$currentuser = ctrl_users::GetUserDetail();
		$sql = "SELECT  * FROM x_apachesapm_filters WHERE x_user_id=:userid And x_flag='1'";
        $numrows = $zdbh->prepare($sql);
        $numrows->bindParam(':userid', $currentuser['userid']);
        $numrows->execute();
        if ($numrows->fetchColumn() <> 0) {
			$sql = $zdbh->prepare($sql);
			$sql->bindParam(':userid', $currentuser['userid']);
			$sql->execute();
			$res = $sql->fetch();
			$whitelist_array=explode("|",$res['x_domain_list']);
				$line='';
				for($i=1; $i<=5; $i++)
				{
				$line.='<tr>';
				$line.='<td>';
				$line.='<b>whitelist_from</b>';
				$line.='</td>';
				$line.='<td>';
				$line.='<input type="text"  name="whitelist_from[]"  value="'.$whitelist_array[$i-1].'" class="vm_txtbx" />';
				$line.='</td>';
				$line.='</tr>';
				}
		}else
		{
				$line='';
				for($i=1; $i<=5; $i++)
				{
				$line.='<tr>';
				$line.='<td>';
				$line.='<b>whitelist_from</b>';
				$line.='</td>';
				$line.='<td>';
				$line.='<input type="text"  name="whitelist_from[]"  class="vm_txtbx" />';
				$line.='</td>';
				$line.='</tr>';
				}
			
		}
				return $line;
	}
  static function dooperation()
    {
	
		global $zdbh;
        global $controller;
        $currentuser = ctrl_users::GetUserDetail();
		
		// // // // // // // #Validation part for reference 
	     // // // // // // // if(trim($_POST['txtthreshold'])>=trim($_POST['txtwindow']))
	   // // // // // // // {
		// // // // // // // self::$v_thresholdwindow = true;
		// // // // // // // return false;
	   // // // // // // // }
	   
	    #############################  Update Spam score Start ####################################
		
	  	$sql = "UPDATE x_apachespam_settings SET x_score='".$_POST['spam_score']."',x_spam_enable='".$_POST['spam_enable']."',x_status='Yes'";
		$sql = $zdbh->prepare($sql);
		$sql->execute();
		
		#############################  Update Spam score End ######################################
	   
	   #############################  WhiteList Start #############################################
	
		$sql = "SELECT  * FROM x_apachesapm_filters WHERE x_user_id=:userid And x_flag='1'";
        $numrows = $zdbh->prepare($sql);
        $numrows->bindParam(':userid', $currentuser['userid']);
        $numrows->execute();
        if ($numrows->fetchColumn() <> 0) {
		// Update the whitelist 
		$domainlist=implode("|",$_POST['whitelist_from']);
		$time = time();
		$sql_update_query="UPDATE x_apachesapm_filters SET x_domain_list=:x_domain_list,x_updatedtime=:x_updatedtime WHERE x_user_id=:userid And x_flag='1'";
		$sql_update= $zdbh->prepare($sql_update_query);
		$sql_update->bindParam(':userid', $currentuser['userid']);
		$sql_update->bindParam(':x_updatedtime', $time);
		$sql_update->bindParam(':x_domain_list', $domainlist);
		$sql_update->execute();
			
		}else
		{
		// Insert the whitelist		
		
		$domainlist=implode("|",$_POST['whitelist_from']);
		$time = time();
		$x_flag='1';
		$sql_update_query="INSERT INTO x_apachesapm_filters(x_user_id,x_domain_list,x_flag,x_updatedtime) VALUES (:userid,:x_domain_list,:x_flag,:x_updatedtime)";
		$sql_update= $zdbh->prepare($sql_update_query);
		$sql_update->bindParam(':userid', $currentuser['userid']);
		$sql_update->bindParam(':x_updatedtime', $time);
		$sql_update->bindParam(':x_flag', $x_flag);
		$sql_update->bindParam(':x_domain_list', $domainlist);
		$sql_update->execute();
		}
		
		#############################  WhiteList End ###############################################
	   
	   #############################  BlackList Start #############################################
		
	 $sql = "SELECT  * FROM x_apachesapm_filters WHERE x_user_id=:userid And x_flag='0'";
        $numrows = $zdbh->prepare($sql);
        $numrows->bindParam(':userid', $currentuser['userid']);
        $numrows->execute();
        if ($numrows->fetchColumn() <> 0) {
		// Update the blacklist 
		$domainlist=implode("|",$_POST['blacklist_from']);
		$time = time();
		$sql_update_query="UPDATE x_apachesapm_filters SET x_domain_list=:x_domain_list,x_updatedtime=:x_updatedtime WHERE x_user_id=:userid And x_flag='0'";
		$sql_update= $zdbh->prepare($sql_update_query);
		$sql_update->bindParam(':userid', $currentuser['userid']);
		$sql_update->bindParam(':x_updatedtime', $time);
		$sql_update->bindParam(':x_domain_list', $domainlist);
		$sql_update->execute();
			
		}else
		{
		// Insert the blacklist		
		
		$domainlist=implode("|",$_POST['blacklist_from']);
		$time = time();
		$x_flag='0';
		$sql_update_query="INSERT INTO x_apachesapm_filters(x_user_id,x_domain_list,x_flag,x_updatedtime) VALUES (:userid,:x_domain_list,:x_flag,:x_updatedtime)";
		$sql_update= $zdbh->prepare($sql_update_query);
		$sql_update->bindParam(':userid', $currentuser['userid']);
		$sql_update->bindParam(':x_updatedtime', $time);
		$sql_update->bindParam(':x_flag', $x_flag);
		$sql_update->bindParam(':x_domain_list', $domainlist);
		$sql_update->execute();
		}
		
		
		#############################  BlackList End ###############################################
	   
		
		self::$ok = true;
        return true;
	}
	
    static function getResult()
    {
        if (!fs_director::CheckForEmptyValue(self::$ok)) {
            return ui_sysmessage::shout(ui_language::translate("<strong>Success:</strong> Apache SpamAssassin™ settings updtaed successfully."), "Ok");
        }
		
        return;
    }

    /**
     * Webinterface sudo methods.
     */
}