Add in userpanewl and fix up table sub in template
This commit is contained in:
		
							
								
								
									
										208
									
								
								Targets/Userpanels/Userpanels-Custom.pm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										208
									
								
								Targets/Userpanels/Userpanels-Custom.pm
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,208 @@
 | 
			
		||||
#
 | 
			
		||||
# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-04-23 10:18:18 
 | 
			
		||||
#
 | 
			
		||||
#
 | 
			
		||||
# Routines to be edited by the developer to provide content and validation for parameters
 | 
			
		||||
# and provison of the control data for table(s)
 | 
			
		||||
#
 | 
			
		||||
use esmith::util;
 | 
			
		||||
use esmith::util::network;
 | 
			
		||||
use esmith::ConfigDB;
 | 
			
		||||
use esmith::HostsDB;
 | 
			
		||||
use esmith::AccountsDB;
 | 
			
		||||
use esmith::NetworksDB;
 | 
			
		||||
use esmith::DomainsDB;
 | 
			
		||||
 | 
			
		||||
use constant FALSE => 0;
 | 
			
		||||
use constant TRUE  => 1;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#The most common ones
 | 
			
		||||
#my $cdb 
 | 
			
		||||
#my $adb 
 | 
			
		||||
#my $ndb 
 | 
			
		||||
#my $hdb 
 | 
			
		||||
#my $ddb 
 | 
			
		||||
 | 
			
		||||
