MiniMagAsm

Changes On Branch root_problem
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch root_problem Excluding Merge-Ins

This is equivalent to a diff from 9deeb7a3a1 to ceb5ded4d4

2014-10-17
11:45
Fixed the incidentally rewrited intex.txt on save with some error. Added new files creation through save. Recompiled with the latest FreshLibDev version. check-in: 4ad267532e user: lhmnai0 tags: trunk
2014-07-30
18:04
Recompiled with the latest fixes of FreshLib.

As long as there was fixed a bug in MD5 algorithm, it is expected some changes in the gravatar images in the user comments. Closed-Leaf check-in: ceb5ded4d4 user: johnfound tags: root_problem

2014-05-03
21:39
Added a new script "download.cgi" with source files "download.fpr" and "download.asm". This is a download manager that will redirect to the proper Fossil repository and artifact. Additionally it keeps a log files with the downloaded files. check-in: d4343b72c3 user: johnfound tags: root_problem
2013-07-25
14:46
Some, dirty fix of DOCUMENT_ROOT problem. It is possible this solution should be in a separate branch... check-in: ac4bbbce1d user: lhmnai0 tags: root_problem
2013-07-22
19:25
Fixed a bug in the feedback.cgi that caused invalid xhtml code to be generated for the user comments. Some experiments with CSS sprites for the main menu icons. check-in: 9deeb7a3a1 user: JohnFound tags: trunk
2013-07-19
12:35
Added .CSS file in order to make human readable sitemap. "sitemap.cgi" changed accordingly. check-in: 1275294b2e user: lhmnai0 tags: trunk

Changes to Sitemap.fpr.

cannot compute difference between binary files

Added download.asm.





































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
include "%lib%/freshlib.inc"

@BinaryType console

options.ShowSkipped = 0
options.ShowSizes = 1
options.DebugMode = 0
options.AlignCode = 0

HeapManager  equ ASM


include "%lib%/freshlib.asm"

uglobal
  hPath      dd ?
  hHost      dd ?
  hQuery     dd ?

  hFileName   dd ?
  hFileHash   dd ?
  hFileRepo   dd ?
  hRemoteIP   dd ?
endg


start:
        InitializeAll

        stdcall GetEnvVariable, 'REMOTE_ADDR'
        jc      .error

        mov     [hRemoteIP], eax

        stdcall GetEnvVariable, 'SCRIPT_FILENAME'
        jc      .error

        mov     [hPath], eax

        stdcall StrSplitFilename, [hPath]
        stdcall StrDel, eax

        stdcall GetEnvVariable, 'HTTP_HOST'
        jc      .error

        mov     ecx, eax

        stdcall StrDup, 'http://'

        stdcall StrCat, eax, ecx
        stdcall StrDel, ecx
        stdcall FixTrailingSlash, eax
        mov     [hHost], eax

        stdcall GetEnvVariable, 'QUERY_STRING'
        jc      .error

        mov     [hQuery], eax

        stdcall GetQueryItem, [hQuery], 'repo='
        jc      .error

        mov     [hFileRepo], eax

        stdcall StrCat, [hHost], 'fossil/repo/'
        stdcall StrCat, [hHost], eax
        stdcall StrCat, [hHost], '/raw/'

        stdcall GetQueryItem, [hQuery], 'file='
        jc      .error

        mov     [hFileName], eax
        stdcall StrCat, [hHost], eax

        stdcall GetQueryItem, [hQuery], 'hash='
        jc      .error

        mov     [hFileHash], eax

        stdcall StrCat, [hHost], '?name='
        stdcall StrCat, [hHost], eax

        stdcall LogTheDownload

        stdcall FileWriteString, [STDOUT], cHeader303
        stdcall FileWriteString, [STDOUT], 'Location: '
        stdcall FileWriteString, [STDOUT], [hHost]
        stdcall FileWriteString, [STDOUT], cCRLF2

        jmp     .exit

.error:
        stdcall FileWriteString, [STDOUT], cHeader404

.exit:
        FinalizeAll
        stdcall TerminateAll, 0


