From: Joe Presbrey Date: Wed, 30 Nov 2005 19:55:43 +0000 (+0000) Subject: user interaction moved to proc.lib.php X-Git-Url: http://andersk.mit.edu/gitweb/sql-web.git/commitdiff_plain/2f91d7fe0fd4b4155a4486b653449dc0fe630c10 user interaction moved to proc.lib.php 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 --- diff --git a/batch/batch.inc.php b/batch/batch.inc.php new file mode 100644 index 0000000..8b65e29 --- /dev/null +++ b/batch/batch.inc.php @@ -0,0 +1,9 @@ + diff --git a/batch/create_db.php b/batch/create_db.php new file mode 100755 index 0000000..f29b3d7 --- /dev/null +++ b/batch/create_db.php @@ -0,0 +1,25 @@ +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 index 0000000..357efcd --- /dev/null +++ b/batch/signup.php @@ -0,0 +1,37 @@ +#!/usr/bin/php +=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 index 0000000..bb961e1 --- /dev/null +++ b/batch/status.php @@ -0,0 +1,13 @@ +canLogin()) die('-1'); + +die('0'); + +?> diff --git a/bin/root_install_signup.sh b/bin/root_install_signup.sh new file mode 100644 index 0000000..84d250a --- /dev/null +++ b/bin/root_install_signup.sh @@ -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 index 0000000..ca2dbc5 --- /dev/null +++ b/bin/signup.c @@ -0,0 +1,6 @@ +#include + +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 index 0000000..55a3d8f --- /dev/null +++ b/lib/proc.lib.php @@ -0,0 +1,42 @@ +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); + } +} + +?> diff --git a/main.php b/main.php index 8fa2c3d..8d60aec 100644 --- 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();