Handle hostnames with upper-case letters
[webmin.git] / proc / open_files.cgi
1 #!/usr/local/bin/perl
2 # open_files.cgi
3 # Display files and network connections that a process has open
4
5 require './proc-lib.pl';
6 &ReadParse();
7 &ui_print_header(undef, $text{'open_title'}, "", "open_proc");
8 %pinfo = &process_info($in{'pid'});
9 &can_edit_process($pinfo{'user'}) || &error($text{'edit_ecannot'});
10 if (!%pinfo) {
11         print "<b>$text{'edit_gone'}</b> <p>\n";
12         &ui_print_footer("", $text{'index_return'});
13         exit;
14         }
15
16 print "<b>",&text('open_proc', "<tt>$pinfo{'args'}</tt>", $in{'pid'}),
17       "</b><p>\n";
18
19 # Show open files
20 print &ui_subheading($text{'open_header1'});
21 @files = &find_process_files($in{'pid'});
22 print &ui_columns_start([ $text{'open_fd'},
23                           $text{'open_type'},
24                           $text{'open_size'},
25                           $text{'open_inode'},
26                           $text{'open_file'} ], 100, 0);
27 foreach $f (@files) {
28         print &ui_columns_row([
29                      $f->{'fd'} eq 'cwd' ? $text{'open_cwd'} :
30                      $f->{'fd'} eq 'rtd' ? $text{'open_rtd'} :
31                      $f->{'fd'} eq 'txt' ? $text{'open_txt'} :
32                      $f->{'fd'} eq 'mem' ? $text{'open_mem'} :
33                                            $f->{'fd'},
34                      $f->{'type'} =~ /^v?dir$/ ? $text{'open_dir'} :
35                      $f->{'type'} =~ /^v?reg$/ ? $text{'open_reg'} :
36                      $f->{'type'} =~ /^v?chr$/ ? $text{'open_chr'} :
37                      $f->{'type'} =~ /^v?blk$/ ? $text{'open_blk'} :
38                                              $f->{'type'},
39                      $f->{'size'},
40                      $f->{'inode'},
41                      $f->{'file'},
42                      ]);
43         }
44 print &ui_columns_end();
45
46 # Show network connections
47 @nets = &find_process_sockets($in{'pid'});
48 if (@nets) {
49         print &ui_subheading($text{'open_header2'});
50
51         print &ui_columns_start([ $text{'open_type'},
52                                   $text{'open_proto'},
53                                   $text{'open_fd'},
54                                   $text{'open_desc'} ], 100, 0,
55                                 [ "", "", "", "colspan=4" ]);
56         foreach $n (@nets) {
57                 @cols = ( uc($n->{'type'}),
58                           uc($n->{'proto'}),
59                           $n->{'fd'} );
60                 @tds = ( "", "", "" );
61                 if ($n->{'listen'} && $n->{'lhost'} eq '*') {
62                         push(@cols, &text('open_listen1',
63                                           "<tt>$n->{'lport'}</tt>"));
64                         push(@tds, "colspan=4");
65                         }
66                 elsif ($n->{'listen'}) {
67                         push(@cols, &text('open_listen2',
68                                           "<tt>$n->{'lhost'}</tt>",
69                                           "<tt>$n->{'lport'}</tt>"));
70                         push(@tds, "colspan=4");
71                         }
72                 elsif ($n->{'rhost'}) {
73                         push(@cols, "<tt>$n->{'lhost'}:$n->{'lport'}</tt>",
74                                     "<tt>-&gt;</tt>",
75                                     "<tt>$n->{'rhost'}:$n->{'rport'}</tt>",
76                                     "<tt>$n->{'state'}</tt>");
77                         }
78                 else {
79                         push(@cols, &text('open_recv', "<tt>$n->{'lhost'}</tt>",
80                                       "<tt>$n->{'lport'}</tt>"));
81                         push(@tds, "colspan=4");
82                         }
83                 print &ui_columns_row(\@cols, \@tds);
84                 }
85         print &ui_columns_end();
86         }
87
88 &ui_print_footer("edit_proc.cgi?$in{'pid'}", $text{'edit_return'},
89                  "", $text{'index_return'});