]> andersk Git - sql-web.git/commitdiff
user interaction moved to proc.lib.php
authorJoe Presbrey <presbrey@mit.edu>
Wed, 30 Nov 2005 19:55:43 +0000 (19:55 +0000)
committerJoe Presbrey <presbrey@mit.edu>
Wed, 30 Nov 2005 19:55:43 +0000 (19:55 +0000)
batch signup, status check, create db
tools has the sql suid binary

git-svn-id: svn://presbrey.mit.edu/sql/mitsql@86 a142d4bd-2cfb-0310-9673-cb33a7e74f58

batch/batch.inc.php [new file with mode: 0644]
batch/create_db.php [new file with mode: 0755]
batch/signup.php [new file with mode: 0755]
batch/status.php [new file with mode: 0755]
bin/root_install_signup.sh [new file with mode: 0644]
bin/signup.c [new file with mode: 0644]
lib/proc.lib.php [new file with mode: 0644]
main.php

diff --git a/batch/batch.inc.php b/batch/batch.inc.php
new file mode 100644 (file)
index 0000000..8b65e29
--- /dev/null
@@ -0,0 +1,9 @@
+<?php
+
+isset($i_u) || $i_u = '';
+isset($i_p) || $i_p = '';
+isset($i_d) || $i_d = '';
+
+$i_d = str_replace(' ', '+', $i_d);
+
+?>
diff --git a/batch/create_db.php b/batch/create_db.php
new file mode 100755 (executable)
index 0000000..f29b3d7
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+
+require_once('../mitsql.cfg.php');
+require_once('mitsql.lib.php');
+require_once('proc.lib.php');
+
+require_once('batch.inc.php');
+
+$Login = new Login($i_u, $i_p);
+if (!$Login->canLogin()) die('-1');
+
+$User = new User($Login->getUserID());
+$myUsername = $User->getUsername();
+
+if (substr($i_d,0,strlen($myUsername)+1) == $myUsername.DELIMETER) {
+       $i_d = explode(DELIMETER, $i_d);
+       array_shift($i_d);
+       $i_d = implode(DELIMETER, $i_d);
+}
+
+list($msg1, $err1) = proc::newdb($User, $i_d);
+if (!empty($err1)) die('-3');
+if (empty($err1)) die('0');
+
+?>
diff --git a/batch/signup.php b/batch/signup.php
new file mode 100755 (executable)
index 0000000..357efcd
--- /dev/null
@@ -0,0 +1,37 @@
+#!/usr/bin/php
+<?php
+
+require_once(dirname(__FILE__).'/../mitsql.cfg.php');
+require_once('mitsql.lib.php');
+
+require_once('batch.inc.php');
+
+$callingUnix = posix_getpwuid(posix_getuid());
+
+$myUsername = escapeshellcmd($callingUnix['name']);
+$hesinfo = explode(':', trim(`hesinfo $myUsername passwd`));
+if (count($hesinfo)>=4) {
+       $myName = explode(',', $hesinfo[4]);
+       $myName = array_shift($myName);
+} else {
+       $myName = $myUsername;
+}
+$myUID = $callingUnix['uid'];
+$myEmail = $myUsername.'@mit.edu';
+$myPassword = substr(uniqid(),0,7);
+
+if ($myUID<1000) exit;
+
+$Login = new Login($myUsername);
+if (!$Login->exists() && !empty($myUsername)) {
+       addUser(array('Name'=>$myName,'Username'=>$myUsername,'Email'=>$myEmail));
+       $Login->refresh();
+}
+if ($Login->canSignup()) {
+       $User = new User($Login->getUserId());
+       echo $User->signup($myPassword);
+       echo "signup\n";
+       die($myPassword);
+}
+
+?>
diff --git a/batch/status.php b/batch/status.php
new file mode 100755 (executable)
index 0000000..bb961e1
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+
+require_once('../mitsql.cfg.php');
+require_once('mitsql.lib.php');
+
+require_once('batch.inc.php');
+
+$Login = new Login($i_u);
+if (!$Login->canLogin()) die('-1');
+
+die('0');
+
+?>
diff --git a/bin/root_install_signup.sh b/bin/root_install_signup.sh
new file mode 100644 (file)
index 0000000..84d250a
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+gcc signup.c -o /home/tools/bin/sql-signup
+chown sql /home/tools/bin/sql-signup
+chmod 4701 /home/tools/bin/sql-signup
diff --git a/bin/signup.c b/bin/signup.c
new file mode 100644 (file)
index 0000000..ca2dbc5
--- /dev/null
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+int main() {
+       system("php /home/sql/web_scripts/main/batch/signup.php");
+       return 0;
+}
diff --git a/lib/proc.lib.php b/lib/proc.lib.php
new file mode 100644 (file)
index 0000000..55a3d8f
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+
+require_once('mitsql.lib.php');
+
+define('MAXDBS', 20);
+
+class proc {
+       static function newdb(&$User, $i_newdb) {
+               $msg1 = $err1 = array();
+               $dbname = $User->getUsername().DELIMETER.$i_newdb;
+               if ($User->isOverQuota()) {
+                       $err1[] = 'You are over your quota. You may not add more databases.';
+               } elseif (count($User->getDBList())>MAXDBS) {
+                       $err1[] = 'You have too many databases. You may not add more databases.';
+               } elseif (empty($i_newdb)) {
+                       $err1[] = 'Your database name may not be empty.';
+               } elseif (!$User->addDB($dbname)) {
+                       if (mysql_error()) {
+                               $err1[] = mysql_error();
+                       } else {
+                               $err1[] = 'Database already exists.';
+                       }
+               } else {
+                       $msg1[] = 'Database `'.$dbname.'` created.';
+               }
+               return array($msg1, $err1);
+       }
+       static function drop(&$User, $i_drop) {
+               $msg1 = $err1 = array();
+               $dropdbs = array_keys($i_drop);
+               foreach($dropdbs as $dbname) {
+                       if ($User->delDB($dbname)) {
+                               $msg1[] = 'Database `'.$dbname.'` dropped.';
+                       } else {
+                               $err1[] = mysql_error();
+                       }
+               }
+               return array($msg1, $err1);
+       }
+}
+
+?>
index 8fa2c3da943e453e456bf31b8459e4f97c942f39..8d60aec421b523e70044a6fbdf3273941dde5622 100644 (file)
--- a/main.php
+++ b/main.php
@@ -2,8 +2,7 @@
 
 require_once('mitsql.cfg.php');
 require_once('mitsql.lib.php');
