Update html, get rid of libraries, add args

This commit is contained in:
zongor 2023-09-02 19:16:55 -04:00
parent 9a34cf12d1
commit 8c76b976bb
5 changed files with 99 additions and 79 deletions

View File

@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
@ -6,12 +6,34 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>MMO Testing Game</title>
<style>
input,
body {
background-color: black;
color: white;
}
input:invalid {
border: 2px dashed black;
border: 2px dashed white;
}
input:valid {
border: 2px solid black;
border: 2px solid white;
}
@media screen and (prefers-color-scheme: light) {
input,
body {
background-color: white;
color: black;
}
input:invalid {
border: 2px dashed black;
}
input:valid {
border: 2px solid black;
}
}
</style>
</head>

Binary file not shown.

View File

@ -1,110 +1,111 @@
program main
use www
use sqliteff
use SM3_module, only: SM3
use iso_varying_string
use, intrinsic :: iso_c_binding, only: c_signed_char, c_size_t
implicit none
character, dimension(:), allocatable :: form_data
character(len=32) :: index_path
character(len=128) :: db_path
character(len=128):: db_path
integer :: err, i, length
logical :: exist
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
call getarg(1, index_path)
index_path = trim(index_path)
call getarg(2, db_path)
db_path = trim(db_path)
call request(form_data, length)
if (length .gt. 0) then
call createDB(db_path)
inquire(file="debug.log", exist=exist)
if (exist) then
open(12, file="debug.log", status="old", position="rewind", action="write")
else
open(12, file="debug.log", status="new", action="write")
inquire (file=db_path, exist=exist)
if (.not. exist) then
write (12, *) trim(adjustl(db_path))
call create_db(db_path)
end if
do i=1,length
write(12, '(A)', advance="NO") form_data(i)
end do
write(12, '(A)')
close(unit=12)
call write_index(index_path)
else
call write_index(index_path)
call add_user(db_path, form_data, length)
end if
call write_index(index_path)
if (allocated(form_data)) deallocate (form_data, stat=err)
if (err /= 0) print *, "index_html: Deallocation request denied"
close (unit=12)
contains
subroutine createDB(db_path)
subroutine create_db(db_path)
character(len=128), intent(in) :: db_path
type(SqliteDatabase_t) :: connection
type(SqliteStatement_t) :: statement
type(VARYING_STRING) :: remaining
integer :: status
character(len=:), allocatable :: command
status = sqliteff_open(db_path, connection)
command = 'CREATE TABLE users ' &
//'(id INTEGER PRIMARY KEY ASC, ' &
//'username TEXT, password TEXT, ' &
//'apperance TEXT, x_pos INTEGER, ' &
//'y_pos INTEGER, last_login INTEGER, ' &
//' created INTEGER);'
write (12, *) command
call execute_command_line(command)
status = sqliteff_prepare( &
connection, &
var_str("CREATE TABLE users (identifier INTEGER PRIMARY KEY ASC, " &
// "username TEXT, password TEXT, apperance TEXT, x_pos INTEGER, " &
// "y_pos INTEGER, last_login INTEGER, created INTEGER);"), &
statement, &
remaining)
end subroutine create_db
if (status .eq. SQLITE_OK) then
status = sqliteff_step(statement)
status = sqliteff_finalize(statement)
status = sqliteff_close(connection)
end if
subroutine add_user(db_path, request, length)
character(len=128), intent(in) :: db_path
character, dimension(:), allocatable, intent(in) :: request
integer, intent(in) :: length
end subroutine createDB
character(len=:), allocatable :: command
character(len=24) :: username
character(len=24) :: password
character(len=32) :: encrypted_password
character(len=32) :: created
character(len=8) :: appearance
integer :: i, s_idx, e_idx
subroutine addUser(db_path, username, password, appearance)
character(len=128), intent(in) :: db_path
character(len=24), intent(in) :: username
character(len=24), intent(in) :: password
character(len=8), intent(in) :: appearance
character(len=32) :: encrypted_password
get_username: do i = 1, length
if (request(i) .eq. '=') then
s_idx = i + 1
end if
type(SqliteDatabase_t) :: connection
type(VARYING_STRING) :: errmsg
integer :: status
integer(8) :: created
character(len=32) :: created_str
if (request(i) .eq. '&') then
e_idx = i - 1
exit get_username
end if
end do get_username
username = transfer(request(s_idx:e_idx), username)
integer(c_signed_char) :: dgst(32)
integer(c_signed_char) :: msg(25)
get_password: do i = e_idx + 2, length
if (request(i) .eq. '=') then
s_idx = i + 1
end if
msg = transfer(password, msg)
call SM3(msg, 25_c_size_t, dgst)
if (request(i) .eq. '&') then
e_idx = i - 1
exit get_password
end if
end do get_password
password = transfer(request(s_idx:e_idx), password)
write (encrypted_password, *) dgst
encrypted_password = adjustl(encrypted_password)
get_appearance: do i = e_idx + 2, length
if (request(i) .eq. '=') then
s_idx = i + 1
end if
end do get_appearance
appearance = transfer(request(s_idx:length), appearance)
created = time()
write (created_str, *) created
created_str = adjustl(created_str)
write (created, *) time()
status = sqliteff_open(db_path, connection)
command = 'sqlite3 '//trim(adjustl(db_path))//' "INSERT INTO users (username, password' &
//', apperance, x_pos, y_pos, last_login, created) VALUES ('''//username &
//''', '''//trim(adjustl(password))//''', '''//trim(adjustl(appearance)) &
//''',0, 0, 0,'//trim(adjustl(created))//');"'
write (12, *) command
call execute_command_line(command)
status = sqliteff_exec( &
connection, &
'INSERT INTO users (username, password, apperance, x_pos, y_pos, last_login, created) &
VALUES ("'//username//'", "'//encrypted_password//'", "#'//appearance//'", &
0, 0, 0, '//created_str//'");', &
errmsg)
status = sqliteff_close(connection)
end subroutine addUser
end subroutine add_user
end program main

View File

@ -16,6 +16,3 @@ implicit-external = false
implicit-typing = false
source-form = "free"
[dependencies]
iso_varying_string.git = "https://gitlab.com/everythingfunctional/iso_varying_string"
sqliteff.git = "https://gitlab.com/everythingfunctional/sqliteff"
sm3-fortran.git = "https://github.com/zoziha/SM3-Fortran"

View File

@ -1,2 +1,2 @@
#!/bin/sh
listen1 'tcp!*!1234' ./build/gfortran_D153B38149EACCAC/app/fortran-micro-httpd ../../common/html/index.html ../../common/sql/test.db3
listen1 'tcp!*!1234' ~/.local/bin/fortran-micro-httpd ../../common/html/index.html ../../common/sql/test.db3