summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xperl-install/standalone/logdrake141
1 files changed, 119 insertions, 22 deletions
diff --git a/perl-install/standalone/logdrake b/perl-install/standalone/logdrake
index 8fbc4ca2a..7e72fbbc9 100755
--- a/perl-install/standalone/logdrake
+++ b/perl-install/standalone/logdrake
@@ -23,16 +23,17 @@
use POSIX;
use Gtk;
use lib qw(/usr/lib/libDrakX);
-
use standalone; #- warning, standalone must be loaded very first, for 'explanations'
use interactive;
use any;
use Config;
+init Gtk;
+Gtk->set_locale;
use my_gtk qw(:helpers :wrappers);
use MDK::Common;
-
+use Data::Dumper;
#-------------------------------------------------------------
# i18n routines
# IMPORTANT: next two routines have to be redefined here to
@@ -53,12 +54,6 @@ sub translate {
$::isInstall and die "Not supported during install.\n";
my $in = 'interactive'->vnew('su', 'default');
-$::isGtk = $in->isa('interactive_gtk');
-exit unless ($::isGtk);
-
-init Gtk;
-Gtk->set_locale;
-
$::isEmbedded = ($::XID, $::CCPID) = "@ARGV" =~ /--embedded (\w+) (\w+)/;
if ($::isEmbedded) {
@@ -70,9 +65,11 @@ if ($::isEmbedded) {
#- parse arguments list.
for (@ARGV) {
/^--version$/ and die 'version: $Id$ '."\n";
- /^--help$/ and die 'logdrake [--version] [--file=myfyle] [--word=myword]';
+ /^--help$/ and die 'logdrake [--version] [--file=myfyle] [--word=myword] [--explain=regexp] [--alert]';
+ /^--explain=(.*)$/ and do { $::isExplain = ($::Explain) = $1; $::isFile=1; $::File="/var/log/explanations"; next };
/^--file=(.*)$/ and do { $::isFile = ($::File) = $1; next };
/^--word=(.*)$/ and do { $::isWord = ($::Word) = $1; next };
+ /^--alert$/ and do { alert_config(); quit(); };
}
$::isTail=1 if ($::isFile);
@@ -171,7 +168,8 @@ my %files = (
"auth" => { file => "/var/log/auth.log", desc => _("authentification") },
"user" => { file => "/var/log/user.log", desc => _("user") },
"messages" => { file => "/var/log/messages", desc => _("messages") },
- "syslog" => { file => "/var/log/syslog", desc => _("syslog") }
+ "syslog" => { file => "/var/log/syslog", desc => _("syslog") },
+ "explanations" => { file => "/var/log/explanations", desc => _("Mandrake Tools Explanations")}
);
#### far from window
@@ -187,7 +185,6 @@ gtkadd($window,
" " . _("but not matching") . " ", $e_no = new Gtk::Entry()
)
),
- # _("tips: you can use OR"),
gtkpack_(new Gtk::HBox(0,0),
1, gtkadd(gtkset_border_width(new Gtk::Frame(_("Choose file")),2),
gtkpack (gtkset_border_width(new Gtk::VBox(0,0),0),
@@ -208,8 +205,9 @@ gtkadd($window,
createScrolledWindow(my $log_text = new Gtk::Text(undef, undef))
),
0, gtkadd (gtkset_layout(new Gtk::HButtonBox,-end),
+ gtksignal_connect(new Gtk::Button (_("Mail/SMS alert")), clicked => \&alert_config),
gtksignal_connect(new Gtk::Button (_("Save")), clicked => \&save),
- gtksignal_connect(new Gtk::Button ($::isEmbedded ? _("Cancel") : _("Quit")), clicked => sub {$::isEmbedded ? kill('USR1', $::CCPID) : Gtk->exit(0)})
+ gtksignal_connect(new Gtk::Button ($::isEmbedded ? _("Cancel") : _("Quit")), clicked => \&quit)
)
)
@@ -224,6 +222,10 @@ Gtk->main_iteration while Gtk->events_pending;
$::isEmbedded and kill 'USR2', $::CCPID;
Gtk->main;
+sub quit {
+$::isEmbedded ? kill('USR1', $::CCPID) : Gtk->exit(0);
+}
+
#-------------------------------------------------------------
# search functions
#-------------------------------------------------------------
@@ -266,6 +268,17 @@ sub parse_file {
}
my @all=catMaybeCompressed ($file);
+
+ if ($isExplain) {
+ my @t, $t;
+ while (@all) {
+ $t = pop @all;
+ last if !($t =~ /$Explain/);
+ push @t, $t;
+ }
+ @all=reverse @t;
+ }
+
my $taille= @all;
foreach (@all) {
$i++;
@@ -351,17 +364,101 @@ sub log_output {
#-------------------------------------------------------------
+# mail/sms alert
+#-------------------------------------------------------------
+
+sub alert_config {
+
+ $::Wizard_pix_up = "wiz_drakgw.png"; # FIXME
+ $::Wizard_title = _("Mail/SMS alert");
+
+my $cron =q(#!/usr/bin/perl
+# generated by logdrake
+use MDK::Common;
+my $r= "*** ". chomp_(`date`) . " ***\n";
+
+);
+
+ my ($load,$mail,$email,$smtp,$sms,$smssend);
+ $load=3;
+
+ begin:
+ $::isWizard = 1;
+ $::Wizard_no_previous = 1;
+ $in->ask_okcancel(_("Mail/SMS alert configuration"),
+ _("Welcome to the mail/SMS configuration utility.\n\nHere, you'll be able to set up \n"),
+ 1) or quit();
+
+ step_service:
+ undef $::Wizard_no_previous;
+ my $l ={
+ http => ["/etc/init.d/httpd", _("Apache is a World Wide Web server. It is used to serve HTML files and CGI."), '$r .= "Apache is not running\n" if (`[ -x /etc/init.d/httpd ] && LC_ALL=C /etc/init.d/httpd status` =~ /\*not\* running/);'],
+ bind => ["/etc/init.d/named", _("named (BIND) is a Domain Name Server (DNS) that is used to resolve host names to IP addresses."), ],
+ ftp => ["/etc/init.d/proftpd", _("proftpd"), '$r .= "FTP server (proftpd) is not running\n" unless (`[ -x /etc/init.d/proftpd ] && /etc/init.d/proftpd status 2>&1 > /dev/null`);'],
+ postfix => ["/etc/init.d/postfix", _("Postfix is a Mail Transport Agent, which is the program that moves mail from one machine to another."), '$r .= "Postfix is not running\n" unless (`[ -x /etc/init.d/postfix ] && LC_ALL=C /etc/init.d/postfix status`);'],
+ samba => ["/etc/init.d/smb", ("samba"), '$r .= "samba is not running\n" unless (`[ -x /etc/init.d/smb ] && LC_ALL=C /etc/init.d/smb status`);'],
+ sshd => ["/etc/init.d/sshd", _("sshd"), '$r .= "sshd is not running\n" unless (`[ -x /etc/init.d/sshd ] && LC_ALL=C /etc/init.d/sshd status`);'],
+ webmin => ["/etc/init.d/webmin", _("webmin"), '$r .= "webmin is not running\n" unless (`[ -x /etc/init.d/webmin ] && LC_ALL=C /etc/init.d/webmin status`);'],
+ xinetd=> ["/etc/init.d/xinetd", _("xinetd"), '$r .= "xinetd is not running\n" unless (`[ -x /etc/init.d/xinetd ] && LC_ALL=C /etc/init.d/yxinetd status`);'],
+ };
+
+ $in->ask_from(_("service setting"),
+ _("You will recieve an alert if one of the selected service is no more running"),
+ [ map { {label => "$_", val=> \${$_}, type => "bool", text => "$l->{$_}[1]" }; } keys %$l
+ ]) or goto begin;
+
+ $cron .= "#- check services\n";
+ for (keys %$l) {
+ $cron .= $l->{$_}[2]."\n" if (${$_});
+ }
+
+ step_load:
+ $in->ask_from(_("load setting"),
+ _("You will recieve an alert if the load is upper than this value"),
+ [
+ { label => "load ", val => \$load, type => 'range', min => 1, max => 50 },
+ ]) or goto step_service;
+
+ $cron .= q@
+#- load
+my ($load) = split ' ', first(cat_("/proc/loadavg"));
+$r .= "Load is huge: $load\n" if ($load >@ . "$load);\n\n";
+
+ step_output:
+ $in->ask_from(_("window title - ask_from"),
+ _("message\nexamples of utilisation of ask_from"),
+ [
+ { label => "mail", val => \$mail, type => "bool", text => "mail output" },
+ { label => "email", val => \$email, disabled => sub { !$mail; }},
+ { label => "smtp ??", val => \$smtp, disabled => sub { !$mail; } },
+ { label => "" },
+ { label => "sms output", val => \$sms, type => "bool", text => "You need to have set up smsend\nThis service can be unavailable on some countries" },
+ { label => "smssend output", val => \$smssend , disabled => sub {!$sms;}},
+ ]) or goto step_load;
+
+#output("/etc/cron.hourly/logdrake_alert.pl", ($cron));
+ $cron .= q@#- report it
+print $r;
+# EOF@;
+ print $cron;
+ $in->exit(0);
+}
+
+
+#-------------------------------------------------------------
# menu callback functions
#-------------------------------------------------------------
sub save {
+ #$file_dialog = new Gtk::FileSelection(_("Save as.."));
+ #$file_dialog->show();
$yy= $in->ask_file(_("Save as.."),"/root") or return;
output($yy,$log_text->get_chars(0,$log_text->get_length()));
}
sub print_hello {
- print( "mcdtg !\n" );
+ print "mcdtg !\n";
}
sub get_main_menu {
@@ -411,17 +508,17 @@ sub destroy_window {
# log
# $Log$
-# Revision 1.3 2002/01/18 20:22:20 gc
-# - write the 'common' part of the 'explanations' stuff,
-# with nice help from Pixel for the tough Perl part
-# - move 'use standalone' up in all standalone apps,
-# to comply to 'explanations'
+# Revision 1.4 2002/01/29 23:19:31 yduret
+# logdrake is now under gi/perl-install/standalone
+#
+# Revision 1.32 2002/01/27 20:47:58 yduret
+# updated, added button in logdrake main screen, bug fix
#
-# Revision 1.2 2001/12/18 17:31:48 yduret
-# fix console mode : exit now
+# Revision 1.31 2002/01/27 01:58:23 yduret
+# added --alert feature
#
-# Revision 1.1 2001/12/13 15:47:23 yduret
-# moving from soft/control-center to here, since there will be a console based version
+# Revision 1.30 2002/01/26 20:42:30 yduret
+# --explain= feature
#
# Revision 1.29 2001/09/15 15:44:22 siegel
# added missing space in "matching" line