From 7786ce2a332b0eba4b3ca7c57f906a32e8715da3 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Fri, 29 Oct 2010 19:46:24 -0500 Subject: Starting repo cleanup to make this not so awful --- pinyadmin/sbin/addaccess | 19 +++++++ pinyadmin/sbin/newrepo | 40 ++++++++++++++ pinyadmin/sbin/newuser | 129 +++++++++++++++++++++++++++++++++++++++++++++ pinyadmin/sbin/pinyconfig | 38 +++++++++++++ pinyadmin/sbin/rebuildrepo | 14 +++++ pinyadmin/sbin/rmaccess | 19 +++++++ pinyadmin/sbin/rmrepo | 21 ++++++++ 7 files changed, 280 insertions(+) create mode 100755 pinyadmin/sbin/addaccess create mode 100755 pinyadmin/sbin/newrepo create mode 100755 pinyadmin/sbin/newuser create mode 100755 pinyadmin/sbin/pinyconfig create mode 100755 pinyadmin/sbin/rebuildrepo create mode 100755 pinyadmin/sbin/rmaccess create mode 100755 pinyadmin/sbin/rmrepo (limited to 'pinyadmin/sbin') diff --git a/pinyadmin/sbin/addaccess b/pinyadmin/sbin/addaccess new file mode 100755 index 0000000..e351114 --- /dev/null +++ b/pinyadmin/sbin/addaccess @@ -0,0 +1,19 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Piny; + +my $env = Piny::Environment->instance( ); + +my ( $reponame, @users ) = @ARGV; + +my $repo = Piny::Repo->new( $reponame ); + +if ( $repo->owner->uid != $env->user->uid ) { + print "You are not the owner of that repo!\n"; + exit( 3 ); +}; + +$repo->add_access( map { Piny::User->new( $_ ) } @users ); diff --git a/pinyadmin/sbin/newrepo b/pinyadmin/sbin/newrepo new file mode 100755 index 0000000..a178ecb --- /dev/null +++ b/pinyadmin/sbin/newrepo @@ -0,0 +1,40 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Moose::Util::TypeConstraints qw( find_type_constraint ); + +use Piny; + +my ( $name ) = @ARGV; + +if ( not defined $name ) { + print "Usage: newrepo REPONAME\n"; + exit 1; +}; + +if ( not find_type_constraint( "Reponame" )->check( $name ) ) { + print "That is not a valid repo name; must be at least 1 character long, begin with a lowercase alphanumeric character, and contain only alphanumeric characters and dashes.\n"; + exit 1; +}; + +my $description; +while( 1 ) { + + print "Provide a one-line description to be used in repo listings, the shorter the better:\n"; + chomp( $description = ); + + if ( not find_type_constraint( "SimpleText" )->check( $description ) ) { + print "Must be 1-80 characters long; control characters (including tab) not allowed.\n"; + next; + }; + + print "Okay! Working, please wait...\n"; + last; + +}; + +my $repo = Piny::Repo->create( $name, $description ); + +print "Repo URL: " . $repo->ikiwiki_url . "\n"; diff --git a/pinyadmin/sbin/newuser b/pinyadmin/sbin/newuser new file mode 100755 index 0000000..e064f06 --- /dev/null +++ b/pinyadmin/sbin/newuser @@ -0,0 +1,129 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Email::Valid::Loose qw( ); + +# If they passed any arguments, complain and exit. +if ( scalar @ARGV ) { + print "You can't pass any arguments to this script!\n"; + exit 2; +}; + +# If they didn't provide a terminal definition, then assume xterm. +# Everybody emulates xterm to at least a basic extent. +if ( not exists $ENV{"TERM"} ) { + $ENV{"TERM"} = "xterm"; + print "I don't know what terminal you're using; guessing xterm...\n"; +}; + +# Disable buffering. +$|++; + +# Configure the strictness of our email checks. +my $checker = Email::Valid::Loose->new + ( "-fqdn" => 1 + , "-fudge" => 0 + , "-local_rules" => 0 + , "-mxcheck" => 1 + , "-tldcheck" => 0 + ); + +my ( $email, $username, $password1, $password2 ); + +while ( 1 ) { + + print "Email address to associate with new user: "; + chomp ( $email = ); + + if ( $email eq "" ) { + print "You must provide an email address!\n"; + next; + }; + + $email = $checker->address( $email ); + if ( not defined $email ) { + print "Please, at least pretend to provide a valid email address.\n"; + next; + }; + + last; + +}; + +while ( 1 ) { + + print "Desired username: "; + chomp ( $username = ); + + if ( $username eq "" ) { + print "You have to enter a username!\n"; + next; + }; + + if ( $username =~ /^git-|^ikiwiki-/ ) { + print "Your username cannot start with git- or ikiwiki-!\n"; + next + }; + + if ( $username !~ /^[a-zA-Z0-9_.][a-zA-Z0-9_.-]+$/ ) { + print( "Usernames must consist only of letters, digits, underscores, periods, and dashes, and not start with a dash. Usernames are case sensitive.\n" ); + next + }; + + last; + +}; + +while ( 1 ) { + + system( "stty", "-echo" ); + print "Desired password: "; + chomp ( $password1 = ); + print "\nRetype password: "; + chomp ( $password2 = ); + print "\n"; + system( "stty", "echo" ); + + if ( $password1 ne $password2 ) { + print "Provided passwords do not match; try again.\n"; + next; + }; + + if ( $password1 eq "" ) { + print "You have to enter a password!\n"; + next; + }; + + last; + +}; + +my @saltchars = + ( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' + , 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' + , '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' + , '.', '/' + ); + +my $salt = "\$6\$"; + +foreach my $n ( 1 .. 16 ) { + $salt .= $saltchars[int ( rand ( scalar @saltchars ) )]; +}; + +$salt .= "\$"; + +my $crypt = crypt( $password1, $salt ); + +my $ret = system( "/usr/sbin/useradd", "-c", "$email", "-k", "/var/empty", "-g", "users", "-m", "-p", $crypt, "-s", "/usr/bin/pinyshell", $username ); + +if ( $ret ) { + print "An error occured creating the user; most likely, that username is already taken.\n"; + exit 1; +}; + +print "Your user has been created. Try logging in!\n"; + +exit 0; diff --git a/pinyadmin/sbin/pinyconfig b/pinyadmin/sbin/pinyconfig new file mode 100755 index 0000000..f6752db --- /dev/null +++ b/pinyadmin/sbin/pinyconfig @@ -0,0 +1,38 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Piny; + +my ( $reponame, $attr, $value ) = @ARGV; + +if ( not defined $reponame or not defined $attr ) { + die "Usage: $0 reponame tweakable [value]\n"; +}; + +$attr = lc $attr; +$attr =~ s/\./_/g; + +my $repo = Piny::Repo->new( $reponame ); + +if ( defined $value ) { + undef $@; + eval { + $repo->config->$attr( $value ); + }; + if ( $@ ) { + print STDERR "$attr is not a legal tweakable, or $value is not a legal value for that tweakable.\n$@\n"; + }; + if ( $value ne $repo->config->$attr ) { + print STDERR "Failed to set $attr (perhaps an override is in place)\n"; + }; +}; + +undef $@; +eval { + print "$attr = " . $repo->config->$attr . "\n"; +}; +if ( $@ ) { + print STDERR "$attr is not a legal tweakable, or its current value is illegal.\n$@\n"; +}; diff --git a/pinyadmin/sbin/rebuildrepo b/pinyadmin/sbin/rebuildrepo new file mode 100755 index 0000000..9d4e359 --- /dev/null +++ b/pinyadmin/sbin/rebuildrepo @@ -0,0 +1,14 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Piny; + +foreach my $reponame ( @ARGV ) { + + my $repo = Piny::Repo->new( $reponame ); + + $repo->rebuild; + +}; diff --git a/pinyadmin/sbin/rmaccess b/pinyadmin/sbin/rmaccess new file mode 100755 index 0000000..d6c22a9 --- /dev/null +++ b/pinyadmin/sbin/rmaccess @@ -0,0 +1,19 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Piny; + +my $env = Piny::Environment->instance( ); + +my ( $reponame, @users ) = @ARGV; + +my $repo = Piny::Repo->new( $reponame ); + +if ( $repo->owner->uid != $env->user->uid ) { + print "You are not the owner of that repo!\n"; + exit( 3 ); +}; + +$repo->remove_access( map { Piny::User->new( $_ ) } @users ); diff --git a/pinyadmin/sbin/rmrepo b/pinyadmin/sbin/rmrepo new file mode 100755 index 0000000..dff8fe5 --- /dev/null +++ b/pinyadmin/sbin/rmrepo @@ -0,0 +1,21 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Piny; + +my $env = Piny::Environment->instance( ); + +foreach my $reponame ( @ARGV ) { + + my $repo = Piny::Repo->new( $reponame ); + + if ( $env->user->uid != 0 and $repo->owner->uid != $env->user->uid ) { + print STDERR "You are not the owner of $reponame!\n"; + exit 1; + }; + + $repo->destroy; + +}; -- cgit v1.2.3