summaryrefslogtreecommitdiff
path: root/pinyadmin/sbin
diff options
context:
space:
mode:
authorJoe Rayhawk <jrayhawk@richardiv.omgwallhack.org>2010-10-30 07:31:35 -0700
committerJoe Rayhawk <jrayhawk@richardiv.omgwallhack.org>2010-10-30 07:31:35 -0700
commitc952a7e6d5e66e2ecd653bb5c177609b59619808 (patch)
treed2be5d0dee505ae00c4b85a5f4129efc2456d5f6 /pinyadmin/sbin
parentd03e1eb495c79c19dc70bbe8eab81eadce98210a (diff)
parent79c284badd015f88d8fd42d941e30bca70dd4eb9 (diff)
downloadpiny-code-c952a7e6d5e66e2ecd653bb5c177609b59619808.tar.gz
piny-code-c952a7e6d5e66e2ecd653bb5c177609b59619808.zip
Merge branch 'master' of piny.be:/srv/git/piny-code
Diffstat (limited to 'pinyadmin/sbin')
-rwxr-xr-xpinyadmin/sbin/addaccess19
-rwxr-xr-xpinyadmin/sbin/newrepo40
-rwxr-xr-xpinyadmin/sbin/newuser129
-rwxr-xr-xpinyadmin/sbin/pinyconfig38
-rwxr-xr-xpinyadmin/sbin/rebuildrepo14
-rwxr-xr-xpinyadmin/sbin/rmaccess19
-rwxr-xr-xpinyadmin/sbin/rmrepo21
7 files changed, 280 insertions, 0 deletions
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 = <STDIN> );
+
+ 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 = <STDIN> );
+
+ 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 = <STDIN> );
+
+ 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 = <STDIN> );
+ print "\nRetype password: ";
+ chomp ( $password2 = <STDIN> );
+ 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;
+
+};