author | benmeyer <benmeyer> | 2002-10-29 15:59:44 (UTC) |
---|---|---|
committer | benmeyer <benmeyer> | 2002-10-29 15:59:44 (UTC) |
commit | 5ca0a08f9f27391370b291df28b3de71db3bb175 (patch) (unidiff) | |
tree | f0730ad64e0dfc84494cc86813a40854b504ee12 | |
parent | bad66a2ea2aea8bec1c7895b0e1a461e2f4859c2 (diff) | |
download | opie-5ca0a08f9f27391370b291df28b3de71db3bb175.zip opie-5ca0a08f9f27391370b291df28b3de71db3bb175.tar.gz opie-5ca0a08f9f27391370b291df28b3de71db3bb175.tar.bz2 |
Added changedns
4 files changed, 230 insertions, 8 deletions
diff --git a/noncore/net/networksetup/interfaces/changedns b/noncore/net/networksetup/interfaces/changedns new file mode 100644 index 0000000..4760a67 --- a/dev/null +++ b/noncore/net/networksetup/interfaces/changedns | |||
@@ -0,0 +1,111 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | SN="`basename $0`"# base portion of our filename | ||
4 | AE="-a" # switch to add an entry | ||
5 | RE="-r" # swithc to remove an entry | ||
6 | EL="/tmp/resolv.conf"# expected location of the system nameserver config file | ||
7 | ARGS="$@" # friendly variable name for all args | ||
8 | |||
9 | usage(){ | ||
10 | echo "usage: | ||
11 | $SN -a {ip} [{ip}...] | ||
12 | $SN -r {ip} [{ip}...]" | ||
13 | } | ||
14 | |||
15 | #if are there at least two arguments? | ||
16 | if [ "$#" -gt 1 ] | ||
17 | then | ||
18 | |||
19 | #remove any old resolv.conf file | ||
20 | rm .resolve.conf .resolve.old .resolve.new 2> /dev/null | ||
21 | |||
22 | #cast current nameserver file into OLD | ||
23 | cat "$EL" > .resolve.old | ||
24 | |||
25 | #build IP list | ||
26 | for ARG in $ARGS | ||
27 | do | ||
28 | if [ "$ARG" != "$1" ] | ||
29 | then | ||
30 | IP_LIST=`echo "$IP_LIST $ARG"` | ||
31 | fi | ||
32 | done | ||
33 | |||
34 | #select case on first switch | ||
35 | case "$1" in | ||
36 | |||
37 | #case '-a' | ||
38 | "$AE") | ||
39 | |||
40 | #for each IP in IP_LIST | ||
41 | for IP in $IP_LIST | ||
42 | do | ||
43 | #add nameserver entery to .newfile | ||
44 | echo "nameserver $IP" >> .resolve.conf | ||
45 | |||
46 | #cat OLD into grep excluding IP lines, | ||
47 | #storing results into NEW | ||
48 | cat .resolve.old | grep -v "$IP" > .resolve.new | ||
49 | |||
50 | #set OLD to NEW | ||
51 | cat .resolve.new > .resolve.old | ||
52 | |||
53 | done | ||
54 | |||
55 | #cat OLD onto end of .newfile | ||
56 | cat .resolve.new >> .resolve.conf | ||
57 | |||
58 | #clean up work files | ||
59 | rm .resolve.new .resolve.old | ||
60 | |||
61 | #move old conf file to old conf file.bak | ||
62 | mv "$EL" "$EL.bak" | ||
63 | |||
64 | #move .newfile to resolve.conf file | ||
65 | mv .resolve.conf "$EL" | ||
66 | |||
67 | echo "Added $IP_LIST to $EL" | ||
68 | ;; | ||
69 | |||
70 | #case '-r' | ||
71 | "$RE") | ||
72 | |||
73 | #for each IP in IP_LIST | ||
74 | for IP in $IP_LIST | ||
75 | do | ||
76 | #cat OLD into grep excluding IP lines, | ||
77 | #storing results into NEW | ||
78 | cat .resolve.old | grep -v "$IP" > .resolve.new | ||
79 | |||
80 | #set OLD to NEW | ||
81 | cat .resolve.new > .resolve.old | ||
82 | |||
83 | done | ||
84 | |||
85 | #move old conf file to old conf file.bak | ||
86 | mv "$EL" "$EL.bak" | ||
87 | |||
88 | #move .newfile to resolve.conf file | ||
89 | mv .resolve.new "$EL" | ||
90 | |||
91 | echo "Removed $IP_LIST from $EL" | ||
92 | |||
93 | ;; | ||
94 | |||
95 | #case else | ||
96 | *) | ||
97 | |||
98 | usage | ||
99 | ;; | ||
100 | |||
101 | |||
102 | #end switch | ||
103 | esac | ||
104 | |||
105 | #else | ||
106 | else | ||
107 | |||
108 | usage | ||
109 | |||
110 | #end | ||
111 | fi | ||
diff --git a/noncore/net/networksetup/interfaces/interfacesetupimp.cpp b/noncore/net/networksetup/interfaces/interfacesetupimp.cpp index e717d6f..97c05cc 100644 --- a/noncore/net/networksetup/interfaces/interfacesetupimp.cpp +++ b/noncore/net/networksetup/interfaces/interfacesetupimp.cpp | |||
@@ -1,148 +1,148 @@ | |||
1 | #include "interfacesetupimp.h" | 1 | #include "interfacesetupimp.h" |
2 | #include "interface.h" | 2 | #include "interface.h" |
3 | #include "interfaces.h" | 3 | #include "interfaces.h" |
4 | 4 | ||
5 | #include <qdialog.h> | 5 | #include <qdialog.h> |
6 | #include <qcombobox.h> | 6 | #include <qcombobox.h> |
7 | #include <qcheckbox.h> | 7 | #include <qcheckbox.h> |
8 | #include <qlineedit.h> | 8 | #include <qlineedit.h> |
9 | #include <qspinbox.h> | 9 | #include <qspinbox.h> |
10 | #include <qgroupbox.h> | 10 | #include <qgroupbox.h> |
11 | #include <qlabel.h> | 11 | #include <qlabel.h> |
12 | 12 | ||
13 | #include <qmessagebox.h> | 13 | #include <qmessagebox.h> |
14 | 14 | ||
15 | #include <assert.h> | 15 | #include <assert.h> |
16 | 16 | ||
17 | #define DNSSCRIPT "interfacednsscript" | 17 | #define DNSSCRIPT "changedns" |
18 | 18 | ||
19 | /** | 19 | /** |
20 | * Constuctor. Set up the connection and load the first profile. | 20 | * Constuctor. Set up the connection and load the first profile. |
21 | */ | 21 | */ |
22 | InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, WFlags fl) : InterfaceSetup(parent, name, fl){ | 22 | InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, WFlags fl) : InterfaceSetup(parent, name, fl){ |
23 | assert(parent); | 23 | assert(parent); |
24 | assert(i); | 24 | assert(i); |
25 | interface = i; | 25 | interface = i; |
26 | interfaces = new Interfaces(); | 26 | interfaces = new Interfaces(); |
27 | bool error = false; | 27 | bool error = false; |
28 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ | 28 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ |
29 | staticGroupBox->hide(); | 29 | staticGroupBox->hide(); |
30 | dhcpCheckBox->hide(); | 30 | dhcpCheckBox->hide(); |
31 | leaseTime->hide(); | 31 | leaseTime->hide(); |
32 | leaseHoursLabel->hide(); | 32 | leaseHoursLabel->hide(); |
33 | } | 33 | } |
34 | } | 34 | } |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * Save the current settings, then write out the interfaces file and close. | 37 | * Save the current settings, then write out the interfaces file and close. |
38 | */ | 38 | */ |
39 | void InterfaceSetupImp::saveChanges(){ | 39 | void InterfaceSetupImp::saveChanges(){ |
40 | if(!saveSettings()) | 40 | if(!saveSettings()) |
41 | return; | 41 | return; |
42 | interfaces->write(); | 42 | interfaces->write(); |
43 | } | 43 | } |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * Save the settings for the current Interface. | 46 | * Save the settings for the current Interface. |
47 | * @return bool true if successfull, false otherwise | 47 | * @return bool true if successfull, false otherwise |
48 | */ | 48 | */ |
49 | bool InterfaceSetupImp::saveSettings(){ | 49 | bool InterfaceSetupImp::saveSettings(){ |
50 | // eh can't really do anything about it other then return. :-D | 50 | // eh can't really do anything about it other then return. :-D |
51 | if(!interfaces->isInterfaceSet()) | 51 | if(!interfaces->isInterfaceSet()) |
52 | return true; | 52 | return true; |
53 | 53 | ||
54 | bool error = false; | 54 | bool error = false; |
55 | // Loopback case | 55 | // Loopback case |
56 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ | 56 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ |
57 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); | 57 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); |
58 | return true; | 58 | return true; |
59 | } | 59 | } |
60 | 60 | ||
61 | if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty() || firstDNSLineEdit->text().isEmpty())){ | 61 | if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty() || firstDNSLineEdit->text().isEmpty())){ |
62 | QMessageBox::information(this, "Empy Fields.", "Please fill in address, subnet,\n gateway and the first dns entries.", "Ok"); | 62 | QMessageBox::information(this, "Empy Fields.", "Please fill in address, subnet,\n gateway and the first dns entries.", "Ok"); |
63 | return false; | 63 | return false; |
64 | } | 64 | } |
65 | interfaces->removeAllInterfaceOptions(); | 65 | interfaces->removeAllInterfaceOptions(); |
66 | 66 | ||
67 | // DHCP | 67 | // DHCP |
68 | if(dhcpCheckBox->isChecked()){ | 68 | if(dhcpCheckBox->isChecked()){ |
69 | interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP); | 69 | interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP); |
70 | interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value())); | 70 | interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value())); |
71 | interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60)); | 71 | interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60)); |
72 | } | 72 | } |
73 | else{ | 73 | else{ |
74 | interfaces->setInterfaceMethod("static"); | 74 | interfaces->setInterfaceMethod("static"); |
75 | interfaces->setInterfaceOption("address", ipAddressEdit->text()); | 75 | interfaces->setInterfaceOption("address", ipAddressEdit->text()); |
76 | interfaces->setInterfaceOption("netmask", subnetMaskEdit->text()); | 76 | interfaces->setInterfaceOption("netmask", subnetMaskEdit->text()); |
77 | interfaces->setInterfaceOption("gateway", gatewayEdit->text()); | 77 | interfaces->setInterfaceOption("gateway", gatewayEdit->text()); |
78 | QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); | 78 | QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); |
79 | interfaces->setInterfaceOption("up "DNSSCRIPT" add ", dns); | 79 | interfaces->setInterfaceOption("up "DNSSCRIPT" -a ", dns); |
80 | interfaces->setInterfaceOption("down "DNSSCRIPT" remove ", dns); | 80 | interfaces->setInterfaceOption("down "DNSSCRIPT" -r ", dns); |
81 | } | 81 | } |
82 | 82 | ||
83 | // IP Information | 83 | // IP Information |
84 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); | 84 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); |
85 | return true; | 85 | return true; |
86 | } | 86 | } |
87 | 87 | ||
88 | /** | 88 | /** |
89 | * The Profile has changed. | 89 | * The Profile has changed. |
90 | * @profile the new profile. | 90 | * @profile the new profile. |
91 | */ | 91 | */ |
92 | void InterfaceSetupImp::setProfile(const QString &profile){ | 92 | void InterfaceSetupImp::setProfile(const QString &profile){ |
93 | QString newInterfaceName = interface->getInterfaceName(); | 93 | QString newInterfaceName = interface->getInterfaceName(); |
94 | if(profile.length() > 0) | 94 | if(profile.length() > 0) |
95 | newInterfaceName += "_" + profile; | 95 | newInterfaceName += "_" + profile; |
96 | // See if we have to make a interface. | 96 | // See if we have to make a interface. |
97 | if(!interfaces->setInterface(newInterfaceName)){ | 97 | if(!interfaces->setInterface(newInterfaceName)){ |
98 | // Add making for this new interface if need too | 98 | // Add making for this new interface if need too |
99 | if(profile != ""){ | 99 | if(profile != ""){ |
100 | interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName); | 100 | interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName); |
101 | if(!interfaces->setMapping(interface->getInterfaceName())){ | 101 | if(!interfaces->setMapping(interface->getInterfaceName())){ |
102 | interfaces->addMapping(interface->getInterfaceName()); | 102 | interfaces->addMapping(interface->getInterfaceName()); |
103 | if(!interfaces->setMapping(interface->getInterfaceName())){ | 103 | if(!interfaces->setMapping(interface->getInterfaceName())){ |
104 | qDebug("InterfaceSetupImp: Added Mapping, but still can't set."); | 104 | qDebug("InterfaceSetupImp: Added Mapping, but still can't set."); |
105 | return; | 105 | return; |
106 | } | 106 | } |
107 | } | 107 | } |
108 | interfaces->setMap("map", newInterfaceName); | 108 | interfaces->setMap("map", newInterfaceName); |
109 | interfaces->setScript("getprofile.sh"); | 109 | interfaces->setScript("getprofile.sh"); |
110 | } | 110 | } |
111 | else{ | 111 | else{ |
112 | interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP); | 112 | interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP); |
113 | if(!interfaces->setInterface(newInterfaceName)){ | 113 | if(!interfaces->setInterface(newInterfaceName)){ |
114 | qDebug("InterfaceSetupImp: Added interface, but still can't set."); | 114 | qDebug("InterfaceSetupImp: Added interface, but still can't set."); |
115 | return; | 115 | return; |
116 | } | 116 | } |
117 | } | 117 | } |
118 | } | 118 | } |
119 | 119 | ||
120 | // We must have a valid interface to get this far so read some settings. | 120 | // We must have a valid interface to get this far so read some settings. |
121 | 121 | ||
122 | // DHCP | 122 | // DHCP |
123 | bool error = false; | 123 | bool error = false; |
124 | if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) | 124 | if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) |
125 | dhcpCheckBox->setChecked(true); | 125 | dhcpCheckBox->setChecked(true); |
126 | else | 126 | else |
127 | dhcpCheckBox->setChecked(false); | 127 | dhcpCheckBox->setChecked(false); |
128 | leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt()); | 128 | leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt()); |
129 | if(error) | 129 | if(error) |
130 | leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60); | 130 | leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60); |
131 | if(error) | 131 | if(error) |
132 | leaseTime->setValue(24); | 132 | leaseTime->setValue(24); |
133 | 133 | ||
134 | // IP Information | 134 | // IP Information |
135 | autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); | 135 | autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); |
136 | QString dns = interfaces->getInterfaceOption("up interfacednsscript add", error); | 136 | QString dns = interfaces->getInterfaceOption("up interfacednsscript -a", error); |
137 | if(dns.contains(" ")){ | 137 | if(dns.contains(" ")){ |
138 | firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); | 138 | firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); |
139 | secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); | 139 | secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); |
140 | } | 140 | } |
141 | ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); | 141 | ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); |
142 | subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); | 142 | subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); |
143 | gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); | 143 | gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); |
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | // interfacesetup.cpp | 147 | // interfacesetup.cpp |
148 | 148 | ||
diff --git a/noncore/settings/networksettings/interfaces/changedns b/noncore/settings/networksettings/interfaces/changedns new file mode 100644 index 0000000..4760a67 --- a/dev/null +++ b/noncore/settings/networksettings/interfaces/changedns | |||
@@ -0,0 +1,111 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | SN="`basename $0`"# base portion of our filename | ||
4 | AE="-a" # switch to add an entry | ||
5 | RE="-r" # swithc to remove an entry | ||
6 | EL="/tmp/resolv.conf"# expected location of the system nameserver config file | ||
7 | ARGS="$@" # friendly variable name for all args | ||
8 | |||
9 | usage(){ | ||
10 | echo "usage: | ||
11 | $SN -a {ip} [{ip}...] | ||
12 | $SN -r {ip} [{ip}...]" | ||
13 | } | ||
14 | |||
15 | #if are there at least two arguments? | ||
16 | if [ "$#" -gt 1 ] | ||
17 | then | ||
18 | |||
19 | #remove any old resolv.conf file | ||
20 | rm .resolve.conf .resolve.old .resolve.new 2> /dev/null | ||
21 | |||
22 | #cast current nameserver file into OLD | ||
23 | cat "$EL" > .resolve.old | ||
24 | |||
25 | #build IP list | ||
26 | for ARG in $ARGS | ||
27 | do | ||
28 | if [ "$ARG" != "$1" ] | ||
29 | then | ||
30 | IP_LIST=`echo "$IP_LIST $ARG"` | ||
31 | fi | ||
32 | done | ||
33 | |||
34 | #select case on first switch | ||
35 | case "$1" in | ||
36 | |||
37 | #case '-a' | ||
38 | "$AE") | ||
39 | |||
40 | #for each IP in IP_LIST | ||
41 | for IP in $IP_LIST | ||
42 | do | ||
43 | #add nameserver entery to .newfile | ||
44 | echo "nameserver $IP" >> .resolve.conf | ||
45 | |||
46 | #cat OLD into grep excluding IP lines, | ||
47 | #storing results into NEW | ||
48 | cat .resolve.old | grep -v "$IP" > .resolve.new | ||
49 | |||
50 | #set OLD to NEW | ||
51 | cat .resolve.new > .resolve.old | ||
52 | |||
53 | done | ||
54 | |||
55 | #cat OLD onto end of .newfile | ||
56 | cat .resolve.new >> .resolve.conf | ||
57 | |||
58 | #clean up work files | ||
59 | rm .resolve.new .resolve.old | ||
60 | |||
61 | #move old conf file to old conf file.bak | ||
62 | mv "$EL" "$EL.bak" | ||
63 | |||
64 | #move .newfile to resolve.conf file | ||
65 | mv .resolve.conf "$EL" | ||
66 | |||
67 | echo "Added $IP_LIST to $EL" | ||
68 | ;; | ||
69 | |||
70 | #case '-r' | ||
71 | "$RE") | ||
72 | |||
73 | #for each IP in IP_LIST | ||
74 | for IP in $IP_LIST | ||
75 | do | ||
76 | #cat OLD into grep excluding IP lines, | ||
77 | #storing results into NEW | ||
78 | cat .resolve.old | grep -v "$IP" > .resolve.new | ||
79 | |||
80 | #set OLD to NEW | ||
81 | cat .resolve.new > .resolve.old | ||
82 | |||
83 | done | ||
84 | |||
85 | #move old conf file to old conf file.bak | ||
86 | mv "$EL" "$EL.bak" | ||
87 | |||
88 | #move .newfile to resolve.conf file | ||
89 | mv .resolve.new "$EL" | ||
90 | |||
91 | echo "Removed $IP_LIST from $EL" | ||
92 | |||
93 | ;; | ||
94 | |||
95 | #case else | ||
96 | *) | ||
97 | |||
98 | usage | ||
99 | ;; | ||
100 | |||
101 | |||
102 | #end switch | ||
103 | esac | ||
104 | |||
105 | #else | ||
106 | else | ||
107 | |||
108 | usage | ||
109 | |||
110 | #end | ||
111 | fi | ||
diff --git a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp index e717d6f..97c05cc 100644 --- a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp +++ b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp | |||
@@ -1,148 +1,148 @@ | |||
1 | #include "interfacesetupimp.h" | 1 | #include "interfacesetupimp.h" |
2 | #include "interface.h" | 2 | #include "interface.h" |
3 | #include "interfaces.h" | 3 | #include "interfaces.h" |
4 | 4 | ||
5 | #include <qdialog.h> | 5 | #include <qdialog.h> |
6 | #include <qcombobox.h> | 6 | #include <qcombobox.h> |
7 | #include <qcheckbox.h> | 7 | #include <qcheckbox.h> |
8 | #include <qlineedit.h> | 8 | #include <qlineedit.h> |
9 | #include <qspinbox.h> | 9 | #include <qspinbox.h> |
10 | #include <qgroupbox.h> | 10 | #include <qgroupbox.h> |
11 | #include <qlabel.h> | 11 | #include <qlabel.h> |
12 | 12 | ||
13 | #include <qmessagebox.h> | 13 | #include <qmessagebox.h> |
14 | 14 | ||
15 | #include <assert.h> | 15 | #include <assert.h> |
16 | 16 | ||
17 | #define DNSSCRIPT "interfacednsscript" | 17 | #define DNSSCRIPT "changedns" |
18 | 18 | ||
19 | /** | 19 | /** |
20 | * Constuctor. Set up the connection and load the first profile. | 20 | * Constuctor. Set up the connection and load the first profile. |
21 | */ | 21 | */ |
22 | InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, WFlags fl) : InterfaceSetup(parent, name, fl){ | 22 | InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, WFlags fl) : InterfaceSetup(parent, name, fl){ |
23 | assert(parent); | 23 | assert(parent); |
24 | assert(i); | 24 | assert(i); |
25 | interface = i; | 25 | interface = i; |
26 | interfaces = new Interfaces(); | 26 | interfaces = new Interfaces(); |
27 | bool error = false; | 27 | bool error = false; |
28 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ | 28 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ |
29 | staticGroupBox->hide(); | 29 | staticGroupBox->hide(); |
30 | dhcpCheckBox->hide(); | 30 | dhcpCheckBox->hide(); |
31 | leaseTime->hide(); | 31 | leaseTime->hide(); |
32 | leaseHoursLabel->hide(); | 32 | leaseHoursLabel->hide(); |
33 | } | 33 | } |
34 | } | 34 | } |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * Save the current settings, then write out the interfaces file and close. | 37 | * Save the current settings, then write out the interfaces file and close. |
38 | */ | 38 | */ |
39 | void InterfaceSetupImp::saveChanges(){ | 39 | void InterfaceSetupImp::saveChanges(){ |
40 | if(!saveSettings()) | 40 | if(!saveSettings()) |
41 | return; | 41 | return; |
42 | interfaces->write(); | 42 | interfaces->write(); |
43 | } | 43 | } |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * Save the settings for the current Interface. | 46 | * Save the settings for the current Interface. |
47 | * @return bool true if successfull, false otherwise | 47 | * @return bool true if successfull, false otherwise |
48 | */ | 48 | */ |
49 | bool InterfaceSetupImp::saveSettings(){ | 49 | bool InterfaceSetupImp::saveSettings(){ |
50 | // eh can't really do anything about it other then return. :-D | 50 | // eh can't really do anything about it other then return. :-D |
51 | if(!interfaces->isInterfaceSet()) | 51 | if(!interfaces->isInterfaceSet()) |
52 | return true; | 52 | return true; |
53 | 53 | ||
54 | bool error = false; | 54 | bool error = false; |
55 | // Loopback case | 55 | // Loopback case |
56 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ | 56 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ |
57 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); | 57 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); |
58 | return true; | 58 | return true; |
59 | } | 59 | } |
60 | 60 | ||
61 | if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty() || firstDNSLineEdit->text().isEmpty())){ | 61 | if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty() || firstDNSLineEdit->text().isEmpty())){ |
62 | QMessageBox::information(this, "Empy Fields.", "Please fill in address, subnet,\n gateway and the first dns entries.", "Ok"); | 62 | QMessageBox::information(this, "Empy Fields.", "Please fill in address, subnet,\n gateway and the first dns entries.", "Ok"); |
63 | return false; | 63 | return false; |
64 | } | 64 | } |
65 | interfaces->removeAllInterfaceOptions(); | 65 | interfaces->removeAllInterfaceOptions(); |
66 | 66 | ||
67 | // DHCP | 67 | // DHCP |
68 | if(dhcpCheckBox->isChecked()){ | 68 | if(dhcpCheckBox->isChecked()){ |
69 | interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP); | 69 | interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP); |
70 | interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value())); | 70 | interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value())); |
71 | interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60)); | 71 | interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60)); |
72 | } | 72 | } |
73 | else{ | 73 | else{ |
74 | interfaces->setInterfaceMethod("static"); | 74 | interfaces->setInterfaceMethod("static"); |
75 | interfaces->setInterfaceOption("address", ipAddressEdit->text()); | 75 | interfaces->setInterfaceOption("address", ipAddressEdit->text()); |
76 | interfaces->setInterfaceOption("netmask", subnetMaskEdit->text()); | 76 | interfaces->setInterfaceOption("netmask", subnetMaskEdit->text()); |
77 | interfaces->setInterfaceOption("gateway", gatewayEdit->text()); | 77 | interfaces->setInterfaceOption("gateway", gatewayEdit->text()); |
78 | QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); | 78 | QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); |
79 | interfaces->setInterfaceOption("up "DNSSCRIPT" add ", dns); | 79 | interfaces->setInterfaceOption("up "DNSSCRIPT" -a ", dns); |
80 | interfaces->setInterfaceOption("down "DNSSCRIPT" remove ", dns); | 80 | interfaces->setInterfaceOption("down "DNSSCRIPT" -r ", dns); |
81 | } | 81 | } |
82 | 82 | ||
83 | // IP Information | 83 | // IP Information |
84 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); | 84 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); |
85 | return true; | 85 | return true; |
86 | } | 86 | } |
87 | 87 | ||
88 | /** | 88 | /** |
89 | * The Profile has changed. | 89 | * The Profile has changed. |
90 | * @profile the new profile. | 90 | * @profile the new profile. |
91 | */ | 91 | */ |
92 | void InterfaceSetupImp::setProfile(const QString &profile){ | 92 | void InterfaceSetupImp::setProfile(const QString &profile){ |
93 | QString newInterfaceName = interface->getInterfaceName(); | 93 | QString newInterfaceName = interface->getInterfaceName(); |
94 | if(profile.length() > 0) | 94 | if(profile.length() > 0) |
95 | newInterfaceName += "_" + profile; | 95 | newInterfaceName += "_" + profile; |
96 | // See if we have to make a interface. | 96 | // See if we have to make a interface. |
97 | if(!interfaces->setInterface(newInterfaceName)){ | 97 | if(!interfaces->setInterface(newInterfaceName)){ |
98 | // Add making for this new interface if need too | 98 | // Add making for this new interface if need too |
99 | if(profile != ""){ | 99 | if(profile != ""){ |
100 | interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName); | 100 | interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName); |
101 | if(!interfaces->setMapping(interface->getInterfaceName())){ | 101 | if(!interfaces->setMapping(interface->getInterfaceName())){ |
102 | interfaces->addMapping(interface->getInterfaceName()); | 102 | interfaces->addMapping(interface->getInterfaceName()); |
103 | if(!interfaces->setMapping(interface->getInterfaceName())){ | 103 | if(!interfaces->setMapping(interface->getInterfaceName())){ |
104 | qDebug("InterfaceSetupImp: Added Mapping, but still can't set."); | 104 | qDebug("InterfaceSetupImp: Added Mapping, but still can't set."); |
105 | return; | 105 | return; |
106 | } | 106 | } |
107 | } | 107 | } |
108 | interfaces->setMap("map", newInterfaceName); | 108 | interfaces->setMap("map", newInterfaceName); |
109 | interfaces->setScript("getprofile.sh"); | 109 | interfaces->setScript("getprofile.sh"); |
110 | } | 110 | } |
111 | else{ | 111 | else{ |
112 | interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP); | 112 | interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP); |
113 | if(!interfaces->setInterface(newInterfaceName)){ | 113 | if(!interfaces->setInterface(newInterfaceName)){ |
114 | qDebug("InterfaceSetupImp: Added interface, but still can't set."); | 114 | qDebug("InterfaceSetupImp: Added interface, but still can't set."); |
115 | return; | 115 | return; |
116 | } | 116 | } |
117 | } | 117 | } |
118 | } | 118 | } |
119 | 119 | ||
120 | // We must have a valid interface to get this far so read some settings. | 120 | // We must have a valid interface to get this far so read some settings. |
121 | 121 | ||
122 | // DHCP | 122 | // DHCP |
123 | bool error = false; | 123 | bool error = false; |
124 | if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) | 124 | if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) |
125 | dhcpCheckBox->setChecked(true); | 125 | dhcpCheckBox->setChecked(true); |
126 | else | 126 | else |
127 | dhcpCheckBox->setChecked(false); | 127 | dhcpCheckBox->setChecked(false); |
128 | leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt()); | 128 | leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt()); |
129 | if(error) | 129 | if(error) |
130 | leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60); | 130 | leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60); |
131 | if(error) | 131 | if(error) |
132 | leaseTime->setValue(24); | 132 | leaseTime->setValue(24); |
133 | 133 | ||
134 | // IP Information | 134 | // IP Information |
135 | autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); | 135 | autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); |
136 | QString dns = interfaces->getInterfaceOption("up interfacednsscript add", error); | 136 | QString dns = interfaces->getInterfaceOption("up interfacednsscript -a", error); |
137 | if(dns.contains(" ")){ | 137 | if(dns.contains(" ")){ |
138 | firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); | 138 | firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); |
139 | secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); | 139 | secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); |
140 | } | 140 | } |
141 | ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); | 141 | ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); |
142 | subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); | 142 | subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); |
143 | gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); | 143 | gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); |
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | // interfacesetup.cpp | 147 | // interfacesetup.cpp |
148 | 148 | ||