Current File : //etc/zpanel/panel/modules/wordpress_installation/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 $indexExists;
static $blank;
static $Success;
static function get_client_ip() {
$ipaddress = '';
if (getenv('HTTP_CLIENT_IP'))
$ipaddress = getenv('HTTP_CLIENT_IP');
else if(getenv('HTTP_X_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_X_FORWARDED_FOR');
else if(getenv('HTTP_X_FORWARDED'))
$ipaddress = getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR'))
$ipaddress = getenv('HTTP_FORWARDED_FOR');
else if(getenv('HTTP_FORWARDED'))
$ipaddress = getenv('HTTP_FORWARDED');
else if(getenv('REMOTE_ADDR'))
$ipaddress = getenv('REMOTE_ADDR');
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
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 doCheckIndexFileExists()
{
global $controller;
if (isset($_POST['inDomain']))
{
if (self::ExecuteCheckIndexFileExists($_POST['inDomain']))
{
self::$ok = TRUE;
return true;
}
else
{
self::$blank = TRUE;
return false;
}
}
else
{
}
return;
}
static function ExecuteCheckIndexFileExists($domain)
{
$checkIndex = ctrl_hrpanel::isIndexFileExists($domain);
echo $checkIndex;exit;
}
static function doInstallWordPress()
{
global $controller;
if (isset($_POST['inDomain']))
{
$install = self::ExecuteInstallWordPress($_POST['inDomain']);
if ($install)
{
$indomain = $_POST['inDomain'];
echo "WordPress has been successfully installed for your domain $indomain. Please check it.";
exit;
}
else
{
echo "WordPress Installation Failed. Please try again.";
exit;
}
}
else
{
self::$blank = TRUE;
return false;
}
return;
}
static function ExecuteInstallWordPress($domain)
{
global $controller;
$wp_oneclick_install = 'modules/' . $controller->GetControllerRequest('URL', 'module') . '/code/InstallWordPress.php' ;
require_once($wp_oneclick_install);
$InstallWordPress = new InstallWordPress();
$admin_username = $_POST['admin_username'];
$admin_password = $_POST['admin_password'];
$Directory = $_POST['Directory'];
$email_id = $_POST['EmailId'];
$overwrite_existing = $_POST['overwrite_existing'];
$ret = $InstallWordPress->InstallWordPress($domain, $email_id, $overwrite_existing, $admin_username, $admin_password, $Directory);
self::assignusertodb();
return $ret;
}
static function assignusertodb()
{
if(isset($_SESSION['cgs_user']) && isset($_SESSION['cgs_id']) && array_key_exists("cgs_user",$_SESSION) && array_key_exists("cgs_id",$_SESSION) )
{
global $zdbh;
$currentuser = ctrl_users::GetUserDetail($uid);
if($_SESSION['cgs_pk_id'] == $currentuser['userid'])
{
$user_name = $_SESSION['cgs_user'];
$sql2 = $zdbh->prepare("select my_name_vc from x_mysql_databases where my_acc_fk =:newid and my_deleted_ts IS NULL");
$sql2->bindParam(':newid',$currentuser['userid']);
$sql2->execute();
$row_count3 = $sql2->rowCount();
if($row_count3 >0)
{
while($rows=$sql2->fetch())
{
$my_name_vc = $rows['my_name_vc'];
try{
$sql = $zdbh->prepare("GRANT ALL PRIVILEGES ON `$my_name_vc`. * TO :username@'localhost' ");
$sql->bindParam(':username', $user_name);
$sql->execute();
$sql = $zdbh->prepare("FLUSH PRIVILEGES");
$sql->execute();
}
catch(Exception $e) { }
}
}
}
}
}
static function ListDomains($uid)
{
global $zdbh;
$currentuser = ctrl_users::GetUserDetail($uid);
$sql = "SELECT * FROM x_vhosts WHERE vh_acc_fk=:userid AND vh_enabled_in=1 AND vh_deleted_ts IS NULL";
$numrows = $zdbh->prepare($sql);
$numrows->bindParam(':userid', $currentuser['userid']);
$numrows->execute();
$domaincount = $numrows->rowCount();
if ($domaincount > 0)
{
$res = array();
while ($rowdomains = $numrows->fetch())
{
$res[] = array('domain' => ui_language::translate($rowdomains['vh_name_vc']));
}
return $res;
}
else
{
return false;
}
}
static function getDomainList()
{
$currentuser = ctrl_users::GetUserDetail();
return self::ListDomains($currentuser['userid']);
}
static function getEmailList()
{
$currentuser = ctrl_users::GetUserDetail();
return $currentuser['email'];
}
static function getResult()
{
if (!fs_director::CheckForEmptyValue(self::$indexExists))
{
return ui_sysmessage::shout(ui_language::translate("Index File is already Exists in your domain."), "zannounceindexExists");
}
if (!fs_director::CheckForEmptyValue(self::$blank))
{
return ui_sysmessage::shout(ui_language::translate("Your Domain can not be empty. Please enter a valid Domain Name and try again."), "zannounceblank");
}
if (!fs_director::CheckForEmptyValue(self::$Success))
{
return ui_sysmessage::shout(ui_language::translate("WordPress for Your Domain has been Installed Successfully. Please check your Domain"), "zannounceSuccess");
}
return "";
}
}