summaryrefslogtreecommitdiffstats
path: root/perl-install/standalone/drakroam
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/standalone/drakroam')
-rwxr-xr-xperl-install/standalone/drakroam142
1 files changed, 103 insertions, 39 deletions
diff --git a/perl-install/standalone/drakroam b/perl-install/standalone/drakroam
index e5fe256e4..5294cfbd4 100755
--- a/perl-install/standalone/drakroam
+++ b/perl-install/standalone/drakroam
@@ -16,14 +16,18 @@ use interactive;
use mygtk2;
use ugtk2 qw(:create :helpers :wrappers);
use Gtk2::SimpleList;
+use network::ethernet;
use network::monitor;
-use network::wireless;
use network::network;
-use network::ethernet;
+use network::tools;
+use network::wireless;
my $in = 'interactive'->vnew('su');
-my $wireless_device = find { detect_devices::is_wireless_interface($_) } detect_devices::getNet();
+my $arg_ap;
+/^--ap=(.*)/ and $arg_ap = $1 foreach @ARGV;
+
+my $wireless_device = detect_devices::get_wireless_interface();
unless ($wireless_device) {
ugtk2::err_dialog(N("Error"), N("You do not have any wireless interface.
@@ -44,13 +48,15 @@ my $wireless_list = Gtk2::SimpleList->new(
N("SSID") => "text",
'' => "pixbuf",
N("Encryption") => "text",
- N("Signal strength") => "pixbuf"
+ N("Operating Mode") => "text",
+ N("Signal strength") => "pixbuf",
);
$wireless_list->get_selection->set_mode('single');
my $dbus = dbus_object::system_bus();
my $monitor = network::monitor->new($dbus);
my $wireless_networks = {};
+my $has_roaming;
my %pixbufs =
(
@@ -62,35 +68,34 @@ my %pixbufs =
);
sub update_networks() {
- $wireless_networks = $monitor->list_wireless;
+ ($wireless_networks, $has_roaming) = network::monitor::list_wireless($monitor, $wireless_device);
@{$wireless_list->{data}} = ();
while (my ($ap, $network) = each(%$wireless_networks)) {
push @{$wireless_list->{data}}, [
$ap,
$network->{current} ? $pixbufs{state}{connected} : undef,
- $network->{ssid} || $ap,
+ $network->{essid} || $ap,
$network->{flags} ? $pixbufs{keyring} : undef,
$network->{flags},
- $pixbufs{link_level}{$network->{approx_level}}
+ $network->{mode},
+ $pixbufs{link_level}{$network->{approx_level}},
];
}
1;
}
-sub configure_selected() {
- my ($selected) = $wireless_list->get_selected_indices or return;
- my $ap = $wireless_list->{data}[$selected][0];
+sub configure_ap {
+ my ($ap) = @_;
my $network = $wireless_networks->{$ap};
-
- my $ssid = $network->{ssid};
+ my $essid = $network->{essid};
my $wireless_net =
- $ssid && exists $net->{wireless}{$ssid} ?
- $net->{wireless}{$ssid} :
+ $essid && exists $net->{wireless}{$essid} ?
+ $net->{wireless}{$essid} :
exists $net->{wireless}{$ap} ?
$net->{wireless}{$ap} :
{};
- $wireless_net->{WIRELESS_ESSID} = $ssid if $ssid;
+ $wireless_net->{WIRELESS_ESSID} = $essid if $essid;
my ($wireless_enc_mode, $wireless_enc_key, $wireless_restricted);
($wireless_enc_key, $wireless_restricted) = network::wireless::get_wep_key_from_iwconfig($wireless_net->{WIRELESS_ENC_KEY});
@@ -101,10 +106,10 @@ sub configure_selected() {
$in->ask_from_({
title => "Wireless settings",
- messages => N("Please enter settings for wireless network \"%s\"", $ssid || $ap)
+ messages => N("Please enter settings for wireless network \"%s\"", $essid || $ap)
},
[
- { label => N("Network name (ESSID)"), val => \$wireless_net->{WIRELESS_ESSID}, disabled => sub { $ssid } },
+ { label => N("Network name (ESSID)"), val => \$wireless_net->{WIRELESS_ESSID}, disabled => sub { $essid } },
{ label => N("Encryption mode"), val => \$wireless_enc_mode,
list => [ keys %network::wireless::wireless_enc_modes ],
sort => 1,
@@ -118,40 +123,96 @@ sub configure_selected() {
) or return;
$wireless_net->{BOOTPROTO} = $dhcp ? 'dhcp' : 'static';
- $wireless_net->{WIRELESS_ENC_KEY} = network::wireless::convert_wep_key_for_iwconfig($wireless_enc_key, $wireless_enc_mode eq 'restricted');
- $wireless_net->{WIRELESS_WPA_DRIVER} = network::wireless::wpa_supplicant_get_driver($wireless_module);
+ $wireless_net->{WIRELESS_ENC_KEY} = $wireless_enc_key && network::wireless::convert_wep_key_for_iwconfig($wireless_enc_key, $wireless_enc_mode eq 'restricted');
+ $wireless_net->{WIRELESS_MODE} = $network->{mode} eq 'Master' ? 'Managed' : $network->{mode};
- my $wireless_file = "/etc/sysconfig/network-scripts/wireless.d/" . ($ssid || $ap);
+ if ($has_roaming || $wireless_enc_mode eq 'wpa-psk') {
+ $wireless_net->{WIRELESS_WPA_DRIVER} = network::wireless::wpa_supplicant_get_driver($wireless_module);
+ network::wireless::wpa_supplicant_add_network($wireless_net->{WIRELESS_ESSID}, $wireless_enc_mode, $wireless_enc_key);
+ } else {
+ delete $wireless_net->{WIRELESS_WPA_DRIVER};
+ }
+
+ my $ssid = $essid || $ap;
+ $net->{wireless}{$ssid} = $wireless_net;
+
+ my $wireless_file = "/etc/sysconfig/network-scripts/wireless.d/$ssid";
network::network::write_interface_settings($wireless_net, $wireless_file);
- network::wireless::wpa_supplicant_add_network($wireless_net->{WIRELESS_ESSID}, $wireless_enc_mode, $wireless_enc_key);
- system('/usr/sbin/wpa_cli reconfigure'); #- this should be handled by the monitoring daemon instead
+ if ($has_roaming) {
+ #- this should be handled by the monitoring daemon instead
+ run_program::run('/usr/sbin/wpa_cli', 'reconfigure');
+ } else {
+ overwrite_wireless_ifcfg($wireless_net);
+ }
1;
}
-sub connect_to_selected() {
- my ($selected) = $wireless_list->get_selected_indices or return;
- my $ap = $wireless_list->{data}[$selected][0];
- my $network = $wireless_networks->{$ap};
-
- if (defined $network->{id}) {
- eval { $monitor->select_network($network->{id}) };
- $@ and err_dialog(N("Wireless connection"), N("Unable to contact daemon"));
- } else {
- configure_selected();
- #- apply config in wpa_supplicant and retry
- }
+sub overwrite_wireless_ifcfg {
+ my ($wireless_net) = @_;
+ my $ifcfg = $net->{ifcfg}{$wireless_device} ||= {};
+ delete $ifcfg->{$_} foreach grep { /wireless/i } keys %$ifcfg;
+ put_in_hash($ifcfg, $wireless_net);
+ network::network::write_interface_conf($net, $wireless_device);
+}
+sub wait_and_run_sub {
+ my ($time, $sub) = @_;
gtkset_mousecursor_wait();
-
- Glib::Timeout->add(5000, sub {
- update_networks();
+ Glib::Timeout->add($time, sub {
+ $sub->();
gtkset_mousecursor_normal();
0;
});
}
+sub connect_to_ap {
+ my ($ap, $o_disable_configure) = @_;
+ my $network = $wireless_networks->{$ap};
+ my $found;
+
+ if ($network) {
+ my $wireless_net = !$has_roaming && ($net->{wireless}{$ap} || $net->{wireless}{$network->{essid}});
+ if (defined $network->{id}) {
+ eval { $monitor->select_network($network->{id}) };
+ $found = !$@;
+ $found or err_dialog(N("Wireless connection"), N("Unable to contact daemon"));
+ } elsif ($wireless_net) {
+ network::tools::stop_interface($wireless_device, 0);
+ overwrite_wireless_ifcfg($wireless_net);
+ network::tools::start_interface($wireless_device, 1);
+ $found = 1;
+ }
+ }
+
+ $found || !$o_disable_configure or return;
+
+ if (!$found) {
+ if ($has_roaming) {
+ configure_ap($ap);
+ #- wait for wpa_supplicant to reconfigure the device
+ wait_and_run_sub(2000, sub { connect_to_ap($ap, 1) });
+ return;
+ } else {
+ network::tools::stop_interface($wireless_device, 0);
+ configure_ap($ap);
+ network::tools::start_interface($wireless_device, 0);
+ }
+ }
+ wait_and_run_sub(5000, \&update_networks);
+}
+
+sub configure_selected() {
+ my ($selected) = $wireless_list->get_selected_indices or return;
+ configure_ap($wireless_list->{data}[$selected][0]);
+}
+
+sub connect_to_selected() {
+ my ($selected) = $wireless_list->get_selected_indices or return;
+ connect_to_ap($wireless_list->{data}[$selected][0]);
+}
+
update_networks();
Glib::Timeout->add(30000, \&update_networks);
@@ -160,7 +221,7 @@ gtkadd($w->{window},
gtknew('VBox', spacing => 5, children => [
$::isEmbedded ? () : (0, Gtk2::Banner->new('/usr/share/mcc/themes/default/drakroam-mdk.png', N("Wireless connection"))),
1, gtknew('HBox', spacing => 5, children => [
- 1, gtknew('ScrolledWindow', width => 420, height => 300, child => $wireless_list),
+ 1, gtknew('ScrolledWindow', width => 500, height => 300, child => $wireless_list),
0, gtknew('VButtonBox', layout => 'edge', children_loose => [
gtknew('Button', text => N("Configure"), clicked => \&configure_selected),
gtknew('Button', text => N("Connect"), clicked => \&connect_to_selected),
@@ -169,5 +230,8 @@ gtkadd($w->{window},
]),
]),
]),
- );
+ );
+
+$arg_ap and Glib::Timeout->add(100, sub { connect_to_ap($arg_ap); 0 });
+
$w->main;