Update to 0.2.5 version

- Added support for uploading a configuration file over a long path
 - Added support for special uri paths (using the "*" symbol) in the configuration for groups of similar uri paths
 - Added the function of reading the contents of an http request
 - Changed the format of the uri address in the configuration file
 - Added a request redirection module
 - Added a module for blocking access to files by url path
 - Updated documentation
 - Updated module examples
This commit is contained in:
2024-06-13 00:42:58 +05:00
parent aca8a10141
commit aa78c565af
28 changed files with 670 additions and 149 deletions

7
example/readme.md Normal file
View File

@@ -0,0 +1,7 @@
# Examples of modules
- `test_unit.asm` - Модуль обрабатывает аргументы URI строки и отправляет ответ в виде RAW данных, без генерации заголовков и строки статуса сервером.
- `test_unit_2.asm` - Модуль обрабатывает агрументы URI, проверяет и устанавливет cookie и отправляет ответ в виде html данных, строка статуса и заголовки генерируются самим сервером. Модуль добавляет дополнительный заголовок в ответ.
- `test_unit4.asm` - Модуль отправляет в ответе заданную в файле конфигурации строку параметров и uri адрес запроса клиента. Используется chunked передача ответа.
- `test_unit5.asm` - Модуль отправляет ответ используя chunked передачу.
- `srv_control.asm` - Модуль, позволяющий удалённо выключать сервер.

View File

@@ -49,7 +49,7 @@ unit_init:
;unit init successful
.exit:
pop edi esi
ret 8
ret 12
server_entry:
@@ -127,13 +127,45 @@ key_token:
key_cmd:
db 'cmd',0
CMD_STOP = 'S'
CMD_REBOOT = 'R'
text403:
db 'Access to server management is prohibited.',\
' An unknown token has been entered'
db '<html><head><title>Login</title><style>',\
'body {display: grid;',\
'grid-template-rows: 1fr 1fr 1fr;',\
'text-align: center;',\
'background-color: blanchedalmond;',\
'}',\
'.f {',\
'display: grid;',\
'grid-template-columns: 1fr 1fr 1fr;',\
'}',\
'.f1 {background-color: aqua;',\
'border: 1px solid black;',\
'border-radius: 2%;}',\
'form {',\
'left: 50%;',\
'position: absolute;',\
'top: 50%;',\
'transform: translate(-50%, -50%);}',\
'</style></head>',\
'<body><h1>Access to server management is prohibited.',\
' An unknown token has been entered</h1>',\
'<div class="f"><div></div>',\
'<div class="f1"><form method="get">',\
'<h2>Enter token:</h2> <input type="text" name="token" /><br />',\
'<input type="submit" value="Submit" />',\
'</form></div>',\
'<div></div></div><div></div>',\
'</body></html>'
.length = $ - text403
text_board:
db '<body> <h1> Control panel of simple-httpd</h1> <a href="?cmd=S&token='
db '<body> <h1> Control panel of simple-httpd</h1>',\
'<a href="?cmd=S&token='
.token:
db ' ">Stop Server</a></body>'
.size = $ - text_board

View File

@@ -45,7 +45,7 @@ unit_init:
mov eax, 1 ;no zero return - unit init successful
.exit:
pop edi esi
ret 8
ret 12
server_entry:

View File

@@ -47,7 +47,7 @@ unit_init:
;unit init successful
.exit:
pop edi esi
ret 8
ret 12
server_entry:
@@ -58,14 +58,33 @@ server_entry:
cmp dword[edi], 0
je .no_cmd
mov edx, [esi + CONNECT_DATA.uri_path]
xor ecx, ecx
dec ecx
@@:
inc ecx
cmp byte[edx + ecx], 0
jne @b
push ecx
add edi, 4
invoke IMPORT.create_resp, esi, 0
invoke IMPORT.create_resp, esi, FLAG_TRANSFER_CHUNKED\
+ FLAG_NO_CONTENT_LENGTH
test eax, eax
jz .exit
push eax
invoke IMPORT.begin_send_resp, eax, 0, 0
mov eax, [esp]
invoke IMPORT.send_resp, eax, edi, [edi - 4]
mov eax, [esp]
invoke IMPORT.send_resp, eax, text_br, text_br.size
mov eax, [esp]
invoke IMPORT.send_resp, eax,\
[esi + CONNECT_DATA.uri_path],\
[esp + 4]
invoke IMPORT.destruct_resp ; arg in stack
add esp, 4
.exit:
pop edi esi
ret 8
@@ -89,6 +108,9 @@ section '.data' data readable writable align 16
text_no_cmd:
db 'For this unit in config not set arguments'
.size = $ - text_no_cmd
text_br:
db '<br>'
.size = $ - text_br
@EXPORT:
export \

View File

@@ -27,7 +27,7 @@ unit_init:
mov eax, 1 ;no zero return - module init successful
.exit:
pop edi esi
ret 8
ret 12
server_entry:

View File

@@ -46,12 +46,12 @@ unit_init:
mov eax, 1 ;no zero return - unit init successful
.exit:
pop edi esi
ret 8
ret 12
server_entry:
push esi edi
mov esi, [esp + 4*2 + 4]
push esi edi ebp
mov esi, [esp + 4*3 + 4]
; work
board_input 'first'
@@ -71,7 +71,7 @@ server_entry:
mov ecx, [eax + 4]
cmp dword[ecx], 'bpo'
jne .no_bpo
.bpo:
board_input 'bpo'
invoke IMPORT.Alloc, sceleton_resp.size
test eax, eax
@@ -94,11 +94,13 @@ server_entry:
rep movsb
pop esi
mov ebp, cookie_bpo
jmp .send_data
.no_bpo:
cmp dword[ecx], 'btp'
jne .err_404
.btp:
board_input 'btp'
invoke IMPORT.Alloc, sceleton_resp.size
test eax, eax
@@ -121,9 +123,24 @@ server_entry:
rep movsb
pop esi
mov ebp, cookie_btp
jmp .send_data
.no_args:
board_input 'no_arg'
; check cookie
invoke IMPORT.find_header, esi, key_cookie
test eax, eax
jz .no_args.send
cmp dword[eax], 'gr=b'
jne .no_args.send
cmp word[eax + 4], 'tp'
je .btp
cmp word[eax + 4], 'po'
je .bpo
.no_args.send:
invoke IMPORT.create_resp, esi, 0
test eax, eax
jz .exit
@@ -132,7 +149,7 @@ server_entry:
invoke IMPORT.send_resp, eax, sceleton_resp, sceleton_resp.size
invoke IMPORT.destruct_resp ; arg in stack
.exit:
pop edi esi
pop ebp edi esi
ret 8
.send_data: ; eax - ptr to buffer
@@ -144,6 +161,10 @@ server_entry:
board_input 'send_data'
push eax
invoke IMPORT.add_http_header, eax, ebp, cookie_length
mov eax, [esp]
invoke IMPORT.send_resp, eax, edi, sceleton_resp.size
invoke IMPORT.destruct_resp ; arg in stack
@@ -198,6 +219,12 @@ btp_name:
db 'Технологи'
.size = $ - btp_name
key_cookie: db 'Cookie', 0
cookie_bpo: db 'Set-Cookie: gr=bpo'
cookie_length = $ - cookie_bpo
cookie_btp: db 'Set-Cookie: gr=btp'
@EXPORT:
export \
unit_init, 'httpd_init', \