Current File : //root/panel/modules/ns/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 $complete;
static $error;
static $writeerror;
static $nosub;
static $alreadyexists;
static $badname;
static $blank;
static $ok;
static $del;
static $validemail;
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 doNameserver()
{
global $controller;
runtime_csfr::Protect();
$currentuser = ctrl_users::GetUserDetail();
$formvars = $controller->GetAllControllerRequests('FORM');
if (self::ExecuteNameserver($currentuser['userid'], $formvars['ns1'], $formvars['ns2'])) {
self::$ok = TRUE;
return true;
} else {
return false;
}
return;
}
static function getns1Value()
{
global $zdbh;
$retval = "";
$sql = "SELECT * FROM x_ns";
$numrows = $zdbh->prepare($sql);
$numrows->execute();
if ($numrows->fetchColumn() > 0) {
$numrows = $zdbh->prepare($sql);
$numrows->execute();
$values=$numrows->fetch();
$retval =$values['ns1'];
}
return $retval;
}
static function getns2Value()
{
global $zdbh;
$retval = "";
$sql = "SELECT * FROM x_ns ";
$numrows = $zdbh->prepare($sql);
$numrows->execute();
if ($numrows->fetchColumn() > 0)
{
$numrows = $zdbh->prepare($sql);
$numrows->execute();
$values=$numrows->fetch();
$retval =$values['ns2'];
}
return $retval;
}
static function ExecuteNameserver($uid, $ns1, $ns2)
{
global $zdbh;
global $controller;
$retval = FALSE;
$sql = "SELECT COUNT(*) FROM x_ns WHERE userid=:uid AND ns_create IS NOT NULL";
$numrows = $zdbh->prepare($sql);
$numrows->bindParam(':uid', $uid);
$numrows->execute();
if ($numrows->fetchColumn() > 0) {
$sql = "SELECT * FROM x_ns";
$numrows = $zdbh->prepare($sql);
$numrows->execute();
$values=$numrows->fetch();
$oldns1=$values['ns1'];
$oldns2=$values['ns2'];
// if (!fs_director::CheckForEmptyValue(self::CheckCreateForErrors($ns1))) {
// if (!fs_director::CheckForEmptyValue(self::CheckCreateForErrors($ns2))) {
$sql = $zdbh->prepare("UPDATE x_ns SET ns1=:ns1,
ns2=:ns2,
ns_create=:time
WHERE userid=:userid");
$sql->bindParam(':userid', $uid);
$sql->bindParam(':ns1', $ns1);
$sql->bindParam(':ns2', $ns2);
$time = time();
$sql->bindParam(':time', $time);
$sql->execute();
if(trim($ns1)=="")
{
$ns1="ns1.:DOMAIN:";
}
if(trim($ns2)=="")
{
$ns2="ns2.:DOMAIN:";
}
$sql = $zdbh->prepare("UPDATE x_dns_create SET dc_target_vc=:ns1 WHERE dc_id_pk='8'");
$sql->bindParam(':ns1', $ns1);
$sql->execute();
$sql = $zdbh->prepare("UPDATE x_dns_create SET dc_target_vc=:ns2 WHERE dc_id_pk='9'");
$sql->bindParam(':ns2', $ns2);
$sql->execute();
if(trim($ns1)!="" && trim($ns2)!="" )
{
if($ns1=="ns1.:DOMAIN:")
{
$sql = $zdbh->prepare("update x_dns set dn_target_vc=concat('ns1.',dn_name_vc) WHERE dn_target_vc=:oldns1");
$sql->bindParam(':oldns1', $oldns1);
$sql->execute();
}else
{
$sql = $zdbh->prepare("UPDATE x_dns SET dn_target_vc=:ns1 WHERE dn_target_vc=:oldns1");
$sql->bindParam(':ns1', $ns1);
$sql->bindParam(':oldns1', $oldns1);
$sql->execute();
}
if( $ns2=="ns2.:DOMAIN:")
{
$sql = $zdbh->prepare("update x_dns set dn_target_vc=concat('ns2.',dn_name_vc) WHERE dn_target_vc=:oldns2");
$sql->bindParam(':oldns2', $oldns2);
$sql->execute();
}
else
{
$sql = $zdbh->prepare("UPDATE x_dns SET dn_target_vc=:ns2 WHERE dn_target_vc=:oldns2");
$sql->bindParam(':ns2', $ns2);
$sql->bindParam(':oldns2', $oldns2);
$sql->execute();
}
// $retval =$values['ns2'];
$gsql=$zdbh->prepare("select vh_id_pk from x_vhosts where vh_deleted_ts is NULL");
$gsql->execute();
if($gsql->fetchColumn() > 0)
{
$gsql=$zdbh->prepare("select vh_id_pk from x_vhosts where vh_deleted_ts is NULL");
$gsql->execute();
$records_list="";
while($rows=$gsql->fetch())
{
$records_list.=$rows['vh_id_pk'].",";
}
$records_list=rtrim($records_list,',');
$sqlup = "UPDATE x_settings SET so_value_tx=:newlist WHERE so_name_vc='dns_hasupdates'";
$sqlup = $zdbh->prepare($sqlup);
$sqlup->bindParam(':newlist', $records_list);
$sqlup->execute();
}
}
$retval = TRUE;
return $retval;
// }
// }
}
else
{
// if (!fs_director::CheckForEmptyValue(self::CheckCreateForErrors($ns1))) {
// if (!fs_director::CheckForEmptyValue(self::CheckCreateForErrors($ns2))) {
$sql = $zdbh->prepare("INSERT INTO x_ns (userid,
ns1,
ns2,
ns_create) VALUES (
:userid,
:ns1,
:ns2,
:time)");
$sql->bindParam(':userid', $uid);
$sql->bindParam(':ns1', $ns1);
$sql->bindParam(':ns2', $ns2);
$time = time();
$sql->bindParam(':time', $time);
$sql->execute();
if(trim($ns1)=="")
{
$ns1="ns1.:DOMAIN:";
}
if(trim($ns2)=="")
{
$ns2="ns2.:DOMAIN:";
}
$sql = $zdbh->prepare("UPDATE x_dns_create SET dc_target_vc=:ns1 WHERE dc_id_pk='8'");
$sql->bindParam(':ns1', $ns1);
$sql->execute();
$sql = $zdbh->prepare("UPDATE x_dns_create SET dc_target_vc=:ns2 WHERE dc_id_pk='9'");
$sql->bindParam(':ns2', $ns2);
$sql->execute();
$retval = TRUE;
return $retval;
// }
// }
}
}
/*==============================END==============================*/
static function CheckCreateForErrors($domain)
{
global $zdbh;
// Check for spaces and remove if found...
$domain = strtolower(str_replace(' ', '', $domain));
// Check to make sure the domain is not blank before we go any further...
if ($domain == '') {
// self::$blank = TRUE;
// return FALSE;
}else
{
// Check for invalid characters in the domain...
if (!self::IsValidDomainName($domain)) {
self::$badname = TRUE;
return FALSE;
}
// Check to make sure the domain is in the correct format before we go any further...
if (strpos($domain, 'www.') === 0) {
self::$error = TRUE;
return FALSE;
}
// Check to see if the domain already exists in Sentora somewhere and redirect if it does....
}
return TRUE;
}
static function IsValidDomainName($a)
{
if (stristr($a, '.')) {
$part = explode(".", $a);
foreach ($part as $check) {
if (!preg_match('/^[a-z\d][a-z\d-]{0,62}$/i', $check) || preg_match('/-$/', $check)) {
return false;
}
}
} else {
return false;
}
return true;
}
static function getResult()
{
if (!fs_director::CheckForEmptyValue(self::$blank)) {
return ui_sysmessage::shout(ui_language::translate("Your Name Server can not be empty. Please enter a valid Name Server and try again."), "zannounceerror");
}
if (!fs_director::CheckForEmptyValue(self::$badname)) {
return ui_sysmessage::shout(ui_language::translate("Your Name Server is not valid. Please enter a valid Name Server: i.e. 'ns1.nameserver.in'"), "zannounceerror");
}
if (!fs_director::CheckForEmptyValue(self::$error)) {
return ui_sysmessage::shout(ui_language::translate("Please remove 'www'."), "zannounceerror");
}
if (!fs_director::CheckForEmptyValue(self::$ok)) {
return ui_sysmessage::shout(ui_language::translate("Name Server Updated successfully."), "zannounceok");
}
if (!fs_director::CheckForEmptyValue(self::$del)) {
return ui_sysmessage::shout(ui_language::translate("SSL Certificate deleted successfully."), "zannounceok");
}
return "";
}
}