#!/usr/bin/perl package change_list_shortname; use strict; use FindBin; use lib "$FindBin::Bin/../"; use lib "$FindBin::Bin/../DADA/perllib"; BEGIN { my $b__dir = ( getpwuid($>) )[7].'/perl'; push @INC,$b__dir.'5/lib/perl5',$b__dir.'5/lib/perl5/x86_64-linux-thread-multi',$b__dir.'lib',map { $b__dir . $_ } @INC; } # use some of those Modules use DADA::Config 11.0.0; use DADA::Template::HTML; use DADA::App::Guts; use DADA::MailingList::Settings; use CGI::Carp qw(fatalsToBrowser); use Carp qw(croak carp); use Fcntl qw( LOCK_SH O_RDONLY O_CREAT LOCK_EX ); my $admin_list; my $root_login; my $list; my $ls; sub reset_globals { $admin_list = undef; $root_login = undef $list = undef $ls = undef } my $Plugin_Config = {}; $Plugin_Config->{Plugin_Name} = 'Change List Shortname'; $Plugin_Config->{Plugin_URL} = $DADA::Config::S_PROGRAM_URL . '/plugins/change_list_shortname'; &init_vars; sub init_vars { # DEV: This NEEDS to be in its own module - perhaps DADA::App::PluginHelper or something? while ( my $key = each %$Plugin_Config ) { if ( exists( $DADA::Config::PLUGIN_CONFIGS->{change_list_shortname}->{$key} ) ) { if ( defined( $DADA::Config::PLUGIN_CONFIGS->{change_list_shortname}->{$key} ) ) { $Plugin_Config->{$key} = $DADA::Config::PLUGIN_CONFIGS->{change_list_shortname}->{$key}; } } } } run() unless caller(); sub run { reset_globals(); my $q = shift || cgi_obj(); my $checksout; my $error_msg; ( $admin_list, $root_login, $checksout, $error_msg ) = check_list_security( -cgi_obj => $q, -Function => 'change_list_shortname' ); if(!$checksout){ return({}, $error_msg); } $list = $admin_list; my $prm = $q->param('prm') || 'cgi_default'; $ls = DADA::MailingList::Settings->new({-list => $list}); my %Mode = ( 'cgi_default' => \&cgi_default, 'verify_change_list_shortname' => \&verify_change_list_shortname, 'change_list_shortname' => \&change_list_shortname, ); if ( exists( $Mode{$prm} ) ) { return $Mode{$prm}->($q); #call the correct subroutine } else { return cgi_default($q); } } sub test_sub { return 'Hello, World!'; } sub cgi_default { my $q = shift; require DADA::Template::Widgets; require DADA::MailingList::Settings; my $scrn = DADA::Template::Widgets::wrap_screen( { -screen => 'plugins/change_list_shortname/default.tmpl', -with => 'admin', -expr => 1, -wrapper_params => { -Root_Login => $root_login, -List => $list, }, -vars => { Plugin_URL => $Plugin_Config->{Plugin_URL}, }, -list_settings_vars_param => { -list => $list, -dot_it => 1, }, } ); return ({}, $scrn); } sub sql_backend_only_message { my $tmpl = q{
This plugin will only work, if you have installed and configured Dada Mail to use one of the SQL backends.
}; require DADA::Template::Widgets; my $scrn = DADA::Template::Widgets::wrap_screen( { -data => \$tmpl, -with => 'admin', -wrapper_params => { -Root_Login => $root_login, -List => $ls->param('list'), },, -vars => { }, -list_settings_vars_param => { -list => $list, -dot_it => 1, }, } ); return ({}, $scrn); } sub verify_change_list_shortname { my $q = shift; my $new_name = strip( xss_filter( scalar $q->param('new_name') ) ); my ( $errors, $flags ) = check_list_setup( -fields => { list => $new_name, }, ); # reset this, as we don't care about all the errors, but: $errors = 0; my $change_list_name_errors = {}; # use Data::Dumper; # die Dumper($flags); for(qw( list list_exists shortname_too_long slashes_in_name weird_characters quotes )){ if($flags->{$_} == 1){ $change_list_name_errors->{'flags_' . $_} = 1; $errors++; } } require DADA::Template::Widgets; my $scrn = DADA::Template::Widgets::screen( { -screen => 'plugins/change_list_shortname/verify.tmpl', -expr => 1, -vars => { Plugin_URL => $Plugin_Config->{Plugin_URL}, errors => $errors, new_name => $new_name, %{$change_list_name_errors}, }, -list_settings_vars_param => { -list => $list, -dot_it => 1, }, } ); return ({}, $scrn); } sub change_list_shortname { my $q = shift; my $new_name = strip(xss_filter($q->param('new_name'))); my %p = %DADA::Config::SQL_PARAMS; #subscriber_table #profile_table # no update needed. #profile_fields_table # no update needed. #profile_fields_attributes_table # no update needed. #archives_table #settings_table #session_table # no update needed. #bounce_scores_table #clickthrough_urls_table # no update needed. #clickthrough_url_log_table #mass_mailing_event_log_table #password_protect_directories_table my $query_string = "UPDATE $p{subscriber_table} SET list = ? WHERE list = ?; UPDATE $p{archives_table} SET list = ? WHERE list = ?; UPDATE $p{bounce_scores_table} SET list = ? WHERE list = ?; UPDATE $p{clickthrough_url_log_table} SET list = ? WHERE list = ?; UPDATE $p{mass_mailing_event_log_table} SET list = ? WHERE list = ?; UPDATE $p{password_protect_directories_table} SET list = ? WHERE list = ?; UPDATE $p{profile_settings_table} SET list = ? WHERE list = ?; UPDATE $p{settings_table} SET list = ? WHERE list = ?; UPDATE $p{settings_table} SET value = ? WHERE value = ? and setting = 'list';"; my @queries = split("\n", $query_string); require DADA::App::DBIHandle; my $dbi_obj = DADA::App::DBIHandle->new; my $dbh = $dbi_obj->dbh_obj; foreach my $query(@queries){ my $sth = $dbh->prepare($query); my $rv = $sth->execute($new_name, $list) or croak "cannot do statement! $DBI::errstr\n"; } require DADA::App::ScreenCache; my $c = DADA::App::ScreenCache->new; $c->flush; return ( {-redirect_uri => $DADA::Config::S_PROGRAM_URL . '?flavor=logout&login_url='. $DADA::Config::S_PROGRAM_URL . '?flavor=' . $DADA::Config::ADMIN_FLAVOR_NAME}, undef); } sub cgi_obj { require CGI; return new CGI; } =pod =head1 Plugin: change_list_shortname.cgi - Change your mailing list's Short Name Your mailing list's, B