Subversion Repositories Kolibri OS

Rev

Rev 109 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                   ;;
  3. ;;    SMTP server for MenuetOS                       ;;
  4. ;;                                                   ;;
  5. ;;    License: GPL / See file COPYING for details    ;;
  6. ;;    Copyright 2002 (c) Ville Turjanmaa             ;;
  7. ;;                                                   ;;
  8. ;;    Compile with FASM for Menuet                   ;;
  9. ;;                                                   ;;
  10. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11.  
  12. version equ '0.1'
  13.  
  14. use32
  15.  
  16.                 org     0x0
  17.  
  18.                 db      'MENUET01'              ; 8 byte id
  19.                 dd      0x01                    ; required os
  20.                 dd      START                   ; program start
  21.                 dd      I_END                   ; program image size
  22.                 dd      0x200000                ; required amount of memory
  23.                 dd      0xffff0
  24.                 dd      0,0
  25.  
  26. include 'macros.inc'
  27.  
  28. save_file:
  29.  
  30. ;   cmp  [file_start],0x100000+10
  31. ;   jbe  nosub
  32. ;   sub  [file_start],8
  33. ;  nosub:
  34.  
  35.    mov  eax,[file_start]
  36.    sub  eax,0x100000
  37.    mov  ebx,files
  38.    mov  [ebx+12],eax
  39.  
  40.    mov  eax,70
  41.    int  0x40
  42.  
  43.    ret
  44.  
  45.  
  46. START:                          ; start of execution
  47.  
  48.     mov  [file_start],0x100000
  49.  
  50.     mov  eax,70
  51.     mov  ebx,filel
  52.     int  0x40
  53.  
  54.     test eax,eax
  55.     jz   @f
  56.     cmp  eax,6
  57.     jnz  notfound
  58. @@:
  59.     add  [file_start],ebx
  60.   notfound:
  61.  
  62.  
  63.     mov  edi,I_END
  64.     mov  ecx,60*120
  65.     mov  al,32
  66.     cld
  67.     rep  stosb
  68.  
  69.     mov  eax,[rxs]
  70.     imul eax,11
  71.     mov  [pos],eax
  72.  
  73.     mov  ebp,0
  74.     mov  edx,I_END
  75.     call draw_window            ; at first, draw the window
  76.  
  77. still:
  78.  
  79.     inc  [cursor_on_off]
  80.  
  81.     mov  eax,5
  82.     mov  ebx,1
  83.     int  0x40
  84.  
  85.     mov  eax,11                 ; wait here for event
  86.     int  0x40
  87.  
  88.     cmp  eax,1                  ; redraw
  89.     je   redraw
  90.     cmp  eax,2                  ; key
  91.     je   key
  92.     cmp  eax,3                  ; button
  93.     je   button
  94.  
  95.     cmp  [I_END+120*60],byte 1
  96.     jne  no_main_update
  97.     mov  [I_END+120*60],byte 0
  98.     mov  edx,I_END
  99.     call draw_channel_text
  100.   no_main_update:
  101.  
  102.     cmp  [server_active],0
  103.     je   noread
  104.     cmp  [status],4
  105.     jne  noread
  106.     call read_incoming_data
  107.     inc  [close_connection]
  108.     cmp  [close_connection],15*100
  109.     jbe  noread
  110.  
  111.     call yq
  112.  
  113.   noread:
  114.  
  115.     call print_status
  116.  
  117.     cmp  [status],4
  118.     je   check_header
  119.  
  120.     jmp  still
  121.  
  122.  
  123. check_header:
  124.  
  125.     cmp [header_sent],1
  126.     je  still
  127.  
  128.     mov  eax,53
  129.     mov  ebx,7
  130.     mov  ecx,[socket]
  131.     mov  edx,6
  132.     mov  esi,r220
  133.     int  0x40
  134.     mov  [header_sent],1
  135.  
  136.     jmp  still
  137.  
  138.  
  139.  
  140. redraw:                         ; redraw
  141.  
  142.     call draw_window
  143.     jmp  still
  144.  
  145.  
  146. button:                         ; button
  147.  
  148.     mov  eax,17                 ; get id
  149.     int  0x40
  150.  
  151.     cmp  ah,1                   ; close program
  152.     jne  noclose
  153.     mov  eax,-1
  154.     int  0x40
  155.   noclose:
  156.  
  157.     call socket_commands
  158.  
  159.     jmp  still
  160.  
  161.  
  162. old_status dd 0x0
  163.  
  164. print_status:
  165.  
  166.     pusha
  167.  
  168.     mov  eax,53
  169.     mov  ebx,6
  170.     mov  ecx,[socket]
  171.     int  0x40
  172.  
  173.     mov  [status],eax
  174.  
  175.     cmp  eax,[old_status]
  176.     je   no_print
  177.  
  178.     mov  [old_status],eax
  179.  
  180.     push eax
  181.  
  182.     mov  eax,13
  183.     mov  ebx,360*65536+30
  184.     mov  ecx,151*65536+10
  185.     mov  edx,0xffffff
  186.     int  0x40
  187.  
  188.     pop  ecx
  189.     mov  eax,47
  190.     mov  ebx,3*65536
  191.     mov  edx,360*65536+151
  192.     mov  esi,0x000000
  193.  
  194.     cmp  [server_active],0
  195.     je   no_print
  196.  
  197.     int  0x40
  198.  
  199.   no_print:
  200.  
  201.     popa
  202.  
  203.     ret
  204.  
  205.  
  206. socket_commands:
  207.  
  208.     cmp  ah,22       ; open socket
  209.     jnz  tst3
  210.     mov  eax,3
  211.     int  0x40
  212.  
  213.     mov  [server_active],1
  214.  
  215.     mov  eax,53
  216.     mov  ebx,5
  217.     mov  ecx,25     ; local port # - http
  218.     mov  edx,0      ; no remote port specified
  219.     mov  esi,0      ; no remote ip specified
  220.     mov  edi,0      ; PASSIVE open
  221.     int  0x40
  222.     mov  [socket], eax
  223.  
  224.     ret
  225.   tst3:
  226.  
  227.  
  228.     cmp  ah,24     ; close socket
  229.     jnz  no_24
  230.     mov  eax,53
  231.     mov  ebx,8
  232.     mov  ecx,[socket]
  233.     int  0x40
  234.     mov  [header_sent],0
  235.     mov  [mail_rp],0
  236.     mov  [server_active],0
  237.  
  238.     ret
  239.   no_24:
  240.  
  241.  
  242.     ret
  243.  
  244.  
  245.  
  246. key:
  247.  
  248.     mov  eax,2
  249.     int  0x40
  250.  
  251.     jmp  still
  252.  
  253.  
  254.  
  255. read_incoming_data:
  256.  
  257.     pusha
  258.  
  259.   read_new_byte:
  260.  
  261.     call read_incoming_byte
  262.     cmp  ecx,-1
  263.     je   no_data_in_buffer
  264.  
  265.     mov  eax,[file_start]
  266.     mov  [eax],bl
  267.     inc  [file_start]
  268.  
  269.     cmp  bl,10
  270.     jne  no_start_command
  271.     mov  [cmd],1
  272.   no_start_command:
  273.  
  274.     cmp  bl,13
  275.     jne  no_end_command
  276.     mov  eax,[cmd]
  277.     mov  [eax+command-2],byte 0
  278.     call analyze_command
  279.     mov  edi,command
  280.     mov  ecx,250
  281.     mov  eax,0
  282.     cld
  283.     rep  stosb
  284.     mov  [cmd],0
  285.   no_end_command:
  286.  
  287.     mov  eax,[cmd]
  288.     cmp  eax,250
  289.     jge  still
  290.  
  291.     mov  [eax+command-2],bl
  292.     inc  [cmd]
  293.  
  294.     jmp  read_new_byte
  295.  
  296.   no_data_in_buffer:
  297.  
  298.     popa
  299.  
  300.     ret
  301.  
  302.  
  303.  
  304.  
  305.  
  306. analyze_command:
  307.  
  308.     pusha
  309.  
  310.     mov  [text_start],I_END
  311.     mov  ecx,[rxs]
  312.     imul ecx,11
  313.     mov  [pos],ecx
  314.  
  315.     mov  bl,13
  316.     call print_character
  317.     mov  bl,10
  318.     call print_character
  319.  
  320.     cmp  [cmd],2
  321.     jbe  nott
  322.     mov  ecx,[cmd]
  323.     sub  ecx,2
  324.     mov  esi,command+0
  325.   newcmdc:
  326.     mov  bl,[esi]
  327.     call print_character
  328.     inc  esi
  329.     loop newcmdc
  330.  
  331.    nott:
  332.  
  333.     mov   edx,I_END
  334.     call  draw_channel_text
  335.  
  336.   cmd_len_ok:
  337.  
  338.     cmp  [command],dword 'data'
  339.     je   datacom
  340.     cmp  [command],dword 'DATA'
  341.     je   datacom
  342.     cmp  [command],dword 'Data'
  343.     je   datacom
  344.     jmp  nodatacom
  345.   datacom:
  346.     inc  [mail_rp]
  347.     mov  eax,53
  348.     mov  ebx,7
  349.     mov  ecx,[socket]
  350.     mov  edx,6
  351.     mov  esi,r354
  352.     int  0x40
  353.     mov  [cmd],0
  354.     popa
  355.     ret
  356.  
  357.   nodatacom:
  358.  
  359.     cmp  [mail_rp],0
  360.     jne  nomrp0
  361.     mov  eax,53
  362.     mov  ebx,7
  363.     mov  ecx,[socket]
  364.     mov  edx,6
  365.     mov  esi,r250
  366.     int  0x40
  367.     mov  [cmd],0
  368.     popa
  369.     ret
  370.   nomrp0:
  371.  
  372.  
  373.  
  374.     cmp  [command],dword 'QUIT'
  375.     je   yesquit
  376.     cmp  [command],dword 'Quit'
  377.     je   yesquit
  378.     cmp  [command],dword 'quit'
  379.     je   yesquit
  380.     jmp  noquit
  381.   yq:
  382.      pusha
  383.  
  384.   yesquit:
  385.  
  386.     mov  [close_connection],0
  387.  
  388.     mov  eax,53
  389.     mov  ebx,7
  390.     mov  ecx,[socket]
  391.     mov  edx,6
  392.     mov  esi,r221
  393.     int  0x40
  394.     mov  [cmd],0
  395.  
  396.     mov  eax,5
  397.     mov  ebx,5
  398.     int  0x40
  399.  
  400.     mov  eax,53
  401.     mov  ebx,8
  402.     mov  ecx,[socket]
  403.     int  0x40
  404.  
  405.     mov  eax,5
  406.     mov  ebx,5
  407.     int  0x40
  408.  
  409.     mov  eax,53
  410.     mov  ebx,8
  411.     mov  ecx,[socket]
  412.     int  0x40
  413.  
  414.     mov  [header_sent],0
  415.     mov  [mail_rp],0
  416.  
  417.     call save_file
  418.  
  419.     mov  eax,5
  420.     mov  ebx,20
  421.     int  0x40
  422.  
  423.     mov  eax,53
  424.     mov  ebx,5
  425.     mov  ecx,25     ; local port # - http
  426.     mov  edx,0      ; no remote port specified
  427.     mov  esi,0      ; no remote ip specified
  428.     mov  edi,0      ; PASSIVE open
  429.     int  0x40
  430.     mov  [socket], eax
  431.  
  432.     popa
  433.     ret
  434.   noquit:
  435.  
  436.  
  437.  
  438.     cmp  [command],byte '.'
  439.     jne  nodot
  440.     mov  eax,53
  441.     mov  ebx,7
  442.     mov  ecx,[socket]
  443.     mov  edx,6
  444.     mov  esi,r250
  445.     int  0x40
  446.     mov  [cmd],0
  447.     popa
  448.     ret
  449.   nodot:
  450.  
  451.     popa
  452.     ret
  453.  
  454.  
  455. r250  db  '250 ',13,10
  456. r221  db  '221 ',13,10
  457. r220  db  '220 ',13,10
  458. r354  db  '354 ',13,10
  459.  
  460.  
  461.  
  462. draw_data:
  463.  
  464.     pusha
  465.  
  466.     add  eax,[text_start]
  467.     mov  [eax],bl
  468.  
  469.     popa
  470.     ret
  471.  
  472.  
  473.  
  474.  
  475. print_text:
  476.  
  477.     pusha
  478.  
  479.     mov  ecx,command-2
  480.     add  ecx,[cmd]
  481.  
  482.   ptr2:
  483.     mov  bl,[eax]
  484.     cmp  bl,dl
  485.     je   ptr_ret
  486.     cmp  bl,0
  487.     je   ptr_ret
  488.     call print_character
  489.     inc  eax
  490.     cmp  eax,ecx
  491.     jbe  ptr2
  492.  
  493.   ptr_ret:
  494.  
  495.     mov  eax,[text_start]
  496.     mov  [eax+120*60],byte 1
  497.  
  498.     popa
  499.     ret
  500.  
  501.  
  502.  
  503. print_character:
  504.  
  505.     pusha
  506.  
  507.     cmp  bl,13     ; line beginning
  508.     jne  nobol
  509.     mov  ecx,[pos]
  510.     add  ecx,1
  511.   boll1:
  512.     sub  ecx,1
  513.     mov  eax,ecx
  514.     xor  edx,edx
  515.     mov  ebx,[rxs]
  516.     div  ebx
  517.     cmp  edx,0
  518.     jne  boll1
  519.     mov  [pos],ecx
  520.     jmp  newdata
  521.   nobol:
  522.  
  523.     cmp  bl,10     ; line down
  524.     jne  nolf
  525.    addx1:
  526.     add  [pos],dword 1
  527.     mov  eax,[pos]
  528.     xor  edx,edx
  529.     mov  ecx,[rxs]
  530.     div  ecx
  531.     cmp  edx,0
  532.     jnz  addx1
  533.     mov  eax,[pos]
  534.     jmp  cm1
  535.   nolf:
  536.   no_lf_ret:
  537.  
  538.  
  539.     cmp  bl,15    ; character
  540.     jbe  newdata
  541.  
  542.     mov  eax,[irc_data]
  543.     shl  eax,8
  544.     mov  al,bl
  545.     mov  [irc_data],eax
  546.  
  547.     mov  eax,[pos]
  548.     call draw_data
  549.  
  550.     mov  eax,[pos]
  551.     add  eax,1
  552.   cm1:
  553.     mov  ebx,[scroll+4]
  554.     imul ebx,[rxs]
  555.     cmp  eax,ebx
  556.     jb   noeaxz
  557.  
  558.     mov  esi,[text_start]
  559.     add  esi,[rxs]
  560.  
  561.     mov  edi,[text_start]
  562.     mov  ecx,ebx
  563.     cld
  564.     rep  movsb
  565.  
  566.     mov  esi,[text_start]
  567.     mov  ecx,[rxs]
  568.     imul ecx,61
  569.     add  esi,ecx
  570.  
  571.     mov  edi,[text_start]
  572.     mov  ecx,[rxs]
  573.     imul ecx,60
  574.     add  edi,ecx
  575.     mov  ecx,ebx
  576.     cld
  577.     rep  movsb
  578.  
  579.     mov  eax,ebx
  580.     sub  eax,[rxs]
  581.   noeaxz:
  582.     mov  [pos],eax
  583.  
  584.   newdata:
  585.  
  586.     mov  eax,[text_start]
  587.     mov  [eax+120*60],byte 1
  588.  
  589.     popa
  590.     ret
  591.  
  592.  
  593.  
  594. read_incoming_byte:
  595.  
  596.     mov  eax, 53
  597.     mov  ebx, 2
  598.     mov  ecx, [socket]
  599.     int  0x40
  600.  
  601.     mov  ecx,-1
  602.  
  603.     cmp  eax,0
  604.     je   no_more_data
  605.  
  606.     mov  eax, 53
  607.     mov  ebx, 3
  608.     mov  ecx, [socket]
  609.     int  0x40
  610.  
  611.     mov  ecx,0
  612.  
  613.   no_more_data:
  614.  
  615.     ret
  616.  
  617.  
  618.  
  619. draw_window:
  620.  
  621.     pusha
  622.  
  623.     mov  eax,12
  624.     mov  ebx,1
  625.     int  0x40
  626.  
  627.     mov  [old_status],300
  628.  
  629.     mov  eax,0                     ; draw window
  630.     mov  ebx,5*65536+400
  631.     mov  ecx,5*65536+200
  632.     mov  edx,0x13ffffff
  633.     mov  edi,labelt
  634.     int  0x40
  635.  
  636.     mov  eax,8                     ; button: open socket
  637.     mov  ebx,23*65536+22
  638.     mov  ecx,169*65536+10
  639.     mov  edx,22
  640.     mov  esi,0x55aa55
  641.     int  0x40
  642.  
  643.     mov  eax,8                     ; button: close socket
  644.     mov  ebx,265*65536+22
  645.     mov  ecx,169*65536+10
  646.     mov  edx,24
  647.     mov  esi,0xaa5555
  648.     int  0x40
  649.  
  650.     mov  eax,38                    ; line
  651.     mov  ebx,5*65536+395
  652.     mov  ecx,108*65536+108
  653.     mov  edx,0x000000
  654.     int  0x40
  655.  
  656.     mov  ebx,5*65536+123          ; info text
  657.     mov  ecx,0x000000
  658.     mov  edx,text
  659.     mov  esi,70
  660.   newline:
  661.     mov  eax,4
  662.     int  0x40
  663.     add  ebx,12
  664.     add  edx,70
  665.     cmp  [edx],byte 'x'
  666.     jne  newline
  667.  
  668.     mov  edx,I_END                ; text from server
  669.     call draw_channel_text
  670.  
  671.     mov  eax,12
  672.     mov  ebx,2
  673.     int  0x40
  674.  
  675.     popa
  676.  
  677.     ret
  678.  
  679.  
  680.  
  681.  
  682.  
  683. draw_channel_text:
  684.  
  685.     pusha
  686.  
  687.     mov   eax,4
  688.     mov   ebx,10*65536+26
  689.     mov   ecx,[scroll+4]
  690.     mov   esi,[rxs]
  691.   dct:
  692.     pusha
  693.     mov   cx,bx
  694.     shl   ecx,16
  695.     mov   cx,9
  696.     mov   eax,13
  697.     mov   ebx,10*65536
  698.     mov   bx,word [rxs]
  699.     imul  bx,6
  700.     mov   edx,0xffffff
  701.     int   0x40
  702.     popa
  703.     push  ecx
  704.     mov   eax,4
  705.     mov   ecx,0
  706.     cmp   [edx],word '* '
  707.     jne   no_red
  708.     mov   ecx,0xff0000
  709.    no_red:
  710.     cmp   [edx],word '**'
  711.     jne   no_light_blue
  712.     cmp   [edx+2],byte '*'
  713.     jne   no_light_blue
  714.     mov   ecx,0x0000ff
  715.   no_light_blue:
  716.     cmp   [edx],byte '#'
  717.     jne   no_blue
  718.     mov   ecx,0x00ff00
  719.   no_blue:
  720.     int   0x40
  721.     add   edx,[rxs]
  722.     add   ebx,10
  723.     pop   ecx
  724.     loop  dct
  725.  
  726.     popa
  727.     ret
  728.  
  729.  
  730.  
  731. text:
  732.  
  733. db '   Incoming mails are written to /rd/1/smtps.txt                      '
  734. db '   The file can be fetched with TinyServer and a Html-browser.        '
  735. db '   Timeout is set to 15 seconds.                                      '
  736. db '                                                                      '
  737. db '        Open SMTP server port 25                Close SMTP            '
  738.  
  739. db 'x' ; <- END MARKER, DONT DELETE
  740.  
  741.  
  742. irc_server_ip   db      192,168,1,1
  743.  
  744. file_start      dd      0x100000
  745.  
  746. files:
  747.        dd  2,0,0,?,0x100000
  748.        db  '/rd/1/smtps.txt',0
  749. filel:
  750.        dd  0,0,0,0x100000,0x100000
  751.        db  '/rd/1/smtps.txt',0
  752.  
  753.  
  754. server_active dd 0
  755.  
  756. status  dd  0x0
  757. header_sent db 0
  758.  
  759. channel_temp:         times   100   db   0
  760. channel_temp_length   dd      0x0
  761.  
  762. close_connection   dd 0x0
  763.  
  764. mail_rp      dd  0
  765.  
  766. socket  dd  0x0
  767.  
  768. bgc  dd  0x000000
  769.      dd  0x000000
  770.      dd  0x00ff00
  771.      dd  0x0000ff
  772.      dd  0x005500
  773.      dd  0xff00ff
  774.      dd  0x00ffff
  775.      dd  0x770077
  776.  
  777. tc   dd  0xffffff
  778.      dd  0xff00ff
  779.      dd  0xffffff
  780.      dd  0xffffff
  781.      dd  0xffffff
  782.      dd  0xffffff
  783.      dd  0xffffff
  784.      dd  0xffffff
  785.  
  786. cursor_on_off  dd  0x0
  787.  
  788. max_windows    dd  20
  789.  
  790. thread_stack   dd  0x9fff0
  791. thread_nro     dd 1
  792. thread_screen  dd I_END+120*80*1
  793.  
  794. action_header_blue  db  10,'*** ',0
  795. action_header_red   db  10,'*** ',0
  796.  
  797. action_header_short db  10,'* ',0
  798.  
  799. posx             dd  0x0
  800. incoming_pos     dd  0x0
  801. incoming_string: times 128 db 0
  802.  
  803. pos          dd  0x0
  804.  
  805. text_start   dd  I_END
  806. irc_data     dd  0x0
  807. print        db  0x0
  808. cmd          dd  0x0
  809. rxs          dd  56
  810.  
  811. res:         db  0,0
  812. command:     times  256  db 0x0
  813.  
  814. nick         dd  0,0,0
  815. irc_command  dd  0,0
  816.  
  817. command_position  dd 0x0
  818. counter           dd  0
  819. send_to_server    db 0
  820.  
  821. channel_list:     times 32*20 db 32
  822. send_to_channel   dd 0x0
  823.  
  824. send_string:         times  100  db  0x0
  825.  
  826. xpos        dd  0
  827. attribute   dd  0
  828. scroll      dd  1
  829.             dd  8
  830.  
  831. numtext     db  '                     '
  832.  
  833. labelt      db  'Tiny SMTP email server v ',version,0
  834.  
  835. I_END:
  836.