cContentType text 'Content-type: text/html', 13, 10
cHeader303   text 'Status: 303 See Other', 13, 10
cHeader404   text 'Status: 404 Not Found', 13, 10, 'Connection: close', 13, 10, 13, 10, '<html><head></head><body><h1>404 Not Found</h1></body></html>', 13, 10
cCRLF        text 13, 10
cCRLF2       text 13, 10, 13, 10


proc GetQueryItem, .hQuery, .itemname
begin
        push    ecx esi

        stdcall StrLen, [.itemname]
        mov     ecx, eax

        stdcall StrPos, [.hQuery], [.itemname]
        jnz     .item_found

        stc
        pop     esi ecx
        return

.item_found:
        lea     esi, [eax+ecx]
        stdcall StrCharPos, esi, '&'
        jnz     .copy_item

        stdcall StrLen, esi
        lea     eax, [esi+eax]

.copy_item:
        sub     eax, esi
        stdcall StrExtract, esi, 0, eax
        stdcall StrURLDecode, eax
        clc
        pop     esi ecx
        return
endp



proc FixTrailingSlash, .hPath
begin
        push    eax ecx
        stdcall StrLen, [.hPath]
        dec     eax
        mov     ecx, eax
        stdcall StrPtr, [.hPath]
        cmp     byte [eax+ecx], '/'
        je      .path_ok
        stdcall StrCharCat, [.hPath], '/'
.path_ok:
        pop     ecx eax
        return
endp



proc LogTheDownload
.time dd ?
.now  dq ?
.date TDateTime
begin
        pushad

        stdcall StrCat, [hPath], 'downloads.inc'

        stdcall GetTimestamp
        mov     [.time], eax

.loop:
        stdcall FileOpenAccess, [hPath], faReadWrite or faOpenAlways
        jnc     .file_ok

        stdcall Sleep, 20

        stdcall GetTimestamp
        sub     eax, [.time]
        cmp     eax, 3000
        jl      .loop

        stc
        popad
        return


.file_ok:
        mov     ebx, eax
        stdcall FileSeek, ebx, 0, fsFromEnd

        stdcall GetTime
        mov     dword [.now], eax
        mov     dword [.now+4], edx

        lea     eax, [.now]
        lea     edx, [.date]
        stdcall TimeToDateTime, eax, edx
        stdcall DateTimeToStr, edx, 0
        mov     esi, eax

        stdcall StrCharInsert, esi, '[', 0
        stdcall StrCharCat, esi, ']:['
        stdcall StrCat, esi, [hRemoteIP]
        stdcall StrCharCat, esi, '],['
        stdcall StrCat, esi, [hFileName]
        stdcall StrCharCat, esi, '],['
        stdcall StrCat, esi, [hFileRepo]
        stdcall StrCharCat, esi, '],['
        stdcall StrCat, esi, [hFileHash]
        stdcall StrCharCat, esi, ']'

        stdcall FileWriteString, ebx, esi
        stdcall FileWriteString, ebx, cCRLF

        stdcall FileClose, ebx

        clc
        popad
        return
endp








Added download.fpr.

cannot compute difference between binary files

Changes to feedback.asm.

290
291
292
293
294
295
296
297
298
299
300

cContentType text 'Content-type: text/html', 13, 10, 13, 10


cErrorNoPost text 'Error! feedback.cgi needs post data.'


@AllImportEmbeded
@AllDataSection









<
<


290
291
292
293
294
295
296


297
298

cContentType text 'Content-type: text/html', 13, 10, 13, 10


cErrorNoPost text 'Error! feedback.cgi needs post data.'






Changes to get.asm.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

uglobal
  hPath     dd ?
  hQuery    dd ?

  hPageName dd ?
endg


cHackDir text '..'
cBadPath text '.'



proc InitScriptVariables
begin
; first read document root.
        stdcall GetEnvVariable, 'DOCUMENT_ROOT'
        jnc     .root_ok

        stdcall StrDupMem, cBadPath

.root_ok:
        mov     [hPath], eax



