Diffstat (limited to 'noncore/settings/networksettings2/ppp/ppp_NNI.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/ppp/ppp_NNI.cpp | 154 |
1 files changed, 84 insertions, 70 deletions
diff --git a/noncore/settings/networksettings2/ppp/ppp_NNI.cpp b/noncore/settings/networksettings2/ppp/ppp_NNI.cpp index ba639de..9e3bb64 100644 --- a/noncore/settings/networksettings2/ppp/ppp_NNI.cpp +++ b/noncore/settings/networksettings2/ppp/ppp_NNI.cpp | |||
@@ -1,221 +1,235 @@ | |||
1 | #include <qfile.h> | 1 | #include <qfile.h> |
2 | #include <qfileinfo.h> | 2 | #include <qfileinfo.h> |
3 | #include "PPPedit.h" | 3 | #include "PPPedit.h" |
4 | #include "ppp_NNI.h" | 4 | #include "ppp_NNI.h" |
5 | #include "ppp_NN.h" | 5 | #include "ppp_NN.h" |
6 | 6 | ||
7 | APPP::APPP( PPPNetNode * PNN ) : ANetNodeInstance( PNN ) { | 7 | APPP::APPP( PPPNetNode * PNN ) : ANetNodeInstance( PNN ) { |
8 | Data.DNS.ServerAssigned = 1; | 8 | Data.DNS.ServerAssigned = 1; |
9 | Data.DNS.DomainName = ""; | 9 | Data.DNS.DomainName = ""; |
10 | 10 | ||
11 | Data.Auth.Mode = 0; | 11 | Data.Auth.Mode = 0; |
12 | Data.Auth.Login.Expect = "ogin:"; | 12 | Data.Auth.Login.Expect = "ogin:"; |
13 | Data.Auth.Password.Expect = "assword:"; | 13 | Data.Auth.Password.Expect = "assword:"; |
14 | Data.Auth.PCEMode = 0; | 14 | Data.Auth.PCEMode = 0; |
15 | Data.Auth.Client = "*"; | 15 | Data.Auth.Client = "*"; |
16 | Data.Auth.Server = "*"; | 16 | Data.Auth.Server = "*"; |
17 | Data.Auth.Secret = ""; | 17 | Data.Auth.Secret = ""; |
18 | 18 | ||
19 | Data.IP.IPAutomatic = 1; | 19 | Data.IP.LocalAddress = "10.0.0.1"; |
20 | Data.IP.IPAddress = ""; | 20 | Data.IP.RemoteAddress = "10.0.0.2"; |
21 | Data.IP.IPSubMask = ""; | 21 | Data.IP.LocalOverrule = 1; |
22 | Data.IP.RemoteOverrule = 1; | ||
23 | |||
22 | Data.IP.GWAutomatic = 1; | 24 | Data.IP.GWAutomatic = 1; |
23 | Data.IP.GWAddress = ""; | 25 | Data.IP.GWAddress = ""; |
24 | Data.IP.GWIsDefault = 1; | 26 | Data.IP.GWIsDefault = 1; |
27 | Data.IP.GWIfNotSet = 1; | ||
28 | |||
29 | Data.Run.PreConnect = ""; | ||
30 | Data.Run.PostConnect = ""; | ||
31 | Data.Run.PreDisconnect = ""; | ||
32 | Data.Run.PostDisconnect = ""; | ||
33 | |||
25 | GUI = 0; | 34 | GUI = 0; |
26 | RT = 0; | 35 | RT = 0; |
27 | 36 | ||
28 | } | 37 | } |
29 | 38 | ||
30 | void APPP::setSpecificAttribute( QString & A, QString & V ) { | 39 | void APPP::setSpecificAttribute( QString & A, QString & V ) { |
31 | if( A.startsWith( "dns" ) ) { | 40 | if( A.startsWith( "dns" ) ) { |
32 | if( A == "dnsserverassigned" ) { | 41 | if( A == "dnsserverassigned" ) { |
33 | Data.DNS.ServerAssigned = (V == "yes"); | 42 | Data.DNS.ServerAssigned = (V == "yes"); |
34 | } else if( A == "dnsdomainname" ) { | 43 | } else if( A == "dnsdomainname" ) { |
35 | Data.DNS.DomainName = V; | 44 | Data.DNS.DomainName = V; |
36 | } else if( A == "dnsserver" ) { | 45 | } else if( A == "dnsserver" ) { |
37 | Data.DNS.Servers.resize( Data.DNS.Servers.size()+1 ); | 46 | Data.DNS.Servers.resize( Data.DNS.Servers.size()+1 ); |
38 | Data.DNS.Servers[Data.DNS.Servers.size()-1] = | 47 | Data.DNS.Servers[Data.DNS.Servers.size()-1] = |
39 | new QString( V ); | 48 | new QString( V ); |
40 | } | 49 | } |
41 | } else if( A.startsWith( "auth" ) ) { | 50 | } else if( A.startsWith( "auth" ) ) { |
42 | if( A == "authmode" ) { | 51 | if( A == "authmode" ) { |
43 | Data.Auth.Mode = V.toShort(); | 52 | Data.Auth.Mode = V.toShort(); |
44 | } else if( A == "authloginexpect" ) { | 53 | } else if( A == "authloginexpect" ) { |
45 | Data.Auth.Login.Expect = V; | 54 | Data.Auth.Login.Expect = V; |
46 | } else if( A == "authloginsend" ) { | 55 | } else if( A == "authloginsend" ) { |
47 | Data.Auth.Login.Send = V; | 56 | Data.Auth.Login.Send = V; |
48 | } else if( A == "authpasswordexpect" ) { | 57 | } else if( A == "authpasswordexpect" ) { |
49 | Data.Auth.Password.Expect = V; | 58 | Data.Auth.Password.Expect = V; |
50 | } else if( A == "authpasswordsend" ) { | 59 | } else if( A == "authpasswordsend" ) { |
51 | Data.Auth.Password.Send = V; | 60 | Data.Auth.Password.Send = V; |
52 | } else if( A == "authpcemode" ) { | 61 | } else if( A == "authpcemode" ) { |
53 | Data.Auth.PCEMode = V.toShort(); | 62 | Data.Auth.PCEMode = V.toShort(); |
54 | } else if( A == "authclient" ) { | 63 | } else if( A == "authclient" ) { |
55 | Data.Auth.Client = V; | 64 | Data.Auth.Client = V; |
56 | } else if( A == "authserver" ) { | 65 | } else if( A == "authserver" ) { |
57 | Data.Auth.Server = V; | 66 | Data.Auth.Server = V; |
58 | } else if( A == "authsecret" ) { | 67 | } else if( A == "authsecret" ) { |
59 | Data.Auth.Secret = V; | 68 | Data.Auth.Secret = V; |
60 | } | 69 | } |
61 | } else if( A.startsWith( "ip" ) ) { | 70 | } else if( A.startsWith( "ip" ) ) { |
62 | if( A == "ipautomatic" ) { | 71 | if( A == "iplocaloverrule" ) { |
63 | Data.IP.IPAutomatic = (V == "yes"); | 72 | Data.IP.LocalOverrule = (V == "yes"); |
64 | } else if( A == "gwautomatic" ) { | 73 | } else if( A == "ipremoteoverrule" ) { |
74 | Data.IP.RemoteOverrule = (V == "yes"); | ||
75 | } else if( A == "ipgwautomatic" ) { | ||
65 | Data.IP.GWAutomatic = (V == "yes"); | 76 | Data.IP.GWAutomatic = (V == "yes"); |
66 | } else if( A == "gwisdefault" ) { | 77 | } else if( A == "ipgwisdefault" ) { |
67 | Data.IP.GWIsDefault = (V == "yes"); | 78 | Data.IP.GWIsDefault = (V == "yes"); |
68 | } else if( A == "ipaddress" ) { | 79 | } else if( A == "ipgwifnotset" ) { |
69 | Data.IP.IPAddress = V; | 80 | Data.IP.GWIfNotSet = (V == "yes"); |
70 | } else if( A == "ipsubmask" ) { | 81 | } else if( A == "iplocaladdress" ) { |
71 | Data.IP.IPSubMask = V; | 82 | Data.IP.LocalAddress = V; |
72 | } else if( A == "gwaddress" ) { | 83 | } else if( A == "ipremoteaddress" ) { |
84 | Data.IP.RemoteAddress = V; | ||
85 | } else if( A == "ipgwaddress" ) { | ||
73 | Data.IP.GWAddress = V; | 86 | Data.IP.GWAddress = V; |
74 | } | 87 | } |
88 | } else if( A.startsWith( "run" ) ) { | ||
89 | if( A == "runpreconnect" ) { | ||
90 | Data.Run.PreConnect = V; | ||
91 | } else if( A == "runpostconnect" ) { | ||
92 | Data.Run.PostConnect = V; | ||
93 | } else if( A == "runpredisconnect" ) { | ||
94 | Data.Run.PreDisconnect = V; | ||
95 | } else if( A == "runpostdisconnect" ) { | ||
96 | Data.Run.PostDisconnect = V; | ||
97 | } | ||
75 | } | 98 | } |
76 | } | 99 | } |
77 | 100 | ||
78 | void APPP::saveSpecificAttribute( QTextStream & TS ) { | 101 | void APPP::saveSpecificAttribute( QTextStream & TS ) { |
79 | TS << "dnsserverassigned=" << | 102 | TS << "dnsserverassigned=" << |
80 | ( ( Data.DNS.ServerAssigned ) ? "yes" : "no" ) << endl; | 103 | ( ( Data.DNS.ServerAssigned ) ? "yes" : "no" ) << endl; |
81 | TS << "dnsdomainname=" << Data.DNS.DomainName << endl; | 104 | TS << "dnsdomainname=" << Data.DNS.DomainName << endl; |
82 | for( unsigned int i = 0; i < Data.DNS.Servers.size(); i ++ ) { | 105 | for( unsigned int i = 0; i < Data.DNS.Servers.size(); i ++ ) { |
83 | TS << "dnsserver=" << *(Data.DNS.Servers[i]) << endl; | 106 | TS << "dnsserver=" << *(Data.DNS.Servers[i]) << endl; |
84 | } | 107 | } |
85 | TS << "authmode=" << Data.Auth.Mode << endl; | 108 | TS << "authmode=" << Data.Auth.Mode << endl; |
86 | TS << "authloginexpect=" << quote( Data.Auth.Login.Expect ) << endl; | 109 | TS << "authloginexpect=" << quote( Data.Auth.Login.Expect ) << endl; |
87 | TS << "authloginsend=" << quote( Data.Auth.Login.Send ) << endl; | 110 | TS << "authloginsend=" << quote( Data.Auth.Login.Send ) << endl; |
88 | TS << "authpasswordexpect=" << quote( Data.Auth.Password.Expect ) << endl; | 111 | TS << "authpasswordexpect=" << quote( Data.Auth.Password.Expect ) << endl; |
89 | TS << "authpasswordsend=" << quote( Data.Auth.Password.Send ) << endl; | 112 | TS << "authpasswordsend=" << quote( Data.Auth.Password.Send ) << endl; |
90 | TS << "authpcemode=" << Data.Auth.PCEMode << endl; | 113 | TS << "authpcemode=" << Data.Auth.PCEMode << endl; |
91 | TS << "authclient=" << Data.Auth.Client << endl; | 114 | TS << "authclient=" << Data.Auth.Client << endl; |
92 | TS << "authserver=" << Data.Auth.Server << endl; | 115 | TS << "authserver=" << Data.Auth.Server << endl; |
93 | TS << "authsecret=" << quote( Data.Auth.Secret ) << endl; | 116 | TS << "authsecret=" << quote( Data.Auth.Secret ) << endl; |
94 | TS << "ipautomatic=" << ( ( Data.IP.IPAutomatic ) ? "yes" : "no" ) << endl; | 117 | TS << "ipgwautomatic=" << ( ( Data.IP.GWAutomatic ) ? "yes" : "no" ) << endl; |
95 | TS << "gwautomatic=" << ( ( Data.IP.GWAutomatic ) ? "yes" : "no" ) << endl; | 118 | TS << "ipgwisdefault=" << ( ( Data.IP.GWIsDefault ) ? "yes" : "no" ) << endl; |
96 | TS << "gwisdefault=" << ( ( Data.IP.GWIsDefault ) ? "yes" : "no" ) << endl; | 119 | TS << "ipgwifnotset=" << ( ( Data.IP.GWIfNotSet ) ? "yes" : "no" ) << endl; |
97 | TS << "ipaddress=" << Data.IP.IPAddress << endl; | 120 | TS << "iplocaloverrule=" << ( ( Data.IP.LocalOverrule ) ? "yes" : "no" ) << endl; |
98 | TS << "ipsubmask=" << Data.IP.IPSubMask << endl; | 121 | TS << "ipremoteoverrule=" << ( ( Data.IP.RemoteOverrule ) ? "yes" : "no" ) << endl; |
99 | TS << "gwaddress=" << Data.IP.GWAddress << endl; | 122 | TS << "iplocaladdress=" << Data.IP.LocalAddress << endl; |
123 | TS << "ipremoteaddress=" << Data.IP.RemoteAddress << endl; | ||
124 | TS << "ipgwaddress=" << Data.IP.GWAddress << endl; | ||
125 | |||
126 | TS << "runpreconnect=" << Data.Run.PreConnect << endl; | ||
127 | TS << "runpostconnect=" << Data.Run.PostConnect << endl; | ||
128 | TS << "runpredisconnect=" << Data.Run.PreDisconnect << endl; | ||
129 | TS << "runpostdisconnect=" << Data.Run.PostDisconnect << endl; | ||
130 | |||
100 | } | 131 | } |
101 | 132 | ||
102 | QWidget * APPP::edit( QWidget * parent ) { | 133 | QWidget * APPP::edit( QWidget * parent ) { |
103 | GUI = new PPPEdit( parent ); | 134 | GUI = new PPPEdit( parent ); |
104 | GUI->showData( Data ); | 135 | GUI->showData( Data ); |
105 | return GUI; | 136 | return GUI; |
106 | } | 137 | } |
107 | 138 | ||
108 | QString APPP::acceptable( void ) { | 139 | QString APPP::acceptable( void ) { |
109 | return ( GUI ) ? GUI->acceptable( ) : QString(); | 140 | return ( GUI ) ? GUI->acceptable( ) : QString(); |
110 | } | 141 | } |
111 | 142 | ||
112 | void APPP::commit( void ) { | 143 | void APPP::commit( void ) { |
113 | if( GUI && GUI->commit( Data ) ) { | 144 | if( GUI && GUI->commit( Data ) ) { |
114 | setModified( 1 ); | 145 | setModified( 1 ); |
115 | } | 146 | } |
116 | } | 147 | } |
117 | 148 | ||
118 | QFile * APPP::openFile( const QString & ID ) { | 149 | bool APPP::openFile( SystemFile & SF ) { |
119 | QFile * F = 0; | 150 | if( SF.name() == "peers" ) { |
120 | QString S; | 151 | SF.setPath( removeSpaces( |
121 | 152 | QString( "/tmp/ppp/peers/" ) + connection()->name() ) ); | |
122 | if( ID == "peers" ) { | 153 | return 1; |
123 | S = removeSpaces( QString("/tmp/") + connection()->name() ); | 154 | } else if ( SF.name() == "chatscripts" ) { |
124 | 155 | SF.setPath( removeSpaces( | |
125 | F = new QFile( S ); | 156 | QString( "/tmp/chatscripts/" ) + connection()->name() ) ); |
126 | 157 | return 1; | |
127 | if( ! F->open( IO_WriteOnly ) ) { | ||
128 | Log(("Cannot open file %s\n", S.latin1() )); | ||
129 | return 0; | ||
130 | } | ||
131 | } else if ( ID == "chatscripts" ) { | ||
132 | S = removeSpaces( QString("/tmp/") + connection()->name() + ".chat" ); | ||
133 | F = new QFile( S ); | ||
134 | |||
135 | if( ! F->open( IO_WriteOnly ) ) { | ||
136 | Log(("Cannot open file %s\n", S.latin1() )); | ||
137 | return 0; | ||
138 | } | ||
139 | } | 158 | } |
140 | if( F ) { | 159 | return 0; |
141 | Log(("Generate proper file %s = %s\n", | ||
142 | ID.latin1(), F->name().latin1())); | ||
143 | } | ||
144 | return F; | ||
145 | } | 160 | } |
146 | 161 | ||
147 | short APPP::generateFile( const QString & ID, | 162 | short APPP::generateFile( SystemFile & SF, long DevNr ) { |
148 | const QString & Path, | ||
149 | QTextStream & TS, | ||
150 | long DevNr ) { | ||
151 | short rvl, rvd; | 163 | short rvl, rvd; |
152 | 164 | ||
153 | rvl = 1; | 165 | rvl = 1; |
154 | rvd = 1; | 166 | rvd = 1; |
155 | 167 | ||
156 | if( ID == "pap-secrets" ) { | 168 | if( SF.name() == "pap-secrets" ) { |
157 | Log(("Generate PPP for %s\n", ID.latin1() )); | 169 | Log(("Generate PPP for %s\n", SF.name().latin1() )); |
170 | |||
158 | if( Data.Auth.Mode == 1 && Data.Auth.PCEMode == 0 ) { | 171 | if( Data.Auth.Mode == 1 && Data.Auth.PCEMode == 0 ) { |
159 | TS << "# secrets for " | 172 | SF << "# secrets for " |
160 | << connection()->name().latin1() | 173 | << connection()->name().latin1() |
161 | << endl; | 174 | << endl; |
162 | TS << Data.Auth.Client | 175 | SF << Data.Auth.Client |
163 | << " " | 176 | << " " |
164 | << Data.Auth.Server | 177 | << Data.Auth.Server |
165 | << " " | 178 | << " " |
166 | << Data.Auth.Secret | 179 | << Data.Auth.Secret |
167 | << endl; | 180 | << endl; |
168 | rvl = 0; | 181 | rvl = 0; |
169 | rvd = connection()->getToplevel()->generateFileEmbedded( | 182 | rvd = connection()->getToplevel()->generateFileEmbedded( |
170 | ID, Path, TS, DevNr ); | 183 | SF, DevNr ); |
171 | } | 184 | } |
172 | } else if( ID == "chap-secrets" ) { | 185 | } else if( SF.name() == "chap-secrets" ) { |
173 | Log(("Generate PPP for %s\n", ID.latin1() )); | 186 | Log(("Generate PPP for %s\n", SF.name().latin1() )); |
174 | if( Data.Auth.Mode == 1 && Data.Auth.PCEMode != 0 ) { | 187 | if( Data.Auth.Mode == 1 && Data.Auth.PCEMode != 0 ) { |
175 | // used for both EAP and Chap | 188 | // used for both EAP and Chap |
176 | TS << "# secrets for " | 189 | SF << "# secrets for " |
177 | << connection()->name().latin1() | 190 | << connection()->name().latin1() |
178 | << endl; | 191 | << endl; |
179 | TS << Data.Auth.Client | 192 | SF << Data.Auth.Client |
180 | << " " | 193 | << " " |
181 | << Data.Auth.Server | 194 | << Data.Auth.Server |
182 | << " " | 195 | << " " |
183 | << Data.Auth.Secret | 196 | << Data.Auth.Secret |
184 | << endl; | 197 | << endl; |
185 | 198 | ||
186 | rvl = 0; | 199 | rvl = 0; |
187 | rvd = connection()->getToplevel()->generateFileEmbedded( | 200 | rvd = connection()->getToplevel()->generateFileEmbedded( |
188 | ID, Path, TS, DevNr ); | 201 | SF, DevNr ); |
189 | } | 202 | } |
190 | } else if ( ID == "peers" ) { | 203 | } else if ( SF.name() == "peers" ) { |
191 | QFileInfo FI(Path); | 204 | |
192 | Log(("Generate PPP for %s\n", ID.latin1() )); | 205 | QFileInfo FI(SF.path()); |
206 | Log(("Generate PPP for %s\n", SF.name().latin1() )); | ||
193 | 207 | ||
194 | TS << "connect \"/usr/sbin/chat -v -f /etc/ppp/" | 208 | SF << "connect \"/usr/sbin/chat -v -f /etc/chatscripts/" |
195 | << FI.baseName() | 209 | << FI.baseName() |
196 | << ".chat\"" | 210 | << "\"" |
197 | << endl; | 211 | << endl; |
198 | 212 | ||
199 | if( Data.IP.GWIsDefault ) { | 213 | if( Data.IP.GWIsDefault ) { |
200 | TS << "defaultroute" | 214 | SF << "defaultroute" |
201 | << endl; | 215 | << endl; |
202 | } | 216 | } |
203 | 217 | ||
204 | TS << "linkname " | 218 | SF << "linkname " |
205 | << removeSpaces( ID.latin1() ) | 219 | << removeSpaces( SF.name().latin1() ) |
206 | << endl; | 220 | << endl; |
207 | 221 | ||
208 | // insert other data here | 222 | // insert other data here |
209 | rvl = 0; | 223 | rvl = 0; |
210 | rvd = connection()->getToplevel()->generateFileEmbedded( | 224 | rvd = connection()->getToplevel()->generateFileEmbedded( |
211 | ID, Path, TS, DevNr ); | 225 | SF, DevNr ); |
212 | } else if ( ID == "chatscripts" ) { | 226 | } else if ( SF.name() == "chatscripts" ) { |
213 | Log(("Generate PPP for %s\n", ID.latin1() )); | 227 | Log(("Generate PPP for %s\n", SF.name().latin1() )); |
214 | rvl = 0; | 228 | rvl = 0; |
215 | rvd = connection()->getToplevel()->generateFileEmbedded( | 229 | rvd = connection()->getToplevel()->generateFileEmbedded( |
216 | ID, Path, TS, DevNr ); | 230 | SF, DevNr ); |
217 | } | 231 | } |
218 | 232 | ||
219 | return (rvd == 2 || rvl == 2 ) ? 2 : | 233 | return (rvd == 2 || rvl == 2 ) ? 2 : |
220 | (rvd == 0 || rvl == 0 ) ? 0 : 1; | 234 | (rvd == 0 || rvl == 0 ) ? 0 : 1; |
221 | } | 235 | } |