From 361b43dd712750acb2494f848a8102a442ff1f75 Mon Sep 17 00:00:00 2001 From: Joe Date: Fri, 6 May 2022 14:51:55 +0200 Subject: update --- cron/counter.sh | 10 ++++++ src/cron/counter.sh | 10 ------ src/gitjoe/addsshkey.pl | 31 ------------------ src/gitjoe/adduser.pl | 55 -------------------------------- src/gitjoe/chdesc.pl | 37 ---------------------- src/gitjoe/chowner.pl | 37 ---------------------- src/gitjoe/chstate.pl | 44 -------------------------- src/gitjoe/mvrepo.pl | 38 ----------------------- src/gitjoe/newrepo.pl | 76 --------------------------------------------- src/gitjoe/rmrepo.pl | 36 --------------------- src/gitjoe/rmuser.pl | 31 ------------------ src/other/git-ro-daemon.csh | 3 -- vps-do.pl | 65 -------------------------------------- 13 files changed, 10 insertions(+), 463 deletions(-) create mode 100755 cron/counter.sh delete mode 100755 src/cron/counter.sh delete mode 100755 src/gitjoe/addsshkey.pl delete mode 100755 src/gitjoe/adduser.pl delete mode 100755 src/gitjoe/chdesc.pl delete mode 100755 src/gitjoe/chowner.pl delete mode 100755 src/gitjoe/chstate.pl delete mode 100755 src/gitjoe/mvrepo.pl delete mode 100755 src/gitjoe/newrepo.pl delete mode 100755 src/gitjoe/rmrepo.pl delete mode 100755 src/gitjoe/rmuser.pl delete mode 100755 src/other/git-ro-daemon.csh delete mode 100755 vps-do.pl diff --git a/cron/counter.sh b/cron/counter.sh new file mode 100755 index 0000000..b75dd12 --- /dev/null +++ b/cron/counter.sh @@ -0,0 +1,10 @@ +#!/bin/sh -e + +logfile='/var/log/nginx/access.log' +destfile='/usr/local/www/jozan/index.html' +foretext='Unique visitors: ' +botlist='petalbot|googlebot|adsbot-google|ahrefs\.com|pingbot|robots\.txt|pandalytics|serpstatbot|zoombot|semrush.com\/bot|archive\.org_bot|bingbot|vuhuvbot|neevabot|botaflatoon|botfnetowrksx|zaldamosearchbot|facebookexternalhit|mj12bot|polaris botnet|turnitinbot' + +[ -e $logfile ] || exit 1 +[ -e $destfile ] || exit 1 +sed -i '' "s/$foretext.*$/$foretext$(grep -E -v -i "$botlist" $logfile | awk '{print $1}' | sort | uniq | wc -l | tr -d ' ')<\/b>/" $destfile diff --git a/src/cron/counter.sh b/src/cron/counter.sh deleted file mode 100755 index b75dd12..0000000 --- a/src/cron/counter.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -e - -logfile='/var/log/nginx/access.log' -destfile='/usr/local/www/jozan/index.html' -foretext='Unique visitors: ' -botlist='petalbot|googlebot|adsbot-google|ahrefs\.com|pingbot|robots\.txt|pandalytics|serpstatbot|zoombot|semrush.com\/bot|archive\.org_bot|bingbot|vuhuvbot|neevabot|botaflatoon|botfnetowrksx|zaldamosearchbot|facebookexternalhit|mj12bot|polaris botnet|turnitinbot' - -[ -e $logfile ] || exit 1 -[ -e $destfile ] || exit 1 -sed -i '' "s/$foretext.*$/$foretext$(grep -E -v -i "$botlist" $logfile | awk '{print $1}' | sort | uniq | wc -l | tr -d ' ')<\/b>/" $destfile diff --git a/src/gitjoe/addsshkey.pl b/src/gitjoe/addsshkey.pl deleted file mode 100755 index 431ce7d..0000000 --- a/src/gitjoe/addsshkey.pl +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/local/bin/perl - -use strict; -use warnings; -use Term::ANSIColor; -use constant HOME_DIR => '/usr/local/git/'; - -sub main -{ - my $argc = $#ARGV + 1; - if ($argc < 2) { - print colored("Failed!\n", 'bold red') - . "Missing argument, 2 needed " - . colored("[user - ssh public key]", 'bold') - . "\n"; - exit 1; - } - my $usr = $ARGV[0]; - my $sshkey = "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty "; - $sshkey = $sshkey . $ARGV[1]; - my $home_dir = HOME_DIR . $usr . '/'; - open(my $fh, '>>:encoding(UTF-8)', $home_dir . '.ssh/authorized_keys'); - print $fh "$sshkey\n"; - close($fh); - print "Added new ssh key for user " . colored($usr, 'bold green') . ".\n"; - exit; -} - -main(); - -__END__ diff --git a/src/gitjoe/adduser.pl b/src/gitjoe/adduser.pl deleted file mode 100755 index 4e0746d..0000000 --- a/src/gitjoe/adduser.pl +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/local/bin/perl - -use strict; -use warnings; -use Term::ANSIColor; -use constant HOME_DIR => '/usr/local/git/'; - -sub main -{ - my $argc = $#ARGV + 1; - if ($argc < 2) { - print colored("Failed!\n", 'bold red') - . "Missing argument, 2 needed " - . colored("[user - ssh public key]", 'bold') - . "\n"; - exit 1; - } - my $usr = $ARGV[0]; - my $sshkey = "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty "; - $sshkey = $sshkey . $ARGV[1]; - my $home_dir = HOME_DIR . $usr . '/'; - system( - "adduser << EOF -" . $usr . " - - - - - -git-shell -" . HOME_DIR . $usr . " - - - -yes - -yes -no -EOF" - ); - my (undef, undef, $uid, $gid) = getpwnam($usr); - mkdir $home_dir . '.ssh/', 0700; - chown $uid, $gid, $home_dir . '.ssh/'; - open(my $fh, '>:encoding(UTF-8)', $home_dir . '.ssh/authorized_keys'); - print $fh $sshkey . "\n"; - close($fh); - chown $uid, $gid, $home_dir . '.ssh/authorized_keys'; - chmod 0600, $home_dir . '.ssh/authorized_keys'; - print "Created new git user " . colored($usr, 'bold green') . ".\n"; - exit; -} - -main(); - -__END__ diff --git a/src/gitjoe/chdesc.pl b/src/gitjoe/chdesc.pl deleted file mode 100755 index b0c25b7..0000000 --- a/src/gitjoe/chdesc.pl +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/local/bin/perl - -use strict; -use warnings; -use Term::ANSIColor; -use constant HOME_DIR => '/usr/local/git/'; - -sub main -{ - my $argc = $#ARGV + 1; - if ($argc < 3) { - print colored("Failed!\n", 'bold red') - . "Missing argument, 3 needed " - . colored("[user - reponame - new description]", 'bold') - . "\n"; - exit 1; - } - my $usr = $ARGV[0]; - my $repo = $ARGV[1]; - my $desc = $ARGV[2]; - my $home_dir = HOME_DIR . $usr . '/'; - if (substr($repo, -4) ne '.git') { - $repo = $repo . '.git'; - } - $repo = $repo . '/'; - open(my $desc_fh, '>:encoding(UTF-8)', $home_dir . $repo . 'description'); - print $desc_fh $desc; - close($desc_fh); - substr($repo, -1) = ""; - print "Changed git repository " . colored($repo, 'bold green') . " description for user " . colored($usr, 'bold') . ".\n" - . "New description: ". colored($desc, 'bold green') . ".\n"; - exit; -} - -main(); - -__END__ diff --git a/src/gitjoe/chowner.pl b/src/gitjoe/chowner.pl deleted file mode 100755 index f3b1218..0000000 --- a/src/gitjoe/chowner.pl +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/local/bin/perl - -use strict; -use warnings; -use Term::ANSIColor; -use constant HOME_DIR => '/usr/local/git/'; - -sub main -{ - my $argc = $#ARGV + 1; - if ($argc < 3) { - print colored("Failed!\n", 'bold red') - . "Missing argument, 3 needed " - . colored("[user - reponame - new owner]", 'bold') - . "\n"; - exit 1; - } - my $usr = $ARGV[0]; - my $repo = $ARGV[1]; - my $owner = $ARGV[2]; - my $home_dir = HOME_DIR . $usr . '/'; - if (substr($repo, -4) ne '.git') { - $repo = $repo . '.git'; - } - $repo = $repo . '/'; - open(my $owner_fh, '>:encoding(utf-8)', $home_dir . $repo . 'owner'); - print $owner_fh $owner; - close($owner_fh); - substr($repo, -1) = ""; - print "Changed git repository " . colored($repo, 'bold green') . colored(" owner", 'bold') . " for user " . colored($usr, 'bold green') . ".\n" - . "New owner: ". colored($owner, 'bold green') . ".\n"; - exit; -} - -main(); - -__END__ diff --git a/src/gitjoe/chstate.pl b/src/gitjoe/chstate.pl deleted file mode 100755 index 1411e99..0000000 --- a/src/gitjoe/chstate.pl +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/local/bin/perl - -use strict; -use warnings; -use Term::ANSIColor; -use constant HOME_DIR => '/usr/local/git/'; - -sub main -{ - my $argc = $#ARGV + 1; - if ($argc < 2) { - print colored("Failed!\n", 'bold red') - . "Missing argument, 2 needed " - . colored("[user - reponame]", 'bold') - . "\n"; - exit 1; - } - my $usr = $ARGV[0]; - my $repo = $ARGV[1]; - my $home_dir = HOME_DIR . $usr . '/'; - if (substr($repo, -4) ne '.git') { - $repo = $repo . '.git'; - } - my $state; - if (-e $home_dir . $repo . '/git-daemon-export-ok') { - unlink($home_dir . $repo . '/git-daemon-export-ok'); - $state = 'private'; - } - else { - open(my $fh, '>', $home_dir . $repo . '/git-daemon-export-ok'); - close($fh); - $state = 'public'; - my (undef, undef, $uid, $gid) = getpwnam($usr); - chown $uid, $gid, $home_dir . $repo . '/git-daemon-export-ok'; - } - print "Changed git repository " . colored($repo, 'bold green') - . " for user " . colored($usr, 'bold green') - . colored(' visibility state', 'bold') . ' to '. colored($state, 'bold green') . ".\n"; - exit; -} - -main(); - -__END__ diff --git a/src/gitjoe/mvrepo.pl b/src/gitjoe/mvrepo.pl deleted file mode 100755 index 968fdbc..0000000 --- a/src/gitjoe/mvrepo.pl +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/local/bin/perl - -use strict; -use warnings; -use File::Copy; -use Term::ANSIColor; - -use constant HOME_DIR => '/usr/local/git/'; - -sub main -{ - my $argc = $#ARGV + 1; - if ($argc < 3) { - print colored("Failed!\n", 'bold red') - . "Missing argument, 3 needed " - . colored("[user - reponame - new name]", 'bold') - . "\n"; - exit 1; - } - my $usr = $ARGV[0]; - my $repo = $ARGV[1]; - my $newname = $ARGV[2]; - my $home_dir = HOME_DIR . $usr . '/'; - if (substr($repo, -4) ne '.git') { - $repo .= '.git'; - } - if (substr($newname, -4) ne '.git') { - $newname .= '.git'; - } - move($home_dir . $repo, $home_dir . $newname); - print "Changed git repository " . colored($repo, 'bold green') - . " name to " . colored($newname, 'bold green') . " for user " . colored($usr, 'bold') . ".\n"; - exit; -} - -main(); - -__END__ diff --git a/src/gitjoe/newrepo.pl b/src/gitjoe/newrepo.pl deleted file mode 100755 index dc8041b..0000000 --- a/src/gitjoe/newrepo.pl +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/local/bin/perl - -use strict; -use warnings; -use Term::ANSIColor; -use File::Find; -use constant HOME_DIR => '/usr/local/git/'; - -sub main -{ - my $argc = $#ARGV + 1; - if ($argc < 2) { - print colored("Failed!\n", 'bold red') - . "Missing argument, at least 2 needed " - . colored("[user - reponame - (description)]", 'bold') - . "\n"; - exit 1; - } - my $usr = $ARGV[0]; - my $repo = $ARGV[1]; - my $desc = ""; - if ($argc >= 3) { - $desc = $ARGV[2]; - } - my $home_dir = HOME_DIR . $usr . '/'; - if (substr($repo, -4) ne '.git') { - $repo = $repo . '.git'; - } - $repo = $repo . '/'; - mkdir $home_dir . $repo, 0755; - system( - '/usr/local/bin/git', - '-C', - $home_dir . $repo, - 'init', - '--bare' - ); - my (undef, undef, $uid, $gid) = getpwnam($usr); - find( - sub { - chown $uid, $gid, $_; - }, - $home_dir . $repo - ); - system( - '/usr/bin/touch', - $home_dir . $repo . 'git-daemon-export-ok' - ); - chown $uid, $gid, $home_dir . $repo . 'git-daemon-export-ok'; - open(my $owner_fh, '>:encoding(UTF-8)', $home_dir . $repo . 'owner'); - print $owner_fh $usr; - close($owner_fh); - open(my $url_fh, '>:encoding(UTF-8)', $home_dir . $repo . 'url'); - substr($repo, -1) = ""; - print $url_fh 'git://gitjoe.xyz/' . $usr . '/' . $repo; - close($url_fh); - $repo = $repo . '/'; - open(my $desc_fh, '>:encoding(UTF-8)', $home_dir . $repo . 'description'); - if ($argc >= 3) { - print $desc_fh $desc; - } - else { - print $desc_fh 'No description yet'; - } - close($desc_fh); - chown $uid, $gid, $home_dir . $repo . 'description'; - substr($repo, -1) = ""; - print "Created git repository " . colored($repo, 'bold green') . " for user " . colored($usr, 'bold') . ".\n"; - print "Remote url: " . colored($usr . '@gitjoe.xyz:' . $repo, 'bold green') . "\n" - . "Public clone url: " . colored('git://gitjoe.xyz/' . $usr . '/' . $repo, 'bold green') . "\n"; - exit; -} - -main(); - -__END__ diff --git a/src/gitjoe/rmrepo.pl b/src/gitjoe/rmrepo.pl deleted file mode 100755 index b028bb4..0000000 --- a/src/gitjoe/rmrepo.pl +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/local/bin/perl - -use strict; -use warnings; -use Term::ANSIColor; -use constant HOME_DIR => '/usr/local/git/'; - -sub main -{ - my $argc = $#ARGV + 1; - if ($argc < 2) { - print colored("Failed!\n", 'bold red') - . "Missing argument, 2 needed " - . colored("[user - reponame]", 'bold') - . "\n"; - exit 1; - } - my $usr = $ARGV[0]; - my $repo = $ARGV[1]; - my $home_dir = HOME_DIR . $usr . '/'; - if (substr($repo, -4) ne '.git') { - $repo = $repo . '.git'; - } - $repo = $repo . '/'; - system( - '/bin/rm', - '-rfv', - $home_dir . $repo - ); - print "Deleted git repository " . colored($repo, 'bold yellow') . " for user " . colored($usr, 'bold') . ".\n"; - exit; -} - -main(); - -__END__ diff --git a/src/gitjoe/rmuser.pl b/src/gitjoe/rmuser.pl deleted file mode 100755 index 9753950..0000000 --- a/src/gitjoe/rmuser.pl +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/local/bin/perl - -use strict; -use warnings; -use Term::ANSIColor; - -sub main -{ - my $argc = $#ARGV + 1; - if ($argc < 1) { - print colored("Failed!\n", 'bold red') - . "Missing argument, 1 needed " - . colored("[user]", 'bold') - . "\n"; - exit 1; - } - my $usr = $ARGV[0]; - system( - "rmuser << EOF -" . $usr . " -y -y -EOF" - ); - print "Removed git user " . colored($usr, 'bold yellow') . ".\n"; - exit; -} - -main(); - -__END__ diff --git a/src/other/git-ro-daemon.csh b/src/other/git-ro-daemon.csh deleted file mode 100755 index 162fb84..0000000 --- a/src/other/git-ro-daemon.csh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/csh - -exec git daemon --reuseaddr --base-path=/usr/local/git /usr/local/git & diff --git a/vps-do.pl b/vps-do.pl deleted file mode 100755 index 0cc23d1..0000000 --- a/vps-do.pl +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/local/bin/perl - -use strict; -use warnings; -use Term::ANSIColor; - -use constant SCRIPTS_DIR => '/root/scripts/src/'; -use constant SSH_BOY => 'root@jozanofastora.xyz'; - -sub main { - my $argc = $#ARGV + 1; - my $called_script = ''; - my $argv_line = ''; - if ( - $ARGV[0] eq 'addsshkey' || - $ARGV[0] eq 'newuser' || - $ARGV[0] eq 'rmuser' || - $ARGV[0] eq 'chdesc' || - $ARGV[0] eq 'chowner' || - $ARGV[0] eq 'chstate' || - $ARGV[0] eq 'newrepo' || - $ARGV[0] eq 'rmrepo' || - $ARGV[0] eq 'mvrepo' - ) { - $called_script = SCRIPTS_DIR . 'gitjoe/' . $ARGV[0] . '.pl'; - } - else { - print colored("Failed!\n", 'bold red') - . colored($ARGV[0], 'bold yellow') - . ": unknown script. Known scripts are:\n" - . colored("addsshkey\n", 'bold green') - . colored("newuser\n", 'bold green') - . colored("rmuser\n", 'bold green') - . colored("chdesc\n", 'bold green') - . colored("chowner\n", 'bold green') - . colored("chstate\n", 'bold green') - . colored("newrepo\n", 'bold green') - . colored("rmrepo\n", 'bold green') - . colored("mvrepo\n", 'bold green'); - exit 2; - } - print "Calling " . colored($called_script, 'bold green') . " via " . colored(SSH_BOY, 'bold magenta') . ".\n"; - if ($argc > 1) { - print "Arguments:\n"; - my $i = 1; - while ($i < $argc) { - $argv_line = $argv_line . ' "' . $ARGV[$i] . '"'; - print colored($ARGV[$i], 'bold yellow') . "\n"; - $i += 1; - } - } - system( - 'ssh ' . SSH_BOY . " << EOF -" . $called_script . $argv_line . " -exit -EOF -" - ); - print "Done.\n"; - exit; -} - -main(); - -__END__ -- cgit v1.2.3