SM2Gen/Targets/Mailsorting/Mailsorting-Custom.pm

289 lines
9.7 KiB
Perl
Raw Normal View History

#
# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-05-04 12:59:05
#
#
# 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_TABLE {
my $c = shift;
my $ms_data = shift; #Data hash as parameter
# Validation for each field
my $ret = "";
if (! TRUE) #validate $c->param('account')
{$ret .= 'Validation for account failed';}
if (! TRUE) #validate $c->param('username')
{$ret .= 'Validation for username failed';}
if ($ret eq "") {$ret = 'ok';}
return $ret;
}
sub validate_RULES {
my $c = shift;
my $ms_data = shift; #Data hash as parameter
# Validation for each field
my $ret = "";
if (! TRUE) #validate $c->param('basis')
{$ret .= 'Validation for basis failed';}
if (! TRUE) #validate $c->param('criterion')
{$ret .= 'Validation for criterion failed';}
if (! TRUE) #validate $c->param('basis2')
{$ret .= 'Validation for basis2 failed';}
if (! TRUE) #validate $c->param('criterion2')
{$ret .= 'Validation for criterion2 failed';}
if (! TRUE) #validate $c->param('action')
{$ret .= 'Validation for action failed';}
if (! TRUE) #validate $c->param('deliver')
{$ret .= 'Validation for deliver failed';}
if (! TRUE) #validate $c->param('folder')
{$ret .= 'Validation for folder failed';}
if (! TRUE) #validate $c->param('copy')
{$ret .= 'Validation for copy failed';}
if (! TRUE) #validate $c->param('action2')
{$ret .= 'Validation for action2 failed';}
if (! TRUE) #validate $c->param('deliver2')
{$ret .= 'Validation for deliver2 failed';}
if (! TRUE) #validate $c->param('key')
{$ret .= 'Validation for key failed';}
if ($ret eq "") {$ret = 'ok';}
return $ret;
}
sub validate_REMOVE {
my $c = shift;
my $ms_data = shift; #Data hash as parameter
# Validation for each field
my $ret = "";
if (! TRUE) #validate $c->param('RemoveRule')
{$ret .= 'Validation for RemoveRule failed';}
if ($ret eq "") {$ret = 'ok';}
return $ret;
}
# Get singleton data for each panel
sub get_data_for_panel_TABLE {
# Return a hash with the fields required which will be loaded into the shared data
my $c = shift;
my %ret = (
'Data1'=>'Data for TABLE', #Example
# fields from Inputs in TABLE $fields['TABLE']
'account'=>'account contents',
'username'=>'username contents',
);
return %ret;
}
sub get_data_for_panel_RULES {
# Return a hash with the fields required which will be loaded into the shared data
my $c = shift;
my %ret = (
'Data1'=>'Data for RULES', #Example
# fields from Inputs in RULES $fields['RULES']
'basis'=>'basis contents',
'criterion'=>'criterion contents',
'basis2'=>'basis2 contents',
'criterion2'=>'criterion2 contents',
'action'=>'action contents',
'deliver'=>'deliver contents',
'folder'=>'folder contents',
'copy'=>'copy contents',
'action2'=>'action2 contents',
'deliver2'=>'deliver2 contents',
'key'=>'key contents',
);
return %ret;
}
sub get_data_for_panel_REMOVE {
# Return a hash with the fields required which will be loaded into the shared data
my $c = shift;
my %ret = (
'Data1'=>'Data for REMOVE', #Example
# fields from Inputs in REMOVE $fields['REMOVE']
'RemoveRule'=>'RemoveRule contents',
);
return %ret;
}
# Get control data for table(s)
# Define a constant hash for field name mapping
use constant getAllRules_FIELD_MAPPING => (
'MatchAgainst' => 'Source-for-MatchAgainst',
'TheRule' => 'Source-for-TheRule',
'c2ndMatch' => 'Source-for-c2ndMatch',
'c2ndRule' => 'Source-for-c2ndRule',
'Action' => 'Source-for-Action',
'Destination' => 'Source-for-Destination',
'Copy' => 'Source-for-Copy',
'Destination' => 'Source-for-Destination',
'Serial Number' => 'Source-for-Serial Number',
'Modify' => 'Source-for-Modify',
'Remove' => 'Source-for-Remove'
#'target_field2' => 'source_field2',
# Add more mappings as needed
);
sub actual_getAllRules {
my @ret = ();
# Actual code for extracting getAllRules
return @ret;
}
sub get_getAllRules {
# Return an array of hashes of the contents for each row and column for getAllRules
my $c = shift;
my @source_records = $c->actual_getAllRules();
my @transformed_records;
my %Field_Mapping = getAllRules_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_TABLE {
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_RULES {
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_REMOVE {
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_TABLE {
my $c = shift;
my $ms_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 (! TRUE) #copy or perform with value: account e.g. $db->set_prop($dbkey,'account',$c->param('account'),type=>'service'))
{$ret .= 'Perform/save failed for account';}
if (! TRUE) #copy or perform with value: username e.g. $db->set_prop($dbkey,'username',$c->param('username'),type=>'service'))
{$ret .= 'Perform/save failed for username';}
if ($ret eq "") {$ret = 'ok';}
return $ret;
}
sub perform_RULES {
my $c = shift;
my $ms_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 (! TRUE) #copy or perform with value: basis e.g. $db->set_prop($dbkey,'basis',$c->param('basis'),type=>'service'))
{$ret .= 'Perform/save failed for basis';}
if (! TRUE) #copy or perform with value: criterion e.g. $db->set_prop($dbkey,'criterion',$c->param('criterion'),type=>'service'))
{$ret .= 'Perform/save failed for criterion';}
if (! TRUE) #copy or perform with value: basis2 e.g. $db->set_prop($dbkey,'basis2',$c->param('basis2'),type=>'service'))
{$ret .= 'Perform/save failed for basis2';}
if (! TRUE) #copy or perform with value: criterion2 e.g. $db->set_prop($dbkey,'criterion2',$c->param('criterion2'),type=>'service'))
{$ret .= 'Perform/save failed for criterion2';}
if (! TRUE) #copy or perform with value: action e.g. $db->set_prop($dbkey,'action',$c->param('action'),type=>'service'))
{$ret .= 'Perform/save failed for action';}
if (! TRUE) #copy or perform with value: deliver e.g. $db->set_prop($dbkey,'deliver',$c->param('deliver'),type=>'service'))
{$ret .= 'Perform/save failed for deliver';}
if (! TRUE) #copy or perform with value: folder e.g. $db->set_prop($dbkey,'folder',$c->param('folder'),type=>'service'))
{$ret .= 'Perform/save failed for folder';}
if (! TRUE) #copy or perform with value: copy e.g. $db->set_prop($dbkey,'copy',$c->param('copy'),type=>'service'))
{$ret .= 'Perform/save failed for copy';}
if (! TRUE) #copy or perform with value: action2 e.g. $db->set_prop($dbkey,'action2',$c->param('action2'),type=>'service'))
{$ret .= 'Perform/save failed for action2';}
if (! TRUE) #copy or perform with value: deliver2 e.g. $db->set_prop($dbkey,'deliver2',$c->param('deliver2'),type=>'service'))
{$ret .= 'Perform/save failed for deliver2';}
if (! TRUE) #copy or perform with value: key e.g. $db->set_prop($dbkey,'key',$c->param('key'),type=>'service'))
{$ret .= 'Perform/save failed for key';}
if ($ret eq "") {$ret = 'ok';}
return $ret;
}
sub perform_REMOVE {
my $c = shift;
my $ms_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 (! TRUE) #copy or perform with value: RemoveRule e.g. $db->set_prop($dbkey,'RemoveRule',$c->param('RemoveRule'),type=>'service'))
{$ret .= 'Perform/save failed for RemoveRule';}
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;