1#!/usr/local/bin/perl 2# index.cgi 3# Show fetchmail configurations 4 5require './fetchmail-lib.pl'; 6 7# Check if fetchmail is installed 8if (!&has_command($config{'fetchmail_path'})) { 9 &ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0, 10 &help_search_link("fetchmail", "doc", "man", "google")); 11 print "<p>",&text('index_efetchmail', 12 "<tt>$config{'fetchmail_path'}</tt>", 13 "$gconfig{'webprefix'}/config.cgi?$module_name"),"<p>\n"; 14 &ui_print_footer("/", $text{'index'}); 15 exit; 16 } 17 18# Get and show the version 19$ver = &get_fetchmail_version(); 20&ui_print_header(undef, $text{'index_title'}, "", undef, 1, 1, 0, 21 &help_search_link("fetchmail", "doc", "man", "google"), undef, undef, 22 &text('index_version', $ver)); 23 24if ($config{'config_file'}) { 25 # Just read one config file 26 @conf = &parse_config_file($config{'config_file'}); 27 @conf = grep { $_->{'poll'} } @conf; 28 print "<b>",&text('index_file', 29 "<tt>$config{'config_file'}</tt>"),"</b><p>\n"; 30 &show_polls(\@conf, $config{'config_file'}, $config{'daemon_user'}); 31 32 local @uinfo = getpwnam($config{'daemon_user'}); 33 print &ui_hr(); 34 print "<table width=100%>\n"; 35 36 if (&foreign_installed("cron") && $access{'cron'}) { 37 # Show button to manage cron job 38 print "<form action=edit_cron.cgi>\n"; 39 print "<tr> <td><input type=submit ", 40 "value='$text{'index_cron'}'></td>\n"; 41 print "<td>$text{'index_crondesc'}</td> </tr></form>\n"; 42 } 43 44 # Show the fetchmail daemon form 45 foreach $pf ($config{'pid_file'}, 46 "$uinfo[7]/.fetchmail.pid", "$uinfo[7]/.fetchmail") { 47 if (open(PID, "<$pf") && ($line=<PID>) && 48 (($pid,$interval) = split(/\s+/, $line)) && $pid && 49 kill(0, $pid)) { 50 $running++; 51 last; 52 } 53 } 54 print "<tr><td>\n"; 55 if ($running) { 56 # daemon is running - offer to stop it 57 print "<form action=stop.cgi>\n"; 58 print "<input type=submit value='$text{'index_stop'}'></td>\n"; 59 print "<td>",&text('index_stopmsg', 60 "<tt>$config{'daemon_user'}</tt>", 61 $interval),"</td>\n"; 62 } 63 else { 64 # daemon isn't running - offer to start it 65 print "<form action=start.cgi>\n"; 66 print "<input type=submit value='$text{'index_start'}'></td>\n"; 67 print "<td>",&text('index_startmsg', 68 "<input name=interval size=5 value='60'>", 69 "<tt>$config{'daemon_user'}</tt>"),"</td>\n"; 70 } 71 print "</td></tr></table></form>\n"; 72 } 73else { 74 # Build a list of users with fetchmail configurations 75 $ucount = 0; 76 setpwent(); 77 while(@uinfo = getpwent()) { 78 next if ($donehome{$uinfo[7]}++); 79 next if (!&can_edit_user($uinfo[0])); 80 local @conf = &parse_config_file("$uinfo[7]/.fetchmailrc"); 81 @conf = grep { $_->{'poll'} } @conf; 82 if (@conf) { 83 push(@users, [ \@conf, [ @uinfo ] ]); 84 } 85 $ucount++; 86 last if ($config{'max_users'} && 87 $ucount > $config{'max_users'}); 88 } 89 endpwent() if ($gconfig{'os_type'} ne 'hpux'); 90 @users = sort { $a->[1]->[0] cmp $b->[1]->[0] } @users; 91 if (!@users) { 92 # None found 93 print "<br><b>$text{'index_none'}</b><p>\n"; 94 } 95 elsif ($config{'max_users'} && $ucount > $config{'max_users'}) { 96 # Show user search form 97 print "$text{'index_toomany'}<p>\n"; 98 print &ui_form_start("edit_user.cgi"); 99 print "<b>$text{'index_search'}</b>\n"; 100 print &ui_user_textbox("user", undef, 20),"\n"; 101 print &ui_submit($text{'index_show'}),"\n"; 102 print &ui_form_end(); 103 $toomany = 1; 104 } 105 elsif (!$config{'view_mode'}) { 106 # Full details 107 &show_button(); 108 print "<table border width=100%>\n"; 109 print "<tr $tb> <td><b>$text{'index_user'}</b></td> <td><b>$text{'index_conf'}</b></td> </tr>\n"; 110 foreach $u (@users) { 111 print "<tr $cb>\n"; 112 print "<td valign=top><b>",&html_escape($u->[1]->[0]), 113 "</b></td> <td>\n"; 114 &show_polls($u->[0], "$u->[1]->[7]/.fetchmailrc", 115 $u->[1]->[0]); 116 print "</td> </tr>\n"; 117 } 118 print "</table>\n"; 119 } 120 else { 121 # Just show usernames 122 print &ui_table_start($text{'index_header'}, "width=100%", 1); 123 $i = 0; 124 foreach $u (@users) { 125 print "<tr>\n" if ($i%4 == 0); 126 print &ui_link("edit_user.cgi?user=$u->[1]->[0]","$u->[1]->[0]")."</td>\n"; 127 print "</tr>\n" if ($i%4 == 3); 128 $i++; 129 } 130 print &ui_table_end(); 131 } 132 &show_button() if (!$toomany); 133 134 if (&foreign_installed("cron") && $access{'cron'}) { 135 # Show button to manage global cron job 136 print &ui_hr(); 137 print &ui_buttons_start(); 138 print &ui_buttons_row("edit_cron.cgi", 139 $text{'index_cron'}, $text{'index_crondesc2'}); 140 print &ui_buttons_end(); 141 } 142 } 143 144&ui_print_footer("/", $text{'index'}); 145 146sub show_button 147{ 148if ($access{'mode'} != 3 || !$doneheader) { 149 print "<form action=edit_poll.cgi>\n"; 150 print "<input type=hidden name=new value=1>\n"; 151 print "<input type=submit value='$text{'index_ok'}'>\n"; 152 print &unix_user_input("user"); 153 print "</form>\n"; 154 } 155} 156 157