Compare commits
5 Commits
afd8251f64
...
c1a98c5ff6
Author | SHA1 | Date | |
---|---|---|---|
|
c1a98c5ff6 | ||
|
2c891ac180 | ||
|
8e411f0d6c | ||
|
c2279d6d01 | ||
|
3ad8665a49 |
|
@ -36,26 +36,7 @@ class Vhosts extends \Panel\Vhost {
|
|||
$vhost_array = $f3->get('vhost_array');
|
||||
|
||||
/* convert data for frontend display */
|
||||
if ($vhost_array['status'] == 1) {
|
||||
$vhost_array['status'] = 'Enabled';
|
||||
} else {
|
||||
$vhost_array['status'] = 'Disabled';
|
||||
}
|
||||
if ($vhost_array['mbox_limit'] == "NULL") {
|
||||
$vhost_array['mbox_limit'] = 'Unlimited';
|
||||
}
|
||||
|
||||
if ($vhost_array['mbox_quota_default'] == "NULL") {
|
||||
$vhost_array['mbox_quota_default'] = 'Unlimited';
|
||||
} else {
|
||||
$vhost_array['mbox_quota_default'] .= ' GB';
|
||||
}
|
||||
|
||||
if ($vhost_array['mbox_ratelimit_default'] == "NULL") {
|
||||
$vhost_array['mbox_ratelimit_default'] = 'Unlimited';
|
||||
} else {
|
||||
$vhost_array['mbox_ratelimit_default'] .= ' emails per hour';
|
||||
}
|
||||
// nothing to convert
|
||||
|
||||
$f3->set('vhost_array', $vhost_array);
|
||||
|
||||
|
|
126
panel/classes/Panel/Vhost/VhostsAdd.php
Normal file
126
panel/classes/Panel/Vhost/VhostsAdd.php
Normal file
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* vpanel-stack
|
||||
* https://git.stack-source.com/msb/vpanel-stack
|
||||
* Copyright (c) 2022 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
|
||||
* GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
*/
|
||||
|
||||
namespace Panel\Vhost;
|
||||
|
||||
class VhostsAdd extends \Panel\Vhost {
|
||||
|
||||
function beforeRoute($f3) {
|
||||
|
||||
parent::beforeRoute($f3);
|
||||
|
||||
// /* get vm_domains defaults for "add new" form */
|
||||
// $vm_domains_defaults = $f3->call('\Panel::vGet', array("vmail-defaults-get.sh -c", FALSE));
|
||||
// $f3->set('vm_domains_defaults', $vm_domains_defaults[0]);
|
||||
|
||||
}
|
||||
|
||||
static function get($f3) {
|
||||
|
||||
echo \Template::instance()->render('vhost/vhosts-add.html');
|
||||
|
||||
}
|
||||
|
||||
function post($f3) {
|
||||
|
||||
extract($_POST);
|
||||
|
||||
$messages = array();
|
||||
|
||||
/* validate domain */
|
||||
if (preg_match('/^[0-9a-z]([-.]?[0-9a-z])*\.[a-z]{2,24}$/i', strtolower($_POST['domain']))) {
|
||||
// strip www
|
||||
$domain = strtolower($_POST['domain']);
|
||||
} else {
|
||||
$messages[] = "Invalid domain name.";
|
||||
}
|
||||
|
||||
/* validate status */
|
||||
if ($_POST['status'] != 0 && $_POST['status'] != 1) {
|
||||
$messages[] = "Invalid 'Status'.";
|
||||
} else {
|
||||
$status = $_POST['status'];
|
||||
}
|
||||
|
||||
/* validate mbox_limit */
|
||||
if (strtolower($_POST['mbox_limit']) == 'unlimited' || strtolower($_POST['mbox_limit'] == 'null')) {
|
||||
$mbox_limit = "NULL";
|
||||
} elseif (is_numeric($_POST['mbox_limit'])) {
|
||||
/* make sure mbox_limit is a possitive integer */
|
||||
$mbox_limit = abs(intval($_POST['mbox_limit']));
|
||||
if ($mbox_limit < 1) {
|
||||
echo "Mailbox Limit must be a positive number or \"Unlimited\".\n";
|
||||
$messages[] = "Mailbox Limit must be a positive number or \"Unlimited\".";
|
||||
}
|
||||
} else {
|
||||
$messages[] = "Mailbox Limit must be a positive number or \"Unlimited\".";
|
||||
}
|
||||
|
||||
/* validate mbox_quota_default */
|
||||
if (strtolower($_POST['mbox_quota_default']) == 'unlimited' || strtolower($_POST['mbox_quota_default'] == 'null')) {
|
||||
$mbox_quota_default = "NULL";
|
||||
} elseif (is_numeric($_POST['mbox_quota_default'])) {
|
||||
/* make sure mbox_quota_default is a possitive integer */
|
||||
$mbox_quota_default = abs(intval($_POST['mbox_quota_default']));
|
||||
if ($mbox_quota_default < 1) {
|
||||
echo "Default Quota must be a positive number or \"Unlimited\".\n";
|
||||
$messages[] = "Default Quota must be a positive number or \"Unlimited\".";
|
||||
}
|
||||
} else {
|
||||
$messages[] = "Default Quota must be a positive number or \"Unlimited\".";
|
||||
}
|
||||
|
||||
/* validate mbox_ratelimit_default */
|
||||
if (strtolower($_POST['mbox_ratelimit_default']) == 'unlimited' || strtolower($_POST['mbox_ratelimit_default'] == 'null')) {
|
||||
$mbox_ratelimit_default = "NULL";
|
||||
} elseif (is_numeric($_POST['mbox_ratelimit_default'])) {
|
||||
/* make sure mbox_ratelimit_default is a possitive integer */
|
||||
$mbox_ratelimit_default = abs(intval($_POST['mbox_ratelimit_default']));
|
||||
if ($mbox_ratelimit_default < 1) {
|
||||
$messages[] = "Default Rate Limit must be a positive number or \"Unlimited\".";
|
||||
}
|
||||
} else {
|
||||
$messages[] = "Default Rate Limit must be a positive number or \"Unlimited\".";
|
||||
}
|
||||
|
||||
/* check for validation errors */
|
||||
if (count($messages) > 0) {
|
||||
$messages[] = "Please re-submit the form to try again.";
|
||||
$f3->set('SESSION.messages', $messages);
|
||||
$f3->call('\Panel\Vmail\DomainsAdd::get', $f3);
|
||||
} else {
|
||||
/* check if vmail domain already exists */
|
||||
$domain_array = $f3->call('\Panel::vGet', array("vmail-domains-get.sh -d $domain -c", FALSE));
|
||||
if (count($domain_array) == 0) {
|
||||
/* add email domain */
|
||||
exec("/usr/local/bin/vmail-domains-add.sh -d $domain -l $mbox_limit -q $mbox_quota_default -r $mbox_ratelimit_default -s $status", $output, $result_code);
|
||||
if ($result_code == 0) {
|
||||
$messages[] = "Email Domain $domain has been added.";
|
||||
$f3->set('SESSION.messages', $messages);
|
||||
$f3->reroute("/Email/$domain");
|
||||
} else {
|
||||
if (count($output) > 0) {
|
||||
foreach ($output as $k=>$output_message) {
|
||||
$messages[] = "$output_message";
|
||||
}
|
||||
} else {
|
||||
$messages[] = "Unknown error adding Email Domain $domain.";
|
||||
}
|
||||
$f3->set('SESSION.messages', $messages);
|
||||
$f3->call('\Panel\Vmail\DomainsAdd::get', $f3);
|
||||
}
|
||||
} else {
|
||||
$messages[] = "Email Domain '$domain' already exists.";
|
||||
$f3->set('SESSION.messages', $messages);
|
||||
$f3->reroute("/Email/$domain");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -48,7 +48,12 @@ class AliasesAdd extends \Panel\Vmail {
|
|||
if ($result_code == 0) {
|
||||
$messages[] = "Success: Email alias $alias@$domain added.";
|
||||
$f3->set('SESSION.messages', $messages);
|
||||
$mapping = $f3->get('NAV.mapping');
|
||||
if ($mapping == 'vmail') {
|
||||
$f3->reroute("/Accounts/$mbox/Aliases");
|
||||
} else {
|
||||
$f3->reroute("/Email/$domain/Accounts/$mbox/Aliases");
|
||||
}
|
||||
} else {
|
||||
/* failure, set error messages */
|
||||
if (count($output) > 0) {
|
||||
|
|
|
@ -42,7 +42,12 @@ class AliasesDelete extends \Panel\Vmail {
|
|||
$messages[] = "Error deleting alias '$alias@$domain'.";
|
||||
}
|
||||
$f3->set('SESSION.messages', $messages);
|
||||
$mapping = $f3->get('NAV.mapping');
|
||||
if ($mapping == 'vmail') {
|
||||
$f3->reroute("/Aliases");
|
||||
} else {
|
||||
$f3->reroute("/Email/$domain/Aliases");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
44
panel/ui/vhost/vhosts-add.html
Normal file
44
panel/ui/vhost/vhosts-add.html
Normal file
|
@ -0,0 +1,44 @@
|
|||
<include href="header.html" />
|
||||
|
||||
<form action="{{@REALM}}" method="POST">
|
||||
<h4 id="Add_New_Website">Add New Website</h4>
|
||||
<fieldset>
|
||||
<legend>Only the domain name is required</legend>
|
||||
<label for="domain">Domain Name <small>(Do not include 'www', that will be aliased to the main domain)</small></label>
|
||||
<input id="domain" name="domain" type="text" placeholder="example.com" value="" required>
|
||||
|
||||
<label for="username">Username <small>(System username, leave empty for auto-creation)</small></label>
|
||||
<input id="username" name="username" type="text" placeholder="examplec" value="" required>
|
||||
|
||||
Check to jail user: <input type="checkbox" id="jail" name="jail" value="yes" checked>
|
||||
|
||||
<label for="macro">Config <small>(A valid Let's Encrypt certificate is required for VHostHTTPS)</small></label>
|
||||
<select id="macro" name="macro">
|
||||
<option value="VHostHTTP" selected>VHostHTTP</option>
|
||||
<option value="VHostHTTPS">VHostHTTPS</option>
|
||||
</select>
|
||||
|
||||
<label for="status">Status</label>
|
||||
<select id="status" name="status">
|
||||
<option value="1" selected>Enabled</option>
|
||||
<option value="0">Disabled</option>
|
||||
</select>
|
||||
|
||||
<input type="submit" value="Submit">
|
||||
<button id="reset" type="reset" disabled>Reset</button>
|
||||
|
||||
<br>
|
||||
<!-- <small>Any other form instructions go here.</small> -->
|
||||
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
<p>
|
||||
<b>Username</b><br>
|
||||
<b>Jail</b><br>
|
||||
<b>Config</b><br>
|
||||
<b>Status</b> can be used to temporarily disable the website domain without deleting any settings or files.<br>
|
||||
</p>
|
||||
|
||||
|
||||
<include href="footer.html" />
|
|
@ -35,42 +35,7 @@
|
|||
</check>
|
||||
|
||||
<p>
|
||||
<a href="#Add_New_Website">Add new Website form</a>
|
||||
<a href="{{@NAV.fullpath}}/Add">Add new Website form</a>
|
||||
</p>
|
||||
|
||||
<hr>
|
||||
|
||||
<form action="{{@REALM}}" method="POST">
|
||||
<h4 id="Add_New_Website">Add New Website</h4>
|
||||
<fieldset>
|
||||
<legend>Only the domain name is required</legend>
|
||||
<label for="domain">Domain Name <small>(Do not include 'www', that will be aliased to the main domain)</small></label>
|
||||
<input id="domain" name="domain" type="text" placeholder="example.com" value="" required>
|
||||
|
||||
<label for="username">Username <small>(System username, leave empty for auto-creation)</small></label>
|
||||
<input id="username" name="username" type="text" placeholder="examplec" value="" required>
|
||||
|
||||
Check to jail user: <input type="checkbox" id="jail" name="jail" value="yes" checked>
|
||||
|
||||
<label for="macro">Config <small>(A valid Let's Encrypt certificate is required for VHostHTTPS)</small></label>
|
||||
<select id="macro" name="macro">
|
||||
<option value="VHostHTTP" selected>VHostHTTP</option>
|
||||
<option value="VHostHTTPS">VHostHTTPS</option>
|
||||
</select>
|
||||
|
||||
<label for="status">Status</label>
|
||||
<select id="status" name="status">
|
||||
<option value="1" selected>Enabled</option>
|
||||
<option value="0">Disabled</option>
|
||||
</select>
|
||||
|
||||
<input type="submit" value="Submit">
|
||||
<button id="reset" type="reset" disabled>Reset</button>
|
||||
|
||||
<br>
|
||||
<small>Any other form instructions go here.</small>
|
||||
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
<include href="footer.html" />
|
||||
|
|
Loading…
Reference in New Issue
Block a user