# Validation routines - parameters for each panel
 | 
			
		||||
 | 
			
		||||
	sub validate_USERTABLE {
 | 
			
		||||
		my $c = shift;
 | 
			
		||||
		my $prefix_data = shift; #Data hash as parameter
 | 
			
		||||
		# Validation for each field 
 | 
			
		||||
		my $ret = "";
 | 
			
		||||
		
 | 
			
		||||
		if ($ret eq "") {$ret = 'ok';}
 | 
			
		||||
		return $ret;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	sub validate_PANELTABLE {
 | 
			
		||||
		my $c = shift;
 | 
			
		||||
		my $prefix_data = shift; #Data hash as parameter
 | 
			
		||||
		# Validation for each field 
 | 
			
		||||
		my $ret = "";
 | 
			
		||||
		
 | 
			
		||||
		if ($ret eq "") {$ret = 'ok';}
 | 
			
		||||
		return $ret;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Get singleton data for each panel
 | 
			
		||||
 | 
			
		||||
	sub get_data_for_panel_USERTABLE {
 | 
			
		||||
		# Return a hash with the fields required which will be loaded into the shared data 
 | 
			
		||||
		my $c = shift;
 | 
			
		||||
		my %ret = (
 | 
			
		||||
			'Data1'=>'Data for USERTABLE', #Example
 | 
			
		||||
			# fields from Inputs in USERTABLE $fields['USERTABLE']
 | 
			
		||||
			
 | 
			
		||||
		);
 | 
			
		||||
		return %ret;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	sub get_data_for_panel_PANELTABLE {
 | 
			
		||||
		# Return a hash with the fields required which will be loaded into the shared data 
 | 
			
		||||
		my $c = shift;
 | 
			
		||||
		my %ret = (
 | 
			
		||||
			'Data1'=>'Data for PANELTABLE', #Example
 | 
			
		||||
			# fields from Inputs in PANELTABLE $fields['PANELTABLE']
 | 
			
		||||
			
 | 
			
		||||
		);
 | 
			
		||||
		return %ret;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Get control data for table(s)
 | 
			
		||||
 | 
			
		||||
	# Define a constant hash for field name mapping
 | 
			
		||||
	use constant users_FIELD_MAPPING => (
 | 
			
		||||
		'Account' => 'Source-for-Account',
 | 
			
		||||
		'Description' => 'Source-for-Description',
 | 
			
		||||
		'Modify' => 'Source-for-Modify'
 | 
			
		||||
		#'target_field2' => 'source_field2',
 | 
			
		||||
		# Add more mappings as needed
 | 
			
		||||
	);
 | 
			
		||||
	
 | 
			
		||||
sub actual_users {
 | 
			
		||||
	my @ret = ();
 | 
			
		||||
	# Actual code for extracting users
 | 
			
		||||
	return @ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sub get_users {
 | 
			
		||||
    # Return an array of hashes of the contents for each row and column for users
 | 
			
		||||
	my $c = shift;
 | 
			
		||||
    my @source_records = $c->actual_users();
 | 
			
		||||
    my @transformed_records;
 | 
			
		||||
    my %Field_Mapping = users_FIELD_MAPPING;
 | 
			
		||||
    # Iterate over each record in the source array
 | 
			
		||||
    for my $source_record (@$source_records) {
 | 
			
		||||
        my %transformed_record;
 | 
			
		||||
        # Iterate over each key-value pair in the $Field_Mapping constant
 | 
			
		||||
        while (my ($target, $source) = each %Field_Mapping) {
 | 
			
		||||
            # Check if the source field exists in the source record
 | 
			
		||||
            if (exists $source_record->{$source}) {
 | 
			
		||||
                # Assign the source field value to the target field in the transformed record
 | 
			
		||||
                $transformed_record{$target} = $source_record->{$source};
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        # Add transformed record to the array if it's not empty
 | 
			
		||||
        push @transformed_records, \%transformed_record if %transformed_record;
 | 
			
		||||
    }
 | 
			
		||||
    return \@transformed_records;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
	# Define a constant hash for field name mapping
 | 
			
		||||
	use constant panels_FIELD_MAPPING => (
 | 
			
		||||
		'Panel' => 'Source-for-Panel',
 | 
			
		||||
		'Description' => 'Source-for-Description',
 | 
			
		||||
		'Select' => 'Source-for-Select'
 | 
			
		||||
		#'target_field2' => 'source_field2',
 | 
			
		||||
		# Add more mappings as needed
 | 
			
		||||
	);
 | 
			
		||||
	
 | 
			
		||||
sub actual_panels {
 | 
			
		||||
	my @ret = ();
 | 
			
		||||
	# Actual code for extracting panels
 | 
			
		||||
	return @ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sub get_panels {
 | 
			
		||||
    # Return an array of hashes of the contents for each row and column for panels
 | 
			
		||||
	my $c = shift;
 | 
			
		||||
    my @source_records = $c->actual_panels();
 | 
			
		||||
    my @transformed_records;
 | 
			
		||||
    my %Field_Mapping = panels_FIELD_MAPPING;
 | 
			
		||||
    # Iterate over each record in the source array
 | 
			
		||||
    for my $source_record (@$source_records) {
 | 
			
		||||
        my %transformed_record;
 | 
			
		||||
        # Iterate over each key-value pair in the $Field_Mapping constant
 | 
			
		||||
        while (my ($target, $source) = each %Field_Mapping) {
 | 
			
		||||
            # Check if the source field exists in the source record
 | 
			
		||||
            if (exists $source_record->{$source}) {
 | 
			
		||||
                # Assign the source field value to the target field in the transformed record
 | 
			
		||||
                $transformed_record{$target} = $source_record->{$source};
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        # Add transformed record to the array if it's not empty
 | 
			
		||||
        push @transformed_records, \%transformed_record if %transformed_record;
 | 
			
		||||
    }
 | 
			
		||||
    return \@transformed_records;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Return hash with values from row in which link clicked on table
 | 
			
		||||
 | 
			
		||||
	sub get_selected_USERTABLE {
 | 
			
		||||
		my $c = shift;
 | 
			
		||||
		my $selected = shift; #Parameter is name of selected row.
 | 
			
		||||
		my $is_new_record = shift; #Indicates new record required (defaults)
 | 
			
		||||
		my %ret = {};
 | 
			
		||||
		return %ret;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	sub get_selected_PANELTABLE {
 | 
			
		||||
		my $c = shift;
 | 
			
		||||
		my $selected = shift; #Parameter is name of selected row.
 | 
			
		||||
		my $is_new_record = shift; #Indicates new record required (defaults)
 | 
			
		||||
		my %ret = {};
 | 
			
		||||
		return %ret;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#after sucessful modify or create or whatever and submit then perfom (if the params validate)
 | 
			
		||||
 | 
			
		||||
	sub perform_USERTABLE {
 | 
			
		||||
		my $c = shift;
 | 
			
		||||
		my $prefix_data = shift; #Data hash as parameter
 | 
			
		||||
		my $ret = "";
 | 
			
		||||
		my $db = $cdb; #maybe one of the others
 | 
			
		||||
		my $dbkey = 'ChangeThis';
 | 
			
		||||
		# To make it write to DB as comment, delete this (regex) string in each if statement "TRUE\) \#copy or perform with value: .* e.g."
 | 
			
		||||
		
 | 
			
		||||
		if ($ret eq "") {$ret = 'ok';}
 | 
			
		||||
		return $ret;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	sub perform_PANELTABLE {
 | 
			
		||||
		my $c = shift;
 | 
			
		||||
		my $prefix_data = shift; #Data hash as parameter
 | 
			
		||||
		my $ret = "";
 | 
			
		||||
		my $db = $cdb; #maybe one of the others
 | 
			
		||||
		my $dbkey = 'ChangeThis';
 | 
			
		||||
		# To make it write to DB as comment, delete this (regex) string in each if statement "TRUE\) \#copy or perform with value: .* e.g."
 | 
			
		||||
		
 | 
			
		||||
		if ($ret eq "") {$ret = 'ok';}
 | 
			
		||||
		return $ret;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
sub create_link{
 | 
			
		||||
	# WIP
 | 
			
		||||
	my ($c,$route, $panel, $index) = @_;
 | 
			
		||||
	my $link = "$route?trt=$panel&Selected=$index";
 | 
			
		||||
	return $link;
 | 
			
		||||
}
 | 
			
		||||
1;
 | 
			
		||||
							
								
								
									
										317
									
								
								Targets/Userpanels/Userpanels.pm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										317
									
								
								Targets/Userpanels/Userpanels.pm
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,317 @@
 | 
			
		||||
package SrvMngr::Controller::Userpanels;
 | 
			
		||||
#
 | 
			
		||||
# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-04-23 10:18:18 
 | 
			
		||||
#
 | 
			
		||||
#----------------------------------------------------------------------
 | 
			
		||||
# heading     : System
 | 
			
		||||
# description : User panel access 
 | 
			
		||||
# navigation  : 2000 400
 | 
			
		||||
#
 | 
			
		||||
# name : userpanels,    method : get,   url : /userpanels,   ctlact : Userpanels#main
 | 
			
		||||
# name : userpanelsu,   method : post,  url : /userpanelsu,  ctlact : Userpanels#do_update
 | 
			
		||||
# name : userpanelsd,   method : get,   url : /userpanelsd,  ctlact : Userpanels#do_display
 | 
			
		||||
#
 | 
			
		||||
# routes : end
 | 
			
		||||
#
 | 
			
		||||
# Documentation: https://wiki.contribs.org/Userpanels
 | 
			
		||||
#----------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# 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;
 | 
			
		||||
use esmith::util::network;
 | 
			
		||||
use esmith::ConfigDB;
 | 
			
		||||
use esmith::AccountsDB;
 | 
			
		||||
use esmith::NetworksDB;
 | 
			
		||||
use esmith::HostsDB;
 | 
			
		||||
use esmith::DomainsDB;
 | 
			
		||||
 | 
			
		||||
my $cdb;
 | 
			
		||||
my $adb;
 | 
			
		||||
my $ndb; 
 | 
			
		||||
my $hdb; 
 | 
			
		||||
my $ddb; 
 | 
			
		||||
 | 
			
		||||
require '/usr/share/smanager/lib/SrvMngr/Controller/Userpanels-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 );
 | 
			
		||||
 | 
			
		||||
	#The most common ones
 | 
			
		||||
	 $cdb = esmith::ConfigDB->open()   || die("Couldn't open config db");
 | 
			
		||||
	 $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
 | 
			
		||||
	 $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
 | 
			
		||||
	 $hdb = esmith::HostsDB->open() 	  || die("Couldn't open Hosts db");
 | 
			
		||||
	 $ddb = esmith::DomainsDB->open()  || die("Couldn't open Domains db");
 | 
			
		||||
 | 
			
		||||
    my %usp_data = ();
 | 
			
		||||
    my $title = $c->l('usp_User_panel_access_');
 | 
			
		||||
    my $modul = '';
 | 
			
		||||
 | 
			
		||||
    $usp_data{'trt'} = 'USERTABLE';
 | 
			
		||||
    
 | 
			
		||||
    #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
 | 
			
		||||
    
 | 
			
		||||
	
 | 
			
		||||
	$c->do_display($usp_data{'trt'});
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# 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 $modul = '';
 | 
			
		||||
 | 
			
		||||
	#The most common ones - you might want to comment out any not used.
 | 
			
		||||
	$cdb = esmith::ConfigDB->open()   || die("Couldn't open config db");
 | 
			
		||||
	$adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
 | 
			
		||||
	$ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
 | 
			
		||||
	$hdb = esmith::HostsDB->open() 	  || die("Couldn't open Hosts db");
 | 
			
		||||
	$ddb = esmith::DomainsDB->open()  || die("Couldn't open Domains db");
 | 
			
		||||
 | 
			
		||||
    my %usp_data = ();
 | 
			
		||||
    my $title = $c->l('usp_User_panel_access_');
 | 
			
		||||
 | 
			
		||||
	# Accessing all POST/GET parameters
 | 
			
		||||
    my $params = $c->req->params->to_hash;
 | 
			
		||||
 | 
			
		||||
    # Get number of POST parameters
 | 
			
		||||
    #my $num_params = keys scaler %$params;
 | 
			
		||||
    
 | 
			
		||||
    #Params are available in the hash "params" - copy to the prefix_data hash
 | 
			
		||||
    #while (my ($key, $value) = each %{$c->req->params->to_hash}) {
 | 
			
		||||
    #    $usp_data{$key} = $value;
 | 
			
		||||
    #}
 | 
			
		||||
 | 
			
		||||
    # the value of trt will tell you which panel has returned    
 | 
			
		||||
    my $trt = $c->param('trt') || 'USERTABLE'; #hidden control on every form.
 | 
			
		||||
    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 'USERTABLE'){
 | 
			
		||||
			#Validate form parameters for panel USERTABLE
 | 
			
		||||
			$ret = $c->validate_USERTABLE(\%usp_data);
 | 
			
		||||
			$thispanel = 'USERTABLE';
 | 
			
		||||
		}
 | 
			
		||||
	
 | 
			
		||||
		if ($trt eq 'PANELTABLE'){
 | 
			
		||||
			#Validate form parameters for panel PANELTABLE
 | 
			
		||||
			$ret = $c->validate_PANELTABLE(\%usp_data);
 | 
			
		||||
			$thispanel = 'PANELTABLE';
 | 
			
		||||
		}
 | 
			
		||||
	
 | 
			
		||||
	if ($ret ne "ok"){
 | 
			
		||||
		$c->do_display($thispanel);
 | 
			
		||||
	} else {
 | 
			
		||||
		#Do whatever is needed, including writing values to the DB
 | 
			
		||||
		
 | 
			
		||||
		
 | 
			
		||||
			if ($trt eq 'USERTABLE'){
 | 
			
		||||
				#do whatever is required ...
 | 
			
		||||
				$ret = $c->perform_USERTABLE(\%usp_data);
 | 
			
		||||
				if ($ret ne "ok") {
 | 
			
		||||
					# return to the panel with error message
 | 
			
		||||
					$c->stash(error => $c->l($ret));
 | 
			
		||||
					$c->stash( 
 | 
			
		||||
						title => $title, 
 | 
			
		||||
						modul => $modul,
 | 
			
		||||
						usp_data  => \%usp_data
 | 
			
		||||
					);
 | 
			
		||||
					$c->render(template => "userpanels");	
 | 
			
		||||
				} else {
 | 
			
		||||
					$c->stash( success => $c->l('usp_USERTABLE_panel_action_was_successful')); #A bit bland - edit it in the lex file
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		
 | 
			
		||||
			if ($trt eq 'PANELTABLE'){
 | 
			
		||||
				#do whatever is required ...
 | 
			
		||||
				$ret = $c->perform_PANELTABLE(\%usp_data);
 | 
			
		||||
				if ($ret ne "ok") {
 | 
			
		||||
					# return to the panel with error message
 | 
			
		||||
					$c->stash(error => $c->l($ret));
 | 
			
		||||
					$c->stash( 
 | 
			
		||||
						title => $title, 
 | 
			
		||||
						modul => $modul,
 | 
			
		||||
						usp_data  => \%usp_data
 | 
			
		||||
					);
 | 
			
		||||
					$c->render(template => "userpanels");	
 | 
			
		||||
				} else {
 | 
			
		||||
					$c->stash( success => $c->l('usp_PANELTABLE_panel_action_was_successful')); #A bit bland - edit it in the lex file
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		
 | 
			
		||||
		# and call any signal-events needed
 | 
			
		||||
		#TBD
 | 
			
		||||
		# Setup shared data and call panel
 | 
			
		||||
		if ('none' eq 'none') {
 | 
			
		||||
			$usp_data{'trt'} = 'USERTABLE';
 | 
			
		||||
		} else {
 | 
			
		||||
			$usp_data{'trt'} = 'none';
 | 
			
		||||
		}	
 | 
			
		||||
		$c->do_display($usp_data{'trt'});
 | 
			
		||||
	} 
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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,$trt) = @_;
 | 
			
		||||
    $c->app->log->info($c->log_req);
 | 
			
		||||
 | 
			
		||||
	#The most common ones - you might want to comment out any not used.
 | 
			
		||||
	$cdb = esmith::ConfigDB->open()   || die("Couldn't open config db");
 | 
			
		||||
	$adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
 | 
			
		||||
	$ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
 | 
			
		||||
	$hdb = esmith::HostsDB->open() 	  || die("Couldn't open Hosts db");
 | 
			
		||||
	$ddb = esmith::DomainsDB->open()  || die("Couldn't open Domains db");
 | 
			
		||||
    
 | 
			
		||||
    my %usp_data = ();
 | 
			
		||||
    my $title = $c->l('usp_User_panel_access_');
 | 
			
		||||
    my $modul = "";
 | 
			
		||||
 | 
			
		||||
	# 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
 | 
			
		||||
    #while (my ($key, $value) = each %{$c->req->params->to_hash}) {
 | 
			
		||||
    #    $usp_data{$key} = $value;
 | 
			
		||||
    #}
 | 
			
		||||
 | 
			
		||||
    # the value of trt will tell you which panel has returned   
 | 
			
		||||
    if (! $trt){ 
 | 
			
		||||
		$trt = $c->param('trt') || 'USERTABLE'; #Indicates where to go now
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
    # Now add in the params from the selected row from the table
 | 
			
		||||
		
 | 
			
		||||
    my %selectedrow;
 | 
			
		||||
    
 | 
			
		||||
		if ($trt eq 'USERTABLE'){
 | 
			
		||||
			#Validate Get selected row (if applicable)  USERTABLE
 | 
			
		||||
				%selectedrow = $c->get_selected_USERTABLE($usp_data{'Selected'},$is_new_record);
 | 
			
		||||
		}
 | 
			
		||||
	
 | 
			
		||||
		if ($trt eq 'PANELTABLE'){
 | 
			
		||||
			#Validate Get selected row (if applicable)  PANELTABLE
 | 
			
		||||
				%selectedrow = $c->get_selected_PANELTABLE($usp_data{'Selected'},$is_new_record);
 | 
			
		||||
		}
 | 
			
		||||
	
 | 
			
		||||
 
 | 
			
		||||
	#Copy in the selected row params to the prefix_data hash to pass to the panel
 | 
			
		||||
	while (my ($key, $value) = each %selectedrow){
 | 
			
		||||
        $usp_data{$key} = $value;
 | 
			
		||||
    }
 | 
			
		||||
	# Where to go now
 | 
			
		||||
	$usp_data{'trt'} = $trt;
 | 
			
		||||
	
 | 
			
		||||
	# Set up other shared data according to the panel to go to
 | 
			
		||||
    
 | 
			
		||||
		if ($trt eq 'USERTABLE'){
 | 
			
		||||
			# pickup any other contents needed and load them into hash shared with panel
 | 
			
		||||
			my %returned_hash;
 | 
			
		||||
			# subroutine returns a hash directly
 | 
			
		||||
			%returned_hash = $c->get_data_for_panel_USERTABLE();
 | 
			
		||||
			# Copy each key-value pair from the returned hash to the prefix data hash
 | 
			
		||||
			while (my ($key, $value) = each %returned_hash) {
 | 
			
		||||
				$usp_data{$key} = $value;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	
 | 
			
		||||
		if ($trt eq 'PANELTABLE'){
 | 
			
		||||
			# pickup any other contents needed and load them into hash shared with panel
 | 
			
		||||
			my %returned_hash;
 | 
			
		||||
			# subroutine returns a hash directly
 | 
			
		||||
			%returned_hash = $c->get_data_for_panel_PANELTABLE();
 | 
			
		||||
			# Copy each key-value pair from the returned hash to the prefix data hash
 | 
			
		||||
			while (my ($key, $value) = each %returned_hash) {
 | 
			
		||||
				$usp_data{$key} = $value;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
	# and table control fields
 | 
			
		||||
     $c->stash(users=>$c->get_users());
 | 
			
		||||
     $c->stash(panels=>$c->get_panels());
 | 
			
		||||
     
 | 
			
		||||
	
 | 
			
		||||
	# Data for panel
 | 
			
		||||
	$c->stash( 
 | 
			
		||||
		title 			=> $title, 
 | 
			
		||||
		modul => $modul,
 | 
			
		||||
		usp_data  => \%usp_data
 | 
			
		||||
	);
 | 
			
		||||
	$c->render(template => "userpanels");
 | 
			
		||||
}    
 | 
			
		||||
1;
 | 
			
		||||
							
								
								
									
										52
									
								
								Targets/Userpanels/_usp_PANELTABLE.html.ep
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								Targets/Userpanels/_usp_PANELTABLE.html.ep
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,52 @@
 | 
			
		||||
%#
 | 
			
		||||
%# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-04-23 10:18:18 
 | 
			
		||||
%#
 | 
			
		||||
<div id="Userpanels-PANELTABLE" class="partial Userpanels-PANELTABLE">
 | 
			
		||||
	<script>
 | 
			
		||||
		window.onload = function() {
 | 
			
		||||
		SelectInput();
 | 
			
		||||
	};
 | 
			
		||||
	</script>
 | 
			
		||||
	% if (config->{debug} == 1) {
 | 
			
		||||
		<pre>
 | 
			
		||||
			%= dumper $usp_data
 | 
			
		||||
		</pre>
 | 
			
		||||
	% }
 | 
			
		||||
	% my $btn = l('usp_APPLY');
 | 
			
		||||
	%= form_for "userpanelsu" => (method => 'POST') => begin
 | 
			
		||||
		% param 'trt' => $usp_data->{trt} unless param 'trt';
 | 
			
		||||
		%= hidden_field 'trt' => $usp_data->{trt}
 | 
			
		||||
		%# Inputs etc in here.
 | 
			
		||||
 | 
			
		||||
		<h1 class='head'><%=l('usp_Allocate_panels_to_a_user')%></h1>
 | 
			
		||||
	
 | 
			
		||||
		<h2 class='subh'><%=l('usp_Select_panels_for_user')%></h2>
 | 
			
		||||
	
 | 
			
		||||
		<br /><table class="sme-border TableSort sme-table tabl2 ">
 | 
			
		||||
			<thead class='tabl2'>
 | 
			
		||||
				<tr table-head-row>
 | 
			
		||||
					<th class='sme-border table-head-col table-head-col-Panel '><%=l('Panel')%></th>
 | 
			
		||||
					<th class='sme-border table-head-col table-head-col-Description '><%=l('usp_Description')%></th>
 | 
			
		||||
					<th class='sme-border table-head-col table-head-col-Select '><%=l('usp_Select')%></th>
 | 
			
		||||
				</tr>
 | 
			
		||||
			</thead>
 | 
			
		||||
			<tbody class='tabl2'>
 | 
			
		||||
				% my $control_data = $c->stash('panels');
 | 
			
		||||
				% foreach my $row (@$control_data) {
 | 
			
		||||
				<tr class='table-row'>
 | 
			
		||||
					<td class='sme-border table-col table-col-Panel'><%=$c->render_to_string(inline=>$row->{'Panel'})%></td>
 | 
			
		||||
					<td class='sme-border table-col table-col-Description'><%=$c->render_to_string(inline=>$row->{'Description'})%></td>
 | 
			
		||||
					<td class='sme-border table-col table-col-Select'><%=$c->render_to_string(inline=>$row->{'Select'})%></td>		
 | 
			
		||||
				</tr>
 | 
			
		||||
				%}
 | 
			
		||||
			</tbody>
 | 
			
		||||
		</table>
 | 
			
		||||
		
 | 
			
		||||
	
 | 
			
		||||
		<span class='data'>
 | 
			
		||||
			%= submit_button l('usp_Save'), class => 'action subm'
 | 
			
		||||
		</span>
 | 
			
		||||
	
 | 
			
		||||
		%# Probably finally by a submit.
 | 
			
		||||
	%end    
 | 
			
		||||
</div>
 | 
			
		||||
							
								
								
									
										52
									
								
								Targets/Userpanels/_usp_USERTABLE.html.ep
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								Targets/Userpanels/_usp_USERTABLE.html.ep
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,52 @@
 | 
			
		||||
%#
 | 
			
		||||
%# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-04-23 10:18:18 
 | 
			
		||||
%#
 | 
			
		||||
<div id="Userpanels-USERTABLE" class="partial Userpanels-USERTABLE">
 | 
			
		||||
	<script>
 | 
			
		||||
		window.onload = function() {
 | 
			
		||||
		SelectInput();
 | 
			
		||||
	};
 | 
			
		||||
	</script>
 | 
			
		||||
	% if (config->{debug} == 1) {
 | 
			
		||||
		<pre>
 | 
			
		||||
			%= dumper $usp_data
 | 
			
		||||
		</pre>
 | 
			
		||||
	% }
 | 
			
		||||
	% my $btn = l('usp_APPLY');
 | 
			
		||||
	%= form_for "userpanelsu" => (method => 'POST') => begin
 | 
			
		||||
		% param 'trt' => $usp_data->{trt} unless param 'trt';
 | 
			
		||||
		%= hidden_field 'trt' => $usp_data->{trt}
 | 
			
		||||
		%# Inputs etc in here.
 | 
			
		||||
 | 
			
		||||
		<h1 class='head'><%=l('usp_Allocate_panels_to_a_user')%></h1>
 | 
			
		||||
	
 | 
			
		||||
		<h2 class='subh'><%=l('usp_Choose_a_user')%></h2>
 | 
			
		||||
	
 | 
			
		||||
		<p class='paragraph para1'>
 | 
			
		||||
			%=l('usp_You_can_modify_individual_users')
 | 
			
		||||
		</p>
 | 
			
		||||
	
 | 
			
		||||
		<br /><table class="sme-border TableSort sme-table tabl1 ">
 | 
			
		||||
			<thead class='tabl1'>
 | 
			
		||||
				<tr table-head-row>
 | 
			
		||||
					<th class='sme-border table-head-col table-head-col-Account '><%=l('usp_Account')%></th>
 | 
			
		||||
					<th class='sme-border table-head-col table-head-col-Name/Description '><%=l('usp_Name/Description')%></th>
 | 
			
		||||
					<th class='sme-border table-head-col table-head-col-Modify '><%=l('usp_Modify')%></th>
 | 
			
		||||
				</tr>
 | 
			
		||||
			</thead>
 | 
			
		||||
			<tbody class='tabl1'>
 | 
			
		||||
				% my $control_data = $c->stash('users');
 | 
			
		||||
				% foreach my $row (@$control_data) {
 | 
			
		||||
				<tr class='table-row'>
 | 
			
		||||
					<td class='sme-border table-col table-col-Account'><%=$c->render_to_string(inline=>$row->{'Account'})%></td>
 | 
			
		||||
					<td class='sme-border table-col table-col-Description'><%=$c->render_to_string(inline=>$row->{'Description'})%></td>
 | 
			
		||||
					<td class='sme-border table-col table-col-Modify'><%=$c->render_to_string(inline=>$row->{'Modify'})%></td>		
 | 
			
		||||
				</tr>
 | 
			
		||||
				%}
 | 
			
		||||
			</tbody>
 | 
			
		||||
		</table>
 | 
			
		||||
		
 | 
			
		||||
	
 | 
			
		||||
		%# Probably finally by a submit.
 | 
			
		||||
	%end    
 | 
			
		||||
</div>
 | 
			
		||||
							
								
								
									
										20
									
								
								Targets/Userpanels/userpanels.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								Targets/Userpanels/userpanels.css
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
/*
 | 
			
		||||
Generated by: SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-04-23 10:18:18
 | 
			
		||||
*/
 | 
			
		||||
.Userpanels-panel {}
 | 
			
		||||
.name {}
 | 
			
		||||
.rout {}
 | 
			
		||||
.head {}
 | 
			
		||||
.subh {}
 | 
			
		||||
.para1 {}
 | 
			
		||||
.tabl1 {}
 | 
			
		||||
thead .tabl1 {}
 | 
			
		||||
tbody .tabl1 {}
 | 
			
		||||
.name {}
 | 
			
		||||
.rout {}
 | 
			
		||||
.head {}
 | 
			
		||||
.subh {}
 | 
			
		||||
.tabl2 {}
 | 
			
		||||
thead .tabl2 {}
 | 
			
		||||
tbody .tabl2 {}
 | 
			
		||||
.subm {}
 | 
			
		||||
							
								
								
									
										60
									
								
								Targets/Userpanels/userpanels.html.ep
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								Targets/Userpanels/userpanels.html.ep
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,60 @@
 | 
			
		||||
%#
 | 
			
		||||
%# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-04-23 10:18:18 
 | 
			
		||||
%#
 | 
			
		||||
% layout 'default', title => "Sme server 2 - User panel access ", share_dir => './';
 | 
			
		||||
%# css specific to this panel:
 | 
			
		||||
% content_for 'module' => begin
 | 
			
		||||
%= stylesheet '/css/userpanels.css'
 | 
			
		||||
%= javascript '/js/userpanels.js'
 | 
			
		||||
<div id="module" class="module Userpanels-panel">
 | 
			
		||||
 | 
			
		||||
    % if (config->{debug} == 1) {
 | 
			
		||||
	<pre>
 | 
			
		||||
		%= dumper $c->current_route
 | 
			
		||||
		%= dumper $usp_data->{trt}
 | 
			
		||||
	</pre>
 | 
			
		||||
    % }
 | 
			
		||||
    
 | 
			
		||||
    <h1><%=$title%></h1>
 | 
			
		||||
 | 
			
		||||
    % if ( stash('modul')) {
 | 
			
		||||
	%= $c->render_to_string(inline => stash('modul') );
 | 
			
		||||
    % }
 | 
			
		||||
 | 
			
		||||
   	%if ($c->stash('first')) {
 | 
			
		||||
	    <br><p>
 | 
			
		||||
		%=$c->render_to_string(inline =>$c->l($c->stash('first')))
 | 
			
		||||
		</p>
 | 
			
		||||
 | 
			
		||||
	%} elsif ($c->stash('success')) {
 | 
			
		||||
		<div class='success '>
 | 
			
		||||
			<p>
 | 
			
		||||
				%= $c->l($c->stash('success'));
 | 
			
		||||
			</p>
 | 
			
		||||
		</div>
 | 
			
		||||
		<br />
 | 
			
		||||
 | 
			
		||||
	%} elsif ($c->stash('error')) { 
 | 
			
		||||
	   <div class='sme-error'>
 | 
			
		||||
			<p>
 | 
			
		||||
				%= $c->l($c->stash('error'));
 | 
			
		||||
			</p>
 | 
			
		||||
    	</div>
 | 
			
		||||
		<br />
 | 
			
		||||
	%}
 | 
			
		||||
 | 
			
		||||
	%#Routing to partials according to trt parameter.
 | 
			
		||||
	%#This ought to be cascading if/then/elsif, but is easier to just stack the if/then's rather like a case statement'
 | 
			
		||||
	
 | 
			
		||||
	% if ($usp_data->{trt} eq "USERTABLE") {
 | 
			
		||||
		%= include 'partials/_usp_USERTABLE'
 | 
			
		||||
	%}
 | 
			
		||||
	
 | 
			
		||||
	% if ($usp_data->{trt} eq "PANELTABLE") {
 | 
			
		||||
		%= include 'partials/_usp_PANELTABLE'
 | 
			
		||||
	%}
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
</div>
 | 
			
		||||
%end
 | 
			
		||||
							
								
								
									
										5
									
								
								Targets/Userpanels/userpanels.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								Targets/Userpanels/userpanels.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
//
 | 
			
		||||
//Generated by: SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-04-23 10:18:18
 | 
			
		||||
//
 | 
			
		||||
$(document).ready(function() {
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										18
									
								
								Targets/Userpanels/userpanels_en.lex
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								Targets/Userpanels/userpanels_en.lex
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
#
 | 
			
		||||
# Generated by SM2Gen version: SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-04-23 10:18:18
 | 
			
		||||
#
 | 
			
		||||
'usp_><%=l('Panel' => '><%=l('panel',
 | 
			
		||||
'usp_PANELTABLE_panel_action_was_successful' => 'PANELTABLE panel action was successful',
 | 
			
		||||
'usp_Choose_a_user' => 'Choose a user',
 | 
			
		||||
'usp_Select_panels_for_user' => 'Select panels for user',
 | 
			
		||||
'usp_Save' => 'Save',
 | 
			
		||||
'usp_Description' => 'Description',
 | 
			
		||||
'usp_USERTABLE_panel_action_was_successful' => 'USERTABLE panel action was successful',
 | 
			
		||||
'usp_Allocate_panels_to_a_user' => 'Allocate panels to a user',
 | 
			
		||||
'usp_APPLY' => 'Apply',
 | 
			
		||||
'usp_You_can_modify_individual_users' => 'You can modify individual users access to the server-manager panels below by clicking on the link next the account You can assign panels to the members of a group with their link Users or Groups in red have some form of extra access You can globally assign a panel by editing the global account',
 | 
			
		||||
'usp_Account' => 'Account',
 | 
			
		||||
'usp_Select' => 'Select',
 | 
			
		||||
'usp_User_panel_access_' => 'User panel access',
 | 
			
		||||
'usp_Name/Description' => 'Name/description',
 | 
			
		||||
'usp_Modify' => 'Modify',
 | 
			
		||||
@@ -76,9 +76,9 @@ sub get_${tablecontrol[0]} {
 | 
			
		||||
	my $c = shift;
 | 
			
		||||
    my @source_records = $c->actual_${tablecontrol[0]}();
 | 
			
		||||
    my @transformed_records;
 | 
			
		||||
    my %Field_Mapping = ${tablecontrol[0]}_FIELD_MAPPING;
 | 
			
		||||
    my %Field_Mapping = ${tablecontrol[0]}_FIELD_MAPPING();
 | 
			
		||||
    # Iterate over each record in the source array
 | 
			
		||||
    for my $source_record (@$source_records) {
 | 
			
		||||
    for my $source_record (@source_records) {
 | 
			
		||||
        my %transformed_record;
 | 
			
		||||
        # Iterate over each key-value pair in the $Field_Mapping constant
 | 
			
		||||
        while (my ($target, $source) = each %Field_Mapping) {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										36
									
								
								json5/Userpanels.json5
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								json5/Userpanels.json5
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
{
 | 
			
		||||
  PackageName: 'Userpanels',
 | 
			
		||||
  prefix: 'usp',
 | 
			
		||||
  MenuHeading: 'System',
 | 
			
		||||
  MenuDescription: 'User panel access ',
 | 
			
		||||
  MenuNavigation: '2000 400',
 | 
			
		||||
  firstPanel: 'USERTABLE',
 | 
			
		||||
  signalEvent: 'smeserver-userpanels-update',
 | 
			
		||||
  html: [ {
 | 
			
		||||
      Name: 'usertable',
 | 
			
		||||
      route: 'USERTABLE',
 | 
			
		||||
      Header: 'Allocate panels to a user',
 | 
			
		||||
      SubHeader: 'Choose a user',
 | 
			
		||||
      Paragraph1: 'You can modify individual users access to the server-manager panels below by clicking on the link next the account. You can assign panels to the members of a group with their link. Users or Groups in red have some form of extra access. You can globally assign a panel by editing the global account',
 | 
			
		||||
      Table1: {
 | 
			
		||||
		  Type:'Table',
 | 
			
		||||
		  TableControl:"users",
 | 
			
		||||
		  TopHeadings: ['Account','Name/Description','Modify'],
 | 
			
		||||
		  Columns: ['Account','Description','Modify']
 | 
			
		||||
	  }
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      Name: 'paneltable',
 | 
			
		||||
      route:'PANELTABLE',
 | 
			
		||||
      Header: 'Allocate panels to a user',
 | 
			
		||||
      SubHeader: 'Select panels for user',
 | 
			
		||||
      Table2: {
 | 
			
		||||
		  Type:'Table',
 | 
			
		||||
		  TableControl:"panels",
 | 
			
		||||
		  TopHeadings: ['Panel','Description','Select'],
 | 
			
		||||
		  Columns: ['Panel','Description','Select']
 | 
			
		||||
	  },
 | 
			
		||||
      Submit: 'Save',
 | 
			
		||||
    }
 | 
			
		||||
    ]
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										22
									
								
								snapshot.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								snapshot.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
{
 | 
			
		||||
    "timestamp": 1744101733.740629,
 | 
			
		||||
    "devices": [
 | 
			
		||||
        {
 | 
			
		||||
            "id": "bf6d349c2d491149a8od3f",
 | 
			
		||||
            "ip": "192.168.1.157",
 | 
			
		||||
            "active": 2,
 | 
			
		||||
            "encrypt": true,
 | 
			
		||||
            "productKey": "qar5l7m9uda7tfa7",
 | 
			
		||||
            "token": true,
 | 
			
		||||
            "wf_cfg": true,
 | 
			
		||||
            "clientLink": 3,
 | 
			
		||||
            "name": "",
 | 
			
		||||
            "key": "",
 | 
			
		||||
            "mac": "",
 | 
			
		||||
            "ability": 0,
 | 
			
		||||
            "dev_type": "default",
 | 
			
		||||
            "origin": "broadcast",
 | 
			
		||||
            "ver": "3.4"
 | 
			
		||||
        }
 | 
			
		||||
    ]
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user