summaryrefslogtreecommitdiff
path: root/pinyweb/cgi-bin/newuser.cgi
blob: 4f1263bbca9885c48f4c1c55233393e1ce67d768 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/perl
$| = 1;

open(STDERR, ">&STDOUT");

use warnings;

use CGI;

use IPC::Open2;

use Piny::Auth;

$q = CGI->new;

print( "Content-type: text/plain\n\n" );

if( $q->param("n") && $q->param("a") && $q->param("p") ) {

  my $auth = Piny::Auth->new( );

  my $code = $auth->hash( { "n" => $q->param( "n" ), "a" => $q->param( "a" ), "p" => $q->param( "p" ) } );

  if ( $q->param("h") && $q->param("h") eq $code ) {
    unless( open2( OUT, IN, "/usr/bin/sudo", "/usr/sbin/newuser", "--batch", $q->param("a"), $q->param("n") ) ) {
      print "could not execute newrepo";
      die;
    };
    # make things flushier
    select((select(IN), $| = 1)[0]);
    select((select(OUT), $| = 1)[0]);
    print( IN $q->param("p") . "\n" );
    close( IN );
    while( <OUT> ) {
      print;
    };
  } else { # No hash, they need one sent to their address
    print( "Dispatching email to " . $q->param("a") . "...\n" );
    unless( open( MAIL, "|/usr/lib/sendmail -t" ) ) {
      print "could not execute sendmail";
      die;
    };
    print( MAIL "To: " . $q->param("a") . "\n" );
    print( MAIL "Subject: Verifying account " . $q->param("n") . "\n" );
    print( MAIL "Content-Type: text/plain; charset=us-ascii\n\n" );
    print( MAIL "http" );
    if( $ENV{"HTTPS"} eq "on" ) {
      print( MAIL "s" );
    };
    print( MAIL "://" . $ENV{"SERVER_NAME"} . $ENV{"SCRIPT_NAME"} . "?" );
    print( MAIL "h=" . $code );
    print( MAIL "&n=" . $q->param("n") );
    print( MAIL "&a=" . $q->param("a") );
    print( MAIL "&p=" . $q->param("p") );
    print( MAIL "\n");
    close( MAIL ); 
    print( "Done!" );
  };
} else {
  print( "Missing parameters." );
};