-
-define('MAXDBS', 20);
+require_once('proc.lib.php');
 
 if (!isLoggedIn()) redirect('index');
 
@@ -13,32 +12,10 @@ $User = new User($Login->getUserID());
 
 if (isPost()) {
        if (isset($i_newdb)) {
-               $dbname = $User->getUsername().DELIMETER.$i_newdb;
-               if ($User->isOverQuota()) {
-                       $err1[] = 'You are over your quota. You may not add more databases.';
-               } elseif (count($User->getDBList())>MAXDBS) {
-                       $err1[] = 'You have too many databases. You may not add more databases.';
-               } elseif (empty($i_newdb)) {
-                       $err1[] = 'Your database name may not be empty.';
-               } elseif (!$User->addDB($dbname)) {
-                       if (mysql_error()) {
-                               $err1[] = mysql_error();
-                       } else {
-                               $err1[] = 'Database already exists.';
-                       }
-               } else {
-                       $msg1[] = 'Database `'.$dbname.'` created.';
-               }
+               list($msg1, $err1) = proc::newdb($User, $i_newdb);
        }
        if (isset($i_drop)) {
-               $dropdbs = array_keys($i_drop);
-               foreach($dropdbs as $dbname) {
-                       if ($User->delDB($dbname)) {
-                               $msg1[] = 'Database `'.$dbname.'` dropped.';
-                       } else {
-                               $err1[] = mysql_error();
-                       }
-               }
+               list($msg1, $err1) = proc::drop($User, $i_drop);
        }
        if (!count($err1))
                $User->refresh();
This page took 0.300106 seconds and 5 git commands to generate.