From 8960fb9ae744f3c0bd223d639106f0f8d77d2c7f Mon Sep 17 00:00:00 2001
From: Matthew Saunders Brown
Date: Wed, 30 Oct 2024 15:10:16 -0700
Subject: [PATCH] add vhosts edit page
---
panel/classes/Panel/Vhost/VhostsEdit.php | 99 ++++++++++++++++++++++++
panel/ui/vhost/vhosts-edit.html | 30 +++++++
2 files changed, 129 insertions(+)
create mode 100644 panel/classes/Panel/Vhost/VhostsEdit.php
create mode 100644 panel/ui/vhost/vhosts-edit.html
diff --git a/panel/classes/Panel/Vhost/VhostsEdit.php b/panel/classes/Panel/Vhost/VhostsEdit.php
new file mode 100644
index 0000000..269e803
--- /dev/null
+++ b/panel/classes/Panel/Vhost/VhostsEdit.php
@@ -0,0 +1,99 @@
+
+ * GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+ */
+
+namespace Panel\Vhost;
+
+class VhostsEdit extends \Panel\Vhost {
+
+ function beforeRoute($f3) {
+
+ parent::beforeRoute($f3);
+ $vhost = $f3->get('PARAMS.vhost');
+
+ if ($f3->get('NAV.mapping') == 'vpanel') {
+ if ($vhost_array = $f3->call('\Panel::vGet', array("vhost-get.sh -d $vhost -c", FALSE))) {
+ $vhost_array = $vhost_array[0];
+ } else {
+ $messages[] = "Error getting info for $vhost.";
+ $f3->set('SESSION.messages', $messages);
+ $f3->reroute("/");
+ }
+ } elseif ($f3->get('NAV.mapping') == 'vhost') {
+ /* exta auth checks if logged in via vhost mapping */
+ if ($f3->exists('SESSION.vhostusername')) {
+ /* vhostusername indicates vhost user login */
+ $username = $f3->get('SESSION.vhostusername');
+ if ($vhost_array = $f3->call('\Panel::vGet', array("vhost-get.sh -u $username -d $vhost -c", FALSE))) {
+ $vhost_array = $vhost_array[0];
+ } else {
+ $messages[] = "Unauthorized request.";
+ $f3->set('SESSION.messages', $messages);
+ $f3->reroute("/");
+ }
+ } else {
+ /* SESSION.vhostusername not set. Something went wrong, redirect back home */
+ $messages[] = "Error verifying system user for domain $domain, can not edit.";
+ $f3->set('SESSION.messages', $messages);
+ $f3->reroute("/");
+ }
+ } else {
+ $messages[] = "Invalid request.";
+ $f3->set('SESSION.messages', $messages);
+ $f3->reroute("/");
+ }
+
+ /* set php fpm version vars */
+ $f3->call('\Panel::setPHPVersions', $f3);
+ $vhost_array['fpm_version'] = $f3->get('PHP.fpm_version');
+ $vhost_array['fpm_versions_array'] = $f3->get('PHP.fpm_versions_array');
+ $vhost_array['fpm_version_count'] = $f3->get('PHP.fpm_version_count');
+
+ $f3->set('vhost_array', $vhost_array);
+
+ }
+
+ static function get($f3) {
+
+ if ($f3->exists('PARAMS.vhost')) {
+
+ $vhost = $f3->get('PARAMS.vhost');
+ $f3->set('page_header', "Edit Website: $vhost");
+ echo \Template::instance()->render('vhost/vhosts-edit.html');
+
+ } else {
+
+ /* vhost should always be set, if not reroute to home */
+ $f3->reroute("/");
+
+ }
+
+ }
+
+ function post($f3) {
+
+ $vhost = $f3->get('PARAMS.vhost');
+ $fpm_version = $_POST['fpm_version'];
+ $config = $f3->get('vhost_array.config');
+
+ exec("/usr/local/bin/vhost-enable.sh -d $vhost -m $config -f $fpm_version", $output, $result_code);
+ if ($result_code == 0) {
+ $messages[] = "Success: PHP set to version $fpm_version for $vhost.";
+ $f3->set('SESSION.messages', $messages);
+ if ($f3->get('NAV.mapping') == 'vhost') {
+ $f3->reroute("/");
+ } else {
+ $f3->reroute("/Websites/$vhost");
+ }
+ } else {
+ $f3->reroute("/Websites/$vhost");
+ }
+
+ }
+
+}
diff --git a/panel/ui/vhost/vhosts-edit.html b/panel/ui/vhost/vhosts-edit.html
new file mode 100644
index 0000000..33ab018
--- /dev/null
+++ b/panel/ui/vhost/vhosts-edit.html
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+