Current File : //root/panel/modules/apachemodule/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
{
    public static $temp_path ="/var/sentora/temp/";
    public static $module_detail = array(
    "limitipconn_module"=>array("module_detail"=>"limitipconn_module","so_detail"=>"mod_limitipconn.so","path"=>"10-limitipconn.conf"),
    "proxy_wstunnel_module"=>array("module_detail"=>"proxy_wstunnel_module","so_detail"=>"mod_proxy_wstunnel.so","path"=>"00-proxy.conf"),
    "version_module"=>array("module_detail"=>"version_module","so_detail"=>"mod_version.so","path"=>"00-base.conf"),
    "proxy_ajp_module"=>array("module_detail"=>"proxy_ajp_module","so_detail"=>"mod_proxy_ajp.so","path"=>"00-proxy.conf"),
    "cache_disk_module"=>array("module_detail"=>"cache_disk_module","so_detail"=>"mod_cache_disk.so","path"=>"00-base.conf"),
    "proxy_ftp_module"=>array("module_detail"=>"proxy_ftp_module","so_detail"=>"mod_proxy_ftp.so","path"=>"00-proxy.conf"),
    "logio_module"=>array("module_detail"=>"logio_module","so_detail"=>"mod_logio.so","path"=>"00-base.conf"),
    "lua_module"=>array("module_detail"=>"lua_module","so_detail"=>"mod_lua.so","path"=>"00-lua.conf"),
    "echo_module"=>array("module_detail"=>"echo_module","so_detail"=>"mod_echo.so","path"=>"00-base.conf")
     
                                    );
    static function n_sanitize($data)
    {
        $data = trim($data);
        $data = stripslashes($data);
        $data = htmlspecialchars($data);
        return $data;
    }
    
    static function remove_space($str)
    {
        $str = trim(preg_replace('/\s+/','', $str));
        return $str;
    }

    static function trim_space($str)
    {
        $str = trim(preg_replace('/\s+/',' ', $str));
        return $str;
    }

  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 dopackdetail()
    {
     	error_reporting(0);
     	global $controller;
     	$currentuser = ctrl_users::GetUserDetail();                
        if(array_key_exists("userid",$currentuser) && is_numeric($currentuser['userid']))
        {
            $status_array = array("limitipconn_module"=>0,"proxy_wstunnel_module"=>0,"version_module"=>0,"proxy_ajp_module"=>0,"cache_disk_module"=>0,
            "proxy_ftp_module"=>0,"logio_module"=>0,"lua_module"=>0,"echo_module"=>0);                
            $apache_path  = self::remove_space(self::call_socket("apachemodule 1",2));
            if(strlen($apache_path) > 0  )
            {
                if(file_exists($apache_path))
                {
                    $apache_module_detail = file($apache_path);
                    //self::call_socket("filedelete $apache_path",1);
                    $module_count = count($apache_module_detail);
	                if($module_count > 0)
	                {
	                    for($i = 0;$i < $module_count;$i++)
	                    {
	                        $apache_str = $apache_module_detail[$i];
	                        if(stripos($apache_str,"_module") != false )
                            {
                                $httpd_str_array    = explode(" ",self::trim_space($apache_str));
                                $httpd_str          = strtolower(self::remove_space($httpd_str_array[0]));          
                                if(array_key_exists($httpd_str,$status_array))
                                {
                                    $status_array[$httpd_str] = 1;       
                                }                    
                            }		    
	                    } 
	                     
	                }
                    $dis_array = array("status"=>1,"apache_array" =>$status_array);
                    echo json_encode($dis_array);
                }
            }
            else
            {
                 $dis_array = array("status"=>0,"msg" =>"Unable to get detail of apache module, please contact system admin" );
                        echo json_encode($dis_array);  
            }
        }
        else
        {
            $dis_array = array("status"=>2,"msg" =>"Current session expire please login again" );
            echo json_encode($dis_array);
        }
        exit;          
    }
    
    static function docheckhttpdinstall()
    {
        error_reporting(0);  
        global $controller;          
        $currentuser = ctrl_users::GetUserDetail();  
        if(array_key_exists("userid",$currentuser) && is_numeric($currentuser['userid']))
        {
            $formvars = $controller->GetAllControllerRequests('FORM');
            if(array_key_exists("stv",$formvars)  && array_key_exists("packs",$formvars) && is_numeric($formvars['stv']) &&  $formvars['packs']!="" )
            {               
                $apache_path    = self::remove_space(self::call_socket("apachemodule 1",2));
                $stv =self::n_sanitize($formvars['stv']);
                $packs =self::n_sanitize($formvars['packs']);
                if(strlen($apache_path) > 0  )
                {
                    if(file_exists($apache_path))
                    {
                        $apache_module_detail = file($apache_path);
                        self::call_socket("filedelete $apache_path",1);
                        $module_count = count($apache_module_detail);
                        if($module_count > 0)
                        {
                            $status_detail = 2;
                            for($i = 0;$i < $module_count;$i++)
                            {
                                $apache_str = $apache_module_detail[$i];
                                if(stripos($apache_str,"_module") != false )
                                {
                                    $httpd_str_array    = explode(" ",self::trim_space($apache_str));
                                    $httpd_str          = strtolower(self::remove_space($httpd_str_array[0]));
                                        if($httpd_str == $packs)
                                        {                                            
                                            $status_detail = 1;       
                                        }
                                                            
                                }		    
                            }
                            if($stv == 2) {  if ($status_detail == 2) { $status_detail = 1; } }
                            $dis_array = array("status"=>$status_detail,"stv"=>$stv);
                            echo json_encode($dis_array); 
                        }
                        else
                        {
                            $dis_array = array("status"=>0,"msg" =>"Unable to get detail of apache module, please contact system admin-------");
                            echo json_encode($dis_array);
                        }
                    }
                }
                else
                {
                    $dis_array = array("status"=>0,"msg" =>"Unable to get detail of apache module, please contact system admin..........." );
                    echo json_encode($dis_array);  
                }
            }
        }
        else
        {
            $dis_array = array("status"=>0,"msg" =>"Unable to get detail of apache module, please contact system admin=======" );
            echo json_encode($dis_array);  
        }   
        exit;          
    }
    
    static function dopackinstall()
    {
        global $controller;
        $currentuser = ctrl_users::GetUserDetail();        
        $formvars = $controller->GetAllControllerRequests('FORM');
        if(array_key_exists("userid",$currentuser) && is_numeric($currentuser['userid']))
        {
            if(array_key_exists("stv",$formvars)  && array_key_exists("packs",$formvars) && is_numeric($formvars['stv']) &&  $formvars['packs']!="" )
            {
                $stv =self::n_sanitize($formvars['stv']);
                $packs =self::n_sanitize($formvars['packs']);
                $ins_array = array(1,2);
                if( in_array($stv,$ins_array))
                { 
                    if(array_key_exists($packs,self::$module_detail))
                    {
                        $mod_data       = self::$module_detail[$packs];
                        $module_name    = $mod_data['module_detail'];
                        $so_name        = $mod_data['so_detail'];
                        $module_path    = $mod_data['path'];
                        if($stv == 1) { self::call_socket("apachemodule 2 $module_name $so_name $module_path",1);  }
                        else{ self::call_socket("apachemodule 3 $module_name",1); }
                        $dis_array = array("status"=>1);
                        echo json_encode($dis_array);
                    }
                    else
                    {             
                        $dis_array = array("status"=>0,"msg" =>"Please Provide proper data " );
                        echo json_encode($dis_array);
                    }
                }
                else
                {
                    $dis_array = array("status"=>0,"msg" =>"Please Provide proper data " );
                    echo json_encode($dis_array);
                }
            } 
            else
            {
                $dis_array = array("status"=>0,"msg" =>"Please Provide proper data " );
                echo json_encode($dis_array);
                
            }
        
        }
        else
        {
            $dis_array = array("status"=>2,"msg" =>"Current session expire please login again" );
            echo json_encode($dis_array);
        }  
        exit;
    }
    
     static function call_socket($cmd_detail,$opt)
	{
        $service_port = 4444 ;
        $address = gethostbyname('localhost');
        $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
        if ($socket === false) {
                return "2";
        }
        $result = socket_connect($socket, $address, $service_port);
        if ($result === false) {
                return "2";
        }
        socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 20, "usec" =>0));
        $in="command ".$cmd_detail;
        $out = '';
        if(@socket_write($socket, $in, strlen($in)))
        {
            sleep(1);
            $s_data ="";
            if($opt == 2)
            {
                $s_data = socket_read($socket,1024);
            }
            socket_close($socket);
            return $s_data;
        }
        else { return "2";  }
    }
    
    
    
    
        

}