summaryrefslogtreecommitdiffstats
path: root/perl-install/proxy.pm
blob: 652388a831d5ce8456e2793aad949012c3b903bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package proxy;

use diagnostics;
use strict;
use run_program;
use common qw(:common :system :file);
use log;
use c;


sub main {
    my ($prefix, $in, $install) = @_;
    my $proxy_cfg = {};
    my $config_file = "$prefix/usr/lib/wgetrc";

    # grab current config
    foreach (cat_($config_file)) {
        ($proxy_cfg->{http_url}, $proxy_cfg->{http_port}) = /http_proxy = (http:.*):(.*)/;
        ($proxy_cfg->{ftp_url}, $proxy_cfg->{ftp_port}) = /ftp_proxy = (ftp:.*):(.*)/;
	($proxy_cfg->{login}) = /http_user = (.*)/;
	($proxy_cfg->{passwd}) = /http_passwd = (.*)/;
	($proxy_cfg->{passwd2}) = /http_passwd = (.*)/;
    }
  begin:
    $::isWizard = 1;
    $::Wizard_no_previous = 1;
    $in->ask_okcancel(_("Proxy configuration"),
                      _("Welcome to the proxy configuration utility.\n\nHere, you'll be able to set up your http and ftp proxies\nwith or without login and password\n"
	               ), 1);

    # http proxy
  step_http_proxy:
    undef $::Wizard_no_previous;
    $proxy_cfg->{http_url} ||= "http:";
    $in->ask_from_entries_refH(_("Proxy configuration"),
                               _("Please fill in the http proxy informations"),
			       [ { label => _("URL"), val => \$proxy_cfg->{http_url} },
				 { label => _("port"), val => \$proxy_cfg->{http_port} }
			       ],
			       complete => sub {
				   if($proxy_cfg->{http_url} && $proxy_cfg->{http_url} !~ /^http:/) {
				       $in->ask_warn('', _("Url should begin with 'http:'"));
				       return (1,0);
				   }
				   if ($proxy_cfg->{http_port} && $proxy_cfg->{http_port} !~ /^\d+$/) {
				       $in->ask_warn('', _("The port part should be numeric"));
				       return (1,1);
				   }
				   0;
			       }
			      ) or goto begin;

    # ftp proxy
    step_ftp_proxy:
    $in->ask_from_entries_refH(_("Proxy configuration"),
                               _("Please fill in the ftp proxy informations"),
			       [ { label => _("URL"), val => \$proxy_cfg->{ftp_url} },
				 { label => _("port"), val => \$proxy_cfg->{ftp_port} }
			       ],
			       complete => sub {
				   if ($proxy_cfg->{ftp_url} && $proxy_cfg->{ftp_url} !~ /^ftp:/) {
				       $in->ask_warn('', _("Url should begin with 'ftp:'"));
				       return (1,0);
				   }
				   if ($proxy_cfg->{ftp_port} && $proxy_cfg->{ftp_port} !~ /^\d+$/) {
				       $in->ask_warn('', _("The port part should be numeric"));
				       return (1,1);
				   }
				   0;
			       }
			      ) or goto step_http_proxy;

    # proxy login/passwd
    step_login:
    $in->ask_from_entries_refH(_("Proxy configuration"),
                               _("Please enter proxy login and password, if any.\nLeave it blank if you don't want login/passwd"),
			       [ { label => _("login"), val => \$proxy_cfg->{login} },
				 { label => _("password"), val => \$proxy_cfg->{passwd}, hidden => 1 },
				 { label => _("re-type password"), val => \$proxy_cfg->{passwd2}, hidden => 1 }
			       ],
			       complete => sub {
				   if ($proxy_cfg->{passwd} ne $proxy_cfg->{passwd2}) {
				       $in->ask_warn('', _("The passwords don't match. Try again!"));
				       return(1,1);
				   }
				   0;
			       }
			      ) or goto step_ftp_proxy;
    # save config
    substInFile {
	s/^(http|ftp)_proxy.*\n//;
	eof and $_ .= "http_proxy = $proxy_cfg->{http_url}:$proxy_cfg->{http_port}
ftp_proxy = $proxy_cfg->{ftp_url}:$proxy_cfg->{ftp_port}\n";
    } $config_file;
    $proxy_cfg->{login} and substInFile {
	s/^http_(user|passwd).*\n//;
	eof and $_ .= "http_user = $proxy_cfg->{login}
http_passwd = $proxy_cfg->{passwd}\n" } $config_file;
    log::l("[drakproxy] Installation complete, exiting\n");
}

#---------------------------------------------
#                WONDERFULL pad
#---------------------------------------------
1;