package mdkapplet_gui; ################################################################################ # Mandriva Online # # # # Copyright (C) 2003-2010 Mandriva # # # # Daouda Lo # # Thierry Vignaud # # # # This program is free software; you can redistribute it and/or modify # # it under the terms of the GNU General Public License Version 2 as # # published by the Free Software Foundation. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program; if not, write to the Free Software # # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ################################################################################ use strict; use feature 'state'; use lib qw(/usr/lib/libDrakX); use common; our @ISA = qw(Exporter); our @EXPORT = qw( @common %local_config $localdir $localfile $width fill_n_run_portable_dialog iso8601_date_to_locale new_link_button new_portable_dialog setVar ); our @EXPORT_OK = qw( run_ask_credentials_dialog run_no_rights_dialog open_ask_powerpack_dialog ); use mygtk2 qw(gtknew); #- do not import gtkadd which conflicts with ugtk2 version use ugtk2 qw(:all); use mdkonline qw(); # you don't want to polute the namespace use interactive; use interactive::gtk; use lib qw(/usr/lib/libDrakX/drakfirsttime); ugtk2::add_icon_path("/usr/share/mdkonline/pixmaps/"); our $localdir = "$ENV{HOME}/.MdkOnline"; our $localfile = "$localdir/mdkonline"; #compatibility mkdir_p($localdir) if !-d $localdir; -e "$ENV{HOME}/.mdkonline" and system("mv", "$ENV{HOME}/.mdkonline", $localfile); # make it work on 2008.X: eval { interactive::gtk::add_padding(Gtk2::Label->new) }; if ($@) { *interactive::gtk::add_padding = sub { $_[0] }; } our %local_config; read_local_config(); our $width = 500; our @common = ( # explicitely wrap (for 2008.1): line_wrap => 1, # workaround infamous 6 years old gnome bug #101968: width => $width - 50, ); sub new_portable_dialog { my ($title) = @_; ugtk2->new($title, width => $width + 20); } sub fill_n_run_portable_dialog { my ($w, $widgets) = @_; # use wizard button order (for both 2008.1 & 2009.0): { local $::isWizard = 1; local $w->{pop_it} = 0; local $::isInstall = 1; my %children; if ($::isEmbedded) { my (@children_tight, $child); @children_tight = @$widgets; $child = pop @children_tight; %children = ( children => [ (map { (0, $_) } @children_tight), 1, gtknew('Label'), 0, $child, ] ); } else { %children = (children_tight => $widgets); } gtkadd($w->{window}, gtknew('VBox', %children)); } $w->{ok}->grab_focus; $w->main; } sub new_link_button { my ($url, $text) = @_; my $link = Gtk2::LinkButton->new($url, $text); $link->set_uri_hook(sub { my (undef, $url) = @_; run_program::raw({ detach => 1, setuid => get_parent_uid() }, 'www-browser', $url); }); $link; } sub read_local_config() { %local_config = getVarsFromSh($localfile); } sub setVar { my ($var, $st) = @_; my %s = getVarsFromSh($localfile); $s{$var} = $st; setVarsInSh($localfile, \%s); read_local_config(); } sub iso8601_date_to_locale { my ($date) = @_; return $date if $date !~ /(\d\d\d\d)-?(\d\d)-?(\d\d)/; require POSIX; POSIX::strftime("%x", 0, 0, 0, $3, $2-1, $1-1900); } sub run_ask_credentials_dialog { my ($title, $description, $callback) = @_; my $w = new_portable_dialog($title); my $password_text; state $email_text; my $password_w = gtknew('Entry'); my $email_w = gtknew('Entry', text => $email_text); my $ok_clicked; $password_w->set_visibility(0); $w->{ok_clicked} = sub { $password_text = $password_w->get_text; $email_text = $email_w->get_text; $ok_clicked = 1; Gtk2->main_quit; }; my @widgets = ( mdkonline::get_banner($title), gtknew('Label_Left', text => $description, @common), gtknew('HButtonBox', layout => 'start', children_tight => [ interactive::gtk::add_padding( new_link_button( 'https://my.mandriva.com/info', N("More information on your user account") ) ) ]), gtknew('Table', col_spacings => 5, row_spacings => 5, children => [ [ N("Your email"), $email_w ], [ N("Your password"), $password_w ] ]), gtknew('HButtonBox', layout => 'start', children_tight => [ interactive::gtk::add_padding( new_link_button( 'https://my.mandriva.com/reset/password/', N("Forgotten password") ) ) ]), ugtk2::create_okcancel($w, N("Next"), N("Cancel")), ); fill_n_run_portable_dialog($w, \@widgets); if ($ok_clicked) { $ok_clicked = 0; if ($email_text && $password_text) { $callback->($email_text, $password_text); } else { interactive->vnew->ask_warn( N("Error"), N("Password and email cannot be empty.") ); goto &run_ask_credentials_dialog; } } } sub run_no_rights_dialog { my ($title, $info, $info_url) = @_; my $w = new_portable_dialog($title); my @widgets = ( mdkonline::get_banner($title), gtknew('Label_Left', text => $info, @mdkapplet_gui::common), gtknew('HButtonBox', layout => 'start', children_tight => [ interactive::gtk::add_padding( new_link_button($info_url, N("More Information")) ) ]), create_okcancel($w, N("Close"), undef) ); fill_n_run_portable_dialog($w, \@widgets); } sub open_ask_powerpack_dialog { my $title = N("Would you like Powerpack?"); my $w = new_portable_dialog($title); my @widgets = ( mdkonline::get_banner($title), gtknew('Label_Left', text => N("Since you don't have Powerpack rights you may visit mandriva store now and get Powerpack subscription."), @common), gtknew('HButtonBox', layout => 'start', children_tight => [ interactive::gtk::add_padding( new_link_button( 'http://store.mandriva.com/', N("Get Powerpack subscription!") ) ) ]), gtknew('Label_Left', text => N("Continue to use your new Powerpack account information to upgrade, or Cancel and upgrade to the Free Edition."), @common), ugtk2::create_okcancel($w, N("Continue and Authenticate!"), N("Cancel, upgrade to Free Edition")), ); return fill_n_run_portable_dialog($w, \@widgets); } 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
package network::connection::xdsl;

