Current File : //etc/sentora/panel/modules/hostname_change/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 $badpassword;
static function doChangeHostname()
{
global $zdbh;
global $controller;
runtime_csfr::Protect();
$currentuser = ctrl_users::GetUserDetail();
$new_hostname = trim($controller->GetControllerRequest('FORM', 'new_hostname'));
$new_host_explode = explode(".", $new_hostname);
if(sizeof($new_host_explode)>2 && $new_host_explode[sizeof($new_host_explode)-1] !="") {
$host_dns_record = dns_get_record($new_hostname,DNS_A);
if($host_dns_record) {
$sock_res= self::socket_connect($new_hostname);
if($sock_res) {
$ret_val = self::pointHostnameInReverseDNS($new_hostname);
if(!$ret_val) {
self::$error = "ok";
$message = "We changed the hostname, but we couldn't point reverse DNS with the new hostname. So please check it from yourside and kindly point reverse dns to the new hostname ".$new_hostname;
self::sendTicket($new_hostname, $message);
} else {
self::$error = "ok";
}
}
} else {
self::$error = "host_point_error";
}
} else {
self::$error = "error";
}
}
static function pointHostnameInReverseDNS($new_hostname)
{
global $zdbh;
global $controller;
$server_ip = ctrl_options::GetSystemOption('server_ip');
$url = 'http://hostingraja.info/api/SetReverseDnsHostname.php';
$postvalues="ip=$server_ip&hostname=$new_hostname";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postvalues);
$output = curl_exec($ch);
$output = trim($output);
curl_close($ch);
return $output;
}
public function sendTicket($new_hostname, $message) {
echo "Sending Ticket...";
$mail_body = "<html>";
$mail_body .= "<body>";
$mail_body .= "<div>";
$mail_body .= "<div>ISSUE: Point RDNS to the new Hostname.</div>" ;
$mail_body .= "<div>".$message."</div>" ;
$mail_body .= "</div>";
$mail_body .= "</body>";
$mail_body .= "</html>";
$email = 'support@hostingraja.info';
$subject = "Add RDNS to the new Hostname- ".$new_hostname;
// To send HTML mail, the 'Content-type' header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: Support <support@hostingraja.in>' . "\r\n";
mail($email,$subject,$mail_body, $headers);
}
static function socket_connect($new_hostname)
{
$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 "."hostname_change ".$new_hostname;
$out = '';
if(@socket_write($socket, $in, strlen($in)))
{
sleep(1);
$s_data = socket_read($socket,1024);
socket_close($socket);
return $s_data;
}
else { return ""; }
}
static function getResult()
{
if (!fs_director::CheckForEmptyValue(self::$error)) {
if (self::$error == "ok") {
return ui_sysmessage::shout(ui_language::translate("Hostname has been changed successfully!"), "zannounceok");
}
if (self::$error == "error") {
return ui_sysmessage::shout(ui_language::translate("An error occured and your hostname could not be updated. Please ensure your hostname is proper or not."), "zannounceerror");
}
if (self::$error == "host_point_error") {
return ui_sysmessage::shout(ui_language::translate("An error occured and your hostname could not be updated. Please ensure your hostname is pointed to this server or not."), "zannounceerror");
}
}
}
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 getCurrentID()
{
global $zdbh;
global $controller;
$currentuser = ctrl_users::GetUserDetail();
$uid = $currentuser['userid'];
$query = "SELECT * from x_password_strength WHERE ps_user_vc='$uid'";
$res = $zdbh->prepare($query);
$res->execute();
$results = $res->rowCount();
$val = "";
if($results == 0)
{
return "result";
}
else
if($results > 0)
{
while($rows=$res->fetch())
{
if($rows['ps_cpenabled_in'] == 0)
{
return "result";
}
else if($rows['ps_cpenabled_in'] == 1)
{
return $val;
}
}
}
}
static function getCurrentPassID()
{
global $zdbh;
global $controller;
$currentuser = ctrl_users::GetUserDetail();
$uid = $currentuser['userid'];
$query = "SELECT * from x_password_strength WHERE ps_user_vc='$uid'";
$res = $zdbh->prepare($query);
$res->execute();
$results = $res->rowCount();
$val = "";
if($results == 0)
{
return "nNewPass";
}
else
if($results > 0)
{
while($rows=$res->fetch())
{
if($rows['ps_cpenabled_in'] == 0)
{
return "inNewPass";
}
else if($rows['ps_cpenabled_in'] == 1)
{
return $val;
}
}
}
}
}