Subversion Repositories Kolibri OS

Rev

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

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