Added ubi_sLinkList module which manages simple singly-linked lists.
[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
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 (!lp_load(servicesf,False)) {
47                 printf("Can't load %s - run testparm to debug it\n", servicesf);
48                 return;
49         }
50
51         strcpy(fname,lp_lockdir());
52         standard_sub_basic(fname);
53         trim_string(fname,"","/");
54         strcat(fname,"/STATUS..LCK");
55
56         f = fopen(fname,"r");
57         if (!f) {
58                 printf("Couldn't open status file %s\n",fname);
59                 if (!lp_status(-1))
60                         printf("You need to have status=yes in your smb config file\n");
61                 return;
62         }
63
64
65         printf("\nSamba version %s\n<p>",VERSION);
66
67         while (!feof(f)) {
68                 if (fread(&crec,sizeof(crec),1,f) != 1)
69                         break;
70                 if (crec.magic == 0x280267 && process_exists(crec.pid)) {
71                         printf("%-10.10s   %-8s %-8s %5d   %-8s (%s) %s<br>",
72                                crec.name,uidtoname(crec.uid),
73                                gidtoname(crec.gid),crec.pid,
74                                crec.machine,crec.addr,
75                                asctime(LocalTime(&crec.start)));
76                 }
77         }
78         fclose(f);
79 }
80
81 int main(int argc, char *argv[])
82 {
83         print_header();
84         show_connections();
85         print_footer();
86         return 0;
87 }