Current File : //etc/zpanel/panel/modules/OutgoingEmailStatistics/code/controller.ext.php
<?php
/**
 *
 * Apache Log Viewer for ZPanel 10.1.0
 * Version : 101
 * Author :  Aderemi Adewale (modpluz @ ZPanel Forums)
 * Email : goremmy@gmail.com
 */

class module_controller {

    /**
     * The 'worker' methods.
     */



   /* Load CSS and JS files */

static function getinit()
{
}

    static function getCSFR_Tag() {
        return runtime_csfr::Token();
    }

    static function getModuleName() {
        $module_name = ui_module::GetModuleName();
        return $module_name;

    }

    static function getModuleIcon() {
        global $controller;
		// Check if the current userland theme has a module icon override
	 if(trim(strtolower(ui_template::GetUserTemplate()))=="zentora-master")
        {
	$mod_dir=$controller->GetControllerRequest('URL', 'module') ;
         if (file_exists('etc/styles/' . ui_template::GetUserTemplate() . '/img/style/' . $mod_dir . '.jpg'))
            return './etc/styles/' . ui_template::GetUserTemplate() . '/img/style/' . $mod_dir . '.jpg';
		else 
			  $module_icon = "/modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/icon.png";
				return $module_icon;
        }else 
		{
        $module_icon = "/modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/icon.png";
        return $module_icon;
		}
	}


    static function getModuleDesc() {
        $message = ui_language::translate(ui_module::GetModuleDescription());
        return $message;
    }
    
    static function getOutgoingMailData()
    {
        $temp = tempnam('', '');
        $sock_res= self::socket_connect($temp);   
        $output = shell_exec("cat $temp");
        unlink($temp);
        $output = trim($output);
        $output_array = explode("\n",$output);
        $all_data = array();
        if(count($output_array) <= 0)
        {
            return false;
        }
        foreach($output_array as $data)
        {
            $data_arra = explode("==>",$data);
            $time = strrchr(trim($data_arra[0]), ' ');
            $send_time = strtok($data_arra[0], ":");
            $from_domain_name = trim(substr($data_arra[1], strpos($data_arra[1], "@") + 1));
            $to_domain_name = trim(substr($data_arra[2], strpos($data_arra[2], "@") + 1));
            $user_agent = trim($data_arra[4]);
            $spam_score = trim($data_arra[3]);
            $all_data[$from_domain_name]['date_time'][$send_time] = $all_data[$from_domain_name]['date_time'][$send_time]+1;

            if(!array_key_exists($all_data[$from_domain_name][$to_domain_name]))
                $all_data[$from_domain_name][$to_domain_name] = 1;
            $all_data[$from_domain_name][$to_domain_name] = $all_data[$from_domain_name][$to_domain_name]+1;

            if(!array_key_exists($all_data[$from_domain_name][$user_agent]))
                $all_data[$from_domain_name][$user_agent] = 1;
            $all_data[$from_domain_name][$user_agent] = $all_data[$from_domain_name][$user_agent]+1;

            if(!array_key_exists($all_data[$from_domain_name][$user_agent]))
                $all_data[$from_domain_name][$user_agent] = 1;
            $all_data[$from_domain_name][$user_agent] = $all_data[$from_domain_name][$user_agent]+1;

            if(!array_key_exists($all_data[$from_domain_name]['spam_score_more_than_5']))
                $all_data[$from_domain_name]['spam_score_more_than_5'] = 1;

            if($spam_score >= 5)
                $all_data[$from_domain_name]['spam_score_more_than_5'] = $all_data[$from_domain_name]['spam_score_more_than_5']+1;
        }

        
        foreach ($all_data as $domain_name => $data)
        {
            $more_than_40_email_per_hour = null;
            foreach($data['date_time'] as $date)
            {
                if($date > 40)
                {
                    $more_than_40_email_per_hour = $more_than_40_email_per_hour+1;
                }
            }
            if($more_than_40_email_per_hour != null)
            {
                if(!array_key_exists($all_data[$domain_name]['more_than_40_email_per_hour']))
                    $all_data[$domain_name]['more_than_40_email_per_hour'] = $more_than_40_email_per_hour;

            }
            unset($all_data[$domain_name]['date_time']);
        }
        
        $out = null;
        foreach($all_data as $domain_name => $domain_data)
        {
            $out .= "<div class='each_email_data'><div class='domain_name'>Outgoing Email Data for the Domain : $domain_name</div>";
            $out .= "<table  cellpadding='10'>";
            $out .= "<tr><th>Mail Statistic</th><th>Count</th></tr>";

            foreach($domain_data as $status => $data)
            {
                            //$return_arr[$i] = $data;
                //$i++;
                $out .= "<tr>
                            <td>".$status."</td>
                            <td>".$data."</td>
                        </tr>";
            }
            $out .= '</table></div>';
        }        
        return $out;
        //echo json_encode($return_arr, JSON_NUMERIC_CHECK);exit;
    }

    static function ExecuteLogFileData($temp)
    {
        return json_encode($all_data, JSON_NUMERIC_CHECK);
    }

  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 socket_connect($arg)
    {
        $service_port = 4444 ;
        $address = gethostbyname('localhost');
        $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
        if ($socket === false) 
        {
                return "";
        }
        $result = socket_connect($socket, $address, $service_port);
        if ($result === false) 
        {
                return "";
        }
        socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 2000, "usec" =>0));
        $in="command "."copy_outgoing_mail_log_data_to_tmp ".$arg;
        $out = '';
        if(@socket_write($socket, $in, strlen($in)))
        {
            sleep(1);
            $s_data = socket_read($socket,1024);
            socket_close($socket);
            return $s_data;
        }
        else
        {
            return "";  
        }
    } 

    /**
     * Webinterface sudo methods.
     */
}

?>