]> andersk Git - sql-web.git/blob - batch/signup.php
lighttpd remote signups
[sql-web.git] / batch / signup.php
1 #!/usr/bin/php -q
2 <?php
3
4 require_once(dirname(__FILE__).'/../mitsql.cfg.php');
5 require_once('mitsql.lib.php');
6
7 require_once('batch.inc.php');
8
9 if (isset($argv) && count($argv)>=4) {
10     $myUsername = $argv[1];
11     $myUID = $argv[3];
12     if ($myUID<100) exit('bad UID');
13 } elseif (defined('SIGNUP_PW') && strlen(SIGNUP_PW) && (isset($_SERVER['HTTP_AUTHORIZATION']) || isset($_SERVER['PHP_AUTH_PW'])) && SIGNUP_PW == $_SERVER['PHP_AUTH_PW']) {
14     $myUsername = $i_u;
15 } else {
16     exit;
17 }
18
19 if (empty($myUsername)) exit('bad User');
20 $hescmd = "hesinfo $myUsername passwd";
21 $hesinfo = explode(':', trim(exec($hescmd)));
22 if (count($hesinfo)>=4) {
23         $myName = explode(',', $hesinfo[4]);
24         $myName = array_shift($myName);
25 } else {
26         $myName = $myUsername;
27 }
28 $myEmail = $myUsername.'@mit.edu';
29 $myPassword = trim(exec(dirname(__FILE__).'/../bin/nicepass.py'));
30 if (empty($myPassword)) exit('bad Password');
31
32 $Login = new Login($myUsername);
33 if (!$Login->exists() && !empty($myUsername)) {
34         addUser(array('Name'=>$myName,'Username'=>$myUsername,'Email'=>$myEmail));
35         $Login->refresh();
36 }
37 if ($Login->canSignup()) {
38         $User = new User($Login->getUserId());
39         $User->signup($myPassword);
40         exit($myPassword);
41 }
42
43 ?>
This page took 0.031543 seconds and 5 git commands to generate.