; fix the trailing slash

        stdcall StrLen, [hPath]
        dec     eax
        mov     ecx, eax
        stdcall StrPtr, [hPath]
        cmp     byte [eax+ecx], DIR_SLASH
        je      .path_ok

        stdcall StrCharCat, [hPath], DIR_SLASH

; then read query string
.path_ok:
;        stdcall StrCat, [hPath], 'test/'

        stdcall GetEnvVariable, 'QUERY_STRING'
        jnc     .query_ok
        stdcall StrNew
.query_ok:
        mov     [hQuery], eax











|






|






>
>

|

|
|
|
|
|
|
|
|



<







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

41
42
43
44
45
46
47

uglobal
  hPath     dd ?
  hQuery    dd ?

  hPageName dd ?
endg


cHackDir text '..'
cBadPath text './'



proc InitScriptVariables
begin
; first read document root.
        stdcall GetEnvVariable, 'SCRIPT_FILENAME'
        jnc     .root_ok

        stdcall StrDupMem, cBadPath

.root_ok:
        mov     [hPath], eax
        stdcall StrSplitFilename, eax
        stdcall StrDel, eax

; fix the trailing slash - NOT NEEDED if SCRIPT_FILENAME is used as a root directory.

;        stdcall StrLen, [hPath]
;        dec     eax
;        mov     ecx, eax
;        stdcall StrPtr, [hPath]
;        cmp     byte [eax+ecx], DIR_SLASH
;        je      .path_ok
;
;        stdcall StrCharCat, [hPath], DIR_SLASH

; then read query string
.path_ok:


        stdcall GetEnvVariable, 'QUERY_STRING'
        jnc     .query_ok
        stdcall StrNew
.query_ok:
        mov     [hQuery], eax

Changes to index.asm.

46
47
48
49
50
51
52



53
54
55
56
57
58
59

        stdcall GetTimestamp
        mov     [StartTime], eax

        InitializeAll

        stdcall InitScriptVariables




        stdcall GetPostData
        jc      .post_data_ok

        stdcall StrDup, cSysMessagePreview
        mov     [hSysMessage], eax








>
>
>







46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

        stdcall GetTimestamp
        mov     [StartTime], eax

        InitializeAll

        stdcall InitScriptVariables

;        stdcall FileWriteString, [STDOUT], [hPath]
;        jmp     .exit

        stdcall GetPostData
        jc      .post_data_ok

        stdcall StrDup, cSysMessagePreview
        mov     [hSysMessage], eax

85
86
87
88
89
90
91
92
93
94
95

cContentType text 'Content-type: text/html', 13, 10, 13, 10

cLinkPage     text ' href="index.cgi?page='
cScript       text 'index.cgi?page='


@AllImportEmbeded
@AllDataSection









<
<


88
89
90
91
92
93
94


95
96

cContentType text 'Content-type: text/html', 13, 10, 13, 10

cLinkPage     text ' href="index.cgi?page='
cScript       text 'index.cgi?page='






Changes to save.asm.

38
39
40
41
42
43
44









45
46
47
48
49
50
51
        stdcall GetTimestamp
        mov     [StartTime], eax

        InitializeAll


        stdcall InitScriptVariables









        stdcall GetPostData
        jc      .no_post_data

; save the article

        stdcall StrDup, [hPath]
        stdcall StrCat, eax, [hPageName]







>
>
>
>
>
>
>
>
>







38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
        stdcall GetTimestamp
        mov     [StartTime], eax

        InitializeAll


        stdcall InitScriptVariables

; in the case of "save.cgi" get the path one directory back.

        stdcall StrLen, [hPath]
        dec     eax
        stdcall StrTrim, [hPath], eax
        stdcall StrSplitFilename, [hPath]
        stdcall StrDel, eax

        stdcall GetPostData
        jc      .no_post_data

; save the article

        stdcall StrDup, [hPath]
        stdcall StrCat, eax, [hPageName]
68
69
70
71
72
73
74
75
76
77



78


79
80
81
82
83
84
85
86
87
88
89

90
91

