3 # Pass everything to samba's SWAT tool
5 require './samba-lib.pl';
10 &error_setup("<blink><font color=red>$text{'eacl_aviol'}</font></blink>");
11 &error("$text{'eacl_np'} $text{'eacl_pcswat'}") unless $access{'swat'};
13 # Check is hosts allow is in force
15 if (&getval('allow hosts')) {
16 &ui_print_header(undef, $text{'error'}, "");
17 print &text('swat_msg3', $text{'sec_onlyallow'}), "<p>\n";
18 &foreign_require("inetd", "inetd-lib.pl");
19 local @inets = &foreign_call("inetd", "list_inets");
21 if ($i->[3] eq 'swat' && $i->[1]) {
22 # swat is configured in inetd!
23 local $p = getservbyname('swat', 'tcp');
24 $url = "http://$ENV{'SERVER_NAME'}:$p/";
25 print &text('swat_msg4', "<a href='$url'>$url</a>"), "<p>\n";
28 &ui_print_footer("", $text{'index_sharelist'});
32 # Check if we have the password
33 &read_file("$module_config_directory/swat", \%swat) || &ask_password();
35 # Execute SWAT process
44 open(STDOUT, ">&OUTw");
45 open(STDERR, ">&OUTw");
46 close(OUTr); close(INw);
48 exec($config{'swat_path'});
49 print "Exec failed : $!\n";
52 close(OUTw); close(INr);
54 # Feed HTTP request and read output
55 $auth = &encode_base64("$swat{'user'}:$swat{'pass'}");
57 select(INw); $| = 1; select(STDOUT);
58 $path = $ENV{'PATH_INFO'} || "/";
59 if ($ENV{'REQUEST_METHOD'} eq 'GET') {
60 print INw "GET $path?$in HTTP/1.0\n";
61 print INw "Authorization: basic $auth\n";
65 print INw "POST $path HTTP/1.0\r\n";
66 print INw "Authorization: basic $auth\r\n";
67 print INw "Content-length: ",length($in),"\r\n";
68 print INw "Content-type: application/x-www-form-urlencoded\r\n";
73 if ($reply =~ /\s401\s/) {
76 if ($ENV{'PATH_INFO'} =~ /\.(gif|jpg|jpeg|png)$/i) {
77 # An image .. just output it
78 while(<OUTr>) { print; }
81 # An HTML page .. fix up links
82 $url = "$gconfig{'webprefix'}/$module_name/swat.cgi";
84 s/src="(\/[^"]*)"/src="$url$1"/gi;
85 s/href="(\/[^"]*)"/href="$url$1"/gi;
86 s/action="(\/[^"]*)"/action="$url$1"/gi;
87 s/"(\/status?[^"]*)"/"$url$1"/gi;
88 print $_ if (!/<\/body>/i && !/<\/html>/i);
90 print "<table width=100% cellpadding=0 cellspacing=0><tr><td>\n";
91 &ui_print_footer("/$module_name/", $text{'index_sharelist'}, 1);
92 print "</td> <td align=right><a href='/$module_name/logout.cgi'>",
93 "$text{'swat_logout'}</a></td> </tr></table></body></html>\n";
98 &ui_print_header(undef, $text{'swat_title'}, "");
100 print $text{'swat_msg1'}, " <br>\n";
103 print $text{'swat_msg2'}, " <br>\n";
105 print "<form action=swat_save.cgi>\n";
106 print "<center><table border>\n";
107 print "<tr $tb> <td><b>$text{'swat_list'}</b></td> </tr>\n";
108 print "<tr $cb> <td><table cellpadding=2>\n";
109 print "<tr> <td><b>$text{'swat_username'}</b></td>\n";
110 print "<td><input name=user size=20 value='$swat{'user'}'></td> </tr>\n";
111 print "<tr> <td><b>$text{'swat_password'}</b></td>\n";
112 print "<td><input name=pass size=20 type=password></td> </tr>\n";
113 print "</table></td></tr></table>\n";
114 print "<input type=submit value=\"", $text{'swat_login'},
115 "\"> <input type=reset value=\"", $text{'swat_clear'}, "\">\n";
116 print "</center></form>\n";
117 &ui_print_footer("", $text{'index_sharelist'});