add FLAG_HIDE to "config file" option (so it can't be set in swat)
[samba.git] / source / wsmbstatus.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4    html status reporting
5    Copyright (C) Andrew Tridgell 1997-1998
6    
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.
11    
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.
16    
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.
20 */
21
22 #ifdef SYSLOG
23 #undef SYSLOG
24 #endif
25
26 #include "includes.h"
27
28 static void print_header(void)
29 {
30         printf("Content-type: text/html\n\n");
31         printf("<HTML>\n<HEAD>\n<TITLE>smbstatus</TITLE>\n</HEAD>\n<BODY>\n\n");
32 }
33
34 static void print_footer(void)
35 {
36         printf("\n</BODY>\n</HTML>\n");
37 }
38
39 static void show_connections(void)
40 {
41         static pstring servicesf = CONFIGFILE;
42         pstring fname;
43         FILE *f;
44         struct connect_record crec;
45
46         if(!get_myname(myhostname,NULL))
47         {
48             printf("Failed to get my hostname.\n");
49             return;
50         }
51
52         if (!lp_load(servicesf,False)) {
53                 printf("Can't load %s - run testparm to debug it\n", servicesf);
54                 return;
55         }
56
57         strcpy(fname,lp_lockdir());
58         standard_sub_basic(fname);
59         trim_string(fname,"","/");
60         strcat(fname,"/STATUS..LCK");
61
62         f = fopen(fname,"r");
63         if (!f) {
64                 printf("Couldn't open status file %s\n",fname);
65                 if (!lp_status(-1))
66                         printf("You need to have status=yes in your smb config file\n");
67                 return;
68         }
69
70
71         printf("\nSamba version %s\n<p>",VERSION);
72
73         while (!feof(f)) {
74                 if (fread(&crec,sizeof(crec),1,f) != 1)
75                         break;
76                 if (crec.magic == 0x280267 && process_exists(crec.pid)) {
77                         printf("%-10.10s   %-8s %-8s %5d   %-8s (%s) %s<br>",
78                                crec.name,uidtoname(crec.uid),
79                                gidtoname(crec.gid),crec.pid,
80                                crec.machine,crec.addr,
81                                asctime(LocalTime(&crec.start)));
82                 }
83         }
84         fclose(f);
85 }
86
87 int main(int argc, char *argv[])
88 {
89         print_header();
90         show_connections();
91         print_footer();
92         return 0;
93 }