92
93
94
95
96
97
98
99
100
101
102
103
        stdcall FileWriteString, ebx, [hSource]
        jc      .file_write_error

        stdcall FileClose, ebx
        jc      .file_write_error

        stdcall LogEvent, cArticleModified, [hPageName], [hFileTitle]

cArticleModified text 'edited.'




        stdcall StrDup, cSaveOKMessage


        mov     [hSysMessage], eax

.finish:
        stdcall ReadTemplate, cTemplateFileName
        jc      .template_ok
        mov     [pHTMLTemplate], eax

.template_ok:
        stdcall FileWrite, [STDOUT], cContentType, cContentType.length
        stdcall WriteTemplate, [pHTMLTemplate], [STDOUT], SaveVarCallback


        FinalizeAll
        stdcall TerminateAll,0


.no_post_data:
        stdcall StrDup, cErrorNoPost
        mov     [hSysMessage], eax
        jmp     .finish


.file_write_error:
        push    eax
        stdcall FileClose, ebx

        stdcall StrDup, 'Error write file: '







<


>
>
>
|
>
>
|

|

|

|
<



>


>




|







77
78
79
80
81
82
83

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
        stdcall FileWriteString, ebx, [hSource]
        jc      .file_write_error

        stdcall FileClose, ebx
        jc      .file_write_error

        stdcall LogEvent, cArticleModified, [hPageName], [hFileTitle]

cArticleModified text 'edited.'

        stdcall FileWriteString, [STDOUT], 'Location: '
        stdcall FileWriteString, [STDOUT], '/index.cgi?page='
        stdcall FileWriteString, [STDOUT], [hPageName]
        stdcall FileWriteString, [STDOUT], cCRLF
        stdcall FileWriteString, [STDOUT], cCRLF
        jmp     .exit


.finish_error:
        stdcall ReadTemplate, cTemplateFileName
        jc      @f
        mov     [pHTMLTemplate], eax
@@:

        stdcall FileWrite, [STDOUT], cContentType, cContentType.length
        stdcall WriteTemplate, [pHTMLTemplate], [STDOUT], SaveVarCallback

.exit:
        FinalizeAll
        stdcall TerminateAll,0


.no_post_data:
        stdcall StrDup, cErrorNoPost
        mov     [hSysMessage], eax
        jmp     .finish_error


.file_write_error:
        push    eax
        stdcall FileClose, ebx

        stdcall StrDup, 'Error write file: '
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
        mov     ecx, eax
        pop     eax
        mov     [hSysMessage], ecx
        stdcall NumToStr, eax, ntsSigned or ntsDec
        stdcall StrCat, ecx, eax
        stdcall StrDel, eax
        stdcall StrCharCat, ecx, $0a
        jmp     .finish



cCRLF             text $0d, $0a
cTemplateFileName text 'save/save.inc'
cDefaultTemplate  text '<html><head></head><body>$sysmsg$<hr /><a href="/">Home</a></body></html>'


cContentType text 'Content-type: text/html', 13, 10, 13, 10


cErrorNoPost text 'Error! save.cgi needs post data.'
cSaveOKMessage text 'The file was saved.'


@AllImportEmbeded
@AllDataSection









|









<
<

|


<
<


130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146


147
148
149
150


151
152
        mov     ecx, eax
        pop     eax
        mov     [hSysMessage], ecx
        stdcall NumToStr, eax, ntsSigned or ntsDec
        stdcall StrCat, ecx, eax
        stdcall StrDel, eax
        stdcall StrCharCat, ecx, $0a
        jmp     .finish_error



cCRLF             text $0d, $0a
cTemplateFileName text 'save/save.inc'
cDefaultTemplate  text '<html><head></head><body>$sysmsg$<hr /><a href="/">Home</a></body></html>'


cContentType text 'Content-type: text/html', 13, 10, 13, 10


cErrorNoPost text 'Error! save.cgi needs post data.'
cSaveOKMessage text 'The file has been saved.'






Changes to sitemap.asm.

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

36
37

