#!/usr/bin/perl use strict; use lib qw(/usr/lib/libDrakX); use standalone; use common; use mouse; use detect_devices; use ugtk2 qw(:create :dialogs :helpers :wrappers); use interactive; use Libconf qw(:functions); use Libconf::Glueconf::NUT::Ups_conf; # config files: my %files = (devices => "/etc/ups/ups.conf", access => "/etc/ups/upsd.conf", users => "/etc/ups/upsd.users", ); my ($struct, $users); # NUT configuration my ($w, $in); # GUI my %indexes; 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}); if ($users) { log::explanations("Updating NUT users configuration accordingly"); $users->writeConf($files{users}); } require services; services::restart("upsd"); } sub read_nut_config() { $struct = Libconf::Glueconf::NUT::Ups_conf->new({ filename => $files{devices} }); } sub readDriversList() { my (%ups, @ups); local $_; foreach (cat_(first(glob("/usr/share/doc/nut/docs/driver.list")))) { /^#/ and next; if (my ($vendor, $model, $extra, $driver) = /^"(.*)"\s+"(.*)"\s+"(.*)"\s+"(.*)"/) { $ups{$vendor}{$model . $extra} = { driver => $driver, extra => $extra, }; push @ups, "$vendor|$model ($extra)"; } } \%ups, \@ups; } my %models; sub add_device_wizard { my ($in, $config) = @_; my ($ups_models, $model_list) = readDriversList(); my ($ups, $vendor, $model, $extra, $name, $driver, $port, @new_devices, $opts); my %methods = ( # network => N("Connected through the network"), # need SNMP probe # serial => N("Connected through a serial port"), # usb => N("Connected through an usb cable"), auto => N("Connected through a serial port or an usb cable"), manual => N("Manual configuration"), ); my $method = $methods{auto}; require wizards; my $wiz = wizards->new({ #defaultimage => "logdrake.png", # FIXME name => N("Add an UPS device"), pages => { welcome => { name => N("Welcome to the UPS configuration utility. 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 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} }, }, auto => { end => 1, pre => sub { local $::isWizard; my $_wait = $in->wait_message(N("Please wait"), N("Detection in progress")); # UPS autoconfig: detect_devices::probeSerialDevices() if !$::testing; @new_devices = (); foreach my $ups_device (detect_devices::getUPS()) { my $str = $ups_device->{name} || $ups_device->{DESCRIPTION}; $str =~ s/ /_/g; $name = $str; if (!exists $struct->{$str}) { $port = $struct->{$str}{port} = $ups_device->{port} || $ups_device->{DEVICE}; $driver = $struct->{$str}{driver} = $ups_device->{driver}; push @new_devices, $str; } } }, name => sub { if (@new_devices) { N("Congratulations") . "\n\n" . N("The wizard successfully added the following UPS devices:") . join("\n\n-", @new_devices); } else { N("No new UPS devices was found"Dta1xxNw network driver