diff options
| author | Pasha <pasha@member.fsf.org> | 2024-01-20 10:09:23 +0000 | 
|---|---|---|
| committer | Pasha <pasha@member.fsf.org> | 2024-01-20 10:09:23 +0000 | 
| commit | 76669f6c298bcf3f69a0e1df5c524a7cff3e367d (patch) | |
| tree | 9704c3470c1f3ca91510d9af01b8e8eb81969ed9 /web/NetUseAdminWeb | |
| download | netusemod-76669f6c298bcf3f69a0e1df5c524a7cff3e367d.tar.gz netusemod-76669f6c298bcf3f69a0e1df5c524a7cff3e367d.tar.bz2 | |
Diffstat (limited to 'web/NetUseAdminWeb')
27 files changed, 1260 insertions, 0 deletions
| diff --git a/web/NetUseAdminWeb/.dancer b/web/NetUseAdminWeb/.dancer new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/web/NetUseAdminWeb/.dancer diff --git a/web/NetUseAdminWeb/MANIFEST b/web/NetUseAdminWeb/MANIFEST new file mode 100644 index 0000000..f8395c9 --- /dev/null +++ b/web/NetUseAdminWeb/MANIFEST @@ -0,0 +1,20 @@ +MANIFEST +config.yml +Makefile.PL +.dancer +MANIFEST.SKIP +cpanfile +bin/app.psgi +public/500.html +public/favicon.ico +public/dispatch.fcgi +public/404.html +public/dispatch.cgi +views/index.tt +t/002_index_route.t +t/001_base.t +environments/production.yml +environments/development.yml +lib/NetUseAdminWeb.pm +public/css/error.css +views/layouts/main.tt diff --git a/web/NetUseAdminWeb/MANIFEST.SKIP b/web/NetUseAdminWeb/MANIFEST.SKIP new file mode 100644 index 0000000..9ee88b4 --- /dev/null +++ b/web/NetUseAdminWeb/MANIFEST.SKIP @@ -0,0 +1,17 @@ +^\.git\/ +maint +^tags$ +.last_cover_stats +Makefile$ +^blib +^pm_to_blib +^.*.bak +^.*.old +^t.*sessions +^cover_db +^.*\.log +^.*\.swp$ +MYMETA.* +^.gitignore +^.svn\/ +^NetUseAdminWeb- diff --git a/web/NetUseAdminWeb/Makefile.PL b/web/NetUseAdminWeb/Makefile.PL new file mode 100644 index 0000000..0054f7d --- /dev/null +++ b/web/NetUseAdminWeb/Makefile.PL @@ -0,0 +1,42 @@ +use strict; +use warnings; +use ExtUtils::MakeMaker; + +#    NetUseMod is a program to moderate Usenet posts via web interface. +#    Copyright (C) 2024  Salahuddin <salahuddin@member.fsf.org> +# +#    This program is free software: you can redistribute it and/or modify +#    it under the terms of the GNU General Public License as published by +#    the Free Software Foundation, either version 3 of the License, or +#    (at your option) any later version. +# +#    This program is distributed in the hope that it will be useful, +#    but WITHOUT ANY WARRANTY; without even the implied warranty of +#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +#    GNU General Public License for more details. +# +#    You should have received a copy of the GNU General Public License +#    along with this program.  If not, see <https://www.gnu.org/licenses/>. + +# Normalize version strings like 6.30_02 to 6.3002, +# so that we can do numerical comparisons on it. +my $eumm_version = $ExtUtils::MakeMaker::VERSION; +$eumm_version =~ s/_//; + +WriteMakefile( +    NAME                => 'NetUseAdminWeb', +    AUTHOR              => q{YOUR NAME <youremail@example.com>}, +    VERSION_FROM        => 'lib/NetUseAdminWeb.pm lib/NetUseAdminWeb.pm', +    ABSTRACT            => 'YOUR APPLICATION ABSTRACT', +    ($eumm_version >= 6.3001 +      ? ('LICENSE'=> 'perl') +      : ()), +    PL_FILES            => {}, +    PREREQ_PM => { +        'Test::More' => 0, +        'YAML'       => 0, +        'Dancer2'     => 0.400001, +    }, +    dist                => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, +    clean               => { FILES => 'NetUseAdminWeb-*' }, +); diff --git a/web/NetUseAdminWeb/bin/app.psgi b/web/NetUseAdminWeb/bin/app.psgi new file mode 100755 index 0000000..358e5ad --- /dev/null +++ b/web/NetUseAdminWeb/bin/app.psgi @@ -0,0 +1,61 @@ +#!/usr/bin/perl + +#    NetUseMod is a program to moderate Usenet posts via web interface. +#    Copyright (C) 2024  Salahuddin <salahuddin@member.fsf.org> +# +#    This program is free software: you can redistribute it and/or modify +#    it under the terms of the GNU General Public License as published by +#    the Free Software Foundation, either version 3 of the License, or +#    (at your option) any later version. +# +#    This program is distributed in the hope that it will be useful, +#    but WITHOUT ANY WARRANTY; without even the implied warranty of +#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +#    GNU General Public License for more details. +# +#    You should have received a copy of the GNU General Public License +#    along with this program.  If not, see <https://www.gnu.org/licenses/>. + +use strict; +use warnings; +use FindBin; +use lib "$FindBin::Bin/../lib"; + + +# use this block if you don't need middleware, and only have a single target Dancer app to run here +use NetUseAdminWeb; + +NetUseAdminWeb->to_app; + +=begin comment +# use this block if you want to include middleware such as Plack::Middleware::Deflater + +use NetUseAdminWeb; +use Plack::Builder; + +builder { +    enable 'Deflater'; +    NetUseAdminWeb->to_app; +} + +=end comment + +=cut + +=begin comment +# use this block if you want to mount several applications on different path + +use NetUseAdminWeb; +use NetUseAdminWeb_admin; + +use Plack::Builder; + +builder { +    mount '/'      => NetUseAdminWeb->to_app; +    mount '/admin'      => NetUseAdminWeb_admin->to_app; +} + +=end comment + +=cut + diff --git a/web/NetUseAdminWeb/config.yml b/web/NetUseAdminWeb/config.yml new file mode 100644 index 0000000..06bafea --- /dev/null +++ b/web/NetUseAdminWeb/config.yml @@ -0,0 +1,78 @@ +#    NetUseMod is a program to moderate Usenet posts via web interface. +#    Copyright (C) 2024  Salahuddin <salahuddin@member.fsf.org> +# +#    This program is free software: you can redistribute it and/or modify +#    it under the terms of the GNU General Public License as published by +#    the Free Software Foundation, either version 3 of the License, or +#    (at your option) any later version. +# +#    This program is distributed in the hope that it will be useful, +#    but WITHOUT ANY WARRANTY; without even the implied warranty of +#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +#    GNU General Public License for more details. +# +#    You should have received a copy of the GNU General Public License +#    along with this program.  If not, see <https://www.gnu.org/licenses/>. + +# This is the main configuration file of your Dancer2 app +# env-related settings should go to environments/$env.yml +# all the settings in this file will be loaded at Dancer's startup. + +# === Basic configuration === + +# Your application's name +appname: "NetUseAdminWeb" + +# The default layout to use for your application (located in +# views/layouts/main.tt) +layout: "main" + +# when the charset is set to UTF-8 Dancer2 will handle for you +# all the magic of encoding and decoding. You should not care +# about unicode within your app when this setting is set (recommended). +charset: "UTF-8" + +# === Engines === +# +# NOTE: All the engine configurations need to be under a single "engines:" +# key.  If you uncomment engine configurations below, make sure to delete +# all "engines:" lines except the first.  Otherwise, only the last +# "engines:" block will take effect. + +# template engine +# simple: default and very basic template engine +# template_toolkit: TT + +template: "simple" + +# template: "template_toolkit" +# engines: +#   template: +#     template_toolkit: +#       # Note: start_tag and end_tag are regexes +#       start_tag: '<%' +#       end_tag:   '%>' + +# session engine +# +# Simple: in-memory session store - Dancer2::Session::Simple +# YAML: session stored in YAML files - Dancer2::Session::YAML +# +# Check out metacpan for other session storage options: +# https://metacpan.org/search?q=Dancer2%3A%3ASession&search_type=modules +# +# Default value for 'cookie_name' is 'dancer.session'. If you run multiple +# Dancer apps on the same host then you will need to make sure 'cookie_name' +# is different for each app. +# +#engines: +#  session: +#    Simple: +#      cookie_name: testapp.session +# +#engines: +#  session: +#    YAML: +#      cookie_name: eshop.session +#      is_secure: 1 +#      is_http_only: 1 diff --git a/web/NetUseAdminWeb/cpanfile b/web/NetUseAdminWeb/cpanfile new file mode 100644 index 0000000..db1c1ee --- /dev/null +++ b/web/NetUseAdminWeb/cpanfile @@ -0,0 +1,36 @@ +requires "Dancer2" => "0.400001"; + +recommends "YAML"                    => "0"; +recommends "URL::Encode::XS"         => "0"; +recommends "CGI::Deurl::XS"          => "0"; +recommends "CBOR::XS"                => "0"; +recommends "YAML::XS"                => "0"; +recommends "Class::XSAccessor"       => "0"; +recommends "Crypt::URandom"          => "0"; +recommends "HTTP::XSCookies"         => "0"; +recommends "HTTP::XSHeaders"         => "0"; +recommends "Math::Random::ISAAC::XS" => "0"; +recommends "MooX::TypeTiny"          => "0"; +recommends "Type::Tiny::XS"          => "0"; +recommends "Unicode::UTF8"           => "0"; + +feature 'accelerate', 'Accelerate Dancer2 app performance with XS modules' => sub { +    requires "URL::Encode::XS"         => "0"; +    requires "CGI::Deurl::XS"          => "0"; +    requires "YAML::XS"                => "0"; +    requires "Class::XSAccessor"       => "0"; +    requires "Cpanel::JSON::XS"        => "0"; +    requires "Crypt::URandom"          => "0"; +    requires "HTTP::XSCookies"         => "0"; +    requires "HTTP::XSHeaders"         => "0"; +    requires "Math::Random::ISAAC::XS" => "0"; +    requires "MooX::TypeTiny"          => "0"; +    requires "Type::Tiny::XS"          => "0"; +    requires "Unicode::UTF8"           => "0"; +}; + +on "test" => sub { +    requires "Test::More"            => "0"; +    requires "HTTP::Request::Common" => "0"; +}; + diff --git a/web/NetUseAdminWeb/environments/development.yml b/web/NetUseAdminWeb/environments/development.yml new file mode 100644 index 0000000..e4e01a9 --- /dev/null +++ b/web/NetUseAdminWeb/environments/development.yml @@ -0,0 +1,36 @@ +#    NetUseMod is a program to moderate Usenet posts via web interface. +#    Copyright (C) 2024  Salahuddin <salahuddin@member.fsf.org> +# +#    This program is free software: you can redistribute it and/or modify +#    it under the terms of the GNU General Public License as published by +#    the Free Software Foundation, either version 3 of the License, or +#    (at your option) any later version. +# +#    This program is distributed in the hope that it will be useful, +#    but WITHOUT ANY WARRANTY; without even the implied warranty of +#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +#    GNU General Public License for more details. +# +#    You should have received a copy of the GNU General Public License +#    along with this program.  If not, see <https://www.gnu.org/licenses/>. + +# configuration file for development environment + +# the logger engine to use +# console: log messages to STDOUT (your console where you started the +#          application server) +# file:    log message to a file in log/ +logger: "console" + +# the log level for this environment +# core is the lowest, it shows Dancer2's core log messages as well as yours +# (debug, info, warning and error) +log: "core" + +# should Dancer2 show a stacktrace when an 5xx error is caught? +# if set to yes, public/500.html will be ignored and either +# views/500.tt, 'error_template' template, or a default error template will be used. +show_stacktrace: 1 + +# print the banner +startup_info: 1 diff --git a/web/NetUseAdminWeb/environments/production.yml b/web/NetUseAdminWeb/environments/production.yml new file mode 100644 index 0000000..4fe4eb0 --- /dev/null +++ b/web/NetUseAdminWeb/environments/production.yml @@ -0,0 +1,29 @@ +#    NetUseMod is a program to moderate Usenet posts via web interface. +#    Copyright (C) 2024  Salahuddin <salahuddin@member.fsf.org> +# +#    This program is free software: you can redistribute it and/or modify +#    it under the terms of the GNU General Public License as published by +#    the Free Software Foundation, either version 3 of the License, or +#    (at your option) any later version. +# +#    This program is distributed in the hope that it will be useful, +#    but WITHOUT ANY WARRANTY; without even the implied warranty of +#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +#    GNU General Public License for more details. +# +#    You should have received a copy of the GNU General Public License +#    along with this program.  If not, see <https://www.gnu.org/licenses/>. + +# configuration file for production environment + +# only log warning and error messsages +log: "warning" + +# log message to a file in logs/ +logger: "file" + +# hide errors +show_stacktrace: 0 + +# disable server tokens in production environments +no_server_tokens: 1 diff --git a/web/NetUseAdminWeb/lib/NetUseAdminWeb.pm b/web/NetUseAdminWeb/lib/NetUseAdminWeb.pm new file mode 100644 index 0000000..9524309 --- /dev/null +++ b/web/NetUseAdminWeb/lib/NetUseAdminWeb.pm @@ -0,0 +1,302 @@ +package NetUseAdminWeb; + +#    NetUseMod is a program to moderate Usenet posts via web interface. +#    Copyright (C) 2024  Salahuddin <salahuddin@member.fsf.org> +# +#    This program is free software: you can redistribute it and/or modify +#    it under the terms of the GNU General Public License as published by +#    the Free Software Foundation, either version 3 of the License, or +#    (at your option) any later version. +# +#    This program is distributed in the hope that it will be useful, +#    but WITHOUT ANY WARRANTY; without even the implied warranty of +#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +#    GNU General Public License for more details. +# +#    You should have received a copy of the GNU General Public License +#    along with this program.  If not, see <https://www.gnu.org/licenses/>. + +use Dancer2; +use File::Copy 'move'; +use HTML::Entities; + +our $VERSION = '0.1'; + +my $post_to_usenet = 1;     # toggle for testing +my $usenet_host = 'YOUR_USENET_PROVIDER'; +my $usenet_port = '119';    # production 536 ssl +my $rnews_location = '/usr/bin/rnews'; +# set user and password in /etc/news/passwd.nntp +# to submit news to your newsgroup provider. + +my $send_rec_ack = 1; +my $noreply_mail = 'no-reply@YOUR_DOMAIN'; + +my $mail_format = 'YOUR_HOME_DIR/NetUseMod/scripts/mail_format.sh'; +my $admin_user = 'XXXXXXXX'; +my $admin_pass = 'XXXXXXXX'; + +# example: /home/username/ +my $dir_base = 'YOUR_HOME_DIR'; +my $dir_incoming = 'incoming_news'; +my $dir_processed = 'processed_news'; +my $dir_rejected = 'rejected_news'; + + +sub sendReceiveAck { +    my ($from, $subject, $description) = @_; +    system('echo "' . $description . '." | mail -s "Re: ' .  $subject . '" -r ' . $noreply_mail . ' \'' . $from . '\''); +} + +sub postToNewsGroup { +    my $processed_dest_file = shift; +    system($rnews_location . ' -h ' . $usenet_host . ' -P ' . $usenet_port . ' -S ' . $usenet_host . ' < ' . $processed_dest_file); +} + +sub formatNews { +    my ($filename, $processed_dest_file) = @_; +    system('cat ' . $filename . ' | ' . $mail_format . ' > ' . $processed_dest_file); +} + +sub getFileData { +    my $filename = shift; +    if ($filename eq '') { +	return ''; +    } +    open(FH, '<', $filename) or die $!; +    my $file_data = ''; +    while(<FH>){ +	$file_data .= $_; +    } +    close(FH); +    return $file_data; +} + +hook before => sub { +    if (!session('user') && +	request->path !~ m{^/login} ) { +        forward '/login', { requested_path => request->path }; +    } +}; + +get '/' => sub { +    template 'index'; +}; + +sub get_news_list { +    my $dir_type = shift; +    my $dirname = $dir_base . $dir_type . "/";  +    opendir my($dh), $dirname or die "Couldn't open dir '$dirname': $!"; +    my @files = readdir $dh; +    closedir $dh; +    # remve .. . entries. +    for(my $index = 0; $index <= $#files; $index++){ +	if ($files[$index] eq '.') { +	    splice(@files, $index, 1); +	    #index value changed +	    last; +	} +    } +    for(my $index = 0; $index <= $#files; $index++){ +	if ($files[$index] eq '..') { +	    splice(@files, $index, 1); +	    #index value changed +	    last; +	} +    } +    my %file_list; +    foreach(@files) { +        my $fh = $dirname . '/'	. $_; +        my $epoch_timestamp = (stat($fh))[8]; +        my $timestamp       = localtime($epoch_timestamp); +        $file_list{$_} = $timestamp; +    } +    return %file_list; +} + +get '/listincomingnews' => sub { +    my %file_list = get_news_list($dir_incoming); +    my $listnews = ''; +    for(keys %file_list){ +	$listnews .= "<tr>"; +	$listnews .= '<td>' . $_ . '</td>'; +	$listnews .= '<td>' . $file_list{$_} . '</td>';  # created time +	$listnews .= '<td><a href="/viewfile?filename=' . $_ . '&dirtype=' .$dir_incoming . '">view</a></td>'; +	$listnews .= "</tr>"; +    } +    template 'listnews', { listnews => $listnews }; +}; + +get '/viewfile' => sub { +    my $filename_param = query_parameters->get('filename'); +    my $dir_type = query_parameters->get('dirtype'); +    my $filename = $dir_base . $dir_type . '/' .  $filename_param; +    my $file_data = ''; +    $file_data = getFileData($filename); +    if ($file_data eq '') { +	template 'generic', { message => "emtpy" }; +    } +    $file_data = encode_entities($file_data); +    $file_data =~ s/\n/<br>/g; +    my $accept_reject_html_block = ''; +    if ($dir_type eq $dir_incoming) { +	my $accept_html_button = '<a href="/acceptnews?filename=' . $filename_param . '">Accept</a>'; +	my $reject_html_button = '<a href="/rejectnews?filename=' . $filename_param . '">Reject</a>'; +	$accept_reject_html_block = $accept_html_button . '  ' . $reject_html_button; +    } +    template 'viewnews', { file_data => $file_data, accept_reject_html_block => $accept_reject_html_block }; +}; + +get '/listprocessednews' => sub { +    my %file_list = get_news_list($dir_processed); +    my $listnews = ''; +    for(keys %file_list){ +	$listnews .= "<tr>"; +	$listnews .= '<td>' . $_ . '</td>'; +	$listnews .= '<td>' . $file_list{$_} . '</td>';  # created time +	$listnews .= '<td><a href="/viewfile?filename=' . $_ . '&dirtype=' . $dir_processed . '">view</a></td>'; +	$listnews .= "</tr>"; +    } +    template 'listnews', { listnews => $listnews }; +}; + +get '/listrejectednews' => sub { +    my %file_list = get_news_list($dir_rejected); +    my $listnews = ''; +    for(keys %file_list){ +	$listnews .= "<tr>"; +	$listnews .= '<td>' . $_ . '</td>'; +	$listnews .= '<td>' . $file_list{$_} . '</td>';  # created time +	$listnews .= '<td><a href="/viewfile?filename=' . $_ . '&dirtype=' . $dir_rejected . '">view</a></td>'; +	$listnews .= "</tr>"; +    } +    template 'listnews', { listnews => $listnews }; +}; + +get '/acceptnews' => sub { +    my $filename_param = query_parameters->get('filename'); +    my $filename = $dir_base . '/' . $dir_incoming . '/' . $filename_param; +    my $file_data = ''; +    $file_data = getFileData($filename); +    if ($file_data eq '') { +	template 'generic', { message => "emtpy" }; +    } +    $file_data = encode_entities($file_data); +    $file_data =~ s/\n/<br>/g; +    template 'acceptnews', { file_data => $file_data, filename_param => $filename_param }; +}; + +post '/acceptnews' => sub { +    my $filename_param = body_parameters->get('filename_param'); +    my $filename = $dir_base . '/' . $dir_incoming . '/' . $filename_param; +    my $dest_filename = $dir_base . '/' . $dir_processed . '/' . $filename_param; +    my $processed_dest_file = $dest_filename . '_processed'; +    formatNews($filename, $processed_dest_file); +    if ($post_to_usenet eq 1) { +	postToNewsGroup($processed_dest_file); +    } +    move($filename, $dest_filename)or die "The move operation failed: $!"; +    template 'generic', { message => 'Success' }; +}; + +get '/rejectnews' => sub { +    my $filename_param = query_parameters->get('filename'); +    my $filename = $dir_base . '/' . $dir_incoming . '/' . $filename_param; +    my $file_data = ''; +    $file_data = getFileData($filename); +    if ($file_data eq '') { +	template 'generic', { message => "emtpy" }; +    } +    $file_data = encode_entities($file_data); +    $file_data =~ s/\n/<br>/g; +    template 'rejectnews', { file_data => $file_data, filename_param => $filename_param }; +}; + +sub parseFromAndSubject { +    my $message       = shift; +    my $from          = ''; +    my $subject       = ''; +    my @message_array = split(/\n/, $message); + +    foreach(@message_array) { +        # first empty line +        if(/^$/) { +            last; +        } +        if( /^From: / ) { +            $from = $_; +            $from=~ s/^From: //i; +        } elsif( /^Subject: / ) { +            $subject = $_; +            $subject =~ s/^Subject: //i; +        } +    } +    # trim +    $from =~ s/^\s+|\s+$//g; +    $subject =~ s/^\s+|\s+$//g; +    return ($from, $subject); +} + +post '/rejectnews' => sub { +    my $submitbutton = body_parameters->get('submitbutton'); +    my $filename_param = body_parameters->get('filename_param'); +    my $reject_reason = body_parameters->get('reject_reason'); +    my $filename = $dir_base . '/' . $dir_incoming . '/' . $filename_param; +    my $dest_filename = $dir_base . '/' . $dir_rejected . '/' . $filename_param; + +    if (index($submitbutton, 'Send reject notification') != -1) { +	# TODO: send notification +	if ($send_rec_ack eq 1) { +	    open(FH, '<', $filename) or die $!; +	    my $file_data = ''; +	    while(<FH>){ +		# first empty line +		if(/^$/) { +		    last; +		} +		$file_data .= $_; +	    } +	    close(FH); +	    my ($from, $subject) = parseFromAndSubject($file_data); +	    # TODO: check return value +	    sendReceiveAck($from, $subject, $reject_reason); +	} +    } +    # add error in error variable +    move($filename, $dest_filename)or die "The move operation failed: $!"; + +    my $message = 'Success'; +    template 'generic', { message => $message }; +}; + +get '/login' => sub { +    if (session('user')) { +	redirect '/'; +    } else { +	template 'login', { path => param('requested_path') }; +    } +}; + +post '/login' => sub { +    my $user_value = body_parameters->get('user'); +    my $pass_value = body_parameters->get('pass'); +    my $error_message = ''; + +    if($user_value eq $admin_user && $pass_value eq $admin_pass) { +	session user => $user_value; +	redirect body_parameters->get('path') || '/'; +    } else { +	$error_message = 'Invalid login/password.'; +    } + +    if($error_message ne '') { +	return template 'generic', { message => $error_message}; +    } +}; + +get '/logout' => sub { +    app->destroy_session; +    redirect '/'; +}; + +true; diff --git a/web/NetUseAdminWeb/public/404.html b/web/NetUseAdminWeb/public/404.html new file mode 100644 index 0000000..48632d0 --- /dev/null +++ b/web/NetUseAdminWeb/public/404.html @@ -0,0 +1,37 @@ +<!DOCTYPE html> + +<!-- +    NetUseMod is a program to moderate Usenet posts via web interface. +    Copyright (C) 2024  Salahuddin <salahuddin@member.fsf.org> + +    This program is free software: you can redistribute it and/or modify +    it under the terms of the GNU General Public License as published by +    the Free Software Foundation, either version 3 of the License, or +    (at your option) any later version. + +    This program is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +    GNU General Public License for more details. + +    You should have received a copy of the GNU General Public License +    along with this program.  If not, see <https://www.gnu.org/licenses/>. +--> + +<html lang="en"> +<head> +  <meta charset="utf-8"> +  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes"> +  <title>Error 404</title> +  <link rel="stylesheet" href="/css/error.css"> +</head> +<body> +<h1>Error 404</h1> +<div id="content"> +<h2>Page Not Found</h2><p>Sorry, this is the void.</p> +</div> +<div id="footer"> +Powered by <a href="http://perldancer.org/">Dancer2</a>. +</div> +</body> +</html> diff --git a/web/NetUseAdminWeb/public/500.html b/web/NetUseAdminWeb/public/500.html new file mode 100644 index 0000000..064ead8 --- /dev/null +++ b/web/NetUseAdminWeb/public/500.html @@ -0,0 +1,37 @@ +<!DOCTYPE html> + +<!-- +    NetUseMod is a program to moderate Usenet posts via web interface. +    Copyright (C) 2024  Salahuddin <salahuddin@member.fsf.org> + +    This program is free software: you can redistribute it and/or modify +    it under the terms of the GNU General Public License as published by +    the Free Software Foundation, either version 3 of the License, or +    (at your option) any later version. + +    This program is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +    GNU General Public License for more details. + +    You should have received a copy of the GNU General Public License +    along with this program.  If not, see <https://www.gnu.org/licenses/>. +--> + +<html lang="en"> +<head> +  <meta charset="utf-8"> +  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes"> +  <title>Error 500</title> +  <link rel="stylesheet" href="/css/error.css"> +</head> +<body> +<h1>Error 500</h1> +<div id="content"> +<h2>Internal Server Error</h2><p>Wooops, something went wrong</p> +</div> +<div id="footer"> +Powered by <a href="http://perldancer.org/">Dancer2</a>. +</div> +</body> +</html> diff --git a/web/NetUseAdminWeb/public/README b/web/NetUseAdminWeb/public/README new file mode 100644 index 0000000..d2ca5e4 --- /dev/null +++ b/web/NetUseAdminWeb/public/README @@ -0,0 +1,7 @@ +    Copyright (C) 2024 Salahuddin <salahuddin@member.fsf.org> + +    The following file(s) are licensed under the GNU General Public License +    as published by the Free Software Foundation, either version 3 of +    the License, or (at your option) any later version. + +favicon.ico diff --git a/web/NetUseAdminWeb/public/css/error.css b/web/NetUseAdminWeb/public/css/error.css new file mode 100644 index 0000000..15c38f3 --- /dev/null +++ b/web/NetUseAdminWeb/public/css/error.css @@ -0,0 +1,104 @@ +/* +    NetUseMod is a program to moderate Usenet posts via web interface. +    Copyright (C) 2024  Salahuddin <salahuddin@member.fsf.org> + +    This program is free software: you can redistribute it and/or modify +    it under the terms of the GNU General Public License as published by +    the Free Software Foundation, either version 3 of the License, or +    (at your option) any later version. + +    This program is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +    GNU General Public License for more details. + +    You should have received a copy of the GNU General Public License +    along with this program.  If not, see <https://www.gnu.org/licenses/>. +*/ + +body { +    font-family: Lucida,sans-serif; +} + +h1 { +    color: #AA0000; +    border-bottom: 1px solid #444; +} + +h2 { color: #444; } + +pre { +    font-family: "lucida console","monaco","andale mono","bitstream vera sans mono","consolas",monospace; +    font-size: 12px; +    border-left: 2px solid #777; +    padding-left: 1em; +} + +footer { +    font-size: 10px; +} + +span.key { +    color: #449; +    font-weight: bold; +    width: 120px; +    display: inline; +} + +span.value { +    color: #494; +} + +/* these are for the message boxes */ + +pre.content { +    background-color: #eee; +    color: #000; +    padding: 1em; +    margin: 0; +    border: 1px solid #aaa; +    border-top: 0; +    margin-bottom: 1em; +    overflow-x: auto; +} + +div.title { +    font-family: "lucida console","monaco","andale mono","bitstream vera sans mono","consolas",monospace; +    font-size: 12px; +    background-color: #aaa; +    color: #444; +    font-weight: bold; +    padding: 3px; +    padding-left: 10px; +} + +table.context { +    border-spacing: 0; +} + +table.context th, table.context td { +    padding: 0; +} + +table.context th { +    color: #889; +    font-weight: normal; +    padding-right: 15px; +    text-align: right; +} + +.errline { +    color: red; +} + +pre.error { +    background: #334; +    color: #ccd; +    padding: 1em; +    border-top: 1px solid #000; +    border-left: 1px solid #000; +    border-right: 1px solid #eee; +    border-bottom: 1px solid #eee; +    overflow-x: auto; +} + diff --git a/web/NetUseAdminWeb/public/dispatch.cgi b/web/NetUseAdminWeb/public/dispatch.cgi new file mode 100755 index 0000000..8a15355 --- /dev/null +++ b/web/NetUseAdminWeb/public/dispatch.cgi @@ -0,0 +1,33 @@ +#!/usr/bin/env perl + +#    NetUseMod is a program to moderate Usenet posts via web interface. +#    Copyright (C) 2024  Salahuddin <salahuddin@member.fsf.org> +# +#    This program is free software: you can redistribute it and/or modify +#    it under the terms of the GNU General Public License as published by +#    the Free Software Foundation, either version 3 of the License, or +#    (at your option) any later version. +# +#    This program is distributed in the hope that it will be useful, +#    but WITHOUT ANY WARRANTY; without even the implied warranty of +#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +#    GNU General Public License for more details. +# +#    You should have received a copy of the GNU General Public License +#    along with this program.  If not, see <https://www.gnu.org/licenses/>. + +BEGIN { $ENV{DANCER_APPHANDLER} = 'PSGI';} +use Dancer2; +use FindBin '$RealBin'; +use Plack::Runner; + +# For some reason Apache SetEnv directives don't propagate +# correctly to the dispatchers, so forcing PSGI and env here +# is safer. +set apphandler => 'PSGI'; +set environment => 'production'; + +my $psgi = path($RealBin, '..', 'bin', 'app.psgi'); +die "Unable to read startup script: $psgi" unless -r $psgi; + +Plack::Runner->run($psgi); diff --git a/web/NetUseAdminWeb/public/dispatch.fcgi b/web/NetUseAdminWeb/public/dispatch.fcgi new file mode 100755 index 0000000..6341d58 --- /dev/null +++ b/web/NetUseAdminWeb/public/dispatch.fcgi @@ -0,0 +1,35 @@ +#!/usr/bin/env perl + +#    NetUseMod is a program to moderate Usenet posts via web interface. +#    Copyright (C) 2024  Salahuddin <salahuddin@member.fsf.org> +# +#    This program is free software: you can redistribute it and/or modify +#    it under the terms of the GNU General Public License as published by +#    the Free Software Foundation, either version 3 of the License, or +#    (at your option) any later version. +# +#    This program is distributed in the hope that it will be useful, +#    but WITHOUT ANY WARRANTY; without even the implied warranty of +#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +#    GNU General Public License for more details. +# +#    You should have received a copy of the GNU General Public License +#    along with this program.  If not, see <https://www.gnu.org/licenses/>. + +BEGIN { $ENV{DANCER_APPHANDLER} = 'PSGI';} +use Dancer2; +use FindBin '$RealBin'; +use Plack::Handler::FCGI; + +# For some reason Apache SetEnv directives don't propagate +# correctly to the dispatchers, so forcing PSGI and env here +# is safer. +set apphandler => 'PSGI'; +set environment => 'production'; + +my $psgi = path($RealBin, '..', 'bin', 'app.psgi'); +my $app = do($psgi); +die "Unable to read startup script: $@" if $@; +my $server = Plack::Handler::FCGI->new(nproc => 5, detach => 1); + +$server->run($app); diff --git a/web/NetUseAdminWeb/public/favicon.ico b/web/NetUseAdminWeb/public/favicon.icoBinary files differ new file mode 100644 index 0000000..7e29f9a --- /dev/null +++ b/web/NetUseAdminWeb/public/favicon.ico diff --git a/web/NetUseAdminWeb/t/001_base.t b/web/NetUseAdminWeb/t/001_base.t new file mode 100644 index 0000000..3e116db --- /dev/null +++ b/web/NetUseAdminWeb/t/001_base.t @@ -0,0 +1,21 @@ +use strict; +use warnings; + +#    NetUseMod is a program to moderate Usenet posts via web interface. +#    Copyright (C) 2024  Salahuddin <salahuddin@member.fsf.org> +# +#    This program is free software: you can redistribute it and/or modify +#    it under the terms of the GNU General Public License as published by +#    the Free Software Foundation, either version 3 of the License, or +#    (at your option) any later version. +# +#    This program is distributed in the hope that it will be useful, +#    but WITHOUT ANY WARRANTY; without even the implied warranty of +#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +#    GNU General Public License for more details. +# +#    You should have received a copy of the GNU General Public License +#    along with this program.  If not, see <https://www.gnu.org/licenses/>. + +use Test::More tests => 1; +use_ok 'NetUseAdminWeb'; diff --git a/web/NetUseAdminWeb/t/002_index_route.t b/web/NetUseAdminWeb/t/002_index_route.t new file mode 100644 index 0000000..6333f5a --- /dev/null +++ b/web/NetUseAdminWeb/t/002_index_route.t @@ -0,0 +1,32 @@ +use strict; +use warnings; + +#    NetUseMod is a program to moderate Usenet posts via web interface. +#    Copyright (C) 2024  Salahuddin <salahuddin@member.fsf.org> +# +#    This program is free software: you can redistribute it and/or modify +#    it under the terms of the GNU General Public License as published by +#    the Free Software Foundation, either version 3 of the License, or +#    (at your option) any later version. +# +#    This program is distributed in the hope that it will be useful, +#    but WITHOUT ANY WARRANTY; without even the implied warranty of +#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +#    GNU General Public License for more details. +# +#    You should have received a copy of the GNU General Public License +#    along with this program.  If not, see <https://www.gnu.org/licenses/>. + +use NetUseAdminWeb; +use Test::More tests => 2; +use Plack::Test; +use HTTP::Request::Common; +use Ref::Util qw<is_coderef>; + +my $app = NetUseAdminWeb->to_app; +ok( is_coderef($app), 'Got app' ); + +my $test = Plack::Test->create($app); +my $res  = $test->request( GET '/' ); + +ok( $res->is_success, '[GET /] successful' ); diff --git a/web/NetUseAdminWeb/views/acceptnews.tt b/web/NetUseAdminWeb/views/acceptnews.tt new file mode 100644 index 0000000..95b1b6c --- /dev/null +++ b/web/NetUseAdminWeb/views/acceptnews.tt @@ -0,0 +1,30 @@ +<!-- +    NetUseMod is a program to moderate Usenet posts via web interface. +    Copyright (C) 2024  Salahuddin <salahuddin@member.fsf.org> + +    This program is free software: you can redistribute it and/or modify +    it under the terms of the GNU General Public License as published by +    the Free Software Foundation, either version 3 of the License, or +    (at your option) any later version. + +    This program is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +    GNU General Public License for more details. + +    You should have received a copy of the GNU General Public License +    along with this program.  If not, see <https://www.gnu.org/licenses/>. +--> + +<div id="page"> +  <div id="content"> +    <% file_data %> +    <br /><br /> +    <form action="<% request.uri_base %>/acceptnews" method="POST"> +      <input type='hidden' name='filename_param' value='<% filename_param %>'/> +      <br /> +      <input type="submit" name="submitbutton" value="Publish"> +    </form> +  <br /> +  </div> +</div> diff --git a/web/NetUseAdminWeb/views/generic.tt b/web/NetUseAdminWeb/views/generic.tt new file mode 100644 index 0000000..8629624 --- /dev/null +++ b/web/NetUseAdminWeb/views/generic.tt @@ -0,0 +1,23 @@ +<!-- +    NetUseMod is a program to moderate Usenet posts via web interface. +    Copyright (C) 2024  Salahuddin <salahuddin@member.fsf.org> + +    This program is free software: you can redistribute it and/or modify +    it under the terms of the GNU General Public License as published by +    the Free Software Foundation, either version 3 of the License, or +    (at your option) any later version. + +    This program is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +    GNU General Public License for more details. + +    You should have received a copy of the GNU General Public License +    along with this program.  If not, see <https://www.gnu.org/licenses/>. +--> + +<div id="page"> +<div id="content"> +  <% message %> +</div> +</div> diff --git a/web/NetUseAdminWeb/views/index.tt b/web/NetUseAdminWeb/views/index.tt new file mode 100644 index 0000000..d16bc34 --- /dev/null +++ b/web/NetUseAdminWeb/views/index.tt @@ -0,0 +1,27 @@ +<!-- +    NetUseMod is a program to moderate Usenet posts via web interface. +    Copyright (C) 2024  Salahuddin <salahuddin@member.fsf.org> + +    This program is free software: you can redistribute it and/or modify +    it under the terms of the GNU General Public License as published by +    the Free Software Foundation, either version 3 of the License, or +    (at your option) any later version. + +    This program is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +    GNU General Public License for more details. + +    You should have received a copy of the GNU General Public License +    along with this program.  If not, see <https://www.gnu.org/licenses/>. +--> + +<div id="page"> +  <div id="content"> +    <a href="<% request.uri_base %>/listincomingnews">Incoming news</a> +    <br /><br /> +    <a href="<% request.uri_base %>/listprocessednews">Processed news</a> +    <br /><br /> +    <a href="<% request.uri_base %>/listrejectednews">Rejected news</a> +  </div> +</div> diff --git a/web/NetUseAdminWeb/views/layouts/main.tt b/web/NetUseAdminWeb/views/layouts/main.tt new file mode 100644 index 0000000..19f2134 --- /dev/null +++ b/web/NetUseAdminWeb/views/layouts/main.tt @@ -0,0 +1,132 @@ +<!DOCTYPE html> + +<!-- +    NetUseMod is a program to moderate Usenet posts via web interface. +    Copyright (C) 2024  Salahuddin <salahuddin@member.fsf.org> + +    This program is free software: you can redistribute it and/or modify +    it under the terms of the GNU General Public License as published by +    the Free Software Foundation, either version 3 of the License, or +    (at your option) any later version. + +    This program is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +    GNU General Public License for more details. + +    You should have received a copy of the GNU General Public License +    along with this program.  If not, see <https://www.gnu.org/licenses/>. +--> + +<html lang="en"> +<head> +  <meta charset="<% settings.charset %>"> +  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes"> +  <style> +    body { +	margin: 0; +	margin-bottom: 25px; +	padding: 0; +	background-color: #ddd; +	background-repeat: no-repeat; +	background-position: top left; +	font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana"; +	font-size: 16px; +	color: #333; +    } + +    * { +	box-sizing: border-box; +    } + +    input, button, select, option, textarea { +	font-size: 100%; +    } + +    header { +	background-color: #777; +	padding: 15px; +	text-align: center; +	font-size: 18px; +	color: white; +    } + +    header a { +	color:  white; +    } + +    footer { +	position: fixed; +	left: 0; +	bottom: 0; +	width: 100%; + +	background-color: #777; +	padding: 10px; +	text-align: center; +	color: white; +	font-size: 14px; +    } + +    footer a { +	color:  white; +    } + +    section { +	padding: 20px; +	display: inline-block; +	width: 100%; +	background-color: white; +    } + +    article { +	margin: auto; +	width: 100%; +	font-size: 16px; +	border: 2px solid #777; +	padding: 15px; +	background-color: f1f1f1; +	max-width: 900px; +    } + +    table { +	font-family: Arial, Helvetica, sans-serif; +	border-collapse: collapse; +	width: 100%; +    } + +    table td, table th { +	border: 1px solid #ddd; +	padding: 8px; +    } + +    table tr:nth-child(even) { +	background-color: #f2f2f2; +    } + +    table tr:hover {background-color: #ddd;} + +    table th { +	padding-top: 12px; +	padding-bottom: 12px; +	text-align: left; +	background-color: #777; +	color: white; +    } +  </style> +  <title><% title %></title> +</head> +<body> +  <header> +    <a href="<% request.uri_base %>/">Home</a>   <a href="<% request.uri_base %>/logout">Logout</a> +  </header> +  <section> +    <article> +      <% content %> +    </article> +</section> +<footer> +Powered by <a href="http://perldancer.org/">Dancer2</a> <% dancer_version %> +</footer> +</body> +</html> diff --git a/web/NetUseAdminWeb/views/listnews.tt b/web/NetUseAdminWeb/views/listnews.tt new file mode 100644 index 0000000..ba8af99 --- /dev/null +++ b/web/NetUseAdminWeb/views/listnews.tt @@ -0,0 +1,30 @@ +<!-- +    NetUseMod is a program to moderate Usenet posts via web interface. +    Copyright (C) 2024  Salahuddin <salahuddin@member.fsf.org> + +    This program is free software: you can redistribute it and/or modify +    it under the terms of the GNU General Public License as published by +    the Free Software Foundation, either version 3 of the License, or +    (at your option) any later version. + +    This program is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +    GNU General Public License for more details. + +    You should have received a copy of the GNU General Public License +    along with this program.  If not, see <https://www.gnu.org/licenses/>. +--> + +<div id="page"> +  <div id="content"> +    <table> +    <tr> +      <th>Filename</th> +      <th>Created</th> +      <th>Action</th> +    </tr> +    <% listnews %> +    </table> +  </div> +</div> diff --git a/web/NetUseAdminWeb/views/login.tt b/web/NetUseAdminWeb/views/login.tt new file mode 100644 index 0000000..2ea2c8b --- /dev/null +++ b/web/NetUseAdminWeb/views/login.tt @@ -0,0 +1,33 @@ +<!-- +    NetUseMod is a program to moderate Usenet posts via web interface. +    Copyright (C) 2024  Salahuddin <salahuddin@member.fsf.org> + +    This program is free software: you can redistribute it and/or modify +    it under the terms of the GNU General Public License as published by +    the Free Software Foundation, either version 3 of the License, or +    (at your option) any later version. + +    This program is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +    GNU General Public License for more details. + +    You should have received a copy of the GNU General Public License +    along with this program.  If not, see <https://www.gnu.org/licenses/>. +--> + +<div id="page"> +  <div id="content" align="center"> +    <form action="<% request.uri_base %>/login" method="POST"> +        <br /> +        <label>UserName: </label> +        <input type="text" name='user'> +        <br /><br /> +        <label>Password: </label> +        <input type="password" name='pass'> +        <br /><br /> +        <input type='hidden' name='path' value='<% path %>'/> +        <button type="submit">Login</button> +    </form> +  </div> +</div> diff --git a/web/NetUseAdminWeb/views/rejectnews.tt b/web/NetUseAdminWeb/views/rejectnews.tt new file mode 100644 index 0000000..fc19e41 --- /dev/null +++ b/web/NetUseAdminWeb/views/rejectnews.tt @@ -0,0 +1,33 @@ +<!-- +    NetUseMod is a program to moderate Usenet posts via web interface. +    Copyright (C) 2024  Salahuddin <salahuddin@member.fsf.org> + +    This program is free software: you can redistribute it and/or modify +    it under the terms of the GNU General Public License as published by +    the Free Software Foundation, either version 3 of the License, or +    (at your option) any later version. + +    This program is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +    GNU General Public License for more details. + +    You should have received a copy of the GNU General Public License +    along with this program.  If not, see <https://www.gnu.org/licenses/>. +--> + +<div id="page"> +  <div id="content"> +    <% file_data %> +    <br /><br /> +    <form action="<% request.uri_base %>/rejectnews" method="POST"> +      <input type='hidden' name='filename_param' value='<% filename_param %>'/> +      <textarea id="reject_reason" name="reject_reason" rows="6" cols="50"></textarea> +      <br /><br /><br /> +      <input type="submit" name="submitbutton" value="Send reject notification"> +     +      <input type="submit" name="submitbutton" value="Ignore message (don't send notification)"> +    </form> +    <br /> +  </div> +</div> diff --git a/web/NetUseAdminWeb/views/viewnews.tt b/web/NetUseAdminWeb/views/viewnews.tt new file mode 100644 index 0000000..f6d7f52 --- /dev/null +++ b/web/NetUseAdminWeb/views/viewnews.tt @@ -0,0 +1,25 @@ +<!-- +    NetUseMod is a program to moderate Usenet posts via web interface. +    Copyright (C) 2024  Salahuddin <salahuddin@member.fsf.org> + +    This program is free software: you can redistribute it and/or modify +    it under the terms of the GNU General Public License as published by +    the Free Software Foundation, either version 3 of the License, or +    (at your option) any later version. + +    This program is distributed in the hope that it will be useful, +    but WITHOUT ANY WARRANTY; without even the implied warranty of +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +    GNU General Public License for more details. + +    You should have received a copy of the GNU General Public License +    along with this program.  If not, see <https://www.gnu.org/licenses/>. +--> + +<div id="page"> +  <div id="content"> +    <% file_data %> +    <br /><br /> +    <% accept_reject_html_block %> +  </div> +</div> | 
