#!/usr/local/bin/perl # swat.cgi # Pass everything to samba's SWAT tool require './samba-lib.pl'; &ReadParse(); # check acls &error_setup(""); &error("$text{'eacl_np'} $text{'eacl_pcswat'}") unless $access{'swat'}; # Check is hosts allow is in force &get_share("global"); if (&getval('allow hosts')) { &ui_print_header(undef, $text{'error'}, ""); print &text('swat_msg3', $text{'sec_onlyallow'}), "
\n"; &foreign_require("inetd", "inetd-lib.pl"); local @inets = &foreign_call("inetd", "list_inets"); foreach $i (@inets) { if ($i->[3] eq 'swat' && $i->[1]) { # swat is configured in inetd! local $p = getservbyname('swat', 'tcp'); $url = "http://$ENV{'SERVER_NAME'}:$p/"; print &text('swat_msg4', "$url"), "
\n";
}
}
&ui_print_footer("", $text{'index_sharelist'});
exit;
}
# Check if we have the password
&read_file("$module_config_directory/swat", \%swat) || &ask_password();
# Execute SWAT process
pipe(OUTr, OUTw);
pipe(INr, INw);
local $pid = fork();
if (!$pid) {
untie(*STDIN);
untie(*STDOUT);
untie(*STDERR);
open(STDIN, "<&INr");
open(STDOUT, ">&OUTw");
open(STDERR, ">&OUTw");
close(OUTr); close(INw);
undef %ENV;
exec($config{'swat_path'});
print "Exec failed : $!\n";
exit 1;
}
close(OUTw); close(INr);
# Feed HTTP request and read output
$auth = &encode_base64("$swat{'user'}:$swat{'pass'}");
$auth =~ s/\n//g;
select(INw); $| = 1; select(STDOUT);
$path = $ENV{'PATH_INFO'} || "/";
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
print INw "GET $path?$in HTTP/1.0\n";
print INw "Authorization: basic $auth\n";
print INw "\n";
}
else {
print INw "POST $path HTTP/1.0\r\n";
print INw "Authorization: basic $auth\r\n";
print INw "Content-length: ",length($in),"\r\n";
print INw "Content-type: application/x-www-form-urlencoded\r\n";
print INw "\r\n",$in;
}
close(INw);
$reply = \n";
&ui_print_footer("/$module_name/", $text{'index_sharelist'}, 1);
print " ",
"$text{'swat_logout'}