38
39
40
41
42
43
44
45
46
47
48
  StartTime  dd ?

  hPath      dd ?
  hHost      dd ?

endg

  cBadPath text '.'


;        rb 256          ; FASM ELF generator sometimes is buggy. Inserting some more bytes, fixes the problem.

start:

        stdcall GetTimestamp
        mov     [StartTime], eax

        InitializeAll



        stdcall GetEnvVariable, 'DOCUMENT_ROOT'
        jnc     .root_ok

        stdcall StrDupMem, cBadPath
.root_ok:
        stdcall FixTrailingSlash, eax
        mov     [hPath], eax

        stdcall GetEnvVariable, 'HTTP_HOST'
        jnc     .host_ok

        stdcall StrDup, 'InvalidHost'

.host_ok:







<
<











>
|
|
>
|
<
<
<







16
17
18
19
20
21
22


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38



39
40
41
42
43
44
45
  StartTime  dd ?

  hPath      dd ?
  hHost      dd ?

endg




;        rb 256          ; FASM ELF generator sometimes is buggy. Inserting some more bytes, fixes the problem.

start:

        stdcall GetTimestamp
        mov     [StartTime], eax

        InitializeAll


; first read document root.
        stdcall GetEnvVariable, 'SCRIPT_FILENAME'
        mov     [hPath], eax
        stdcall StrSplitFilename, eax
        stdcall StrDel, eax




        stdcall GetEnvVariable, 'HTTP_HOST'
        jnc     .host_ok

        stdcall StrDup, 'InvalidHost'

.host_ok:
258
259
260
261
262
263
264
265
266
267
268
endp






@AllImportEmbeded
@AllDataSection









<
<


255
256
257
258
259
260
261


262
263
endp










Changes to test_env.asm.

99
100
101
102
103
104
105
106
107
108
109
endp






@AllImportEmbeded
@AllDataSection









<
<

<
99
100
101
102
103
104
105


106

endp










Changes to test_env.fpr.

cannot compute difference between binary files

Added www/content/0index.txt.

















>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
Test article
# Test article

РЕДАКТИРАНЕ2 The answer is 42

This is test article to be used for experiments with saving and editing articles.

another text

Deleted www/content/index.txt.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Introduction
# Introduction

## What is MiniMagAsm?

MiniMagAsm is minimalistic, but powerful and flexible content management system ( [CMS] ),
implemented entirely in assembly language.

[CMS] http://en.wikipedia.org/wiki/Content_management_system

## Is it free?

MiniMagAsm is free, open source project, distributed under the terms of ["The Fresh Artistic License"].

["The Fresh Artistic License"] /index.cgi?page=content/docs/tfal.txt

*"Author"* of MiniMagAsm is John Found.

## How to get the source?

The source code of MiniMagAsm is hosted in the [repository].

The version control system used is [fossil-scm], but you can visit the above address
and download .zip files with the latest version (or any of the previous versions as well).

[repository] http://chiselapp.com/user/johnfound/repository/MiniMagAsm/index
[fossil-scm] http://fossil-scm.org/

## How to use MiniMagAsm?

In order to use MiniMagAsm you will need а web server, supporting binary executables as CGI scripts.

All decent hosting providers allows this feature. Usually they refer to it as CGI-BIN or simply mention
C++ in one line with PHP, Perl, etc.

The server hardware must be x86 compatible and the operating system Linux or Windows.

About installation and use of MiniMagAsm you should read [docs/manual_en.txt][the user manual].
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<












































































Added www/download.cgi.

cannot compute difference between binary files

Changes to www/feedback.cgi.

cannot compute difference between binary files

Changes to www/index.cgi.

cannot compute difference between binary files

Added www/robots.txt.











>
>
>
>
>
1
2
3
4
5
User-agent: *
Crawl-delay: 5
Disallow: /archive.cgi/
Sitemap: http://asm32.hopto.org/sitemap.cgi

Changes to www/save/save.cgi.

cannot compute difference between binary files

Changes to www/sitemap.cgi.

cannot compute difference between binary files

Changes to www/test_env.cgi.

cannot compute difference between binary files