Rev 5589 | Rev 5686 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5586 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2010-2015. All rights reserved. ;; |
||
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;; ;; |
||
6 | ;; Written by hidnplayr@kolibrios.org ;; |
||
7 | ;; ;; |
||
8 | ;; GNU GENERAL PUBLIC LICENSE ;; |
||
9 | ;; Version 2, June 1991 ;; |
||
10 | ;; ;; |
||
11 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
12 | |||
13 | ipcfg: |
||
14 | |||
15 | mcall 40, EVM_MOUSE + EVM_MOUSE_FILTER + EVM_REDRAW + EVM_BUTTON + EVM_KEY + EVM_STACK |
||
16 | |||
17 | ; Create the 'ip..' string with correct device number |
||
18 | call create_str_ini_int |
||
19 | |||
20 | ; Try to read settings from .ini file |
||
21 | invoke ini.get_str, net_ini, str_ini_int, str_ini_ip_type, ini_buf, 16, sz_0 |
||
22 | test eax, eax |
||
23 | jz @f |
||
24 | ; If settings not found, use default settings from 'ip?' section |
||
25 | mov dword[str_ini_int], 'ip?' |
||
26 | @@: |
||
27 | |||
28 | ; Read ip/subnet/gateway type |
||
5610 | hidnplayr | 29 | mov [option_ip], op_ip_disabled |
5586 | hidnplayr | 30 | invoke ini.get_str, net_ini, str_ini_int, str_ini_ip_type, ini_buf, 16, sz_0 |
5610 | hidnplayr | 31 | test eax, eax |
32 | jnz .ip_type_loaded |
||
5589 | hidnplayr | 33 | mov eax, dword[ini_buf] |
34 | or eax, 0x20202020 |
||
5610 | hidnplayr | 35 | cmp eax, 'auto' |
36 | jne @f |
||
37 | ; cmp byte[ini_buf+4], 0 |
||
38 | ; jne @f |
||
5586 | hidnplayr | 39 | mov [option_ip], op_ip_auto |
5610 | hidnplayr | 40 | jmp .ip_type_loaded |
5586 | hidnplayr | 41 | @@: |
5610 | hidnplayr | 42 | cmp eax, 'dhcp' |
43 | jne @f |
||
44 | ; cmp byte[ini_buf+4], 0 |
||
45 | ; jne @f |
||
46 | mov [option_ip], op_ip_auto |
||
47 | jmp .ip_type_loaded |
||
48 | @@: |
||
49 | cmp eax, 'stat' |
||
50 | jne @f |
||
51 | ; mov eax, dword[ini_buf+3] |
||
52 | ; or eax, 0x202020 |
||
53 | ; cmp eax, 'tic' |
||
54 | ; jne @f |
||
55 | mov [option_ip], op_ip_static |
||
56 | ; jmp .ip_type_loaded |
||
57 | @@: |
||
58 | .ip_type_loaded: |
||
5586 | hidnplayr | 59 | |
60 | ; Read DNS type |
||
5610 | hidnplayr | 61 | mov [option_dns], op_dns_auto |
5586 | hidnplayr | 62 | invoke ini.get_str, net_ini, str_ini_int, str_ini_dns_type, ini_buf, 16, sz_0 |
5610 | hidnplayr | 63 | test eax, eax |
64 | jnz @f |
||
5589 | hidnplayr | 65 | mov eax, dword[ini_buf] |
66 | or eax, 0x20202020 |
||
67 | cmp eax, 'stat' |
||
5610 | hidnplayr | 68 | jne @f |
69 | ; mov eax, dword[ini_buf+3] |
||
70 | ; or eax, 0x202020 |
||
71 | ; cmp eax, 'tic' |
||
72 | ; jne @f |
||
73 | mov [option_dns], op_dns_static |
||
5586 | hidnplayr | 74 | @@: |
75 | |||
76 | ; Read all IP addresses |
||
77 | mov [str_edit_ip], 0 |
||
78 | mov [str_edit_subnet], 0 |
||
79 | mov [str_edit_gateway], 0 |
||
80 | mov [str_edit_dns], 0 |
||
81 | |||
82 | invoke ini.get_str, net_ini, str_ini_int, str_ini_ip, str_edit_ip, 16, sz_0 |
||
83 | invoke ini.get_str, net_ini, str_ini_int, str_ini_subnet, str_edit_subnet, 16, sz_0 |
||
84 | invoke ini.get_str, net_ini, str_ini_int, str_ini_gateway, str_edit_gateway, 16, sz_0 |
||
85 | invoke ini.get_str, net_ini, str_ini_int, str_ini_dns, str_edit_dns, 16, sz_0 |
||
86 | |||
87 | invoke edit_set_text, edit_ip, str_edit_ip |
||
88 | invoke edit_set_text, edit_subnet, str_edit_subnet |
||
89 | invoke edit_set_text, edit_gateway, str_edit_gateway |
||
90 | invoke edit_set_text, edit_dns, str_edit_dns |
||
91 | |||
92 | .parse_settings: |
||
93 | call toggle_editboxes |
||
94 | |||
95 | .draw: |
||
96 | ; get system colors |
||
97 | mcall 48, 3, sc, 40 |
||
98 | |||
99 | mcall 12, 1 |
||
100 | |||
101 | mov edx, [sc.work] |
||
102 | or edx, 0x34000000 |
||
103 | xor esi, esi |
||
104 | mov edi, str_title |
||
105 | mcall 0, 50 shl 16 + 200, 30 shl 16 + 200 |
||
106 | |||
107 | mov ecx, 0x80000000 |
||
108 | or ecx, [sc.work_text] |
||
5610 | hidnplayr | 109 | ; mov ebx, 47 shl 16 + 25 |
5586 | hidnplayr | 110 | ; mov edx, str_mode |
111 | ; mcall |
||
5610 | hidnplayr | 112 | mov ebx, 59 shl 16 + 50 |
5586 | hidnplayr | 113 | mov edx, sz_ip |
114 | mcall 4 |
||
5610 | hidnplayr | 115 | mov ebx, 5 shl 16 + 70 |
5586 | hidnplayr | 116 | mov edx, sz_subnet |
117 | mcall |
||
5610 | hidnplayr | 118 | mov ebx, 29 shl 16 + 90 |
5586 | hidnplayr | 119 | mov edx, sz_gateway |
120 | mcall |
||
5610 | hidnplayr | 121 | ; mov ebx, 47 shl 16 + 95 |
5586 | hidnplayr | 122 | ; mov edx, str_mode |
123 | ; mcall |
||
5610 | hidnplayr | 124 | mov ebx, 53 shl 16 + 135 |
5586 | hidnplayr | 125 | mov edx, sz_dns |
126 | mcall |
||
127 | |||
128 | invoke edit_box_draw, edit_ip |
||
129 | invoke edit_box_draw, edit_subnet |
||
130 | invoke edit_box_draw, edit_gateway |
||
131 | invoke edit_box_draw, edit_dns |
||
132 | |||
133 | invoke option_box_draw, Option_boxs1 |
||
134 | invoke option_box_draw, Option_boxs2 |
||
135 | |||
5610 | hidnplayr | 136 | mcall 8, 80 shl 16 + 100, 155 shl 16 + 16, 2, [sc.work_button] |
5586 | hidnplayr | 137 | |
138 | mov ecx, 0x80000000 |
||
139 | or ecx, [sc.work_button_text] |
||
5610 | hidnplayr | 140 | mov ebx, 112 shl 16 + 160 |
5586 | hidnplayr | 141 | mov edx, sz_apply |
142 | mcall 4 |
||
143 | |||
144 | mcall 12, 2 |
||
145 | |||
146 | .loop: |
||
147 | mcall 10 |
||
148 | dec eax |
||
149 | jz .draw |
||
150 | dec eax |
||
151 | jz .key |
||
152 | dec eax |
||
153 | jz .btn |
||
154 | |||
155 | cmp [edit_ip.color], 0xcacaca |
||
156 | je @f |
||
157 | invoke edit_box_mouse, edit_ip |
||
158 | invoke edit_box_mouse, edit_subnet |
||
159 | invoke edit_box_mouse, edit_gateway |
||
160 | @@: |
||
161 | |||
162 | cmp [edit_dns.color], 0xcacaca |
||
163 | je @f |
||
164 | invoke edit_box_mouse, edit_dns |
||
165 | @@: |
||
166 | |||
167 | push [option_ip] [option_dns] |
||
168 | invoke option_box_mouse, Option_boxs1 |
||
169 | invoke option_box_mouse, Option_boxs2 |
||
170 | pop ebx eax |
||
171 | cmp eax, [option_ip] |
||
172 | jne @f |
||
173 | cmp ebx, [option_dns] |
||
174 | je .loop |
||
175 | @@: |
||
176 | call toggle_editboxes |
||
177 | jmp .draw |
||
178 | |||
179 | .btn: |
||
180 | mcall 17 |
||
181 | |||
182 | test ah , ah |
||
183 | jz .loop |
||
184 | |||
185 | cmp ah, 2 ; apply |
||
186 | jne .exit |
||
187 | |||
188 | ; Apply settings! |
||
189 | .apply: |
||
190 | xor edi, edi |
||
191 | |||
192 | cmp [edit_ip.color], 0xcacaca |
||
193 | je .skip_ip |
||
194 | mov [edit_ip.color], 0xffffff |
||
195 | mov esi, str_edit_ip |
||
196 | call validate_ip |
||
197 | test eax, eax |
||
198 | jz @f |
||
199 | mov [edit_ip.color], 0xff4444 |
||
200 | inc edi |
||
201 | @@: |
||
202 | |||
203 | mov [edit_subnet.color], 0xffffff |
||
204 | mov esi, str_edit_subnet |
||
205 | call validate_ip |
||
206 | test eax, eax |
||
207 | jz @f |
||
208 | mov [edit_subnet.color], 0xff4444 |
||
209 | inc edi |
||
210 | @@: |
||
211 | |||
212 | mov [edit_gateway.color], 0xffffff |
||
213 | mov esi, str_edit_gateway |
||
214 | call validate_ip |
||
215 | test eax, eax |
||
216 | jz @f |
||
217 | mov [edit_gateway.color], 0xff4444 |
||
218 | inc edi |
||
219 | @@: |
||
220 | .skip_ip: |
||
221 | |||
222 | cmp [edit_dns.color], 0xcacaca |
||
223 | je .skip_dns |
||
224 | mov [edit_dns.color], 0xffffff |
||
225 | mov esi, str_edit_dns |
||
226 | call validate_ip |
||
227 | test eax, eax |
||
228 | jz @f |
||
229 | mov [edit_dns.color], 0xff4444 |
||
230 | inc edi |
||
231 | @@: |
||
232 | .skip_dns: |
||
233 | |||
234 | test edi, edi |
||
235 | jnz .draw |
||
236 | |||
237 | ; Settings look valid, save them to the ini file |
||
238 | ; Re-create 'ip..' string, we dont want to save to 'ip?' section. |
||
239 | call create_str_ini_int |
||
240 | |||
241 | cmp [option_ip], op_ip_auto |
||
5610 | hidnplayr | 242 | jne @f |
243 | invoke ini.set_str, net_ini, str_ini_int, str_ini_ip_type, sz_auto, 4 |
||
244 | jmp .ip_type_ok |
||
5586 | hidnplayr | 245 | @@: |
5610 | hidnplayr | 246 | cmp [option_ip], op_ip_static |
247 | jne @f |
||
248 | invoke ini.set_str, net_ini, str_ini_int, str_ini_ip_type, sz_static, 6 |
||
249 | jmp .ip_type_ok |
||
250 | @@: |
||
251 | ; cmp [option_ip], op_ip_disabled |
||
252 | ; jne @f |
||
253 | invoke ini.set_str, net_ini, str_ini_int, str_ini_ip_type, sz_disabled, 8 |
||
254 | ; @@: |
||
255 | .ip_type_ok: |
||
5586 | hidnplayr | 256 | |
257 | cmp [option_dns], op_dns_auto |
||
5610 | hidnplayr | 258 | invoke ini.set_str, net_ini, str_ini_int, str_ini_dns_type, sz_auto, 4 |
5586 | hidnplayr | 259 | jmp @f |
260 | .dns_static: |
||
5610 | hidnplayr | 261 | invoke ini.set_str, net_ini, str_ini_int, str_ini_dns_type, sz_static, 6 |
5586 | hidnplayr | 262 | @@: |
263 | |||
264 | invoke ini.set_str, net_ini, str_ini_int, str_ini_ip, str_edit_ip, [edit_ip.size] |
||
265 | invoke ini.set_str, net_ini, str_ini_int, str_ini_subnet, str_edit_subnet, [edit_subnet.size] |
||
266 | invoke ini.set_str, net_ini, str_ini_int, str_ini_gateway, str_edit_gateway, [edit_gateway.size] |
||
267 | invoke ini.set_str, net_ini, str_ini_int, str_ini_dns, str_edit_dns, [edit_dns.size] |
||
268 | |||
269 | .exit: |
||
270 | mcall -1 |
||
271 | |||
272 | .key: |
||
273 | mcall 2 |
||
274 | |||
275 | ; Stupid editbox doesnt allow us to disable edit boxes nor filter input decently, so we do it here. |
||
276 | cmp ah, 13 |
||
277 | je .apply |
||
278 | cmp ah, 8 |
||
279 | je @f |
||
280 | cmp ah, '.' |
||
281 | je @f |
||
282 | cmp ah, '0' |
||
283 | jb .loop |
||
284 | cmp ah, '9' |
||
285 | ja .loop |
||
286 | @@: |
||
287 | cmp [edit_ip.color], 0xffffff |
||
288 | jne @f |
||
289 | invoke edit_box_key, edit_ip |
||
290 | invoke edit_box_key, edit_subnet |
||
291 | invoke edit_box_key, edit_gateway |
||
292 | @@: |
||
293 | |||
294 | cmp [edit_dns.color], 0xffffff |
||
295 | jne @f |
||
296 | invoke edit_box_key, edit_dns |
||
297 | @@: |
||
298 | |||
299 | jmp .loop |
||
300 | |||
301 | toggle_editboxes: |
||
302 | |||
303 | mov [edit_ip.color], 0xffffff |
||
304 | mov [edit_subnet.color], 0xffffff |
||
305 | mov [edit_gateway.color], 0xffffff |
||
306 | cmp [option_ip], op_ip_static |
||
307 | je @f |
||
308 | mov [edit_ip.color], 0xcacaca |
||
309 | mov [edit_subnet.color], 0xcacaca |
||
310 | mov [edit_gateway.color], 0xcacaca |
||
311 | @@: |
||
312 | |||
5610 | hidnplayr | 313 | mov [edit_dns.color], 0xcacaca |
314 | cmp [option_ip], op_ip_disabled |
||
315 | je @f |
||
316 | cmp [option_dns], op_dns_static |
||
317 | jne @f |
||
5586 | hidnplayr | 318 | mov [edit_dns.color], 0xffffff |
319 | @@: |
||
320 | |||
321 | ret |
||
322 | |||
323 | |||
324 | ; in: esi = ptr to ascii ip |
||
325 | ; out: eax = 0 - ok / -1 - error |
||
326 | validate_ip: |
||
327 | xor ecx, ecx ; octet count |
||
328 | .outer_loop: |
||
329 | xor ebx, ebx ; current number |
||
330 | inc ecx |
||
331 | .inner_loop: |
||
332 | lodsb ; load one character from ascii string |
||
333 | test al, al |
||
334 | je .finish |
||
335 | cmp al, '.' |
||
336 | je .outer_loop |
||
337 | ; Convert current digit from ascii to bin, if valid |
||
338 | sub al, '0' |
||
339 | jb .invalid |
||
340 | cmp al, 9 |
||
341 | ja .invalid |
||
342 | ; multiply current number by 10 |
||
343 | add bl, bl |
||
344 | jc .invalid |
||
345 | lea ebx, [ebx + 4 * ebx] |
||
346 | test ebx, 0xffffff00 |
||
347 | jnz .invalid |
||
348 | ; add current digit to current number |
||
349 | add bl, al |
||
350 | jc .invalid |
||
351 | jmp .inner_loop |
||
352 | .finish: |
||
353 | cmp cl, 4 |
||
354 | jne .invalid |
||
355 | xor eax, eax |
||
356 | ret |
||
357 | |||
358 | .invalid: |
||
359 | or eax, -1 |
||
360 | ret |
||
361 | |||
362 | create_str_ini_int: |
||
363 | movzx eax, [device] |
||
364 | mov ebx, 10 |
||
365 | xor edx, edx |
||
366 | push 0 |
||
367 | @@: |
||
368 | div ebx |
||
369 | add dl, '0' |
||
370 | push edx |
||
371 | test eax, eax |
||
372 | jnz @r |
||
373 | @@: |
||
374 | mov edi, str_ini_int+2 |
||
375 | @@: |
||
376 | pop eax |
||
377 | stosb |
||
378 | test eax, eax |
||
379 | jnz @r |
||
380 | |||
381 | ret |
||
382 | |||
383 | |||
384 | ;------------------------- |
||
385 | ; DATA |
||
386 | |||
5610 | hidnplayr | 387 | edit_ip edit_box 100, 80, 45, 0xffffff, 0x6f9480, 0, 0, 0, 15, str_edit_ip, mouse_dd, 0, 0, 1 |
388 | edit_subnet edit_box 100, 80, 65, 0xffffff, 0x6f9480, 0, 0, 0, 15, str_edit_subnet, mouse_dd, 0, 0, 1 |
||
389 | edit_gateway edit_box 100, 80, 85, 0xffffff, 0x6f9480, 0, 0, 0, 15, str_edit_gateway, mouse_dd, 0, 0, 1 |
||
5586 | hidnplayr | 390 | |
5610 | hidnplayr | 391 | edit_dns edit_box 100, 80, 130, 0xffffff, 0x6f9480, 0, 0, 0, 15, str_edit_dns, mouse_dd, 0, 0, 1 |
5586 | hidnplayr | 392 | |
5610 | hidnplayr | 393 | op_ip_disabled option_box option_ip, 15, 5, 6, 12, 0xffffff, 0, 0, sz_disabled, 9 |
394 | op_ip_auto option_box option_ip, 15, 25, 6, 12, 0xffffff, 0, 0, sz_auto, 5 |
||
395 | op_ip_static option_box option_ip, 80, 25, 6, 12, 0xffffff, 0, 0, sz_static, 7 |
||
5586 | hidnplayr | 396 | |
5610 | hidnplayr | 397 | op_dns_auto option_box option_dns, 15, 110, 6, 12, 0xffffff, 0, 0, sz_auto, 5 |
398 | op_dns_static option_box option_dns, 80, 110, 6, 12, 0xffffff, 0, 0, sz_static, 7 |
||
5586 | hidnplayr | 399 | |
400 | option_ip dd op_ip_auto |
||
401 | option_dns dd op_dns_auto |
||
5610 | hidnplayr | 402 | Option_boxs1 dd op_ip_disabled, op_ip_auto, op_ip_static, 0 |
5586 | hidnplayr | 403 | Option_boxs2 dd op_dns_auto, op_dns_static, 0 |
404 | |||
405 | net_ini db '/sys/settings/network.ini', 0 |
||
406 | |||
407 | str_ini_int db 'ip1', 0 |
||
408 | rb 10 |
||
409 | str_ini_ip db 'ip', 0 |
||
410 | str_ini_subnet db 'subnet', 0 |
||
411 | str_ini_gateway db 'gateway', 0 |
||
5610 | hidnplayr | 412 | str_ini_dns db 'dns', 0 |
5586 | hidnplayr | 413 | str_ini_ip_type db 'ip_type', 0 |
414 | str_ini_dns_type db 'dns_type', 0 |
||
415 | |||
5610 | hidnplayr | 416 | str_title db 'IP settings', 0 |
5586 | hidnplayr | 417 | sz_0 db 0 |
418 | sz_ip db 'IP:', 0 |
||
419 | sz_subnet db 'Subnet mask:', 0 |
||
420 | sz_gateway db 'Gateway:', 0 |
||
421 | sz_dns db 'DNS:', 0 |
||
422 | sz_auto db 'Auto', 0 |
||
423 | sz_static db 'Static', 0 |
||
5610 | hidnplayr | 424 | sz_disabled db 'Disabled', 0 |
5586 | hidnplayr | 425 | sz_apply db 'Apply', 0 |
426 | |||
427 | str_edit_ip rb 16 |
||
428 | str_edit_subnet rb 16 |
||
429 | str_edit_gateway rb 16 |
||
430 | str_edit_dns rb 16 |
||
431 | |||
432 | ini_buf rb 16 |
||
433 | |||
434 | mouse_dd dd ? |