summaryrefslogtreecommitdiffstats
path: root/perl-install/standalone/drakups
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/standalone/drakups')
-rwxr-xr-xperl-install/standalone/drakups99
1 files changed, 63 insertions, 36 deletions
diff --git a/perl-install/standalone/drakups b/perl-install/standalone/drakups
index 9f55af292..ee6aeedb1 100755
--- a/perl-install/standalone/drakups
+++ b/perl-install/standalone/drakups
@@ -23,16 +23,25 @@ my ($w, $in); # GUI
my %indexes;
-sub writeconf {
+sub writeconf() {
info_dialog(N("Warning"), "Write support for users is incomplete\n\nIt lacks some support for some extra fields that would be lost else");
log::explanations("Updating NUT configuration accordingly");
$struct->writeConf($files{devices});
- log::explanations("Updating NUT users configuration accordingly");
- $users->writeConf($files{users});
+ if ($users) {
+ log::explanations("Updating NUT users configuration accordingly");
+ $users->writeConf($files{users});
+ }
+
+ require services;
+ services::restart("upsd");
}
-sub readDriversList {
+sub read_nut_config() {
+ $struct = Libconf::Glueconf::NUT::Ups_conf->new($files{devices})
+}
+
+sub readDriversList() {
my (%ups, @ups);
local $_;
foreach (cat_(first(glob("/usr/share/doc/nut-*/docs/driver.list")))) {
@@ -42,12 +51,14 @@ sub readDriversList {
driver => $driver,
extra => $extra,
};
- push @ups, "$vendor|$model";
+ push @ups, "$vendor|$model ($extra)";
}
}
\%ups, \@ups;
}
+my %models;
+
sub add_device_wizard {
my ($in, $config) = @_;
my ($ups_models, $model_list) = readDriversList();
@@ -63,7 +74,7 @@ sub add_device_wizard {
auto => N("Connected through a serial port or an usb cable"),
manual => N("Manual configuration"),
);
- my $method = $methods{manual};
+ my $method = $methods{auto};
$wiz = {
#defaultimage => "logdrake.png", # FIXME
name => N("Add an UPS device"),
@@ -71,14 +82,14 @@ sub add_device_wizard {
welcome => {
name => N("Welcome to the UPS configuration utility.
-Here, you'll be add a new UPS to your system.\n"),
+Here, you'll add a new UPS to your system.\n"),
no_back => 1,
next => 'method'
},
method => {
name => N("We're going to add an UPS device.
-Do you prefer autodetect UPS devices connected to this machine or ?"),
+Do you want to autodetect UPS devices connected to this machine or to manually select them?"),
data => [ { label => N("Autodetection"), val => \$method, type => "list",
list => [ values %methods ] } ],
post => sub { +{ reverse %methods }->{$method} },
@@ -87,7 +98,7 @@ Do you prefer autodetect UPS devices connected to this machine or ?"),
end => 1,
pre => sub {
local $::isWizard;
- my $wait = $in->wait_message(N("Please wait"), N("Detection in progress"));
+ my $_wait = $in->wait_message(N("Please wait"), N("Detection in progress"));
# UPS autoconfig:
detect_devices::probeSerialDevices() if !$::testing;
@new_devices = ();
@@ -95,10 +106,11 @@ Do you prefer autodetect UPS devices connected to this machine or ?"),
foreach my $ups_device (detect_devices::getUPS()) {
my $str = $ups_device->{name} || $ups_device->{DESCRIPTION};
$str =~ s/ /_/g;
+ $name = $str;
if (!exists $struct->{$str}) {
- $struct->{$str}{port} = $ups_device->{port} || $ups_device->{DEVICE};
- $struct->{$str}{driver} = $ups_device->{driver};
+ $port = $struct->{$str}{port} = $ups_device->{port} || $ups_device->{DEVICE};
+ $driver = $struct->{$str}{driver} = $ups_device->{driver};
push @new_devices, $str;
}
}
@@ -106,7 +118,7 @@ Do you prefer autodetect UPS devices connected to this machine or ?"),
name => sub {
if (@new_devices) {
N("Congratulations") . "\n\n" .
- N("The wizard successfully added the following UPS devices:", join("\n\n-", @new_devices))
+ N("The wizard successfully added the following UPS devices:") . join("\n\n-", @new_devices)
} else {
N("No new UPS devices was found");
}
@@ -117,9 +129,9 @@ Do you prefer autodetect UPS devices connected to this machine or ?"),
data => [ { label => N("Manufacturer / Model:"), val => \$ups, list => $model_list,
type => 'combo', sort => 1, separator => '|' }, ],
post => sub {
- ($vendor, $model) = split(/\|/, $ups);
+ ($vendor, $model) = ($1, $2) if $ups =~ /(.*)\|(.*) \(/;
($name, $driver, $port) = ("myups", $ups_models->{$vendor}{$model}{driver}, "");
- ($driver) = split(/\s*/, $driver);
+ ($driver) = split(/\s+/, $driver);
"driver";
},
},
@@ -131,7 +143,7 @@ Please fill in its name, its driver and its port.", $model, $vendor);
data => sub {
[
{ label => N("Name:"), val => \$name, help => N("The name of your ups") },
- { label => N("Driver:"), val => \$driver, help => N("The driver that manage your ups") },
+ { label => N("Driver:"), val => \$driver, help => N("The driver that manages your ups") },
{ label => N("Port:"), val => \$port, format => \&mouse::serial_port2text, type => "combo",
list => [ &mouse::serial_ports() ], not_edit => 0,
help => N("The port on which is connected your ups") },
@@ -154,6 +166,8 @@ Please fill in its name, its driver and its port.", $model, $vendor);
$config->{$name}{driver} = $driver;
$config->{$name}{port} = $port;
+ # refresh the GUI when needed:
+ $models{ups}->append_set(1 => $name, 2 => $driver, 3 => $port) if $models{ups};
log::explanations(qq(Configuring "$name" UPS));
}
@@ -206,19 +220,19 @@ sub edit_row {
}
-sub add_callback() {
- my ($model, $list, $getindex) = @_;
+sub add_callback {
+ my ($model, $_list, $_getindex) = @_;
edit_row($model);
}
-sub edit_callback() {
+sub edit_callback {
my ($model, $list) = @_;
my ($iter) = $list->get_selection->get_selected;
return unless $iter;
edit_row($model, $iter);
}
-sub del_callback() {
+sub del_callback {
my ($model, $list) = @_;
my (undef, $iter) = $list->get_selection->get_selected;
my $removed_idx = $list->get($iter, 0); # 1st column is index
@@ -239,13 +253,14 @@ my @pages = (
$::WizardWindow->destroy if defined $::WizardWindow;
undef $::WizardWindow;
},
- edit => sub { },
- remove => sub { },
+ edit => sub {},
+ remove => sub {},
},
load => sub {
- $struct = Libconf::Glueconf::NUT::Ups_conf->new($files{devices});
+ read_nut_config();
map { [ $_, @{$struct->{$_}}{qw(driver port)} ] } keys %$struct;
},
+ id => "ups",
},
{ name => N("UPS users"),
columns => [ N("Name") ],
@@ -254,35 +269,38 @@ my @pages = (
my ($name) = @_;
$users->{$name} = {};
},
- edit => sub { },
- remove => sub { },
+ edit => sub {},
+ remove => sub {},
},
load => sub {
$users = Libconf::Glueconf::NUT::Ups_conf->new($files{users});
map { [ $_ ] } keys %$users;
},
+ id => "users",
},
{ name => N("Access Control Lists"),
columns => [ N("Name"), N("IP address"), N("IP mask") ],
callbacks => {
- add => sub { },
- edit => sub { },
- remove => sub { },
+ add => sub {},
+ edit => sub {},
+ remove => sub {},
},
load => sub {
load_access_conf();
@acls;
},
+ id => "acls",
},
{ name => N("Rules"),
columns => [ N("Action"), N("Level"), N("ACL name"), N("Password") ],
callbacks => {
- N("Add") => sub { },
- N("Edit") => sub { },
- N("Remove") => sub { },
+ N("Add") => sub {},
+ N("Edit") => sub {},
+ N("Remove") => sub {},
},
load => sub { @rules }, # already loaded when we loaded acls
+ id => "rules",
},
);
@@ -294,6 +312,16 @@ my @pages = (
$in = 'interactive'->vnew;
$ugtk2::wm_icon = "drakups";
+
+$in->do_pkgs->ensure_is_installed('nut-server', '/etc/rc.d/init.d/upsd') if !$::testing;
+
+if (member('--wizard', @ARGV)) {
+ read_nut_config();
+ add_device_wizard($in, $struct);
+ writeconf();
+ $in->exit($@ ? 1 : 0);
+}
+
$w = ugtk2->new(N("DrakUPS"));
if (!$::isEmbedded) {
$::main_window = $w->{rwindow};
@@ -307,9 +335,9 @@ if (!$::isEmbedded) {
my $_msg = N("Welcome to the UPS configuration tools");
$w->{window}->add(gtkpack_(Gtk2::VBox->new,
- 0, Gtk2::Banner->new('drakups', N("DrakUPS")),
+ if_(!$::isEmbedded, 0, Gtk2::Banner->new('drakups', N("DrakUPS"))),
1, my $nb = Gtk2::Notebook->new,
- 0, create_okcancel( my $oc =
+ 0, create_okcancel(my $oc =
{
ok_clicked => sub {
#$_->{save}->() foreach @pages;
@@ -332,11 +360,11 @@ my %labels = (
);
foreach my $i (@pages) {
- my $model = Gtk2::ListStore->new("Glib::Int", ("Glib::String") x listlength(@{$i->{columns}}));
+ my $model = $models{$i->{id}} = Gtk2::ListStore->new("Glib::Int", ("Glib::String") x listlength(@{$i->{columns}}));
my (%buttons, $list);
$indexes{$i->{name}} = 0;
my $idx = \$indexes{$i->{name}};
- my $getindex = sub { ${$idx}++ };
+ my $getindex = sub { $$idx++ };
$nb->append_page(gtkpack_(Gtk2::VBox->new,
1, create_scrolled_window($list = Gtk2::TreeView->new_with_model($model),
[ 'automatic', 'automatic' ]),
@@ -348,7 +376,7 @@ foreach my $i (@pages) {
})
} ([ 'add', N("Add"), $i->{callbacks}{add} || \&add_callback ],
[ 'edit', N("Edit"), \&edit_callback ],
- [ 'remove', N("Remove"), \&del_callback],
+ [ 'remove', N("Remove"), \&del_callback ],
)
)
#(map {
@@ -380,6 +408,5 @@ foreach my $i (@pages) {
#------------------------------------------------------------------
# let's start the show:
-$in->do_pkgs->ensure_is_installed('nut-server', '/usr/sbin/upsd') if !$::testing;
$w->{rwindow}->show_all;
$w->main;