use base qw(network::connection::ppp);

use strict;
use common;

sub get_type_name() { N("DSL") }
sub _get_type_icon() { 'xdsl' }

sub get_devices() {
    require detect_devices;
    require network::connection::isdn;
    require network::connection::ethernet;
    my @usb_devices = detect_devices::get_xdsl_usb_devices();
    $_->{xdsl_type} = 'usb' foreach @usb_devices;
    my @capi_devices  = grep { $_->{driver} =~ /dsl/i } map { network::connection::isdn::find_capi_card($_) } network::connection::isdn->get_devices;
    $_->{xdsl_type} = 'capi' foreach @capi_devices;
    my @ethernet_devices = network::connection::ethernet::get_devices();
    $_->{xdsl_type} = 'ethernet' foreach @ethernet_devices;
    @usb_devices, @capi_devices, @ethernet_devices;
}

sub get_metric { 25 }
sub get_interface() { "ppp0" }

my @non_ppp_protocols = qw(static dhcp);
sub uses_ppp {
    my ($self) = @_;
    !member($self->{protocol}, @non_ppp_protocols);
}

sub uses_atm_arp {
    my ($self) = @_;
    $self->{device}{xdsl_type} eq 'usb' && !$self->uses_ppp;
}

sub uses_atm_bridging {
    my ($self) = @_;
    $self->{device}{xdsl_type} eq 'usb' && member($self->{protocol}, qw(pppoe));
}

my %protocol_settings = (
    pppoa => {
        plugin => sub {
            my ($self) = @_;
            "pppoatm.so " . join('.', $self->{access}{peer}{vpi}, $self->{access}{peer}{vci});
        },
    },
    pppoe => {
        pty => sub {
            my ($self) = @_;
            my $eth_interface = $self->network::connection::ethernet::get_interface;
            qq("pppoe -m 1412 -I $eth_interface");
        },
        options => [
            qw(default-asyncmap noaccomp nobsdcomp novjccomp nodeflate),
            "mru 1492",
            "mtu 1492",
            "lcp-echo-interval 20",
            "lcp-echo-failure 3",
        ],
    },
    pptp => {
        pty => qq("/usr/sbin/pptp 10.0.0.138 --nolaunchpppd"),
        options => [ qw(noipdefault) ],
    },
    capi => {
        plugin => "capiplugin.so avmadsl",
        options => [
            qw(ipcp-accept-remote ipcp-accept-local sync noipx),
            "connect /bin/true",
            "lcp-echo-interval 5",
            "lcp-echo-failure 3",
            "lcp-max-configure 50",
            "lcp-max-terminate 2",
            "mru 1492",
            "mtu 1492"
        ],
    },
);

