Current File : //etc/zpanel/panel/modules/enableErrorlogs/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 $output;
/**
* The 'worker' methods.
*/
static function doUpdateLogSettings()
{
global $zdbh;
global $controller;
$apache_log = $controller->GetControllerRequest('FORM', 'apache_log');
$mysql_log = $controller->GetControllerRequest('FORM', 'mysql_log');
self::UpdateApacheLogSettinginTable($apache_log);
self::UpdateMysqlLogSettinginTable($mysql_log);
$sock_res= self::socket_connect($apache_log, $mysql_log);
$sock_res = trim($sock_res);
echo $sock_res;exit;
}
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 UpdateApacheLogSettinginTable($apache_log)
{
global $zdbh;
$apacheGetLog = "SELECT so_id_pk, so_value_tx FROM x_settings WHERE so_name_vc='apache_log_settings'";
$numrows_GetLog = $zdbh->prepare($apacheGetLog);
$numrows_GetLog->execute();
$rowvhost=$numrows_GetLog->fetch();
$apache_id = $rowvhost['so_id_pk'];
$so_value_tx = $rowvhost['so_value_tx'];
if($apache_id)
{
if($so_value_tx == $apache_log)
return true;
$query = "UPDATE x_settings SET so_value_tx = $apache_log WHERE so_id_pk = $apache_id";
}
else
{
$query = "INSERT INTO x_settings (so_value_tx, so_cleanname_vc, so_name_vc, so_desc_tx, so_module_vc, so_usereditable_en) VALUES ($apache_log, 'Apache Log Settings', 'apache_log_settings', 'Apache Log Enable or Disable settings', 'enableErrorlogs', false)";
}
$numrows_sqlGetLog = $zdbh->prepare($query);
$numrows_sqlGetLog->execute();
return true;
}
static function UpdateMysqlLogSettinginTable($mysql_log)
{
global $zdbh;
$apacheGetLog = "SELECT so_id_pk, so_value_tx FROM x_settings WHERE so_name_vc='mysql_log_settings'";
$numrows_GetLog = $zdbh->prepare($apacheGetLog);
$numrows_GetLog->execute();
$rowvhost=$numrows_GetLog->fetch();
$mysql_id = $rowvhost['so_id_pk'];
$so_value_tx = $rowvhost['so_value_tx'];
if($mysql_id)
{
if ($so_value_tx == $mysql_log)
return true;
$query = "UPDATE x_settings SET so_value_tx = $mysql_log WHERE so_id_pk = $mysql_id";
}
else
{
$query = "INSERT INTO x_settings (so_value_tx, so_cleanname_vc, so_name_vc, so_desc_tx, so_module_vc, so_usereditable_en) VALUES ($mysql_log, 'Mysql Log Settings', 'mysql_log_settings', 'Mysql Log Enable or Disable settings', 'enableErrorlogs', false)";
}
$numrows_sqlGetLog = $zdbh->prepare($query);
$numrows_sqlGetLog->execute();
return true;
}
static function socket_connect($apache_log, $mysql_log)
{
if($apache_log == 'true')
$apache_log = 1;
else
$apache_log =0;
if($mysql_log == 'true')
$mysql_log = 1;
else
$mysql_log = 0;
$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 "."update_log_settings ".$apache_log." ".$mysql_log;
$out = '';
if(@socket_write($socket, $in, strlen($in)))
{
sleep(1);
$s_data = socket_read($socket,1024);
socket_close($socket);
return $s_data;
}
else
{
return "busy";
}
}
static function getApacheLogStatus()
{
global $zdbh;
$apacheGetLog = "SELECT so_id_pk, so_value_tx FROM x_settings WHERE so_name_vc='apache_log_settings'";
$numrows_apacheGetLog = $zdbh->prepare($apacheGetLog);
$numrows_apacheGetLog->execute();
$rowvhost=$numrows_apacheGetLog->fetch();
$get_result = $rowvhost['so_id_pk'];
$so_value_tx = $rowvhost['so_value_tx'];
$output = null;
if($get_result && $so_value_tx == true)
$output="checked";
return $output;
}
static function getMySQLLogStatus()
{
global $zdbh;
$sqlGetLog = "SELECT so_id_pk, so_value_tx FROM x_settings WHERE so_name_vc='mysql_log_settings'";
$numrows_sqlGetLog = $zdbh->prepare($sqlGetLog);
$numrows_sqlGetLog->execute();
$rowvhost=$numrows_sqlGetLog->fetch();
$get_result = $rowvhost['so_id_pk'];
$so_value_tx = $rowvhost['so_value_tx'];
$output = null;
if($get_result && $so_value_tx == true)
$output="checked";
return $output;
}
}