Subversion Repositories Kolibri OS

Rev

Rev 6323 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;; Copyright (C) KolibriOS team 2010-2024. 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
  29.         mov     [option_ip], op_ip_disabled
  30.         invoke  ini.get_str, net_ini, str_ini_int, str_ini_ip_type, ini_buf, 16, sz_0
  31.         test    eax, eax
  32.         jnz     .ip_type_loaded
  33.         mov     eax, dword[ini_buf]
  34.         or      eax, 0x20202020
  35.         cmp     eax, 'auto'
  36.         jne     @f
  37. ;        cmp     byte[ini_buf+4], 0
  38. ;        jne     @f
  39.         mov     [option_ip], op_ip_auto
  40.         jmp     .ip_type_loaded
  41.   @@:
  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:
  59.  
  60. ; Read DNS type
  61.         mov     [option_dns], op_dns_auto
  62.         invoke  ini.get_str, net_ini, str_ini_int, str_ini_dns_type, ini_buf, 16, sz_0
  63.         test    eax, eax
  64.         jnz     @f
  65.         mov     eax, dword[ini_buf]
  66.         or      eax, 0x20202020
  67.         cmp     eax, 'stat'
  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
  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]
  109. ;        mov     ebx, 47 shl 16 + 25
  110. ;        mov     edx, str_mode
  111. ;        mcall
  112.         mov     ebx, 59 shl 16 + 50
  113.         mov     edx, sz_ip
  114.         mcall   4
  115.         mov     ebx, 5 shl 16 + 70
  116.         mov     edx, sz_subnet
  117.         mcall
  118.         mov     ebx, 29 shl 16 + 90
  119.         mov     edx, sz_gateway
  120.         mcall
  121. ;        mov     ebx, 47 shl 16 + 95
  122. ;        mov     edx, str_mode
  123. ;        mcall
  124.         mov     ebx, 53 shl 16 + 135
  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.  
  136.         mcall   8, 80 shl 16 + 100, 155 shl 16 + 16, 2, [sc.work_button]
  137.  
  138.         mov     ecx, 0x80000000
  139.         or      ecx, [sc.work_button_text]
  140.         mov     ebx, 112 shl 16 + 160
  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.         invoke  edit_box_mouse, edit_ip
  156.         invoke  edit_box_mouse, edit_subnet
  157.         invoke  edit_box_mouse, edit_gateway
  158.         invoke  edit_box_mouse, edit_dns
  159.  
  160.         push    [option_ip] [option_dns]
  161.         invoke  option_box_mouse, Option_boxs1
  162.         invoke  option_box_mouse, Option_boxs2
  163.         pop     ebx eax
  164.         cmp     eax, [option_ip]
  165.         jne     @f
  166.         cmp     ebx, [option_dns]
  167.         je      .loop
  168.   @@:
  169.         call    toggle_editboxes
  170.         jmp     .draw
  171.  
  172.   .btn:
  173.         mcall   17
  174.  
  175.         test    ah , ah
  176.         jz      .loop
  177.  
  178.         cmp     ah, 2   ; apply
  179.         jne     .exit
  180.  
  181. ; Apply settings!
  182.   .apply:
  183.         xor     edi, edi
  184.  
  185.         cmp     [option_ip], op_ip_static
  186.         jne     .skip_ip
  187.         mov     [edit_ip.color], 0xffffff
  188.         mov     esi, str_edit_ip
  189.         call    validate_ip
  190.         test    eax, eax
  191.         jz      @f
  192.         mov     [edit_ip.color], 0xff4444
  193.         inc     edi
  194.   @@:
  195.  
  196.         mov     [edit_subnet.color], 0xffffff
  197.         mov     esi, str_edit_subnet
  198.         call    validate_ip
  199.         test    eax, eax
  200.         jz      @f
  201.         mov     [edit_subnet.color], 0xff4444
  202.         inc     edi
  203.   @@:
  204.  
  205.         mov     [edit_gateway.color], 0xffffff
  206.         mov     esi, str_edit_gateway
  207.         call    validate_ip
  208.         test    eax, eax
  209.         jz      @f
  210.         mov     [edit_gateway.color], 0xff4444
  211.         inc     edi
  212.   @@:
  213.   .skip_ip:
  214.  
  215.         cmp     [option_dns], op_dns_static
  216.         jne     .skip_dns
  217.         mov     [edit_dns.color], 0xffffff
  218.         mov     esi, str_edit_dns
  219.         call    validate_ip
  220.         test    eax, eax
  221.         jz      @f
  222.         mov     [edit_dns.color], 0xff4444
  223.         inc     edi
  224.   @@:
  225.   .skip_dns:
  226.  
  227.         test    edi, edi
  228.         jnz     .draw
  229.  
  230. ; Settings look valid, save them to the ini file
  231. ; Re-create 'ip..' string, we dont want to save to 'ip?' section.
  232.         call    create_str_ini_int
  233.  
  234.         cmp     [option_ip], op_ip_auto
  235.         jne     @f
  236.         invoke  ini.set_str, net_ini, str_ini_int, str_ini_ip_type, sz_auto, 4
  237.         jmp     .ip_type_ok
  238.   @@:
  239.         cmp     [option_ip], op_ip_static
  240.         jne     @f
  241.         invoke  ini.set_str, net_ini, str_ini_int, str_ini_ip_type, sz_static, 6
  242.         jmp     .ip_type_ok
  243.   @@:
  244. ;        cmp     [option_ip], op_ip_disabled
  245. ;        jne     @f
  246.         invoke  ini.set_str, net_ini, str_ini_int, str_ini_ip_type, sz_disabled, 8
  247. ;  @@:
  248.   .ip_type_ok:
  249.  
  250.         cmp     [option_dns], op_dns_auto
  251.         jne     .dns_static
  252.         invoke  ini.set_str, net_ini, str_ini_int, str_ini_dns_type, sz_auto, 4
  253.         jmp     @f
  254.   .dns_static:
  255.         invoke  ini.set_str, net_ini, str_ini_int, str_ini_dns_type, sz_static, 6
  256.   @@:
  257.  
  258.         invoke  ini.set_str, net_ini, str_ini_int, str_ini_ip, str_edit_ip, [edit_ip.size]
  259.         invoke  ini.set_str, net_ini, str_ini_int, str_ini_subnet, str_edit_subnet, [edit_subnet.size]
  260.         invoke  ini.set_str, net_ini, str_ini_int, str_ini_gateway, str_edit_gateway, [edit_gateway.size]
  261.         invoke  ini.set_str, net_ini, str_ini_int, str_ini_dns, str_edit_dns, [edit_dns.size]
  262.  
  263.   .exit:
  264.         mcall   -1
  265.  
  266.   .key:
  267.         mcall   2
  268.  
  269. ; Editbox doesnt allow us to filter input decently, so we do it here.
  270.         cmp     ah, 13
  271.         je      .apply
  272.         cmp     ah, 8
  273.         je      @f
  274.         cmp     ah, 0xb0        ; left arrow
  275.         je      @f
  276.         cmp     ah, 0xb3        ; right arrow
  277.         je      @f
  278.         cmp     ah, '.'
  279.         je      @f
  280.         cmp     ah, '0'
  281.         jb      .loop
  282.         cmp     ah, '9'
  283.         ja      .loop
  284.   @@:
  285.         invoke  edit_box_key, edit_ip
  286.         invoke  edit_box_key, edit_subnet
  287.         invoke  edit_box_key, edit_gateway
  288.         invoke  edit_box_key, edit_dns
  289.  
  290.         jmp     .loop
  291.  
  292. toggle_editboxes:
  293.  
  294.         and     [edit_ip.flags], not ed_disabled
  295.         and     [edit_subnet.flags], not ed_disabled
  296.         and     [edit_gateway.flags], not ed_disabled
  297.         cmp     [option_ip], op_ip_static
  298.         je      @f
  299.         or      [edit_ip.flags], ed_disabled
  300.         or      [edit_subnet.flags], ed_disabled
  301.         or      [edit_gateway.flags], ed_disabled
  302.   @@:
  303.  
  304.         or      [edit_dns.flags], ed_disabled
  305.         cmp     [option_ip], op_ip_disabled
  306.         je      @f
  307.         cmp     [option_dns], op_dns_static
  308.         jne     @f
  309.         and     [edit_dns.flags], not ed_disabled
  310.   @@:
  311.  
  312.         ret
  313.  
  314.  
  315. ; in:   esi = ptr to ascii ip
  316. ; out:  eax = 0 - ok / -1 - error
  317. validate_ip:
  318.         xor     ecx, ecx        ; octet count
  319.   .outer_loop:
  320.         xor     ebx, ebx        ; current number
  321.         inc     ecx
  322.   .inner_loop:
  323.         lodsb                   ; load one character from ascii string
  324.         test    al, al
  325.         je      .finish
  326.         cmp     al, '.'
  327.         je      .outer_loop
  328.         ; Convert current digit from ascii to bin, if valid
  329.         sub     al, '0'
  330.         jb      .invalid
  331.         cmp     al, 9
  332.         ja      .invalid
  333.         ; multiply current number by 10
  334.         add     bl, bl
  335.         jc      .invalid
  336.         lea     ebx, [ebx + 4 * ebx]
  337.         test    ebx, 0xffffff00
  338.         jnz     .invalid
  339.         ; add current digit to current number
  340.         add     bl, al
  341.         jc      .invalid
  342.         jmp     .inner_loop
  343.   .finish:
  344.         cmp     cl, 4
  345.         jne     .invalid
  346.         xor     eax, eax
  347.         ret
  348.  
  349.   .invalid:
  350.         or      eax, -1
  351.         ret
  352.  
  353. create_str_ini_int:
  354.         movzx   eax, [device]
  355.         mov     ebx, 10
  356.         xor     edx, edx
  357.         push    0
  358.   @@:
  359.         div     ebx
  360.         add     dl, '0'
  361.         push    edx
  362.         test    eax, eax
  363.         jnz     @r
  364.   @@:
  365.         mov     edi, str_ini_int+2
  366.   @@:
  367.         pop     eax
  368.         stosb
  369.         test    eax, eax
  370.         jnz     @r
  371.  
  372.         ret
  373.  
  374.  
  375. ;-------------------------
  376. ; DATA
  377.  
  378. edit_ip         edit_box 100, 80, 45, 0xffffff, 0x6f9480, 0, 0, 0, 15, str_edit_ip, mouse_dd, 0, 0, 1
  379. edit_subnet     edit_box 100, 80, 65, 0xffffff, 0x6f9480, 0, 0, 0, 15, str_edit_subnet, mouse_dd, 0, 0, 1
  380. edit_gateway    edit_box 100, 80, 85, 0xffffff, 0x6f9480, 0, 0, 0, 15, str_edit_gateway, mouse_dd, 0, 0, 1
  381.  
  382. edit_dns        edit_box 100, 80, 130, 0xffffff, 0x6f9480, 0, 0, 0, 15, str_edit_dns, mouse_dd, 0, 0, 1
  383.  
  384. op_ip_disabled  option_box option_ip, 15, 5, 6, 12, 0xffffff, 0, 0, sz_disabled, 9
  385. op_ip_auto      option_box option_ip, 15, 25, 6, 12, 0xffffff, 0, 0, sz_auto, 5
  386. op_ip_static    option_box option_ip, 80, 25, 6, 12, 0xffffff, 0, 0, sz_static, 7
  387.  
  388. op_dns_auto     option_box option_dns, 15, 110, 6, 12, 0xffffff, 0, 0, sz_auto, 5
  389. op_dns_static   option_box option_dns, 80, 110, 6, 12, 0xffffff, 0, 0, sz_static, 7
  390.  
  391. option_ip       dd op_ip_auto
  392. option_dns      dd op_dns_auto
  393. Option_boxs1    dd op_ip_disabled, op_ip_auto, op_ip_static, 0
  394. Option_boxs2    dd op_dns_auto, op_dns_static, 0
  395.  
  396. net_ini         db '/sys/settings/network.ini', 0
  397.  
  398. str_ini_int     db 'ip1', 0
  399.                 rb 10
  400. str_ini_ip      db 'ip', 0
  401. str_ini_subnet  db 'subnet', 0
  402. str_ini_gateway db 'gateway', 0
  403. str_ini_dns     db 'dns', 0
  404. str_ini_ip_type db 'ip_type', 0
  405. str_ini_dns_type db 'dns_type', 0
  406.  
  407. str_title       db 'IP settings', 0
  408. sz_0            db 0
  409. sz_ip           db 'IP:', 0
  410. sz_subnet       db 'Subnet mask:', 0
  411. sz_gateway      db 'Gateway:', 0
  412. sz_dns          db 'DNS:', 0
  413. sz_auto         db 'Auto', 0
  414. sz_static       db 'Static', 0
  415. sz_disabled     db 'Disabled', 0
  416. sz_apply        db 'Apply', 0
  417.  
  418. str_edit_ip     rb 16
  419. str_edit_subnet rb 16
  420. str_edit_gateway rb 16
  421. str_edit_dns    rb 16
  422.  
  423. ini_buf         rb 16
  424.  
  425. mouse_dd        dd ?