Subversion Repositories Kolibri OS

Rev

Rev 5610 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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
  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.         invoke  ini.set_str, net_ini, str_ini_int, str_ini_dns_type, sz_auto, 4
  252.         jmp     @f
  253.   .dns_static:
  254.         invoke  ini.set_str, net_ini, str_ini_int, str_ini_dns_type, sz_static, 6
  255.   @@:
  256.  
  257.         invoke  ini.set_str, net_ini, str_ini_int, str_ini_ip, str_edit_ip, [edit_ip.size]
  258.         invoke  ini.set_str, net_ini, str_ini_int, str_ini_subnet, str_edit_subnet, [edit_subnet.size]
  259.         invoke  ini.set_str, net_ini, str_ini_int, str_ini_gateway, str_edit_gateway, [edit_gateway.size]
  260.         invoke  ini.set_str, net_ini, str_ini_int, str_ini_dns, str_edit_dns, [edit_dns.size]
  261.  
  262.   .exit:
  263.         mcall   -1
  264.  
  265.   .key:
  266.         mcall   2
  267.  
  268. ; Editbox doesnt allow us to filter input decently, so we do it here.
  269.         cmp     ah, 13
  270.         je      .apply
  271.         cmp     ah, 8
  272.         je      @f
  273.         cmp     ah, '.'
  274.         je      @f
  275.         cmp     ah, '0'
  276.         jb      .loop
  277.         cmp     ah, '9'
  278.         ja      .loop
  279.   @@:
  280.         invoke  edit_box_key, edit_ip
  281.         invoke  edit_box_key, edit_subnet
  282.         invoke  edit_box_key, edit_gateway
  283.         invoke  edit_box_key, edit_dns
  284.  
  285.         jmp     .loop
  286.  
  287. toggle_editboxes:
  288.  
  289.         and     [edit_ip.flags], not ed_disabled
  290.         and     [edit_subnet.flags], not ed_disabled
  291.         and     [edit_gateway.flags], not ed_disabled
  292.         cmp     [option_ip], op_ip_static
  293.         je      @f
  294.         or      [edit_ip.flags], ed_disabled
  295.         or      [edit_subnet.flags], ed_disabled
  296.         or      [edit_gateway.flags], ed_disabled
  297.   @@:
  298.  
  299.         or      [edit_dns.flags], ed_disabled
  300.         cmp     [option_ip], op_ip_disabled
  301.         je      @f
  302.         cmp     [option_dns], op_dns_static
  303.         jne     @f
  304.         and     [edit_dns.flags], not ed_disabled
  305.   @@:
  306.  
  307.         ret
  308.  
  309.  
  310. ; in:   esi = ptr to ascii ip
  311. ; out:  eax = 0 - ok / -1 - error
  312. validate_ip:
  313.         xor     ecx, ecx        ; octet count
  314.   .outer_loop:
  315.         xor     ebx, ebx        ; current number
  316.         inc     ecx
  317.   .inner_loop:
  318.         lodsb                   ; load one character from ascii string
  319.         test    al, al
  320.         je      .finish
  321.         cmp     al, '.'
  322.         je      .outer_loop
  323.         ; Convert current digit from ascii to bin, if valid
  324.         sub     al, '0'
  325.         jb      .invalid
  326.         cmp     al, 9
  327.         ja      .invalid
  328.         ; multiply current number by 10
  329.         add     bl, bl
  330.         jc      .invalid
  331.         lea     ebx, [ebx + 4 * ebx]
  332.         test    ebx, 0xffffff00
  333.         jnz     .invalid
  334.         ; add current digit to current number
  335.         add     bl, al
  336.         jc      .invalid
  337.         jmp     .inner_loop
  338.   .finish:
  339.         cmp     cl, 4
  340.         jne     .invalid
  341.         xor     eax, eax
  342.         ret
  343.  
  344.   .invalid:
  345.         or      eax, -1
  346.         ret
  347.  
  348. create_str_ini_int:
  349.         movzx   eax, [device]
  350.         mov     ebx, 10
  351.         xor     edx, edx
  352.         push    0
  353.   @@:
  354.         div     ebx
  355.         add     dl, '0'
  356.         push    edx
  357.         test    eax, eax
  358.         jnz     @r
  359.   @@:
  360.         mov     edi, str_ini_int+2
  361.   @@:
  362.         pop     eax
  363.         stosb
  364.         test    eax, eax
  365.         jnz     @r
  366.  
  367.         ret
  368.  
  369.  
  370. ;-------------------------
  371. ; DATA
  372.  
  373. edit_ip         edit_box 100, 80, 45, 0xffffff, 0x6f9480, 0, 0, 0, 15, str_edit_ip, mouse_dd, 0, 0, 1
  374. edit_subnet     edit_box 100, 80, 65, 0xffffff, 0x6f9480, 0, 0, 0, 15, str_edit_subnet, mouse_dd, 0, 0, 1
  375. edit_gateway    edit_box 100, 80, 85, 0xffffff, 0x6f9480, 0, 0, 0, 15, str_edit_gateway, mouse_dd, 0, 0, 1
  376.  
  377. edit_dns        edit_box 100, 80, 130, 0xffffff, 0x6f9480, 0, 0, 0, 15, str_edit_dns, mouse_dd, 0, 0, 1
  378.  
  379. op_ip_disabled  option_box option_ip, 15, 5, 6, 12, 0xffffff, 0, 0, sz_disabled, 9
  380. op_ip_auto      option_box option_ip, 15, 25, 6, 12, 0xffffff, 0, 0, sz_auto, 5
  381. op_ip_static    option_box option_ip, 80, 25, 6, 12, 0xffffff, 0, 0, sz_static, 7
  382.  
  383. op_dns_auto     option_box option_dns, 15, 110, 6, 12, 0xffffff, 0, 0, sz_auto, 5
  384. op_dns_static   option_box option_dns, 80, 110, 6, 12, 0xffffff, 0, 0, sz_static, 7
  385.  
  386. option_ip       dd op_ip_auto
  387. option_dns      dd op_dns_auto
  388. Option_boxs1    dd op_ip_disabled, op_ip_auto, op_ip_static, 0
  389. Option_boxs2    dd op_dns_auto, op_dns_static, 0
  390.  
  391. net_ini         db '/sys/settings/network.ini', 0
  392.  
  393. str_ini_int     db 'ip1', 0
  394.                 rb 10
  395. str_ini_ip      db 'ip', 0
  396. str_ini_subnet  db 'subnet', 0
  397. str_ini_gateway db 'gateway', 0
  398. str_ini_dns     db 'dns', 0
  399. str_ini_ip_type db 'ip_type', 0
  400. str_ini_dns_type db 'dns_type', 0
  401.  
  402. str_title       db 'IP settings', 0
  403. sz_0            db 0
  404. sz_ip           db 'IP:', 0
  405. sz_subnet       db 'Subnet mask:', 0
  406. sz_gateway      db 'Gateway:', 0
  407. sz_dns          db 'DNS:', 0
  408. sz_auto         db 'Auto', 0
  409. sz_static       db 'Static', 0
  410. sz_disabled     db 'Disabled', 0
  411. sz_apply        db 'Apply', 0
  412.  
  413. str_edit_ip     rb 16
  414. str_edit_subnet rb 16
  415. str_edit_gateway rb 16
  416. str_edit_dns    rb 16
  417.  
  418. ini_buf         rb 16
  419.  
  420. mouse_dd        dd ?