wip: convert to cmdline

This commit is contained in:
zongor 2023-09-02 22:09:31 -04:00
parent 8c76b976bb
commit e56dad405c
3 changed files with 27 additions and 24 deletions

BIN
common/sql/test.db3 Normal file

Binary file not shown.

View File

@ -21,9 +21,8 @@ program main
call request(form_data, length) call request(form_data, length)
if (length .gt. 0) then if (length .gt. 0) then
inquire (file=db_path, exist=exist) inquire (file=trim(adjustl(db_path)), exist=exist)
if (.not. exist) then if (.not. exist) then
write (12, *) trim(adjustl(db_path))
call create_db(db_path) call create_db(db_path)
end if end if
@ -42,12 +41,13 @@ contains
character(len=128), intent(in) :: db_path character(len=128), intent(in) :: db_path
character(len=:), allocatable :: command character(len=:), allocatable :: command
command = 'CREATE TABLE users ' & command = 'sqlite3 '//trim(adjustl(db_path)) &
//' ''CREATE TABLE users ' &
//'(id INTEGER PRIMARY KEY ASC, ' & //'(id INTEGER PRIMARY KEY ASC, ' &
//'username TEXT, password TEXT, ' & //'username TEXT, password TEXT, ' &
//'apperance TEXT, x_pos INTEGER, ' & //'apperance TEXT, x_pos INTEGER, ' &
//'y_pos INTEGER, last_login INTEGER, ' & //'y_pos INTEGER, last_login INTEGER, ' &
//' created INTEGER);' //' created INTEGER);'''
write (12, *) command write (12, *) command
call execute_command_line(command) call execute_command_line(command)
@ -59,50 +59,53 @@ contains
integer, intent(in) :: length integer, intent(in) :: length
character(len=:), allocatable :: command character(len=:), allocatable :: command
character(len=24) :: username
character(len=24) :: password
character(len=32) :: encrypted_password
character(len=32) :: created character(len=32) :: created
character(len=8) :: appearance integer :: i, s_u_idx, e_u_idx, s_p_idx, e_p_idx, s_a_idx
integer :: i, s_idx, e_idx
get_username: do i = 1, length get_username: do i = 1, length
if (request(i) .eq. '=') then if (request(i) .eq. '=') then
s_idx = i + 1 s_u_idx = i + 1
end if end if
if (request(i) .eq. '&') then if (request(i) .eq. '&') then
e_idx = i - 1 e_u_idx = i - 1
exit get_username exit get_username
end if end if
end do get_username end do get_username
username = transfer(request(s_idx:e_idx), username) ! username = transfer(request(s_idx:e_idx), username)
get_password: do i = e_idx + 2, length get_password: do i = e_u_idx + 2, length
if (request(i) .eq. '=') then if (request(i) .eq. '=') then
s_idx = i + 1 s_p_idx = i + 1
end if end if
if (request(i) .eq. '&') then if (request(i) .eq. '&') then
e_idx = i - 1 e_p_idx = i - 1
exit get_password exit get_password
end if end if
end do get_password end do get_password
password = transfer(request(s_idx:e_idx), password) ! password = transfer(request(s_idx:e_idx), password)
get_appearance: do i = e_idx + 2, length get_appearance: do i = e_p_idx + 2, length
if (request(i) .eq. '=') then if (request(i) .eq. '=') then
s_idx = i + 1 s_a_idx = i + 1
end if end if
end do get_appearance end do get_appearance
appearance = transfer(request(s_idx:length), appearance) ! appearance = transfer(request(s_a_idx:length), appearance)
write (created, *) time() write (created, *) time()
command = 'sqlite3 '//trim(adjustl(db_path))//' "INSERT INTO users (username, password' & command = 'sqlite3 ' &
//', apperance, x_pos, y_pos, last_login, created) VALUES ('''//username & //trim(adjustl(db_path)) &
//''', '''//trim(adjustl(password))//''', '''//trim(adjustl(appearance)) & //' "INSERT INTO users (username,password' &
//''',0, 0, 0,'//trim(adjustl(created))//');"' //',apperance,x_pos,y_pos,last_login,created) VALUES (''' &
//request(s_u_idx:e_u_idx) &
//''',''' &
//request(s_p_idx:e_p_idx) &
//''',''' &
//request(s_a_idx:length) &
//''',0,0,0,' &
//created//');"'
write (12, *) command write (12, *) command
call execute_command_line(command) call execute_command_line(command)

View File

@ -11,7 +11,7 @@ contains
integer, intent(in) :: length integer, intent(in) :: length
write (output_unit, '(A)') "HTTP/1.1 200 OK" write (output_unit, '(A)') "HTTP/1.1 200 OK"
write (output_unit, '(A)') "Server: fortran-µhttpd" write (output_unit, '(A)') "Server: fortran-micro-httpd"
write (output_unit, '(A)') "Content-Type: text/html; charset=UTF-8" write (output_unit, '(A)') "Content-Type: text/html; charset=UTF-8"
write (output_unit, '(A)', advance='no') "Content-length: " write (output_unit, '(A)', advance='no') "Content-length: "
write (output_unit, *) length write (output_unit, *) length