2024-10-18 20:01:59 +02:00
|
|
|
package SrvMngr::Controller::Letsencrypt;
|
|
|
|
#
|
2024-11-22 15:00:54 +01:00
|
|
|
# Generated by SM2Gen version:0.8 Chameleon version:4.5.4 On Python:3.12.3 at 2024-11-17 14:48:52
|
2024-10-18 20:01:59 +02:00
|
|
|
#
|
|
|
|
#----------------------------------------------------------------------
|
2024-11-04 18:08:38 +01:00
|
|
|
# heading : Network
|
|
|
|
# description : Letsencrypt certificate
|
|
|
|
# navigation : 6000 6600
|
2024-10-18 20:01:59 +02:00
|
|
|
#
|
|
|
|
# name : letsencrypt, method : get, url : /letsencrypt, ctlact : Letsencrypt#main
|
|
|
|
# name : letsencryptu, method : post, url : /letsencryptu, ctlact : Letsencrypt#do_update
|
|
|
|
# name : letsencryptd, method : get, url : /letsencryptd, ctlact : Letsencrypt#do_display
|
|
|
|
#
|
|
|
|
# routes : end
|
|
|
|
#
|
|
|
|
# Documentation: https://wiki.contribs.org/Letsencrypt
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#
|
|
|
|
# Scheme of things:
|
|
|
|
#
|
|
|
|
# TBA!!
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use Mojo::Base 'Mojolicious::Controller';
|
|
|
|
|
|
|
|
use constant FALSE => 0;
|
|
|
|
use constant TRUE => 1;
|
|
|
|
|
|
|
|
use Locale::gettext;
|
|
|
|
use SrvMngr::I18N;
|
|
|
|
use SrvMngr qw(theme_list init_session);
|
|
|
|
|
|
|
|
use Data::Dumper;
|
|
|
|
|
|
|
|
use esmith::util;
|
2024-11-22 15:00:54 +01:00
|
|
|
use esmith::util::network;
|
2024-11-13 17:45:14 +01:00
|
|
|
use esmith::ConfigDB;
|
2024-10-18 20:01:59 +02:00
|
|
|
use esmith::AccountsDB;
|
|
|
|
use esmith::NetworksDB;
|
|
|
|
use esmith::HostsDB;
|
|
|
|
use esmith::DomainsDB;
|
|
|
|
|
|
|
|
|
|
|
|
#The most common ones
|
|
|
|
our $cdb = esmith::ConfigDB->open() || die("Couldn't open config db");
|
|
|
|
our $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
|
|
|
|
our $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
|
|
|
|
our $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db");
|
|
|
|
our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
|
|
|
|
|
|
|
|
require '/usr/share/smanager/lib/SrvMngr/Controller/Letsencrypt-Custom.pm'; #The code that is to be added by the developer
|
|
|
|
|
|
|
|
sub main {
|
|
|
|
#
|
|
|
|
# Initial entry - route is "/<whatever>"
|
|
|
|
#
|
|
|
|
#set initial panel
|
|
|
|
#for initial panel:
|
|
|
|
#Specifiy panel to enter
|
|
|
|
#load up _data hash with DB fields
|
|
|
|
#load up stash with pointer(s) to control fields hash(= get-))
|
|
|
|
#and a pointer to the prefix_data hash
|
|
|
|
#render initial panel
|
|
|
|
|
|
|
|
my $c = shift;
|
|
|
|
$c->app->log->info( $c->log_req );
|
|
|
|
|
|
|
|
my %lets_data = ();
|
2024-11-04 18:08:38 +01:00
|
|
|
my $title = $c->l('lets_Letsencrypt_certificate');
|
2024-10-18 20:01:59 +02:00
|
|
|
my $modul = '';
|
|
|
|
|
2024-11-13 17:45:14 +01:00
|
|
|
$lets_data{'trt'} = 'LIST';
|
2024-10-18 20:01:59 +02:00
|
|
|
|
|
|
|
#Load any DB entries into the <prefix>_data area so as they are preset in the form
|
|
|
|
# which DB - this only really works if the initial panel is a PARAMS type panel and not a TABLE
|
|
|
|
my $db = $cdb; #pickup local or global db or Default to config
|
|
|
|
|
2024-11-04 18:08:38 +01:00
|
|
|
|
|
|
|
#pickup any other contents needed and load them into hash shared with panel
|
|
|
|
my %returned_hash;
|
|
|
|
# subroutine returns a hash directly
|
2024-11-22 15:00:54 +01:00
|
|
|
%returned_hash = $c->get_data_for_panel_LIST();
|
2024-11-04 18:08:38 +01:00
|
|
|
# Copy each key-value pair from the returned hash to the prefix data hash
|
|
|
|
while (my ($key, $value) = each %returned_hash) {
|
|
|
|
$lets_data{$key} = $value;
|
|
|
|
}
|
2024-10-18 20:01:59 +02:00
|
|
|
|
|
|
|
# and table control fields
|
2024-11-22 15:00:54 +01:00
|
|
|
$c->stash(DomainList=>$c->get_DomainList());
|
2024-11-04 18:08:38 +01:00
|
|
|
|
2024-10-18 20:01:59 +02:00
|
|
|
|
|
|
|
$c->stash(
|
|
|
|
title => $title,
|
|
|
|
modul => $modul,
|
|
|
|
lets_data => \%lets_data
|
|
|
|
);
|
|
|
|
$c->render( template => "letsencrypt" );
|
|
|
|
}
|
|
|
|
|
|
|
|
# Post request with params - submit from the form
|
|
|
|
sub do_update {
|
|
|
|
#
|
|
|
|
# Return after submit pushed on panel (this is a post) - route is "/<whatever>u"
|
|
|
|
# parameters in the params hash.
|
|
|
|
#
|
|
|
|
#load up all params into prefix_data hash:
|
|
|
|
#By panel (series of if statements - only one executed):
|
|
|
|
#call validate-PANEL() - return ret = ok or error message
|
|
|
|
|
|
|
|
#if validation not ok:
|
|
|
|
#render back to current panel with error message in stash
|
|
|
|
#otherwise:
|
|
|
|
#By panel (series of if statements - only one executed):
|
|
|
|
#do whatever is required: call perform-PANEL() - return "ok" or Error Message
|
|
|
|
#call signal-event for any global actions specified (check it exists - error and continue?)
|
|
|
|
#if action smeserver-<whatever>-update exists
|
|
|
|
#signal_event smeserver-<whatever>-update
|
|
|
|
#call signal-event for any specific actions for thids panel (check it exists first - error and continue)
|
|
|
|
#set success in stash
|
|
|
|
#if no "nextpanel" entry:
|
|
|
|
#set firstpanel
|
|
|
|
#else
|
|
|
|
#set nextpanel
|
|
|
|
#call render
|
|
|
|
|
|
|
|
my $c = shift;
|
|
|
|
$c->app->log->info($c->log_req);
|
|
|
|
|
|
|
|
my %lets_data = ();
|
2024-11-04 18:08:38 +01:00
|
|
|
my $title = $c->l('lets_Letsencrypt_certificate');
|
2024-10-18 20:01:59 +02:00
|
|
|
|
|
|
|
# Accessing all POST parameters
|
|
|
|
my %params = $c->req->params->to_hash;
|
|
|
|
|
|
|
|
# Get number of POST parameters
|
|
|
|
my $num_params = keys %params;
|
|
|
|
|
|
|
|
#Params are available in the hash "params" - copy to the prefix_data hash
|
2024-11-13 17:45:14 +01:00
|
|
|
#while (my ($key, $value) = each %{$c->req->params->to_hash}) {
|
|
|
|
# $lets_data{$key} = $value;
|
|
|
|
#}
|
2024-10-18 20:01:59 +02:00
|
|
|
|
|
|
|
# the value of trt will tell you which panel has returned
|
2024-11-13 17:45:14 +01:00
|
|
|
my $trt = $c->param('trt') || 'LIST'; #hidden control on every form.
|
2024-10-18 20:01:59 +02:00
|
|
|
my $ret = 'ok';
|
|
|
|
#Validate the parameters in a custom sub one for each panel (although only one of these will be executed)
|
|
|
|
|
|
|
|
my $thispanel;
|
|
|
|
|
|
|
|
if ($trt eq 'LIST'){
|
|
|
|
#Validate form parameters for panel LIST
|
|
|
|
$ret = $c->validate_LIST(\%lets_data);
|
|
|
|
$thispanel = 'LIST';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($trt eq 'PARAMS'){
|
|
|
|
#Validate form parameters for panel PARAMS
|
|
|
|
$ret = $c->validate_PARAMS(\%lets_data);
|
|
|
|
$thispanel = 'PARAMS';
|
|
|
|
}
|
|
|
|
|
2024-11-04 18:08:38 +01:00
|
|
|
if ($trt eq 'CHECKALLDOMAINS'){
|
|
|
|
#Validate form parameters for panel CHECKALLDOMAINS
|
|
|
|
$ret = $c->validate_CHECKALLDOMAINS(\%lets_data);
|
|
|
|
$thispanel = 'CHECKALLDOMAINS';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($trt eq 'CHECKALLENABLEDDOMAINS'){
|
|
|
|
#Validate form parameters for panel CHECKALLENABLEDDOMAINS
|
|
|
|
$ret = $c->validate_CHECKALLENABLEDDOMAINS(\%lets_data);
|
|
|
|
$thispanel = 'CHECKALLENABLEDDOMAINS';
|
|
|
|
}
|
|
|
|
|
2024-11-22 15:00:54 +01:00
|
|
|
if ($trt eq 'CHECKONEDOMAIN'){
|
|
|
|
#Validate form parameters for panel CHECKONEDOMAIN
|
|
|
|
$ret = $c->validate_CHECKONEDOMAIN(\%lets_data);
|
|
|
|
$thispanel = 'CHECKONEDOMAIN';
|
2024-11-06 16:16:27 +01:00
|
|
|
}
|
|
|
|
|
2024-10-18 20:01:59 +02:00
|
|
|
|
|
|
|
if ($ret ne "ok") {
|
|
|
|
# return to the panel with error message
|
|
|
|
$c->stash(error => $c->l($ret));
|
|
|
|
$c->render("letsencrypt");
|
|
|
|
} else {
|
|
|
|
#Do whatever is needed, including writing values to the DB
|
|
|
|
|
|
|
|
if ($trt eq 'LIST'){
|
|
|
|
#do whatever is required ...
|
|
|
|
$ret = $c->perform_LIST(\%lets_data);
|
|
|
|
if ($ret ne "ok") {
|
|
|
|
# return to the panel with error message
|
|
|
|
$c->stash(error => $c->l($ret));
|
|
|
|
$c->render("letsencrypt");
|
|
|
|
} else {
|
|
|
|
$c->stash( success => $c->l('lets_LIST_panel_action_was_successful')); #A bit bland - edit it in the lex file
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($trt eq 'PARAMS'){
|
|
|
|
#do whatever is required ...
|
|
|
|
$ret = $c->perform_PARAMS(\%lets_data);
|
|
|
|
if ($ret ne "ok") {
|
|
|
|
# return to the panel with error message
|
|
|
|
$c->stash(error => $c->l($ret));
|
|
|
|
$c->render("letsencrypt");
|
|
|
|
} else {
|
|
|
|
$c->stash( success => $c->l('lets_PARAMS_panel_action_was_successful')); #A bit bland - edit it in the lex file
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-04 18:08:38 +01:00
|
|
|
if ($trt eq 'CHECKALLDOMAINS'){
|
|
|
|
#do whatever is required ...
|
|
|
|
$ret = $c->perform_CHECKALLDOMAINS(\%lets_data);
|
|
|
|
if ($ret ne "ok") {
|
|
|
|
# return to the panel with error message
|
|
|
|
$c->stash(error => $c->l($ret));
|
|
|
|
$c->render("letsencrypt");
|
|
|
|
} else {
|
|
|
|
$c->stash( success => $c->l('lets_CHECKALLDOMAINS_panel_action_was_successful')); #A bit bland - edit it in the lex file
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($trt eq 'CHECKALLENABLEDDOMAINS'){
|
|
|
|
#do whatever is required ...
|
|
|
|
$ret = $c->perform_CHECKALLENABLEDDOMAINS(\%lets_data);
|
|
|
|
if ($ret ne "ok") {
|
|
|
|
# return to the panel with error message
|
|
|
|
$c->stash(error => $c->l($ret));
|
|
|
|
$c->render("letsencrypt");
|
|
|
|
} else {
|
|
|
|
$c->stash( success => $c->l('lets_CHECKALLENABLEDDOMAINS_panel_action_was_successful')); #A bit bland - edit it in the lex file
|
|
|
|
}
|
|
|
|
}
|
2024-10-18 20:01:59 +02:00
|
|
|
|
2024-11-22 15:00:54 +01:00
|
|
|
if ($trt eq 'CHECKONEDOMAIN'){
|
2024-11-06 16:16:27 +01:00
|
|
|
#do whatever is required ...
|
2024-11-22 15:00:54 +01:00
|
|
|
$ret = $c->perform_CHECKONEDOMAIN(\%lets_data);
|
2024-11-06 16:16:27 +01:00
|
|
|
if ($ret ne "ok") {
|
|
|
|
# return to the panel with error message
|
|
|
|
$c->stash(error => $c->l($ret));
|
|
|
|
$c->render("letsencrypt");
|
|
|
|
} else {
|
2024-11-22 15:00:54 +01:00
|
|
|
$c->stash( success => $c->l('lets_CHECKONEDOMAIN_panel_action_was_successful')); #A bit bland - edit it in the lex file
|
2024-11-06 16:16:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-04 18:08:38 +01:00
|
|
|
# and call any signal-events needed
|
2024-10-18 20:01:59 +02:00
|
|
|
|
2024-11-04 18:08:38 +01:00
|
|
|
|
2024-10-18 20:01:59 +02:00
|
|
|
# Setup shared data and call panel
|
|
|
|
$c->stash(
|
|
|
|
title => $title,
|
|
|
|
lets_data => \%lets_data
|
|
|
|
);
|
|
|
|
if ('none' eq 'none') {
|
2024-11-13 17:45:14 +01:00
|
|
|
$lets_data{'trt'} = 'LIST';
|
2024-10-18 20:01:59 +02:00
|
|
|
} else {
|
|
|
|
$lets_data{'trt'} = 'none';
|
|
|
|
}
|
2024-11-04 18:08:38 +01:00
|
|
|
$c->do_display()
|
2024-10-18 20:01:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub do_display {
|
|
|
|
#
|
|
|
|
# Return after link clicked in table (this is a get) - route is "/<whatever>d"
|
|
|
|
# Expects ?trt=PANEL&selected="TableRowName" plus any other required
|
|
|
|
#
|
|
|
|
# OR it maybe a post from the main panel to add a new record
|
|
|
|
#
|
|
|
|
#load up all supplied params into prefix_data hash
|
|
|
|
#call get-selected-PANEL() - returns hash of all relevent parameters
|
|
|
|
#load up returned hash into prefix_data
|
|
|
|
#render - to called panel
|
|
|
|
|
|
|
|
my $c = shift;
|
|
|
|
$c->app->log->info($c->log_req);
|
|
|
|
|
|
|
|
my %lets_data = ();
|
2024-11-04 18:08:38 +01:00
|
|
|
my $title = $c->l('lets_Letsencrypt_certificate');
|
2024-10-18 20:01:59 +02:00
|
|
|
|
|
|
|
# Accessing all parameters
|
|
|
|
my %params = $c->req->params->to_hash;
|
|
|
|
|
|
|
|
# Get number of parameters
|
|
|
|
my $num_params = keys %params;
|
|
|
|
|
|
|
|
#Tag as Post or Get (ie. create new entry or edit existing one
|
|
|
|
my $is_new_record = ($c->req->method() eq 'POST');
|
|
|
|
|
|
|
|
#Params are available in the hash "params" - copy to the prefix_data hash
|
2024-11-13 17:45:14 +01:00
|
|
|
#while (my ($key, $value) = each %{$c->req->params->to_hash}) {
|
|
|
|
# $lets_data{$key} = $value;
|
|
|
|
#}
|
2024-10-18 20:01:59 +02:00
|
|
|
|
|
|
|
# the value of trt will tell you which panel has returned
|
2024-11-13 17:45:14 +01:00
|
|
|
my $trt = $c->param('trt') || 'LIST'; #Indicates where to go now
|
2024-10-18 20:01:59 +02:00
|
|
|
|
|
|
|
# Now add in the params from the selected row from the table
|
|
|
|
|
|
|
|
my %selectedrow;
|
|
|
|
|
|
|
|
if ($trt eq 'LIST'){
|
|
|
|
#Validate form parameters for panel LIST
|
|
|
|
%selectedrow = $c->get_selected_LIST($lets_data{'Selected'},$is_new_record);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($trt eq 'PARAMS'){
|
|
|
|
#Validate form parameters for panel PARAMS
|
|
|
|
%selectedrow = $c->get_selected_PARAMS($lets_data{'Selected'},$is_new_record);
|
|
|
|
}
|
|
|
|
|
2024-11-04 18:08:38 +01:00
|
|
|
if ($trt eq 'CHECKALLDOMAINS'){
|
|
|
|
#Validate form parameters for panel CHECKALLDOMAINS
|
|
|
|
%selectedrow = $c->get_selected_CHECKALLDOMAINS($lets_data{'Selected'},$is_new_record);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($trt eq 'CHECKALLENABLEDDOMAINS'){
|
|
|
|
#Validate form parameters for panel CHECKALLENABLEDDOMAINS
|
|
|
|
%selectedrow = $c->get_selected_CHECKALLENABLEDDOMAINS($lets_data{'Selected'},$is_new_record);
|
|
|
|
}
|
|
|
|
|
2024-11-22 15:00:54 +01:00
|
|
|
if ($trt eq 'CHECKONEDOMAIN'){
|
|
|
|
#Validate form parameters for panel CHECKONEDOMAIN
|
|
|
|
%selectedrow = $c->get_selected_CHECKONEDOMAIN($lets_data{'Selected'},$is_new_record);
|
2024-11-06 16:16:27 +01:00
|
|
|
}
|
|
|
|
|
2024-10-18 20:01:59 +02:00
|
|
|
|
|
|
|
#Copy in the selected row params to the prefix_data hash to pass to the panel
|
|
|
|
while (my ($key, $value) = each %selectedrow){
|
|
|
|
$lets_data{$key} = $value;
|
|
|
|
}
|
|
|
|
# Where to go now
|
|
|
|
$lets_data{'trt'} = $trt;
|
|
|
|
|
2024-11-04 18:08:38 +01:00
|
|
|
# Set up other shared data according to the panel to go to
|
|
|
|
|
|
|
|
if ($trt eq 'LIST'){
|
|
|
|
# pickup any other contents needed and load them into hash shared with panel
|
|
|
|
my %returned_hash;
|
|
|
|
# subroutine returns a hash directly
|
2024-11-22 15:00:54 +01:00
|
|
|
%returned_hash = $c->get_data_for_panel_LIST();
|
2024-11-04 18:08:38 +01:00
|
|
|
# Copy each key-value pair from the returned hash to the prefix data hash
|
|
|
|
while (my ($key, $value) = each %returned_hash) {
|
|
|
|
$lets_data{$key} = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($trt eq 'PARAMS'){
|
|
|
|
# pickup any other contents needed and load them into hash shared with panel
|
|
|
|
my %returned_hash;
|
|
|
|
# subroutine returns a hash directly
|
2024-11-22 15:00:54 +01:00
|
|
|
%returned_hash = $c->get_data_for_panel_PARAMS();
|
2024-11-04 18:08:38 +01:00
|
|
|
# Copy each key-value pair from the returned hash to the prefix data hash
|
|
|
|
while (my ($key, $value) = each %returned_hash) {
|
|
|
|
$lets_data{$key} = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($trt eq 'CHECKALLDOMAINS'){
|
|
|
|
# pickup any other contents needed and load them into hash shared with panel
|
|
|
|
my %returned_hash;
|
|
|
|
# subroutine returns a hash directly
|
2024-11-22 15:00:54 +01:00
|
|
|
%returned_hash = $c->get_data_for_panel_CHECKALLDOMAINS();
|
2024-11-04 18:08:38 +01:00
|
|
|
# Copy each key-value pair from the returned hash to the prefix data hash
|
|
|
|
while (my ($key, $value) = each %returned_hash) {
|
|
|
|
$lets_data{$key} = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($trt eq 'CHECKALLENABLEDDOMAINS'){
|
|
|
|
# pickup any other contents needed and load them into hash shared with panel
|
|
|
|
my %returned_hash;
|
|
|
|
# subroutine returns a hash directly
|
2024-11-22 15:00:54 +01:00
|
|
|
%returned_hash = $c->get_data_for_panel_CHECKALLENABLEDDOMAINS();
|
2024-11-04 18:08:38 +01:00
|
|
|
# Copy each key-value pair from the returned hash to the prefix data hash
|
|
|
|
while (my ($key, $value) = each %returned_hash) {
|
|
|
|
$lets_data{$key} = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-22 15:00:54 +01:00
|
|
|
if ($trt eq 'CHECKONEDOMAIN'){
|
2024-11-06 16:16:27 +01:00
|
|
|
# pickup any other contents needed and load them into hash shared with panel
|
|
|
|
my %returned_hash;
|
|
|
|
# subroutine returns a hash directly
|
2024-11-22 15:00:54 +01:00
|
|
|
%returned_hash = $c->get_data_for_panel_CHECKONEDOMAIN();
|
2024-11-06 16:16:27 +01:00
|
|
|
# Copy each key-value pair from the returned hash to the prefix data hash
|
|
|
|
while (my ($key, $value) = each %returned_hash) {
|
|
|
|
$lets_data{$key} = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-04 18:08:38 +01:00
|
|
|
|
|
|
|
# and table control fields
|
2024-11-22 15:00:54 +01:00
|
|
|
$c->stash(DomainList=>$c->get_DomainList());
|
|
|
|
|
2024-11-04 18:08:38 +01:00
|
|
|
|
2024-10-18 20:01:59 +02:00
|
|
|
# Data for panel
|
|
|
|
$c->stash(
|
|
|
|
title => $title,
|
|
|
|
lets_data => \%lets_data
|
|
|
|
);
|
|
|
|
$c->render("letsencrypt");
|
|
|
|
}
|
2024-11-04 18:08:38 +01:00
|
|
|
1;
|