More work on AddPrinterDriver() and AddPrinterEx() client RPC's
[Samba/gbeck.git] / source / web / statuspage.c
blob5c800797c0413a8d7166d8d86f98d93570f7197c
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 web status page
5 Copyright (C) Andrew Tridgell 1997-1998
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
25 static char *tstring(time_t t)
27 static pstring buf;
28 pstrcpy(buf, asctime(LocalTime(&t)));
29 all_string_sub(buf," "," ",sizeof(buf));
30 return buf;
33 static void print_share_mode(share_mode_entry *e, char *fname)
35 printf("<tr><td>%d</td>",(int)e->pid);
36 printf("<td>");
37 switch ((e->share_mode>>4)&0xF) {
38 case DENY_NONE: printf("DENY_NONE"); break;
39 case DENY_ALL: printf("DENY_ALL "); break;
40 case DENY_DOS: printf("DENY_DOS "); break;
41 case DENY_READ: printf("DENY_READ "); break;
42 case DENY_WRITE:printf("DENY_WRITE "); break;
44 printf("</td>");
46 printf("<td>");
47 switch (e->share_mode&0xF) {
48 case 0: printf("RDONLY "); break;
49 case 1: printf("WRONLY "); break;
50 case 2: printf("RDWR "); break;
52 printf("</td>");
54 printf("<td>");
55 if((e->op_type &
56 (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) ==
57 (EXCLUSIVE_OPLOCK|BATCH_OPLOCK))
58 printf("EXCLUSIVE+BATCH ");
59 else if (e->op_type & EXCLUSIVE_OPLOCK)
60 printf("EXCLUSIVE ");
61 else if (e->op_type & BATCH_OPLOCK)
62 printf("BATCH ");
63 else if (e->op_type & LEVEL_II_OPLOCK)
64 printf("LEVEL_II ");
65 else
66 printf("NONE ");
67 printf("</td>");
69 printf("<td>%s</td><td>%s</td></tr>\n",
70 dos_to_unix(fname,False),tstring(e->time.tv_sec));
74 /* kill off any connections chosen by the user */
75 static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state)
77 struct connections_data crec;
78 memcpy(&crec, dbuf.dptr, sizeof(crec));
80 if (crec.cnum == -1 && process_exists(crec.pid)) {
81 char buf[30];
82 slprintf(buf,sizeof(buf)-1,"kill_%d", (int)crec.pid);
83 if (cgi_variable(buf)) {
84 kill_pid(crec.pid);
87 return 0;
90 /* traversal fn for showing machine connections */
91 static int traverse_fn2(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state)
93 struct connections_data crec;
94 memcpy(&crec, dbuf.dptr, sizeof(crec));
96 if (crec.cnum != -1 || !process_exists(crec.pid)) return 0;
98 printf("<tr><td>%d</td><td>%s</td><td>%s</td><td>%s</td>\n",
99 (int)crec.pid,
100 crec.machine,crec.addr,
101 tstring(crec.start));
102 if (geteuid() == 0) {
103 printf("<td><input type=submit value=\"X\" name=\"kill_%d\"></td>\n",
104 (int)crec.pid);
106 printf("</tr>\n");
108 return 0;
111 /* traversal fn for showing share connections */
112 static int traverse_fn3(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void* state)
114 struct connections_data crec;
115 memcpy(&crec, dbuf.dptr, sizeof(crec));
117 if (crec.cnum == -1 || !process_exists(crec.pid)) return 0;
119 printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td><td>%s</td><td>%s</td></tr>\n",
120 crec.name,uidtoname(crec.uid),
121 gidtoname(crec.gid),(int)crec.pid,
122 crec.machine,
123 tstring(crec.start));
124 return 0;
128 /* show the current server status */
129 void status_page(void)
131 char *v;
132 int autorefresh=0;
133 int refresh_interval=30;
134 TDB_CONTEXT *tdb;
136 if (cgi_variable("smbd_restart")) {
137 stop_smbd();
138 start_smbd();
141 if (cgi_variable("smbd_start")) {
142 start_smbd();
145 if (cgi_variable("smbd_stop")) {
146 stop_smbd();
149 if (cgi_variable("nmbd_restart")) {
150 stop_nmbd();
151 start_nmbd();
153 if (cgi_variable("nmbd_start")) {
154 start_nmbd();
157 if (cgi_variable("nmbd_stop")) {
158 stop_nmbd();
161 if (cgi_variable("autorefresh")) {
162 autorefresh = 1;
163 } else if (cgi_variable("norefresh")) {
164 autorefresh = 0;
165 } else if (cgi_variable("refresh")) {
166 autorefresh = 1;
169 if ((v=cgi_variable("refresh_interval"))) {
170 refresh_interval = atoi(v);
173 tdb = tdb_open(lock_path("connections.tdb"), 0, 0, O_RDONLY, 0);
174 if (tdb) tdb_traverse(tdb, traverse_fn1, NULL);
176 printf("<H2>Server Status</H2>\n");
178 printf("<FORM method=post>\n");
180 if (!autorefresh) {
181 printf("<input type=submit value=\"Auto Refresh\" name=autorefresh>\n");
182 printf("<br>Refresh Interval: ");
183 printf("<input type=text size=2 name=\"refresh_interval\" value=%d>\n",
184 refresh_interval);
185 } else {
186 printf("<input type=submit value=\"Stop Refreshing\" name=norefresh>\n");
187 printf("<br>Refresh Interval: %d\n", refresh_interval);
188 printf("<input type=hidden name=refresh value=1>\n");
191 printf("<p>\n");
193 if (!tdb) {
194 /* open failure either means no connections have been
195 made or status=no */
196 if (!lp_status(-1))
197 printf("You need to have status=yes in your smb config file\n");
201 printf("<table>\n");
203 printf("<tr><td>version:</td><td>%s</td></tr>",VERSION);
205 fflush(stdout);
206 printf("<tr><td>smbd:</td><td>%srunning</td>\n",smbd_running()?"":"not ");
207 if (geteuid() == 0) {
208 if (smbd_running()) {
209 printf("<td><input type=submit name=\"smbd_stop\" value=\"Stop smbd\"></td>\n");
210 } else {
211 printf("<td><input type=submit name=\"smbd_start\" value=\"Start smbd\"></td>\n");
213 printf("<td><input type=submit name=\"smbd_restart\" value=\"Restart smbd\"></td>\n");
215 printf("</tr>\n");
217 fflush(stdout);
218 printf("<tr><td>nmbd:</td><td>%srunning</td>\n",nmbd_running()?"":"not ");
219 if (geteuid() == 0) {
220 if (nmbd_running()) {
221 printf("<td><input type=submit name=\"nmbd_stop\" value=\"Stop nmbd\"></td>\n");
222 } else {
223 printf("<td><input type=submit name=\"nmbd_start\" value=\"Start nmbd\"></td>\n");
225 printf("<td><input type=submit name=\"nmbd_restart\" value=\"Restart nmbd\"></td>\n");
227 printf("</tr>\n");
229 printf("</table>\n");
230 fflush(stdout);
232 printf("<p><h3>Active Connections</h3>\n");
233 printf("<table border=1>\n");
234 printf("<tr><th>PID</th><th>Client</th><th>IP address</th><th>Date</th>\n");
235 if (geteuid() == 0) {
236 printf("<th>Kill</th>\n");
238 printf("</tr>\n");
240 if (tdb) tdb_traverse(tdb, traverse_fn2, NULL);
242 printf("</table><p>\n");
244 printf("<p><h3>Active Shares</h3>\n");
245 printf("<table border=1>\n");
246 printf("<tr><th>Share</th><th>User</th><th>Group</th><th>PID</th><th>Client</th><th>Date</th></tr>\n\n");
248 if (tdb) tdb_traverse(tdb, traverse_fn3, NULL);
250 printf("</table><p>\n");
252 printf("<h3>Open Files</h3>\n");
253 printf("<table border=1>\n");
254 printf("<tr><th>PID</th><th>Sharing</th><th>R/W</th><th>Oplock</th><th>File</th><th>Date</th></tr>\n");
256 locking_init(1);
257 share_mode_forall(print_share_mode);
258 locking_end();
259 printf("</table>\n");
261 if (tdb) tdb_close(tdb);
263 printf("</FORM>\n");
265 if (autorefresh) {
266 /* this little JavaScript allows for automatic refresh
267 of the page. There are other methods but this seems
268 to be the best alternative */
269 printf("<script language=\"JavaScript\">\n");
270 printf("<!--\nsetTimeout('window.location.replace(\"%s/status?refresh_interval=%d&refresh=1\")', %d)\n",
271 cgi_baseurl(),
272 refresh_interval,
273 refresh_interval*1000);
274 printf("//-->\n</script>\n");