Wizard/Examples/ISDN/Settings.pm untested

filter: Statementstmt 0.0% 0 / 95 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 144 CC 12 SCAR 38.3
CC
12
Cov
0%
Action_SettingsSave
110.0
init
6.0
ShowMe
6.0
CRAP 45.8
1 # -*- perl -*-
2  
3 use strict;
4  
5 use Wizard::State ();
6 use Wizard::SaveAble ();
7 use Wizard::SaveAble::ShellVars ();
8 use Wizard::Examples::ISDN ();
9 use File::Spec ();
10 use File::Path ();
11 use Socket ();
12 use Symbol ();
13  
14  
15 package Wizard::Examples::ISDN::Settings;
16  
17 @Wizard::Examples::ISDN::Settings::ISA = qw(Wizard::Examples::ISDN);
18 $Wizard::Examples::ISDN::Settings::VERSION = '0.01';
19  
20 sub init {
21 my $self = shift;
22 return $self->SUPER::init(1) unless shift;
23 my $item = $self->{'settings'} || die "Missing settings";
24 ($self->SUPER::init(1), $item);
25 }
26  
27 sub GetKey { 'host';};
28  
29 sub ShowMe {
30 my($self, $wiz, $sets) = @_;
31 (['Wizard::Elem::Title',
32 'value' => 'Edit ISDN settings'],
33 ['Wizard::Elem::Select', 'name' => 'isdn-settings-I4L_HARDWARE_ENABLED',
34 'options' => ['yes', 'no'],
35 'value' => $sets->{'isdn-settings-I4L_HARDWARE_ENABLED'},
36 'descr' => 'Enable ISDN subsystem'],
37 ['Wizard::Elem::Text', 'name' => 'isdn-settings-I4L_HARDWARE',
38 'value' => $sets->{'isdn-settings-I4L_HARDWARE'},
39 'descr' => 'Name of the ISDN cards, for example "Fritz"'],
40 ['Wizard::Elem::Text', 'name' => 'isdn-settings-I4L_HARDWARE_IO',
41 'value' => $sets->{'isdn-settings-I4L_HARDWARE_IO'},
42 'descr' => 'IO address of the ISDN hardware'],
43 ['Wizard::Elem::Text', 'name' => 'isdn-settings-I4L_HARDWARE_IRQ',
44 'value' => $sets->{'isdn-settings-I4L_HARDWARE_IRQ'},
45 'descr' => 'IRQ number of the ISDN hardware'],
46 ['Wizard::Elem::Select', 'name' => 'isdn-settings-I4L_HARDWARE_PROTO',
47 'options' => ['1TR6 (1)', 'Euro ISDN (2)'],
48 'value' => ($sets->{'isdn-settings-I4L_HARDWARE_PROTO'} eq '1' ? '1TR6 (1)' : 'Euro ISDN (2)'),
49 'descr' => 'ISDN protocol, 1TR6 or Euro ISDN'],
50 ['Wizard::Elem::Text', 'name' => 'isdn-settings-I4L_HARDWARE_PHONE',
51 'value' => $sets->{'isdn-settings-I4L_HARDWARE_PHONE'},
52 'descr' => 'Local MSN or EAZ; maybe empty'],
53 ['Wizard::Elem::Text', 'name' => 'isdn-settings-INTERNET_PHONE_OUT',
54 'value' => $sets->{'isdn-settings-INTERNET_PHONE_OUT'},
55 'descr' => 'Phone number of the Internet dailup line; may be empty'],
56 ['Wizard::Elem::Text', 'name' => 'isdn-settings-INTERNET_PHONE_IN',
57 'value' => $sets->{'isdn-settings-INTERNET_PHONE_IN'},
58 'descr' => 'Phone number of the Internet dailin line; may be empty'],
59 ['Wizard::Elem::Select', 'name' => 'isdn-settings-INTERNET_ENABLED',
60 'options' => ['yes', 'no'],
61 'value' => $sets->{'isdn-settings-INTERNET_ENABLED'},
62 'descr' => 'Use this ISDN card for Internet'],
63 ['Wizard::Elem::Text', 'name' => 'isdn-settings-INTERNET_USER',
64 'value' => $sets->{'isdn-settings-INTERNET_USER'},
65 'descr' => 'User name to login as'],
66 ['Wizard::Elem::Text', 'name' => 'isdn-settings-INTERNET_PASSWORD',
67 'value' => $sets->{'isdn-settings-INTERNET_PASSWORD'},
68 'descr' => 'Password to use'],
69 ['Wizard::Elem::Text', 'name' => 'isdn-settings-SERVICE_PHONE_OUT',
70 'value' => $sets->{'isdn-settings-SERVICE_PHONE_OUT'},
71 'descr' => 'Phone number of the service dialup line; may be empty'],
72 ['Wizard::Elem::Text', 'name' => 'isdn-settings-SERVICE_PHONE_IN',
73 'value' => $sets->{'isdn-settings-SERVICE_PHONE_IN'},
74 'descr' => 'Phone number of the service dialin line; may be empty'],
75 ['Wizard::Elem::Select', 'name' => 'isdn-settings-SERVICE_ENABLED',
76 'options' => ['yes', 'no'],
77 'value' => $sets->{'isdn-settings-SERVICE_ENABLED'},
78 'descr' => 'Use this ISDN card for Service dailup'],
79 ['Wizard::Elem::Select', 'name' => 'isdn-settings-SERVICE_RAWIP',
80 'options' => ['yes', 'no'],
81 'value' => $sets->{'isdn-settings-SERVICE_RAWIP'},
82 'descr' => 'Use RawIp on the Service line'],
83 ['Wizard::Elem::Select', 'name' => 'isdn-settings-SERVICE_CALLBACK',
84 'options' => ['yes', 'no'],
85 'value' => $sets->{'isdn-settings-SERVICE_CALLBACK'},
86 'descr' => 'Enable Callback on the service line'],
87 ['Wizard::Elem::Text', 'name' => 'isdn-settings-SERVICE_USER',
88 'value' => $sets->{'isdn-settings-SERVICE_USER'},
89 'descr' => 'Service user name (used only if RawIp is disabled; may be empty'],
90 ['Wizard::Elem::Text', 'name' => 'isdn-settings-SERVICE_PASSWORD',
91 'value' => $sets->{'isdn-settings-SERVICE_PASSWORD'},
92 'descr' => 'Password of the service user'],
93 ['Wizard::Elem::Text', 'name' => 'isdn-settings-SERVICE_IP_LOCAL',
94 'value' => $sets->{'isdn-settings-SERVICE_IP_LOCAL'},
95 'descr' => 'Local IP address of the service line'],
96 ['Wizard::Elem::Text', 'name' => 'isdn-settings-SERVICE_IP_REMOTE',
97 'value' => $sets->{'isdn-settings-SERVICE_IP_REMOTE'},
98 'descr' => 'Rempote IP address of the service line'],
99 ['Wizard::Elem::Submit', 'name' => 'Action_SettingsSave',
100 'value' => 'Save these settings', 'id' => 1],
101 ['Wizard::Elem::Submit', 'name' => 'Action_Reset',
102 'value' => 'Return to ISDN menu', 'id' => 98],
103 ['Wizard::Elem::Submit', 'name' => 'Wizard::Examples::ISDN::Action_Reset',
104 'value' => 'Return to top menu', 'id' => 99]);
105 }
106  
107  
108 sub Action_SettingsSave {
109 my($self, $wiz) = @_;
110 my ($prefs, $basedir, $sets) = $self->init(1);
111
112 foreach my $opt ($wiz->param()) {
113 $sets->{$opt} = $wiz->param($opt) if (($opt =~ /^isdn-settings/) && defined($wiz->param($opt)));
114 }
115
116 $sets->{'isdn-settings-I4L_HARDWARE_PROTO'} = '1' if $sets->{'isdn-settings-I4L_HARDWARE_PROTO'} =~ /^1TR6/i;
117 $sets->{'isdn-settings-I4L_HARDWARE_PROTO'} = '2' if $sets->{'isdn-settings-I4L_HARDWARE_PROTO'} =~ /^Euro/i;
118  
119 # Verify the new settings
120 my $errors = '';
121 my $ip_local = $sets->{'isdn-settings-SERVICE_IP_LOCAL'};
122 my $ip_remote = $sets->{'isdn-settings-SERVICE_IP_REMOTE'};
123  
124 if ($ip_local) {
125 $errors .= "Cannot resolve Service Local IP address $ip_local.\n"
126 unless Socket::inet_aton($ip_local);
127 }
128 if ($ip_remote) {
129 $errors .= "Cannot resolve Service Remote IP address $ip_remote.\n"
130 unless Socket::inet_aton($ip_remote);
131 }
132 die $errors if $errors;
133  
134 $sets->Modified(1);
135 $self->Store($wiz, 1);
136 my $cmd = $prefs->{'isdn-prefs-upadatecmd'};
137 my $cmdp = $cmd; $cmdp =~ s/\ .*$//g;
138 system($cmd) if(-x $cmdp);
139  
140 $self->Wizard::Examples::ISDN::Action_Reset($wiz);
141 }
142  
143 sub Action_Reset {
144 my($self, $wiz) = @_;
145 my ($prefs) = $self->init();
146  
147 my $cfile = $prefs->{'isdn-prefs-cfile'};
148 $self->{'settings'} = Wizard::SaveAble::ShellVars->new('file' => $cfile, 'load' => 1, 'prefix' => 'isdn-settings-');
149 $self->Store($wiz);
150  
151 return $self->ShowMe($wiz, $self->{'settings'});
152 }
153  
154  
155  
156  
157  
158  
159  
160  
161  
162