my @thirdparty_settings = (
    {
        matching => 'speedtch',
        description => N_("Alcatel speedtouch USB modem"),
        url => "http://www.speedtouch.com/supuser.htm",
        name => 'speedtouch',
        firmware =>
          {
              package => 'speedtouch-firmware',
              test_file => 'speedtch-*.bin*',
              extract => {
                  name => 'speedtouch-firmware-extractor',
                  test_file => '/usr/sbin/firmware-extractor',
                  windows_source => 'alcaudsl.sys',
                  floppy_source => 'mgmt*.o',
                  default_source => '/usr/share/speedtouch/mgmt.o',
                  run => sub {
                      my ($file) = @_;
                      run_program::raw({ root => $::prefix, chdir => $network::thirdparty::firmware_directory },
                                       '/usr/sbin/firmware-extractor', $file);
                  },
              },
          },
        links => 'http://linux-usb.sourceforge.net/SpeedTouch/mandrake/index.html',
        ppp => {
            options => [ qw(noaccomp sync) ],
        },
    },

    {
        name => 'eciadsl',
        explanations => N_("The ECI Hi-Focus modem cannot be supported due to binary driver distribution problem.

You can find a driver on http://eciadsl.flashtux.org/"),
        no_distro_package => 1,
        tools => {
            test_file => '/usr/sbin/pppoeci',
        },
        ppp => {
            options => [
                qw(noipdefault noaccomp sync),
                "linkname eciadsl",
                "lcp-echo-interval 0",
            ],
            protocols => {
                pppoe => {
                    pty => sub {
                        my ($self) = @_;
                        qq("/usr/bin/pppoeci -v 1 -vpi $self->{access}{peer}{vpi} -vci $self->{access}{peer}{vci}");
                    },
                },
            },
        },
    },

    {
        matching => 'ueagle_atm',
        description => 'Eagle chipset (from Analog Devices), e.g. Sagem F@st 800/840/908',
        url => 'http://www.eagle-usb.org/',
        name => 'ueagle',
        firmware => {
            test_file => 'ueagle-atm/eagle*.fw',
        },
        links => 'http://atm.eagle-usb.org/wakka.php?wiki=UeagleAtmDoc',
    },

    {
        matching => qr/^unicorn_.*_atm$/,
        description => 'Bewan Adsl (Unicorn)',
        url => 'http://www.bewan.com/bewan/users/downloads/',
        name => 'unicorn',
        kernel_module => 1,
        tools => {
            optional => 1,
            test_file => '/usr/bin/bewan_adsl_status',
        },
        sleep => 10,
        ppp => {
            options => [
                qw(default-asyncmap hide-password noaccomp nobsdcomp nodeflate novjccomp sync),
                "lcp-echo-interval 20",
                "lcp-echo-failure 3",
            ],
        },
    },

    {
        name => 'cxacru',
        firmware => {
            test_file => 'cxacru-fw.bin',
            no_distro_package => 1,
            explanations => N_("Modems using Conexant AccessRunner chipsets cannot be supported due to binary firmware distribution problem."),
            url => 'http://accessrunner.sourceforge.net/firmware.shtml',
        },
    }
);

sub get_thirdparty_settings() {
    \@thirdparty_settings;
}

sub get_providers {
    my ($self) = @_;
    require network::connection::providers::xdsl;
    if_($self->{device}{xdsl_type} ne 'capi', \%network::connection::providers::xdsl::data, '|');
}

sub get_protocols {
    my ($self) = @_;
    $self->{device}{xdsl_type} eq 'capi' ?
      {
            capi   => N("DSL over CAPI"),
      } :
      {
        dhcp   => N("Dynamic Host Configuration Protocol (DHCP)"),
        static => N("Manual TCP/IP configuration"),
        pptp   => N("Point to Point Tunneling Protocol (PPTP)"),
        pppoe  => N("PPP over Ethernet (PPPoE)"),
        pppoa  => N("PPP over ATM (PPPoA)"),
      };
}

sub guess_protocol {
    my ($self, $net) = @_;
    $self->{protocol} = $self->{provider} && $self->{provider}{method};
    if ($self->{device}{xdsl_type} eq 'capi') {
        $self->{protocol} = 'capi';
    } elsif ($self->{device}{xdsl_type} eq 'ethernet') {
        require network::connection::ethernet;