Current File : //etc/zpanel/panel/modules/webserver/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 $blank;
static $ok;
static $vok;
static $nok;
static $edit;
static $samepackage;
static $okupdate;
/**
* The 'worker' methods.
*/
static function dooperation()
{
global $zdbh;
global $controller;
$currentuser = ctrl_users::GetUserDetail();
if(isset($_POST['postoperation']))
{
// if($_POST['postoperation']=="varnishrestart" || $_POST['postoperation']=="apacherestart" || $_POST['postoperation']=="nginxrestart" )
if($_POST['postoperation']=="varnishrestart" || $_POST['postoperation']=="apacherestart")
{
$sql = "INSERT INTO x_web_server(x_service) VALUES (:x_service)";
$numrows = $zdbh->prepare($sql);
$numrows->bindParam(':x_service',$_POST['postoperation']);
$numrows->execute();
if($_POST['postoperation']=="apacherestart")
{
self::$ok = TRUE;
return;
}else if($_POST['postoperation']=="varnishrestart")
{
self::$vok = TRUE;
return;
}else
{
self::$nok = TRUE;
return;
}
}else if($_POST['postoperation']=="apachedefault")
{
//set off into x_varnish table
$sql = "SELECT COUNT(*) FROM x_varnish WHERE x_user_id=:userid";
//$numrows = $zdbh->query($sql);
$numrows = $zdbh->prepare($sql);
$numrows->bindParam(':userid', $currentuser['userid']);
$numrows->execute();
if ($numrows->fetchColumn() <> 0) {
// update the column
$sql = "Update x_varnish SET x_varnish=:x_varnish,
x_isactive=:x_isactive,x_nginx=:x_nginx
WHERE x_user_id=:userid";
$time = time();
$x_isactive=0;
$varnish_val="Off";
$x_nginx="Off";
$sql = $zdbh->prepare($sql);
$sql->bindParam(':userid', $currentuser['userid']);
$sql->bindParam(':x_varnish',$varnish_val);
$sql->bindParam(':x_nginx',$x_nginx);
$sql->bindParam(':x_isactive', $x_isactive);
$sql->execute();
$customport=80;
$sql = $zdbh->prepare("Update x_vhosts SET vh_custom_port_in='".$customport."' WHERE vh_acc_fk='".$currentuser['userid']."'");
$sql->execute();
$gsql=$zdbh->prepare("select vh_id_pk from x_vhosts where vh_acc_fk=:userid AND vh_deleted_ts is NULL");
$gsql->bindParam(':userid', $userid);
$gsql->execute();
$records_list="";
$iter=0;
while($res=$gsql->fetch())
{
if($iter==0)
{
$records_list=$res['vh_id_pk'];
$iter=1;
}
else
{
$records_list=$res['vh_id_pk'];
}
}
$sql = "UPDATE x_settings SET so_value_tx=:newlist WHERE so_name_vc='dns_hasupdates'";
$sql = $zdbh->prepare($sql);
$sql->bindParam(':newlist', $records_list);
$sql->execute();
$sql = $zdbh->prepare("UPDATE x_settings
SET so_value_tx='true'
WHERE so_name_vc='apache_changed'");
$sql->execute();
//shell_exec('sh /etc/sentora/panel/cronshell.sh');
}else
{
// insert the column
$sql = "INSERT INTO x_varnish ( x_user_id,
x_varnish,
x_interval,
x_timeout,
x_window,
x_threshold,
x_lastupdate,x_isactive,x_nginx) VALUES (
:userid,
:x_varnish,
:x_interval,
:x_timeout,
:x_window,
:x_threshold,
:time,
:x_isactive,
:x_nginx)";
$time = time();
$x_isactive=0;
$x_interval=5;
$x_timeout=1;
$x_window=5;
$x_threshold=3;
$varnish_val="Off";
$x_nginx="Off";
$sql = $zdbh->prepare($sql);
$sql->bindParam(':userid', $currentuser['userid']);
$sql->bindParam(':x_varnish',$varnish_val);
$sql->bindParam(':x_nginx',$x_nginx);
$sql->bindParam(':x_interval',$x_interval);
$sql->bindParam(':x_timeout',$x_timeout);
$sql->bindParam(':x_window',$x_window);
$sql->bindParam(':x_isactive',$x_isactive);
$sql->bindParam(':x_threshold',$x_threshold);
$sql->bindParam(':time', $time);
$sql->execute();
$customport=80;
$sql = $zdbh->prepare("Update x_vhosts SET vh_custom_port_in='".$customport."' WHERE vh_acc_fk='".$currentuser['userid']."'");
$sql->execute();
$gsql=$zdbh->prepare("select vh_id_pk from x_vhosts where vh_acc_fk=:userid AND vh_deleted_ts is NULL");
$gsql->bindParam(':userid', $userid);
$gsql->execute();
$records_list="";
$iter=0;
while($res=$gsql->fetch())
{
if($iter==0)
{
$records_list=$res['vh_id_pk'];
$iter=1;
}
else
{
$records_list=$res['vh_id_pk'];
}
}
$sql = "UPDATE x_settings SET so_value_tx=:newlist WHERE so_name_vc='dns_hasupdates'";
$sql = $zdbh->prepare($sql);
$sql->bindParam(':newlist', $records_list);
$sql->execute();
$sql = $zdbh->prepare("UPDATE x_settings
SET so_value_tx='true'
WHERE so_name_vc='apache_changed'");
$sql->execute();
}
//shell_exec('sh /etc/sentora/panel/cronshell.sh');
/* ////////////////////////////////////// Java File Path Added ////////////////////////////////////// */
$sql_tomcat = $zdbh->prepare("SELECT * FROM x_java_version");
$sql_tomcat->execute();
$row_tomcat= $sql_tomcat->fetch();
// $java_file_path=$row_java['x_file_path'];
$java_domain_name=$domain;
$java_domain_full_path=$vhost_path;
$tomcat_path=$row_tomcat['x_file_path'];
$service_domain_port = 4444 ;
$address_domain = gethostbyname('localhost');
$socket_domain = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket_domain === false)
{
}
else
{
$result = socket_connect($socket_domain, $address_domain, $service_domain_port);
if ($result === false)
{
}
else
{
socket_set_option($socket_domain, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 2000, "usec" =>0));
$in="command enablejavawithapache $tomcat_path";
socket_write($socket_domain, $in, strlen($in));
socket_close($socket_domain);
}
}
/* ////////////////////////////////////// Java File Path End ////////////////////////////////////// */
self::$ok = true;
return true;
}
else if($_POST['postoperation']=="varnishdefault")
{
//set off into x_varnish table
$sql = "SELECT COUNT(*) FROM x_varnish WHERE x_user_id=:userid";
$numrows = $zdbh->prepare($sql);
$numrows->bindParam(':userid', $currentuser['userid']);
$numrows->execute();
if ($numrows->fetchColumn() <> 0) {
// update the column
$sql = "Update x_varnish SET x_varnish=:x_varnish,
x_isactive=:x_isactive,x_nginx=:x_nginx
WHERE x_user_id=:userid";
$time = time();
$x_isactive=0;
$varnish_val="On";
$x_nginx="Off";
$sql = $zdbh->prepare($sql);
$sql->bindParam(':userid', $currentuser['userid']);
$sql->bindParam(':x_varnish',$varnish_val);
$sql->bindParam(':x_nginx',$x_nginx);
$sql->bindParam(':x_isactive', $x_isactive);
$sql->execute();
$customport=8080;
$sql = $zdbh->prepare("Update x_vhosts SET vh_custom_port_in='".$customport."' WHERE vh_acc_fk='".$currentuser['userid']."'");
$sql->execute();
$gsql=$zdbh->prepare("select vh_id_pk from x_vhosts where vh_acc_fk=:userid AND vh_deleted_ts is NULL");
$gsql->bindParam(':userid', $userid);
$gsql->execute();
$records_list="";
$iter=0;
while($res=$gsql->fetch())
{
if($iter==0)
{
$records_list=$res['vh_id_pk'];
$iter=1;
}
else
{
$records_list=$res['vh_id_pk'];
}
}
$sql = "UPDATE x_settings SET so_value_tx=:newlist WHERE so_name_vc='dns_hasupdates'";
$sql = $zdbh->prepare($sql);
$sql->bindParam(':newlist', $records_list);
$sql->execute();
$sql = $zdbh->prepare("UPDATE x_settings
SET so_value_tx='true'
WHERE so_name_vc='apache_changed'");
$sql->execute();
//shell_exec('sh /etc/sentora/panel/cronshell.sh');
}else
{
// insert the column
$sql = "INSERT INTO x_varnish ( x_user_id,
x_varnish,
x_interval,
x_timeout,
x_window,
x_threshold,
x_lastupdate,x_isactive,x_nginx) VALUES (
:userid,
:x_varnish,
:x_interval,
:x_timeout,
:x_window,
:x_threshold,
:time,
:x_isactive,:x_nginx)";
$time = time();
$x_isactive=0;
$x_interval=5;
$x_timeout=1;
$x_window=5;
$x_threshold=3;
$varnish_val="On";
$x_nginx="Off";
$sql = $zdbh->prepare($sql);
$sql->bindParam(':userid', $currentuser['userid']);
$sql->bindParam(':x_varnish',$varnish_val);
$sql->bindParam(':x_interval',$x_interval);
$sql->bindParam(':x_timeout',$x_timeout);
$sql->bindParam(':x_window',$x_window);
$sql->bindParam(':x_isactive',$x_isactive);
$sql->bindParam(':x_threshold',$x_threshold);
$sql->bindParam(':x_nginx',$x_nginx);
$sql->bindParam(':time', $time);
$sql->execute();
$customport=8080;
$sql = $zdbh->prepare("Update x_vhosts SET vh_custom_port_in='".$customport."' WHERE vh_acc_fk='".$currentuser['userid']."'");
$sql->execute();
$gsql=$zdbh->prepare("select vh_id_pk from x_vhosts where vh_acc_fk=:userid AND vh_deleted_ts is NULL");
$gsql->bindParam(':userid', $userid);
$gsql->execute();
$records_list="";
$iter=0;
while($res=$gsql->fetch())
{
if($iter==0)
{
$records_list=$res['vh_id_pk'];
$iter=1;
}
else
{
$records_list=$res['vh_id_pk'];
}
}
$sql = "UPDATE x_settings SET so_value_tx=:newlist WHERE so_name_vc='dns_hasupdates'";
$sql = $zdbh->prepare($sql);
$sql->bindParam(':newlist', $records_list);
$sql->execute();
$sql = $zdbh->prepare("UPDATE x_settings
SET so_value_tx='true'
WHERE so_name_vc='apache_changed'");
$sql->execute();
//shell_exec('sh /etc/sentora/panel/cronshell.sh');
//shell_exec('sh /etc/sentora/panel/cronshell.sh');
}
/* ////////////////////////////////////// Java File Path Added ////////////////////////////////////// */
$sql_tomcat = $zdbh->prepare("SELECT * FROM x_java_version");
$sql_tomcat->execute();
$row_tomcat= $sql_tomcat->fetch();
// $java_file_path=$row_java['x_file_path'];
$java_domain_name=$domain;
$java_domain_full_path=$vhost_path;
$tomcat_path=$row_tomcat['x_file_path'];
$service_domain_port = 4444 ;
$address_domain = gethostbyname('localhost');
$socket_domain = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket_domain === false)
{
}
else
{
$result = socket_connect($socket_domain, $address_domain, $service_domain_port);
if ($result === false)
{
}
else
{
socket_set_option($socket_domain, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 2000, "usec" =>0));
$in="command enablejavaonly $tomcat_path";
socket_write($socket_domain, $in, strlen($in));
socket_close($socket_domain);
}
}
/* ////////////////////////////////////// Java File Path End ////////////////////////////////////// */
self::$vok = true;
return true;
}
}
self::$error = TRUE;
return;
}
static function getResult()
{
if (!fs_director::CheckForEmptyValue(self::$error)) {
return ui_sysmessage::shout(ui_language::translate("<strong>Error:</strong> There was an error for restart the server."), "Error");
}
if (!fs_director::CheckForEmptyValue(self::$ok)) {
return ui_sysmessage::shout(ui_language::translate("<strong>Success:</strong> Apache & java restarted successfully."), "Ok");
}
if (!fs_director::CheckForEmptyValue(self::$vok)) {
return ui_sysmessage::shout(ui_language::translate("<strong>Success:</strong> java restarted successfully."), "Ok");
}
if (!fs_director::CheckForEmptyValue(self::$nok)) {
return ui_sysmessage::shout(ui_language::translate("<strong>Success:</strong> Nginx restarted successfully."), "Ok");
}
return;
}
static function getShowServerName()
{
global $zdbh;
global $controller;
$currentuser = ctrl_users::GetUserDetail();
$sql = "SELECT * FROM x_varnish WHERE x_user_id=:userid";
//$numrows = $zdbh->query($sql);
$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();
if($res['x_nginx']=="On")
{
return 'Notice: Your server currently running under the nginx server' ;
}else
{
if($res['x_varnish']=="On")
return 'Notice: Your server currently running under the Java server Only ' ;
else
return 'Notice: Your server currently running under the apache server with java' ;
}
}else
{
return "Notice: Your server currently running under the apache server";
}
}
/**
* Webinterface sudo methods.
*/
/* //////////////////////// apache starting enable ///////////////// */
static function getcheckedapache()
{
global $zdbh;
global $controller;
$currentuser = ctrl_users::GetUserDetail();
$sql = "SELECT * FROM x_varnish WHERE x_user_id=:userid";
//$numrows = $zdbh->query($sql);
$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();
if($res['x_varnish']=="Off" && $res['x_nginx']=="Off" )
return 'checked' ;
else
return '';
}else
{
return "";
}
}
static function getenabledapachedefault()
{
global $zdbh;
global $controller;
$currentuser = ctrl_users::GetUserDetail();
$sql = "SELECT * FROM x_varnish WHERE x_user_id=:userid";
//$numrows = $zdbh->query($sql);
$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();
if($res['x_varnish']=="Off" && $res['x_nginx']=="Off" )
return 'disabled' ;
else
return '';
}else
{
return '';
}
}
static function getenabledapacherestart()
{
global $zdbh;
global $controller;
$currentuser = ctrl_users::GetUserDetail();
$sql = "SELECT * FROM x_varnish WHERE x_user_id=:userid";
//$numrows = $zdbh->query($sql);
$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();
if($res['x_varnish']=="Off" && $res['x_nginx']=="Off" )
return '' ;
else
return 'disabled';
}else
{
return "";
}
}
/* //////////////////////// apache Ending enable ///////////////// */
/* //////////////////////// varnish Starting enable ///////////////// */
static function getcheckedvarnish()
{
global $zdbh;
global $controller;
$currentuser = ctrl_users::GetUserDetail();
$sql = "SELECT * FROM x_varnish WHERE x_user_id=:userid";
//$numrows = $zdbh->query($sql);
$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();
if($res['x_varnish']=="On" && $res['x_nginx']=="Off" )
return 'checked' ;
else
return '';
}else
{
return "";
}
}
static function getenabledvarnishdefault()
{
global $zdbh;
global $controller;
$currentuser = ctrl_users::GetUserDetail();
$sql = "SELECT * FROM x_varnish WHERE x_user_id=:userid";
//$numrows = $zdbh->query($sql);
$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();
if($res['x_varnish']=="On" && $res['x_nginx']=="Off" )
return 'disabled' ;
else
return '';
}else
{
return "";
}
}
static function getenabledvarnishrestart()
{
global $zdbh;
global $controller;
$currentuser = ctrl_users::GetUserDetail();
$sql = "SELECT * FROM x_varnish WHERE x_user_id=:userid";
//$numrows = $zdbh->query($sql);
$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();
if($res['x_varnish']=="On" && $res['x_nginx']=="Off" )
return '' ;
else
return 'disabled';
}else
{
return "";
}
}
/* //////////////////////// varnish Ending enable ///////////////// */
/* //////////////////////// NGINX starting enable ///////////////// */
static function getcheckednginx()
{
global $zdbh;
global $controller;
$currentuser = ctrl_users::GetUserDetail();
$sql = "SELECT * FROM x_varnish WHERE x_user_id=:userid";
//$numrows = $zdbh->query($sql);
$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();
if($res['x_varnish']=="Off" && $res['x_nginx']=="On" )
return 'checked' ;
else
return '';
}else
{
return "";
}
}
static function getenablednginxdefault()
{
global $zdbh;
global $controller;
$currentuser = ctrl_users::GetUserDetail();
$sql = "SELECT * FROM x_varnish WHERE x_user_id=:userid";
//$numrows = $zdbh->query($sql);
$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();
if($res['x_varnish']=="Off" && $res['x_nginx']=="On" )
return 'disabled' ;
else
return '';
}else
{
return 'disabled';
}
}
static function getenablednginxrestart()
{
global $zdbh;
global $controller;
$currentuser = ctrl_users::GetUserDetail();
$sql = "SELECT * FROM x_varnish WHERE x_user_id=:userid";
//$numrows = $zdbh->query($sql);
$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();
if($res['x_varnish']=="Off" && $res['x_nginx']=="On" )
return '' ;
else
return 'disabled';
}else
{
return "";
}
}
/* //////////////////////// NGINX Ending enable ///////////////// */
}