Current File : //etc/sentora/panel/modules/tomcatlogviewer/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 {

    static $logfile;
    static $error;
    static $ok;
    static $FromLine;
    static $ToLine;
    static $tempFile;

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



   /* Load CSS and JS files */
    static function getInit() {
        global $controller;
        $line = '<link rel="stylesheet" type="text/css" href="modules/' . $controller->GetControllerRequest('URL', 'module') . '/assets/logviewer.css">';
        $line .= '<script type="text/javascript" src="modules/' . $controller->GetControllerRequest('URL', 'module') . '/assets/logviewer.js"></script>';
        return $line;
    }



    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 getisDisplayLogs()
    {
        $temp = tempnam('', '');
        $sock_res= self::socket_connect($temp);   
        $log_content="<pre>";
        $sock_res = trim($sock_res);
        $line_arra = explode(" ",$sock_res);
        self::$FromLine = $line_arra[0];
        self::$ToLine = $line_arra[1];
        $log_content.=shell_exec("cat $temp");
        $log_content.="</pre>";
        unlink($temp);
        return $log_content;
    }

    static function doAnotherSetLogs()
    {
        global $controller;
        $FromLine = $controller->GetControllerRequest('FORM', 'FromLine');
        $ToLine = $controller->GetControllerRequest('FORM', 'ToLine');
        $temp = tempnam('', '');
        if($FromLine < 0)
        {
            echo "All logs has been completed.";exit; 
        }
        $log_content="<pre>";
        $argv = "$temp $FromLine $ToLine";
        $sock_res= self::socket_connect($argv);
        $log_content.=shell_exec("cat $temp");
        $log_content.="</pre>";
        unlink($temp);
        echo $log_content;exit;
    }

    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 "."get_tomcat_logs ".$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 "";  
        }
    } 

    static function getFromLine()
    {
        return self::$FromLine;
    }

    static function getToLine()
    {
        return self::$ToLine;
    }

    /**
     * Webinterface sudo methods.
     */
}

?>