1#!/usr/local/bin/perl 2# index.cgi 3# Display the icons for various types of proftpd config options 4 5require './proftpd-lib.pl'; 6 7# Check if proftpd is installed 8@st = stat($config{'proftpd_path'}); 9if (!@st) { 10 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0, 11 &help_search_link("proftpd", "man", "doc", "google")); 12 print &text('index_eproftpd', "<tt>$config{'proftpd_path'}</tt>", 13 "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n"; 14 15 &foreign_require("software", "software-lib.pl"); 16 $lnk = &software::missing_install_link("proftpd",$text{'index_proftpd'}, 17 "../$module_name/", $text{'index_title'}); 18 print $lnk,"<p>\n" if ($lnk); 19 20 &ui_print_footer("/", $text{'index'}); 21 exit; 22 } 23 24# Check if the config file exists 25$conf = &get_config(); 26if (!@$conf) { 27 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0, 28 &help_search_link("proftpd", "man", "doc", "google")); 29 print &text('index_econf', "<tt>$config{'proftpd_conf'}</tt>", 30 "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n"; 31 &ui_print_footer("/", $text{'index'}); 32 exit; 33 } 34 35# Check if the executable has changed .. 36if ($site{'size'} != $st[7]) { 37 # Check if it really is proftpd and the right version 38 $site{'size'} = $st[7]; 39 $ver = &get_proftpd_version(\$out); 40 if (!$ver) { 41 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0, 42 &help_search_link("proftpd", "man", "doc", "google")); 43 print &text('index_eproftpd2', 44 "<tt>$config{'proftpd_path'}</tt>", 45 "$gconfig{'webprefix'}/config.cgi?$module_name", 46 "<tt>$config{'proftpd_path'} -v</tt>", 47 "<pre>$out</pre>"),"<p>\n"; 48 &ui_print_footer("/", $text{'index'}); 49 exit; 50 } 51 $site{'version'} = $ver; 52 if ($site{'version'} < 0.99) { 53 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0, 54 &help_search_link("proftpd", "man", "doc", "google")); 55 print &text('index_eversion', 56 "<tt>$config{'proftpd_path'}</tt>", 57 "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n"; 58 &ui_print_footer("/", $text{'index'}); 59 exit; 60 } 61 62 # Get the list of modules 63 local @mods; 64 open(MODS, "$config{'proftpd_path'} -l |"); 65 while(<MODS>) { 66 s/\r|\n//g; 67 if (/^\s*(\S+)\.c$/) { 68 push(@mods, $1); 69 } 70 } 71 close(MODS); 72 $site{'modules'} = join(" ", @mods); 73 &write_file("$module_config_directory/site", \%site); 74 } 75 76&ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0, 77 &help_search_link("proftpd", "man", "doc", "google"), 78 undef, undef, &text('index_version', $site{'version'})); 79$conf = &get_config(); 80 81# Display global category icons 82print &ui_subheading($text{'index_global'}); 83$ft_icon = { "icon" => "images/dir.gif", 84 "name" => $text{'ftpaccess_title'}, 85 "link" => "ftpaccess.cgi" }; 86$us_icon = { "icon" => "images/ftpusers.gif", 87 "name" => $text{'ftpusers_title'}, 88 "link" => "edit_ftpusers.cgi" }; 89$ed_icon = { "icon" => "images/edit.gif", 90 "name" => $text{'manual_configs'}, 91 "link" => "allmanual_form.cgi" }; 92&config_icons("root global", "edit_global.cgi?", $ft_icon, $us_icon, $ed_icon); 93 94# Display global per-directory/limit options 95$global = &find_directive_struct("Global", $conf); 96$gconf = $global->{'members'} if ($global); 97@dir = ( &find_directive_struct("Directory", $gconf) , 98 &find_directive_struct("Limit", $gconf) ); 99if (@dir) { 100 print &ui_hr(); 101 print &ui_subheading($text{'virt_header'}); 102 foreach $d (@dir) { 103 if ($d->{'name'} eq 'Limit') { 104 push(@links, "limit_index.cgi?limit=". 105 &indexof($d, @$gconf)."&global=1"); 106 push(@titles, &text('virt_limit', $d->{'value'})); 107 push(@icons, "images/limit.gif"); 108 } 109 else { 110 push(@links, "dir_index.cgi?idx=". 111 &indexof($d, @$gconf)."&global=1"); 112 push(@titles, &text('virt_dir', $d->{'value'})); 113 push(@icons, "images/dir.gif"); 114 } 115 } 116 &icons_table(\@links, \@titles, \@icons, 3); 117 } 118 119print "<table width=100%><tr><td>\n"; 120 121print "<form action=create_dir.cgi>\n"; 122print "<input type=hidden name=global value=1>\n"; 123print "<table border>\n"; 124print "<tr $tb> <td><b>$text{'virt_adddir'}</b></td> </tr>\n"; 125print "<tr $cb> <td><table>\n"; 126print "<tr> <td><b>$text{'virt_path'}</b></td>\n"; 127print "<td><input name=dir size=30>\n"; 128print "<input type=submit value=\"$text{'create'}\"></td> </tr>\n"; 129print "</table></td></tr></table></form>\n"; 130 131print "</td><td>\n"; 132 133print "<form action=create_limit.cgi>\n"; 134print "<input type=hidden name=global value=1>\n"; 135print "<table border>\n"; 136print "<tr $tb> <td><b>$text{'virt_addlimit'}</b></td> </tr>\n"; 137print "<tr $cb> <td><table>\n"; 138print "<tr> <td><b>$text{'virt_cmds'}</b></td>\n"; 139print "<td><input name=cmd size=20>\n"; 140print "<input type=submit value=\"$text{'create'}\"></td> </tr>\n"; 141print "</table></td></tr></table></form>\n"; 142 143print "</td></tr></table>\n"; 144 145 146# Start virtual server list with default 147push(@vname, $text{'index_defserv'}); 148push(@vlink, "virt_index.cgi"); 149push(@vdesc, $text{'index_defdesc'}); 150push(@vaddr, $text{'index_any'}); 151push(@vserv, &def(&find_directive("ServerName", $conf), $text{'default'})); 152 153# Add other virtual servers 154@virt = &find_directive_struct("VirtualHost", $conf); 155foreach $v (@virt) { 156 $vm = $v->{'members'}; 157 push(@vname, $text{'index_virt'}); 158 push(@vlink, "virt_index.cgi?virt=".&indexof($v, @$conf)); 159 push(@vaddr, $v->{'value'}); 160 $sname = &find_directive("ServerName", $vm); 161 local $ip = &to_ipaddress($v->{'value'}); 162 push(@vdesc, &text('index_vdesc', $ip ? $ip : $text{'index_eip'})); 163 push(@vserv, &def(&find_vdirective("ServerName", $vm, $conf), 164 $text{'index_auto'})); 165 } 166 167# Show virtual servers 168print &ui_hr(); 169print &ui_subheading($text{'index_virts'}); 170 171if ($config{'show_list'} && scalar(@vname)) { 172 # as list for people with lots of servers 173 print "<table width=100% border=1>\n"; 174 print "<tr $tb> <td><b>$text{'index_type'}</b></td> ", 175 "<td><b>$text{'index_addr'}</b></td> ", 176 "<td><b>$text{'index_name'}</b></td> </tr>\n"; 177 for($i=0; $i<@vname; $i++) { 178 print "<tr $cb>\n"; 179 print "<td><a href=\"$vlink[$i]\">", 180 &html_escape($vname[$i]),"</a></td>\n"; 181 print "<td>",&html_escape($vaddr[$i]),"</td>\n"; 182 print "<td>",&html_escape($vserv[$i]),"</td>\n"; 183 print "</tr>\n"; 184 } 185 print "</table>\n"; 186 } 187else { 188 # as icons for niceness 189 print "<table width=100% cellpadding=5>\n"; 190 for($i=0; $i<@vname; $i++) { 191 print "<tr> <td valign=top align=center nowrap>"; 192 print '<div class="row icons-row inline-row">'; 193 &generate_icon("images/virt.gif", &html_escape($vname[$i]), 194 $vlink[$i]); 195 print "</div>\n"; 196 print "</td> <td valign=top>\n"; 197 print &html_escape($vdesc[$i]),"<br>\n"; 198 print "<table width=100%><tr>\n"; 199 print "<td width=30%><b>$text{'index_addr'}</b> ", 200 &html_escape($vaddr[$i]),"</td>\n"; 201 print "<td width=70%><b>$text{'index_name'}</b> ", 202 &html_escape($vserv[$i]),"</td></tr>\n"; 203 print "</table></td> </tr>\n"; 204 } 205 print "</table>\n"; 206 } 207 208print "<form action=create_virt.cgi>\n"; 209print "<table border>\n"; 210print "<tr $tb> <td><b>$text{'index_create'}</b></td> </tr>\n"; 211print "<tr $cb> <td><table>\n"; 212print "<tr> <td><b>$text{'index_addr'}</b></td>\n"; 213print "<td><input name=addr size=25></td> </tr>\n"; 214print "<tr> <td><b>$text{'index_port'}</b></td>\n"; 215print "<td>",&opt_input(undef, "Port", $text{'default'}, 6),"</td> </tr>\n"; 216print "<tr> <td><b>$text{'index_name'}</b></td>\n"; 217print "<td>",&opt_input(undef, "ServerName", $text{'default'}, 25); 218print " \n"; 219print "<input type=submit value=\"$text{'create'}\"></td> </tr>\n"; 220print "</table></td></tr></table>\n"; 221print "</form>\n"; 222 223# Find out how ProFTPd is running 224($inet, $inet_mod) = &running_under_inetd(); 225if (!$inet) { 226 # Get the FTP server pid 227 $pid = &get_proftpd_pid(); 228 print &ui_hr(); 229 print &ui_buttons_start(); 230 } 231if (!$inet && $pid) { 232 print &ui_buttons_row("apply.cgi", 233 $text{'index_apply'}, 234 &get_proftpd_version() > 1.22 ? 235 $text{'index_applymsg2'} : 236 $text{'index_applymsg'}); 237 print &ui_buttons_row("stop.cgi", 238 $text{'index_stop'}, $text{'index_stopmsg'}); 239 } 240elsif (!$inet && !$pid) { 241 print &ui_buttons_row("start.cgi", 242 $text{'index_start'}, 243 $inet_mod ? &text('index_startmsg', "/$inet_mod/") 244 : $text{'index_startmsg2'}); 245 } 246if (!$inet) { 247 print &ui_buttons_end(); 248 } 249 250&ui_print_footer("/", $text{'index'}); 251 252