]>
Commit | Line | Data |
---|---|---|
b43ab1a6 JP |
1 | <?php |
2 | /* | |
3 | (c) 2005 Joe Presbrey | |
4 | written for SIPB/MIT | |
5 | ||
6 | add switching of what owner to manage | |
7 | - to support group sql "lockers" | |
8 | */ | |
9 | ||
10 | if (file_exists('/mit/presbrey/web_tmp')) | |
11 | ini_set('session.save_path','/mit/presbrey/web_tmp'); | |
12 | ini_set('display_errors', 1); | |
13 | ignore_user_abort(1); | |
14 | error_reporting(E_ALL); | |
15 | set_time_limit(0); | |
16 | session_start(); | |
17 | if (isset($_GET['reset'])) { session_destroy(); session_start(); } | |
18 | require_once('mitsql.lib.php'); | |
19 | ||
20 | if (!isset($_SESSION['owner'])) { | |
21 | if (isset($_GET['owner'])) { | |
22 | $_SESSION['owner'] = $_GET['owner']; | |
23 | redirectLocal('/'); | |
24 | } | |
25 | if (isset($_POST['owner'])) { | |
26 | $_SESSION['owner'] = $_POST['owner']; | |
27 | redirectLocal('/'); | |
28 | } | |
29 | if (is_null(getSSLIdent())) { | |
30 | redirect('https://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']); | |
31 | echo '<p class="err">Your SSL certificate could not be verified, please authenticate manually below.</p>'; | |
32 | // echo '<form method="',FORM_METHOD,'"><input type="text" name="owner" value="',$_SESSION['owner'],'"><input type=submit value="owner"></form>'; | |
33 | echo '<p>(This will be fixed when I do group locker SQL support)</p>'; | |
34 | } else { | |
35 | $_SESSION['owner'] = getSSLIdent(); | |
36 | } | |
37 | } | |
38 | if (isset($_SESSION['realuser'])) { | |
39 | $realuser = $_SESSION['realuser']; | |
40 | } else $realuser = null; | |
41 | ||
42 | ob_start(); | |
43 | include('style.inc'); | |
44 | ||
45 | if (isset($_SESSION['owner'])) { | |
46 | $owner = $_SESSION['owner']; | |
47 | $dbm = new DBManage($owner); | |
48 | } else exit; | |
49 | ||
50 | ?><p><h2>SQL Databases: <?php echo $owner; ?></h2><?php | |
51 | if (isset($realuser)) { | |
52 | ?><h4> [ <a href="?op=admin"><?php echo $realuser; ?></a> ]</h4><?php | |
53 | } | |
54 | ?></p><?php | |
55 | ||
56 | $inputvars = array('initpw', 'op', 'name', 'owner'); | |
57 | foreach($inputvars as $i) { | |
58 | $newvar = 'i_'.$i; | |
59 | $$newvar = isset($_GET[$i]) ? $_GET[$i] : null; | |
60 | } | |
61 | ||
62 | if (isset($i_op)) { | |
63 | switch($i_op) { | |
64 | case 'admin': | |
65 | if (isset($i_owner)) { | |
66 | $_SESSION['owner'] = $i_owner; | |
67 | $_SESSION['realuser'] = $_SESSION['owner']; | |
68 | redirectLocal('/'); | |
69 | } else { | |
70 | redirectLocal('/admin/'); | |
71 | } | |
72 | case 'init': | |
73 | if (strlen($i_initpw)<PASS_MIN_LEN) { | |
74 | echo '<p class="err">',TEXT_REGPASSTOOSHORT,'</p>'; | |
75 | } else { | |
76 | if (!$dbm->isInit()) { | |
77 | $dbm->init($i_initpw); | |
78 | redirectLocal('/'); | |
79 | } else { | |
80 | echo '<p class="err">Your account is already initialized.</p>'; | |
81 | } | |
82 | } | |
83 | break; | |
84 | case 'uninit': | |
85 | echo '<p>This operation will remove all the databases and accounts for: ',$owner,'. Are you sure?</p>'; | |
86 | echo '<form method="',FORM_METHOD,'"><tr><td><div align="left"><input type=hidden name="op" value="uninit2"><input type="submit" value="Remove My Account"></div></td></form>'; | |
87 | exit(); | |
88 | break; | |
89 | case 'uninit2': | |
90 | $dbm->uninit(); | |
91 | redirectLocal('/'); | |
92 | break; | |
93 | case 'adddb': | |
94 | if ($dbm->getNumDBs() < $dbm->getNumMaxDBs()) { | |
95 | $dbm->addDB($owner.DELIMETER.$i_name); | |
96 | redirectLocal('/'); | |
97 | } else { | |
98 | echo '<p class="err">',TEXT_DBLIMIT,'</p>'; | |
99 | } | |
100 | break; | |
101 | case 'deldb': | |
102 | if ($dbm->isRegistered($i_name)) { | |
103 | $dbm->delDB($i_name); | |
104 | redirectLocal('/'); | |
105 | } else { | |
106 | echo '<p class="err">',TEXT_NOTREG,'</p>'; | |
107 | } | |
108 | break; | |
109 | case 'createdb': | |
110 | if ($dbm->isRegistered($i_name)) { | |
111 | $dbm->createDB($i_name); | |
112 | redirectLocal('/'); | |
113 | } else { | |
114 | echo '<p class="err">',TEXT_NOTREG,'</p>'; | |
115 | } | |
116 | break; | |
117 | case 'dropdb': | |
118 | if ($dbm->isRegistered($i_name)) { | |
119 | $dbm->dropDB($i_name); | |
120 | redirectLocal('/'); | |
121 | } else { | |
122 | echo '<p class="err">',TEXT_NOTREG,'</p>'; | |
123 | } | |
124 | break; | |
125 | case 'grantdb': | |
126 | if ($dbm->isRegistered($i_name)) { | |
127 | $dbm->grantDB($i_name); | |
128 | redirectLocal('/'); | |
129 | } else { | |
130 | echo '<p class="err">',TEXT_NOTREG,'</p>'; | |
131 | } | |
132 | break; | |
133 | case 'revokedb': | |
134 | if ($dbm->isRegistered($i_name)) { | |
135 | $dbm->revokeDB($i_name); | |
136 | redirectLocal('/'); | |
137 | } else { | |
138 | echo '<p class="err">',TEXT_NOTREG,'</p>'; | |
139 | } | |
140 | break; | |
141 | } | |
142 | $dbm = null; | |
143 | $dbm = new DBManage($owner); | |
144 | } | |
145 | ?> | |
146 | ||
147 | ||
148 | ||
149 | <?php | |
150 | if ($dbm->getNumDBs()) { | |
151 | echo '<table>'; | |
152 | $dbm->printOwnerDBs(); | |
153 | echo '</table>'; | |
154 | } | |
155 | if ($dbm->isInit()) { | |
156 | echo '<form method="',FORM_METHOD,'"><input type=text readonly value="',$owner.DELIMETER,'" style="text-align:right"><input type=text name="name"><input type=hidden name="op" value="adddb"><input type=submit value="Add Database"></form>'; | |
157 | ||
158 | $dbm->printOwner(); | |
159 | echo '<table width="100%" style="margin-top:20px;">'; | |
160 | echo '<form method="',FORM_METHOD,'"><tr><td><div align="left"><input type=hidden name="op" value="uninit"><input type="submit" value="Remove My Account"></div></td></form>'; | |
161 | } else { | |
162 | echo '<h3>',TEXT_NOREG,'</h3>'; | |
163 | echo '<form method="',FORM_METHOD,'">'; | |
164 | echo '<table>'; | |
165 | echo '<tr><td>your SQL server:</td><td>',HOST,'</td></tr>'; | |
166 | echo '<tr><td>your SQL username:</td><td>',$owner,'</td></tr>'; | |
167 | echo '<tr><td>choose a SQL password:</td><td><input type=hidden name="op" value="init"><input type="password" name="initpw" value=""></td></tr></table>'; | |
168 | echo '<table width="100%" style="margin-top:20px;">'; | |
169 | echo '<tr><td></td><td><input type="submit" value="Activate My Account"></td></form>'; | |
170 | } | |
171 | echo '<form method=get><td><div align="right"><input type=hidden name="reset" value=""><input type="submit" value="Restart"></div></td></form></tr></table>'; | |
172 | ||
173 | @mysql_close($cxn); | |
174 | ||
175 | if (DEBUG) { | |
176 | echo '<!--'; | |
177 | print_r($dbm); | |
178 | echo '-->'; | |
179 | } | |
180 | ?> | |
181 | <hr><div align="right"> | |
182 | ||
183 | <address>MIT SQL Service Management v<?php echo VERSION; ?><br /> | |
184 | Direct comments and bugs to: <a href="mailto:presbrey@mit.edu">presbrey@mit.edu</a></address></div> | |
185 | <?php | |
186 | //ob_flush(); | |
187 | ?> |