Current File : //root/panel/modules/virusscanner/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 $editdomain;
static $showform;
static $ResultOk;
static $ResultErr;
static $validscan;
static $tryagain;
/* Load DNS CSS and JS files */
static function getInit()
{
global $controller;
$line = '<link rel="stylesheet" type="text/css" href="modules/' . $controller->GetControllerRequest('URL', 'module') . '/assets/dns.css">';
$line .= '<script type="text/javascript" src="modules/' . $controller->GetControllerRequest('URL', 'module') . '/assets/sentora.js"></script>';
$line .= '<script type="text/javascript" src="modules/' . $controller->GetControllerRequest('URL', 'module') . '/assets/bootstrap-tab.js"></script>';
$line .= '<script type="text/javascript" src="modules/' . $controller->GetControllerRequest('URL', 'module') . '/assets/dns.js"></script>';
return $line;
}
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 getRecordAction()
{
global $zdbh;
global $controller;
$currentuser = ctrl_users::GetUserDetail();
$line = "";
$line .= "<div class=\"zgrid_wrapper\">";
$line .= "<div id=\"dnsTitle\" class=\"account accountTitle\">";
$line .= "<div class=\"content\"><h2>" . ui_language::translate("Virus Scanner") . "</h2>";
$line .= "<div>";
$line .= "</div><br class=\"clear\">";
$line .= "</div>";
$line .= "</div>";
$line .= "<table>";
$line .= '<tr><td></td><td><input type="radio" name="virus_scan" id="virus_scan" value="mail_scan" >Scan Mail</td></tr>';
$line .= '<tr><td></td><td><input type="radio" name="virus_scan" id="virus_scan" value="home_scan" >Scan Entire Home Directory</td></tr>';
$line .= "<tr><td>";
$line .= '<tr><td> </td><td><button Id="virus_scan1" class="btn btn-primary" style="height:35px;width:140px;" >Scan Now</button></td></tr>';
$line .= "</td></tr>";
$line .= "</table>";
$line .= self::getCSFR_Tag();
$line .= '</div>';
return $line;
}
/*static public function getLastScan()
{
global $zdbh;
global $controller;
$currentuser = ctrl_users::GetUserDetail();
$line = "";
$line .= "<div class=\"zgrid_wrapper\">";
$line .= "<div class=\"zgrid_wrapper_call\">";
$line .= "</div>";
$line .= "<div id=\"dnsTitle\" class=\"account accountTitle\">";
$line .= "<div class=\"content\"><h2>" . ui_language::translate("Last Scan Report") . "</h2>";
$line .= "<div>";
$line .= "</div><br class=\"clear\">";
$line .= "</div>";
$line .= "</div>";
$file = fopen("/usr/local/maldetect/progress.log", "r");
$op = fgets($file);
$op = str_replace("\n",'',$op);
if($op == 'started')
{
$line .= "<h2>Note: Still your Scan Going on.. Please Wait...</h2>";
fclose($file);
}
else if ($op == 'completed')
{
$line .= "<table>";
$line .= '<tr><th>Last Scan Report</th><td><a href="javascript:void(0);" target="_blank" onClick="showLog();">Check Log</a></td><td Id="show_log"></td></tr>';
$line .="";
$op = '';
$line .= '</table>';
fclose($file);
}
else
{
$line .= "You currently do not have any Last Scan Report.";
fclose($file);
}
$line .= '</div>';
return $line;
}*/
static function doLastScan()
{
global $zdbh;
global $controller;
$currentuser = ctrl_users::GetUserDetail();
$line = "";
$line .= "<div class=\"zgrid_wrapper\">";
$line .= "<div id=\"dnsTitle\" class=\"account accountTitle\">";
$line .= "<div class=\"content\"><h2>" . ui_language::translate("Last Scan Report") . "</h2>";
$line .= "<div>";
$line .= "</div><br class=\"clear\">";
$line .= "</div>";
$line .= "</div>";
$currentuser = ctrl_users::GetUserDetail();
$uid = $currentuser['userid'];
$sql = 'SELECT * FROM x_vhosts WHERE vh_acc_fk=:uid AND vh_deleted_ts IS NULL LIMIT 1';
$sql = $zdbh->prepare($sql);
$sql->bindParam(':uid', $uid);
$sql->execute();
$row = $sql->fetch();
$domain = $row['vh_name_vc'];
if($uid == 1)
{
$screen_name = "HR_VirusScan_All";
$file = "/usr/local/maldetect/All_progress.log";
}
else
{
$screen_name = "HR_VirusScan_".$domain;
$file = "/usr/local/maldetect/".$domain."_progress.log";
}
$file = fopen($file, "r");
$op = fgets($file);
$op = str_replace("\n",'',$op);
$op = trim($op);
if($op == 'started')
{
$line .= "<h2>Note: Still your Scan Going on.. Please Wait...</h2>";
fclose($file);
}
else if ($op == 'completed')
{
$line .= "<table>";
$line .= '<tr><th>Last Scan Report: </th><td><a href="javascript:void(0);" onClick="showLog();">Check Log</a></td><td Id="show_log"></td></tr>';
$line .="";
$op = '';
$line .= '</table>';
fclose($file);
}
else
{
$line .= "You currently do not have any Last Scan Report.";
fclose($file);
}
$line .= '</div>';
echo $line; exit;
}
static function doshowLogcontent()
{
try
{
$service_port = 4444 ;
$address = gethostbyname('localhost');
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
echo "Please try again Later. Server service not available.";
exit;
self::$tryagain=true;
socket_close($socket);
return false;
}
$result = socket_connect($socket, $address, $service_port);
if ($result === false) {
echo "Please try again Later. Server service not available.";
exit;
self::$tryagain=true;
socket_close($socket);
return false;
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 10, "usec" =>0));
$in="command ScanReport";
$out = '';
socket_write($socket, $in, strlen($in));
$output = "" ;
$out = socket_read($socket, 2048);
$output .= $out ;
echo "<pre>";
echo $output;
echo "</pre>";
socket_close($socket);
exit;
}
catch(Exception $e)
{
echo "Please try again Later. Server service not available.";
exit;
self::$tryagain=true;
return false;
}
}
static function doVirusScan()
{
global $controller;
if (isset($_POST['virus_scan'])) {
if (self::ExecuteVirusScan($_POST['virus_scan'])) {
return true;
}
}
return false;
}
static function ExecuteVirusScan($virus_scan)
{
global $zdbh;
global $controller;
$out ="";
$currentuser = ctrl_users::GetUserDetail();
$uid = $currentuser['userid'];
$sql = 'SELECT * FROM x_vhosts WHERE vh_acc_fk=:uid AND vh_deleted_ts IS NULL LIMIT 1';
$numrows = $zdbh->prepare($sql);
$numrows->bindParam(':uid', $uid);
$numrows->execute();
$row = $numrows->fetch();
$domain = $row['vh_name_vc'];
if($virus_scan == 'mail_scan')
{
if($uid == 1)
{
$mail ="/var/sentora/vmail/";
}
else
{
$mail ="/var/sentora/vmail/".$domain."/";
}
if (!file_exists($mail))
{
echo "Before scan mail, Please create some mail accounts...";
exit;
}
}
else
{
$uname = $currentuser['username'];
//$mail = "/var/sentora/hostdata/".$uname."/public_html/";
if($uid == 1)
{
$mail = ctrl_options::GetSystemOption('hosted_dir');
}
else
{
$mail = ctrl_options::GetSystemOption('hosted_dir').$uname."/public_html/";
}
}
if (file_exists($mail))
{
if($uid == 1)
$screen_name = "HR_VirusScan_All";
else
$screen_name = "HR_VirusScan_".$domain;
$get_screen_path=shell_exec("whereis screen | awk '{print $2}'");
$get_screen_path=str_replace("\n","",$get_screen_path);
$get_screen_path=str_replace('\n',"",$get_screen_path);
$get_grep_path=shell_exec("whereis grep | awk '{print $2}'");
$get_grep_path=str_replace("\n","",$get_grep_path);
$get_grep_path=str_replace('\n',"",$get_grep_path);
$cmd = "$get_screen_path -list | $get_grep_path \"$screen_name\"";
$output = "";
$output = shell_exec($cmd);
if(trim($output) == "" )
{
/*==============================Socket==============================*/
$service_port = 4444 ;
$address = gethostbyname('localhost');
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false)
{
echo "Please try again Later. Server service not available.";
exit;
self::$tryagain=true;
socket_close($socket);
return false;
}
$result = socket_connect($socket, $address, $service_port);
if ($result === false)
{
echo "Please try again Later. Server service not available.";
exit;
self::$tryagain=true;
socket_close($socket);
return false;
}
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => 1, "usec" =>0));
$in="command VirusScan $mail $screen_name";
$output="<pre>";
socket_write($socket, $in, strlen($in));
$output = "" ;
echo "Once your scan report generate.Please click below log ...";
socket_close($socket);
exit;
}
else
{
echo "Once your scan report generate.Please click below log ...";
exit;
}
}
else
{
socket_shutdown($socket, 2);
socket_close($socket);
exit;
}
echo "Server is busy try sometimes";
socket_shutdown($socket, 2);
socket_close($socket);
exit;
/*==============================END==============================*/
}
static function dofilecheck()
{
$nf_path = "/usr/local/maldetect/sess/session.";
$f_path = $nf_path."last";
if(file_exists($f_path) && is_readable($f_path))
{
$a = file($f_path);
$a1 = trim(preg_replace('/\s+/','', $a[0]));
$dis_arr = array("status"=>0);
$file_data = $a1;
if(strlen($file_data) > 0)
{
$dis_arr['status'] = 1;
$ng_file = $nf_path.$file_data;
$dis_string = file_get_contents($ng_file);
$dis_arr["my_data"] ="<pre>".$dis_string."</pre>";
}
else
{
$dis_arr['status'] = 0;
}
}
else
{
$dis_arr = array("status"=>2);
}
echo json_encode($dis_arr);
exit;
}
static function getResult()
{
if (!fs_director::CheckForEmptyValue(self::$tryagain)) {
return ui_sysmessage::shout(ui_language::translate("<strong>Error:</strong> Please try again Later. Server service not available."), "Error");
}
if (!fs_director::CheckForEmptyValue(self::$validscan)) {
return ui_sysmessage::shout(ui_language::translate("Your Domain name is not valid. Please enter a valid Domain Name: i.e. 'domain.com'"), "zannounceerror");
}
}
}
?>