public_html
#1
public_html
Hi.

Ok. So, as I've talked, numerous times in the past about public_html being inside of the root domain directory. I've also mentioned the fact that some scripts require some directories/files to be outside of public view.

Well, a few years ago, I uploaded a site to my server that required a directory to be outside of public_html and was wondering why I couldn't finish installing the website.

So, what I did what in the "vhost" file, I changed the link and ended up crashing my server and had to reinstall Sentora.

Now, I finally reinstalled Sentora on my computer the other day. Well, last night, I found where public_html is in the domains/code/controller.ext.php and made some changes:
Code:
<?php /** * @copyright 2014-2015 Sentora Project (http://www.sentora.org/) * Sentora is a GPL fork of the ZPanel Project whose original header follows: * * Special modification to Sentora for Windows * Author modifications Mark Grigoriev (markdark@yandex.ru) * * 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; /** * The 'worker' methods. */ static function ListDomains($uid = 0) { global $zdbh; if ($uid == 0) { $sql = "SELECT * FROM x_vhosts WHERE vh_deleted_ts IS NULL AND vh_type_in=1 ORDER BY vh_name_vc ASC"; $numrows = $zdbh->prepare($sql); } else { $sql = "SELECT * FROM x_vhosts WHERE vh_acc_fk=:uid AND vh_deleted_ts IS NULL AND vh_type_in=1 ORDER BY vh_name_vc ASC"; $numrows = $zdbh->prepare($sql); $numrows->bindParam(':uid', $uid); } $numrows->execute(); if ($numrows->fetchColumn() <> 0) { if ($uid == 0) { $sql = $zdbh->prepare($sql); } else { $sql = $zdbh->prepare($sql); $sql->bindParam(':uid', $uid); } $res = array(); $sql->execute(); while ($rowdomains = $sql->fetch()) { array_push($res, array ('uid' => $rowdomains['vh_acc_fk'], 'name' => $rowdomains['vh_name_vc'], 'directory' => $rowdomains['vh_directory_vc'], 'active' => $rowdomains['vh_active_in'], 'id' => $rowdomains['vh_id_pk'],)); } return $res; } else { return false; } } static function ListDomainDirs($uid) { global $controller; $currentuser = ctrl_users::GetUserDetail($uid); $res = array(); //$handle = @opendir(ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . "/$rootdir/public_html"); //$handle = @opendir(ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . "$rootdir/public_html"); //$handle = @opendir(ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . "/public_html"); $handle = @opendir(ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . $rootdir . "/public_html"); //$chkdir = ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . "/$rootdir/public_html/"; //$chkdir = ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . "$rootdir/public_html/"; //$chkdir = ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . "/public_html/"; $chkdir = ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . $rootdir . "/public_html/"; if (!$handle) { # Log an error as the folder cannot be opened... } else { while ($file = @readdir($handle)) { if ($file != "." && $file != ".." && $file != "_errorpages") { if (is_dir($chkdir . $file)) { array_push($res, array('domains' => $file)); } } } closedir($handle); } return $res; } static function ExecuteDeleteDomain($id) { global $zdbh; runtime_hook::Execute('OnBeforeDeleteDomain'); $sql = $zdbh->prepare("UPDATE x_vhosts SET vh_deleted_ts=:time WHERE vh_id_pk=:id"); $sql->bindParam(':id', $id); $time = time(); $sql->bindParam(':time', $time); $sql->execute(); self::SetWriteApacheConfigTrue(); $retval = TRUE; runtime_hook::Execute('OnAfterDeleteDomain'); return $retval; } static function ExecuteAddDomain($uid, $domain, $destination, $autohome) { global $zdbh; $retval = FALSE; runtime_hook::Execute('OnBeforeAddDomain'); $currentuser = ctrl_users::GetUserDetail($uid); $domain = strtolower(str_replace(' ', '', $domain)); if (!fs_director::CheckForEmptyValue(self::CheckCreateForErrors($domain))) { //** New Home Directory **// if ($autohome == 1) { $destination = "/" . str_replace(".", "_", $domain); //$vhost_path = ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . "/$rootdir/public_html/" . $destination . "/"; //$vhost_path = ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . "$rootdir/public_html/" . $destination . "/"; //$vhost_path = ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . "/public_html/" . $destination . "/"; $vhost_path = ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . $rootdir . "/public_html/" . $destination . "/"; fs_director::CreateDirectory($vhost_path); fs_director::SetFileSystemPermissions($vhost_path, 0777); //** Existing Home Directory **// } else { $destination = "/" . $destination; //$vhost_path = ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . "/$rootdir/public_html/" . $destination . "/"; //$vhost_path = ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . "$rootdir/public_html/" . $destination . "/"; //$vhost_path = ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . "/public_html/" . $destination . "/"; $vhost_path = ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . $rootdir . "/public_html/" . $destination . "/"; } // Error documents:- Error pages are added automatically if they are found in the _errorpages directory // and if they are a valid error code, and saved in the proper format, i.e. <error_number>.html fs_director::CreateDirectory($vhost_path . "/_errorpages/"); $errorpages = ctrl_options::GetSystemOption('static_dir') . "/errorpages/"; if (is_dir($errorpages)) { if ($handle = @opendir($errorpages)) { while (($file = @readdir($handle)) !== false) { if ($file != "." && $file != "..") { $page = explode(".", $file); if (!fs_director::CheckForEmptyValue(self::CheckErrorDocument($page[0]))) { fs_filehandler::CopyFile($errorpages . $file, $vhost_path . '/_errorpages/' . $file); } } } closedir($handle); } } // Lets copy the default welcome page across... if ((!file_exists($vhost_path . "/index.html")) && (!file_exists($vhost_path . "/index.php")) && (!file_exists($vhost_path . "/index.htm"))) { fs_filehandler::CopyFileSafe(ctrl_options::GetSystemOption('static_dir') . "pages/welcome.html", $vhost_path . "/index.html"); } // If all has gone well we need to now create the domain in the database... $sql = $zdbh->prepare("INSERT INTO x_vhosts (vh_acc_fk,     vh_name_vc,     vh_directory_vc,     vh_type_in,     vh_created_ts) VALUES (:userid,    :domain,    :destination,    1,    :time)"); //CLEANER FUNCTION ON $domain and $homedirectory_to_use (Think I got it?) $time = time(); $sql->bindParam(':time', $time); $sql->bindParam(':userid', $currentuser['userid']); $sql->bindParam(':domain', $domain); $sql->bindParam(':destination', $destination); $sql->execute(); // Only run if the Server platform is Windows. if (sys_versions::ShowOSPlatformVersion() == 'Windows') { if (ctrl_options::GetSystemOption('disable_hostsen') == 'false') { // Lets add the hostname to the HOSTS file so that the server can view the domain immediately... @exec("C:/Sentora/sbin/setroute.exe " . $domain . ""); @exec("C:/Sentora/sbin/setroute.exe www." . $domain . ""); @exec("C:/Sentora/sbin/setroute.exe ftp." . $domain . ""); @exec("C:/Sentora/sbin/setroute.exe mail." . $domain . ""); } } self::SetWriteApacheConfigTrue(); $retval = TRUE; runtime_hook::Execute('OnAfterAddDomain'); return $retval; } } 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; } // 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.... $sql = "SELECT COUNT(*) FROM x_vhosts WHERE vh_name_vc=:domain AND vh_deleted_ts IS NULL"; $numrows = $zdbh->prepare($sql); $numrows->bindParam(':domain', $domain); if ($numrows->execute()) { if ($numrows->fetchColumn() > 0) { self::$alreadyexists = TRUE; return FALSE; } } // Check to make sure user not adding a subdomain and blocks stealing of subdomains.... // Get shared domain list $SharedDomains = array(); $a = explode(',', ctrl_options::GetSystemOption('shared_domains')); foreach ($a as $b) { $SharedDomains[] = $b; } if (substr_count($domain, ".") > 1) { $part = explode('.', $domain); foreach ($part as $check) { if (!in_array($check, $SharedDomains)) { if (strlen($check) > 3) { $sql = $zdbh->prepare("SELECT * FROM x_vhosts WHERE vh_name_vc LIKE :check AND vh_type_in !=2 AND vh_deleted_ts IS NULL"); $checkSql = '%' . $check . '%'; $sql->bindParam(':check', $checkSql); $sql->execute(); while ($rowcheckdomains = $sql->fetch()) { $subpart = explode('.', $rowcheckdomains['vh_name_vc']); foreach ($subpart as $subcheck) { if (strlen($subcheck) > 3) { if ($subcheck == $check) { if (substr($domain, -7) == substr($rowcheckdomains['vh_name_vc'], -7)) { self::$nosub = TRUE; return FALSE; } } } } } } } } } return TRUE; } static function CheckErrorDocument($error) { $errordocs = array(100, 101, 102, 200, 201, 202, 203, 204, 205, 206, 207,   300, 301, 302, 303, 304, 305, 306, 307, 400, 401, 402,   403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413,   414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424,   425, 426, 500, 501, 502, 503, 504, 505, 506, 507, 508,   509, 510); return in_array($error, $errordocs); } 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 IsValidEmail($email) { return preg_match('/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i', $email) == 1; } static function SetWriteApacheConfigTrue() { global $zdbh; $sql = $zdbh->prepare("UPDATE x_settings SET so_value_tx='true' WHERE so_name_vc='apache_changed'"); $sql->execute(); } static function IsvalidIP($ip) { return preg_match("^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}^", $ip) == 1; } /** * End 'worker' methods. */ /** * Webinterface sudo methods. */ static function getDomainList() { $currentuser = ctrl_users::GetUserDetail(); $res = array(); $domains = self::ListDomains($currentuser['userid']); if (!fs_director::CheckForEmptyValue($domains)) { foreach ($domains as $row) { $status = self::getDomainStatusHTML($row['active'], $row['id']); $res[] = array('name' => $row['name'], 'directory' => $row['directory'], 'active' => $row['active'], 'status' => $status, 'id' => $row['id']); } return $res; } else { return false; } } static function getCreateDomain() { $currentuser = ctrl_users::GetUserDetail(); return ($currentuser['domainquota'] < 0) or //-1 = unlimited ($currentuser['domainquota'] > ctrl_users::GetQuotaUsages('domains', $currentuser['userid'])); } static function getDomainDirsList() { $currentuser = ctrl_users::GetUserDetail(); $domaindirectories = self::ListDomainDirs($currentuser['userid']); if (!fs_director::CheckForEmptyValue($domaindirectories)) { return $domaindirectories; } else { return false; } } static function doCreateDomain() { global $controller; runtime_csfr::Protect(); $currentuser = ctrl_users::GetUserDetail(); $formvars = $controller->GetAllControllerRequests('FORM'); if (self::ExecuteAddDomain($currentuser['userid'], $formvars['inDomain'], $formvars['inDestination'], $formvars['inAutoHome'])) { self::$ok = TRUE; return true; } else { return false; } return; } static function doDeleteDomain() { global $controller; runtime_csfr::Protect(); $formvars = $controller->GetAllControllerRequests('FORM'); if (isset($formvars['inDelete'])) { if (self::ExecuteDeleteDomain($formvars['inDelete'])) { self::$ok = TRUE; return true; } } return false; } static function doConfirmDeleteDomain() { global $controller; runtime_csfr::Protect(); $currentuser = ctrl_users::GetUserDetail(); $formvars = $controller->GetAllControllerRequests('FORM'); foreach (self::ListDomains($currentuser['userid']) as $row) { if (isset($formvars['inDelete_' . $row['id'] . ''])) { header("location: ./?module=" . $controller->GetCurrentModule() . "&show=Delete&id=" . $row['id'] . "&domain=" . $row['name'] . ""); exit; } } return false; } static function getisDeleteDomain() { global $controller; $urlvars = $controller->GetAllControllerRequests('URL'); return (isset($urlvars['show'])) && ($urlvars['show'] == "Delete"); } static function getCurrentID() { global $controller; $id = $controller->GetControllerRequest('URL', 'id'); return ($id) ? $id : ''; } static function getCurrentDomain() { global $controller; $domain = $controller->GetControllerRequest('URL', 'domain'); return ($domain) ? $domain : ''; } static function getDomainUsagepChart() { $currentuser = ctrl_users::GetUserDetail(); $maximum = $currentuser['domainquota']; if ($maximum < 0) { //-1 = unlimited return '<img src="' . ui_tpl_assetfolderpath::Template() . 'img/misc/unlimited.png" alt="' . ui_language::translate('Unlimited') . '"/>'; } else { $used = ctrl_users::GetQuotaUsages('domains', $currentuser['userid']); $free = max($maximum - $used, 0); return '<img src="etc/lib/pChart2/sentora/z3DPie.php?score=' . $free . '::' . $used . '&labels=Free: ' . $free . '::Used: ' . $used . '&legendfont=verdana&legendfontsize=8&imagesize=240::190&chartsize=120::90&radius=100&legendsize=150::160"' . ' alt="' . ui_language::translate('Pie chart') . '"/>'; } } static function getDomainStatusHTML($int, $id) { global $controller; if ($int == 1) { return '<td><font color="green">' . ui_language::translate('Live') . '</font></td>' . '<td></td>'; } else { return '<td><font color="orange">' . ui_language::translate('Pending') . '</font></td>' . '<td><a href="#" class="help_small" id="help_small_' . $id . '_a"' . 'title="' . ui_language::translate('Your domain will become active at the next scheduled update.  This can take up to one hour.') . '">' . '<img src="/modules/' . $controller->GetControllerRequest('URL', 'module') . '/assets/help_small.png" border="0" /></a>'; } } static function getResult() { 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."), "zannounceerror"); } if (!fs_director::CheckForEmptyValue(self::$badname)) { return ui_sysmessage::shout(ui_language::translate("Your Domain name is not valid.    Please enter a valid Domain Name: i.e. domain.com"), "zannounceerror"); } if (!fs_director::CheckForEmptyValue(self::$alreadyexists)) { return ui_sysmessage::shout(ui_language::translate("The domain already appears to exist on this server."), "zannounceerror"); } if (!fs_director::CheckForEmptyValue(self::$nosub)) { return ui_sysmessage::shout(ui_language::translate("You cannot add a Subdomain here.    Please use the Subdomain manager to add Subdomains."), "zannounceerror"); } if (!fs_director::CheckForEmptyValue(self::$error)) { return ui_sysmessage::shout(ui_language::translate("Please remove www. The www will automatically work with all Domains / Subdomains."), "zannounceerror"); } if (!fs_director::CheckForEmptyValue(self::$writeerror)) { return ui_sysmessage::shout(ui_language::translate("There was a problem writing to the virtual host container file.    Please contact your administrator and report this error.    Your domain will not function until this error is corrected."), "zannounceerror"); } if (!fs_director::CheckForEmptyValue(self::$ok)) { return ui_sysmessage::shout(ui_language::translate("Changes to your domain web hosting has been saved successfully."), "zannounceok"); } return; } /** * Webinterface sudo methods. */ } ?>

Now, I'm trying a few different lines of code for the $vhost_path, $handle,  and $chkdir and nothing is working. public_html isn't being created inside of the domain when I create a new domain. Please help.

Besides, subdomains and parked domains, I need to know where else the public_html is located.

Now, it would be wonderful if someone would create a module that gives server admins the ability to choose if we want public_html inside or outside of the domain/subdomain. Plus, the module be where if a domain is already created and the server admin wants to switch where public_html is created, public_html will change locations and the website files will be rewritten into public_html if server admin chose to switch public_html to being inside of the domain/subdomain directory (i.e. zhostingsolutions_com/public_html/index.html) or vice-versa (i.e. public_html/zhostingsolutions_com/index.html).

Now, a module would be much easier. I'm using the Windows Sentora but it would be wonderful if the module worked with both, Windows and Linux. I plan to host Windows and Linux. Thanks.

In fact, it would be wonderful if it because a Sentora core module.
Reply
#2
RE: public_html
Are you restarting Apache after you edit the files?
***Retail***
SCPH-39002, Running FCMB, HDD-OSD, Mini-OPL.
SCPH-30002 RSW (Automobile Collection Snow White)
SCPH-10000 x2
SCPH-15000
SCPH-18000 x2
DESR-7700
SCPH-2040X x2
Linux Kit
PSBBN V0.20, V0.30
HDD Utility V1.00, V1.01

***Dev***
DTL-H30102 Running FCMB, HDD-OSD, Mini-OPL.
DTL-H20400 - Boxed
Reply
#3
RE: public_html
(06-01-2021, 06:46 AM)Nigel Wrote: Are you restarting Apache after you edit the files?

Yes, I did but the main problem is that I don't know which one of the 4 lines of code for $handle, $chkdir and $vhost_path. Perhaps, there is a different line of code that I need for each part.
Reply
#4
RE: public_html
(06-01-2021, 08:06 AM)zHostingSolutions Wrote: Yes, I did but the main problem is that I don't know which one of the 4 lines of code for $handle, $chkdir and $vhost_path. Perhaps, there is a different line of code that I need for each part.

Looking at the files, I'm pretty sure it's all of the parameters that need editing.

I'm pretty sure I've edited that file before to create a folder inside the 'public_html' folder and pretty sure that's what I ended up doing.

Please report back, as it's been a few years.
***Retail***
SCPH-39002, Running FCMB, HDD-OSD, Mini-OPL.
SCPH-30002 RSW (Automobile Collection Snow White)
SCPH-10000 x2
SCPH-15000
SCPH-18000 x2
DESR-7700
SCPH-2040X x2
Linux Kit
PSBBN V0.20, V0.30
HDD Utility V1.00, V1.01

***Dev***
DTL-H30102 Running FCMB, HDD-OSD, Mini-OPL.
DTL-H20400 - Boxed
Reply
#5
RE: public_html
I also tried other ways to edit the $vhost_path, $handle, and $chkdir in the domains controller but nothing worked.

It would be great if someone just create a module that will allow Linux and Windows Sentora server admins to change the location of the public_html directory for domains, subdomains and parked domains. Therefore, it can rewrite everything that needs to be rewritten to prevent server crashes like I did a few years ago. Thanks.

If I knew how to code the module I would code it and contribute it for server admins who want to do the same thing but I don't know how to code it.
Reply
#6
RE: public_html
Disabling or adding the folder.path to the OPEN_BASEDIR for that specific domain has worked for me.

Also, it will be futile to continue to host on Windows since it is no longer officially supported.
-TGates - Project Council

SEARCH the Forums or read the DOCUMENTATION before posting!
Support Sentora and Donate: HERE

Find my support or modules useful? Donate to TGates HERE
Developers and code testers needed!
Contact TGates for more information
Reply
#7
RE: public_html
Ok.

So, good news is that I got public_html to show up inside of the domain:
C:/Sentora/www/admin/zhostingsolutions.com/public_html

I did it through:
$handle = @opendir(ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . "/$domain/public_html");
$chkdir = ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . "/$domain/public_html/";
$vhost_path = ctrl_options::GetSystemOption('hosted_dir') . $currentuser['username'] . "/$domain/public_html/" . $destination . "/";

However, inside of the public_html, it creates a duplicate:
C:/Sentora/www/admin/zhostingsolutions.com/public_html/zhostingsolutions_com

It still wants to put a domain inside of public_html and I need to change it.

I need it to be:
C:/Sentora/www/admin/zhostingsolutions.com/public_html/

or

C:/Sentora/www/admin/zhostingsolutions_com/public_html/

Am I supposed to use "OPEN_BASEDIR" instead of "hosted_dir" in order to fully accomplish what I'm trying to do?

Like I said, a module would be nice so that it can automatically change the public_html location for domain, subdomain, parked domain and any other path where public_html is throughout Sentora like in the httpd-vhosts.php.

Also, like I said about websites that are already on the server, it will just switch public _html and the domain/subdomain and any files will be transferred into public_html without it breaking any paths or sites on the server.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Public_html Inside Domain/Subdomain zHostingSolutions 2 6 ,333 07-23-2021, 09:57 AM
Last Post: Nigel

Forum Jump:


Users browsing this thread: 1 Guest(s)