Subversion Repositories Kolibri OS

Rev

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