Subversion Repositories Kolibri OS

Rev

Rev 485 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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