2023-08-26 13:58:47 -04:00
|
|
|
program main
|
2023-09-10 15:25:00 -04:00
|
|
|
use, intrinsic :: iso_c_binding
|
2023-08-26 13:58:47 -04:00
|
|
|
use www
|
2023-09-10 11:45:42 -04:00
|
|
|
use db
|
2023-08-26 13:58:47 -04:00
|
|
|
implicit none
|
|
|
|
|
|
|
|
character, dimension(:), allocatable :: form_data
|
|
|
|
character(len=32) :: index_path
|
2023-09-02 19:16:55 -04:00
|
|
|
character(len=128):: db_path
|
2023-08-26 13:58:47 -04:00
|
|
|
integer :: err, i, length
|
|
|
|
logical :: exist
|
|
|
|
|
2023-09-02 19:16:55 -04:00
|
|
|
inquire (file="debug.log", exist=exist)
|
|
|
|
if (exist) then
|
|
|
|
open (12, file="debug.log", status="old", position="append", action="write")
|
|
|
|
else
|
|
|
|
open (12, file="debug.log", status="new", action="write")
|
|
|
|
end if
|
|
|
|
|
2023-08-26 13:58:47 -04:00
|
|
|
call getarg(1, index_path)
|
|
|
|
call getarg(2, db_path)
|
|
|
|
|
|
|
|
call request(form_data, length)
|
|
|
|
|
|
|
|
if (length .gt. 0) then
|
2023-09-10 11:45:42 -04:00
|
|
|
inquire (file=db_path(:Len_Trim(db_path)), exist=exist)
|
2023-09-02 19:16:55 -04:00
|
|
|
if (.not. exist) then
|
|
|
|
call create_db(db_path)
|
2023-08-26 13:58:47 -04:00
|
|
|
end if
|
2023-09-02 19:16:55 -04:00
|
|
|
|
|
|
|
call add_user(db_path, form_data, length)
|
2023-08-26 13:58:47 -04:00
|
|
|
end if
|
|
|
|
|
2023-09-02 19:16:55 -04:00
|
|
|
call write_index(index_path)
|
|
|
|
|
2023-08-26 13:58:47 -04:00
|
|
|
if (allocated(form_data)) deallocate (form_data, stat=err)
|
|
|
|
if (err /= 0) print *, "index_html: Deallocation request denied"
|
|
|
|
|
2023-09-02 19:16:55 -04:00
|
|
|
close (unit=12)
|
2023-08-26 13:58:47 -04:00
|
|
|
contains
|
|
|
|
|
2023-09-02 19:16:55 -04:00
|
|
|
subroutine create_db(db_path)
|
2023-08-26 13:58:47 -04:00
|
|
|
character(len=128), intent(in) :: db_path
|
2023-09-10 11:45:42 -04:00
|
|
|
type(db_type) :: db
|
|
|
|
integer :: rc
|
|
|
|
|
|
|
|
rc = db_open(db, db_path(:Len_Trim(db_path)))
|
|
|
|
rc = db_create_users(db)
|
|
|
|
rc = db_close(db)
|
|
|
|
|
2023-09-02 19:16:55 -04:00
|
|
|
end subroutine create_db
|
2023-08-26 13:58:47 -04:00
|
|
|
|
2023-09-02 19:16:55 -04:00
|
|
|
subroutine add_user(db_path, request, length)
|
|
|
|
character(len=128), intent(in) :: db_path
|
2023-09-10 11:51:03 -04:00
|
|
|
character, dimension(:), allocatable, intent(in) :: request
|
2023-09-02 19:16:55 -04:00
|
|
|
integer, intent(in) :: length
|
|
|
|
|
2023-09-03 00:33:26 -04:00
|
|
|
integer :: i, j, s_idx, e_idx, username_len, password_len
|
|
|
|
character(len=24) :: username
|
|
|
|
character(len=24) :: password
|
2023-09-10 18:51:11 -04:00
|
|
|
integer :: appearance_r, appearance_g, appearance_b
|
2023-09-10 15:25:00 -04:00
|
|
|
real(kind=c_double) :: x_pos = 0.0_c_double
|
|
|
|
real(kind=c_double) :: y_pos = 0.0_c_double
|
2023-09-03 00:33:26 -04:00
|
|
|
logical :: start = .false.
|
|
|
|
|
2023-09-10 11:45:42 -04:00
|
|
|
type(db_type) :: db
|
|
|
|
integer :: rc
|
|
|
|
|
2023-09-03 00:33:26 -04:00
|
|
|
j = 1
|
2023-09-02 19:16:55 -04:00
|
|
|
get_username: do i = 1, length
|
|
|
|
if (request(i) .eq. '=') then
|
2023-09-03 00:33:26 -04:00
|
|
|
s_idx = i + 1
|
|
|
|
start = .true.
|
2023-09-02 19:16:55 -04:00
|
|
|
end if
|
|
|
|
|
|
|
|
if (request(i) .eq. '&') then
|
2023-09-03 00:33:26 -04:00
|
|
|
e_idx = i - 1
|
|
|
|
start = .false.
|
2023-09-02 19:16:55 -04:00
|
|
|
exit get_username
|
|
|
|
end if
|
2023-09-03 00:33:26 -04:00
|
|
|
|
|
|
|
if (start) then
|
|
|
|
username(j:j) = request(i + 1)
|
|
|
|
j = j + 1
|
|
|
|
end if
|
2023-09-02 19:16:55 -04:00
|
|
|
end do get_username
|
2023-09-10 11:45:42 -04:00
|
|
|
username_len = j - 2
|
2023-09-02 19:16:55 -04:00
|
|
|
|
2023-09-03 00:33:26 -04:00
|
|
|
j = 1
|
|
|
|
get_password: do i = e_idx + 2, length
|
2023-09-02 19:16:55 -04:00
|
|
|
if (request(i) .eq. '=') then
|
2023-09-03 00:33:26 -04:00
|
|
|
s_idx = i + 1
|
|
|
|
start = .true.
|
2023-09-02 19:16:55 -04:00
|
|
|
end if
|
|
|
|
|
|
|
|
if (request(i) .eq. '&') then
|
2023-09-03 00:33:26 -04:00
|
|
|
e_idx = i - 1
|
|
|
|
start = .false.
|
2023-09-02 19:16:55 -04:00
|
|
|
exit get_password
|
|
|
|
end if
|
2023-09-03 00:33:26 -04:00
|
|
|
|
|
|
|
if (start) then
|
|
|
|
password(j:j) = request(i + 1)
|
|
|
|
j = j + 1
|
|
|
|
end if
|
2023-09-02 19:16:55 -04:00
|
|
|
end do get_password
|
2023-09-10 11:45:42 -04:00
|
|
|
password_len = j - 2
|
2023-09-02 19:16:55 -04:00
|
|
|
|
2023-09-03 00:33:26 -04:00
|
|
|
get_appearance: do i = e_idx + 2, length
|
2023-09-02 19:16:55 -04:00
|
|
|
if (request(i) .eq. '=') then
|
2023-09-10 18:51:11 -04:00
|
|
|
s_idx = i + 4
|
2023-09-02 19:16:55 -04:00
|
|
|
end if
|
|
|
|
end do get_appearance
|
2023-09-10 18:51:11 -04:00
|
|
|
|
|
|
|
appearance_r = hex2int(request(s_idx), request(s_idx+1))
|
|
|
|
appearance_g = hex2int(request(s_idx+2), request(s_idx+3))
|
|
|
|
appearance_b = hex2int(request(s_idx+4), request(s_idx+5))
|
2023-09-02 19:16:55 -04:00
|
|
|
|
2023-09-10 11:45:42 -04:00
|
|
|
rc = db_open(db, db_path(:Len_Trim(db_path)))
|
2023-09-10 15:25:00 -04:00
|
|
|
rc = db_add_user(db, username(:username_len), password(:password_len), &
|
2023-09-10 18:51:11 -04:00
|
|
|
appearance_r, appearance_g, appearance_b, x_pos, y_pos, 0, time())
|
2023-09-10 11:45:42 -04:00
|
|
|
rc = db_close(db)
|
2023-09-02 19:16:55 -04:00
|
|
|
|
|
|
|
end subroutine add_user
|
2023-08-26 13:58:47 -04:00
|
|
|
|
2023-09-10 18:51:11 -04:00
|
|
|
integer function hex2int(h1, h2) result(val)
|
|
|
|
character, intent(in) :: h1
|
|
|
|
character, intent(in) :: h2
|
|
|
|
integer :: a, b
|
|
|
|
|
|
|
|
if (ichar(h1) .le. ichar('9')) then
|
|
|
|
a = ichar(h1) - ichar('0')
|
|
|
|
else
|
|
|
|
a = iand(ichar(h1), 7) + 9
|
|
|
|
end if
|
|
|
|
|
|
|
|
if (ichar(h2) .le. ichar('9')) then
|
|
|
|
b = ichar(h2) - ichar('0')
|
|
|
|
else
|
|
|
|
b = iand(ichar(h2), 7) + 9
|
|
|
|
end if
|
|
|
|
|
|
|
|
val = shiftl(a, 4) + b
|
|
|
|
end function hex2int
|
2023-09-10 20:22:32 -04:00
|
|
|
|
2023-09-10 11:45:42 -04:00
|
|
|
end program main
|