Subversion Repositories Kolibri OS

Rev

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