summaryrefslogtreecommitdiff
path: root/pinyweb/cgi-bin/piny-newuser.cgi
blob: 64b6b0a1697eadb50eb16856d1673c03b9fefe53 (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
#!/usr/bin/perl
$| = 1;

use warnings;

use CGI;

use IPC::Open2;

$q = CGI->new;

print( "Content-type: text/plain

"

if( $q->param('n') && $q->param('a') && $q->param('p') ) {
  # 03:57:44 omg/jrayhawk: system() lets me specify arguments as an array, and open() lets me work with stdout, but i would like something that does both
  # 03:59:50 omg/jrayhawk: hahaha they recommend i open(, '-|') and then exec() in the child
  # 03:59:55 omg/jrayhawk: fuck you, perl
  $pid = open2( OUT, IN, '-' );
  # make things flushier
  select((select(IN), $| = 1)[0]);
  select((select(OUT), $| = 1)[0]);
  if( $pid ) {
    print( IN $q->param('p') . "\n" );
    while( <OUT> ) {
      print;
    };
  } else {
    exec( '/usr/bin/sudo', '/usr/sbin/newuser', '--batch', $q->param('a'), $q->param('n') ) || print 'could not execute newuser' && die;
  };
} else {
  print 'Missing parameters.';
};