3 # Display the wuFTPd main menu
5 require './wuftpd-lib.pl';
9 # Check if wuftpd is installed
10 if (!-x $config{'ftpd_path'}) {
11 &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1, 0,
12 &help_search_link("wu-ftpd", "man", "doc", "google"));
13 print &text('index_eftpd', "<tt>$config{'ftpd_path'}</tt>",
14 "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
15 &ui_print_footer("/", $text{'index'});
19 # Check if the ftpaccess file exists
20 if (!-r $config{'ftpaccess'}) {
21 &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1, 0,
22 &help_search_link("wu-ftpd", "man", "doc", "google"));
23 print &text('index_eftpaccess', "<tt>$config{'ftpaccess'}</tt>",
24 "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n";
25 &ui_print_footer("/", $text{'index'});
29 @st = stat($config{'ftpd_path'});
30 &read_file("$module_config_directory/ftpd", \%ftpd);
31 if ($ftpd{'size'} != $st[7] || $ftpd{'mtime'} != $st[9]) {
32 # Run the ftpd to check if it is really wuftpd, by starting it
33 # in a separate TCP server process
34 $proto = getprotobyname('tcp');
35 socket(MAIN, PF_INET, SOCK_STREAM, $proto) ||
36 &error("socket failed : $!");
37 setsockopt(MAIN, SOL_SOCKET, SO_REUSEADDR, pack("l", 1));
41 last if (bind(MAIN, pack_sockaddr_in($port, INADDR_ANY)));
43 listen(MAIN, SOMAXCONN);
44 if (!($pid = fork())) {
45 accept(SOCK, MAIN) || exit(1);
49 open(STDIN, "<&SOCK");
50 open(STDOUT, ">&SOCK");
51 open(STDERR, ">&SOCK");
52 exec("$config{'ftpd_path'} -A");
53 print "Exec failed : $!\n";
57 &open_socket("localhost", $port, CONN);
58 select(CONN); $| = 1; select(STDOUT);
62 $version = $1 if (/Version\s+wu-(\d+\.\d+)/i);
68 &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1, 0,
69 &help_search_link("wu-ftpd", "man", "doc", "google"));
70 print &text('index_eversion',
71 "<tt>$config{'ftpd_path'}</tt>",
72 "$gconfig{'webprefix'}/config.cgi?$module_name",
73 "<pre>$out</pre>"),"<p>\n";
74 &ui_print_footer("/", $text{'index'});
78 # Save version information
79 $ftpd{'size'} = $st[7];
80 $ftpd{'mtime'} = $st[9];
81 $ftpd{'version'} = $version;
82 &write_file("$module_config_directory/ftpd", \%ftpd);
85 &ui_print_header(undef, $text{'index_title'}, "", "intro", 1, 1, 0,
86 &help_search_link("wu-ftpd", "man", "doc", "google"), undef, undef,
87 &text('index_version', $ftpd{'version'}));
89 # Display table of icons
90 @names = ( 'class', 'message', 'acl', 'net', 'log',
91 'alias', 'anon', 'perm', 'misc' );
92 @links = map { "edit_${_}.cgi" } @names;
93 @titles = map { $text{"${_}_title"} } @names;
94 @icons = map { "images/${_}.gif" } @names;
95 &icons_table(\@links, \@titles, \@icons, 5);
97 ($inet, $inet_mod) = &running_under_inetd();
99 # Get the FTP server pid
100 $pid = &check_pid_file($config{'pid_file'});
103 if (!$inet && $pid) {
105 print "<form action=restart.cgi>\n";
106 print "<input type=hidden name=pid value='$pid'>\n";
107 print "<table width=100%><tr>\n";
108 print "<td><input type=submit value=\"$text{'index_apply'}\"></td>\n";
109 print "<td>$text{'index_applymsg'}</td>\n";
110 print "</tr></table></form>\n";
112 elsif (!$inet && !$pid) {
114 print "<form action=start.cgi>\n";
115 print "<table width=100%><tr>\n";
116 print "<td><input type=submit value=\"$text{'index_start'}\"></td>\n";
118 print "<td>",&text('index_startmsg', "/$inet_mod/"),"</td>\n";
121 print "<td>$text{'index_startmsg2'}</td>\n";
123 print "</tr></table></form>\n";
126 &ui_print_footer("/", $text{'index'});