Update html, get rid of libraries, add args
This commit is contained in:
parent
9a34cf12d1
commit
8c76b976bb
|
@ -1,4 +1,4 @@
|
||||||
<!DOCTYPE html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
|
@ -6,6 +6,27 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>MMO Testing Game</title>
|
<title>MMO Testing Game</title>
|
||||||
<style>
|
<style>
|
||||||
|
input,
|
||||||
|
body {
|
||||||
|
background-color: black;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
input:invalid {
|
||||||
|
border: 2px dashed white;
|
||||||
|
}
|
||||||
|
|
||||||
|
input:valid {
|
||||||
|
border: 2px solid white;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (prefers-color-scheme: light) {
|
||||||
|
input,
|
||||||
|
body {
|
||||||
|
background-color: white;
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
input:invalid {
|
input:invalid {
|
||||||
border: 2px dashed black;
|
border: 2px dashed black;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +34,7 @@
|
||||||
input:valid {
|
input:valid {
|
||||||
border: 2px solid black;
|
border: 2px solid black;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
Binary file not shown.
|
@ -1,110 +1,111 @@
|
||||||
program main
|
program main
|
||||||
use www
|
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
|
implicit none
|
||||||
|
|
||||||
character, dimension(:), allocatable :: form_data
|
character, dimension(:), allocatable :: form_data
|
||||||
character(len=32) :: index_path
|
character(len=32) :: index_path
|
||||||
character(len=128) :: db_path
|
character(len=128):: db_path
|
||||||
integer :: err, i, length
|
integer :: err, i, length
|
||||||
logical :: exist
|
logical :: exist
|
||||||
|
|
||||||
call getarg(1, index_path)
|
inquire (file="debug.log", exist=exist)
|
||||||
index_path = trim(index_path)
|
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)
|
||||||
call getarg(2, db_path)
|
call getarg(2, db_path)
|
||||||
db_path = trim(db_path)
|
|
||||||
|
|
||||||
call request(form_data, length)
|
call request(form_data, length)
|
||||||
|
|
||||||
if (length .gt. 0) then
|
if (length .gt. 0) then
|
||||||
call createDB(db_path)
|
inquire (file=db_path, exist=exist)
|
||||||
inquire(file="debug.log", exist=exist)
|
if (.not. exist) then
|
||||||
if (exist) then
|
write (12, *) trim(adjustl(db_path))
|
||||||
open(12, file="debug.log", status="old", position="rewind", action="write")
|
call create_db(db_path)
|
||||||
else
|
|
||||||
open(12, file="debug.log", status="new", action="write")
|
|
||||||
end if
|
end if
|
||||||
do i=1,length
|
|
||||||
write(12, '(A)', advance="NO") form_data(i)
|
call add_user(db_path, form_data, length)
|
||||||
end do
|
|
||||||
write(12, '(A)')
|
|
||||||
close(unit=12)
|
|
||||||
call write_index(index_path)
|
|
||||||
else
|
|
||||||
call write_index(index_path)
|
|
||||||
end if
|
end if
|
||||||
|
|
||||||
|
call write_index(index_path)
|
||||||
|
|
||||||
if (allocated(form_data)) deallocate (form_data, stat=err)
|
if (allocated(form_data)) deallocate (form_data, stat=err)
|
||||||
if (err /= 0) print *, "index_html: Deallocation request denied"
|
if (err /= 0) print *, "index_html: Deallocation request denied"
|
||||||
|
|
||||||
|
close (unit=12)
|
||||||
contains
|
contains
|
||||||
|
|
||||||
subroutine createDB(db_path)
|
subroutine create_db(db_path)
|
||||||
character(len=128), intent(in) :: db_path
|
character(len=128), intent(in) :: db_path
|
||||||
type(SqliteDatabase_t) :: connection
|
character(len=:), allocatable :: command
|
||||||
type(SqliteStatement_t) :: statement
|
|
||||||
type(VARYING_STRING) :: remaining
|
|
||||||
integer :: status
|
|
||||||
|
|
||||||
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( &
|
end subroutine create_db
|
||||||
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)
|
|
||||||
|
|
||||||
if (status .eq. SQLITE_OK) then
|
subroutine add_user(db_path, request, length)
|
||||||
status = sqliteff_step(statement)
|
character(len=128), intent(in) :: db_path
|
||||||
status = sqliteff_finalize(statement)
|
character, dimension(:), allocatable, intent(in) :: request
|
||||||
status = sqliteff_close(connection)
|
integer, intent(in) :: length
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
get_username: do i = 1, length
|
||||||
|
if (request(i) .eq. '=') then
|
||||||
|
s_idx = i + 1
|
||||||
end if
|
end if
|
||||||
|
|
||||||
end subroutine createDB
|
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)
|
||||||
|
|
||||||
subroutine addUser(db_path, username, password, appearance)
|
get_password: do i = e_idx + 2, length
|
||||||
character(len=128), intent(in) :: db_path
|
if (request(i) .eq. '=') then
|
||||||
character(len=24), intent(in) :: username
|
s_idx = i + 1
|
||||||
character(len=24), intent(in) :: password
|
end if
|
||||||
character(len=8), intent(in) :: appearance
|
|
||||||
character(len=32) :: encrypted_password
|
|
||||||
|
|
||||||
type(SqliteDatabase_t) :: connection
|
if (request(i) .eq. '&') then
|
||||||
type(VARYING_STRING) :: errmsg
|
e_idx = i - 1
|
||||||
integer :: status
|
exit get_password
|
||||||
integer(8) :: created
|
end if
|
||||||
character(len=32) :: created_str
|
end do get_password
|
||||||
|
password = transfer(request(s_idx:e_idx), password)
|
||||||
|
|
||||||
integer(c_signed_char) :: dgst(32)
|
get_appearance: do i = e_idx + 2, length
|
||||||
integer(c_signed_char) :: msg(25)
|
if (request(i) .eq. '=') then
|
||||||
|
s_idx = i + 1
|
||||||
|
end if
|
||||||
|
end do get_appearance
|
||||||
|
appearance = transfer(request(s_idx:length), appearance)
|
||||||
|
|
||||||
msg = transfer(password, msg)
|
write (created, *) time()
|
||||||
call SM3(msg, 25_c_size_t, dgst)
|
|
||||||
|
|
||||||
write (encrypted_password, *) dgst
|
command = 'sqlite3 '//trim(adjustl(db_path))//' "INSERT INTO users (username, password' &
|
||||||
encrypted_password = adjustl(encrypted_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)
|
||||||
|
|
||||||
created = time()
|
end subroutine add_user
|
||||||
write (created_str, *) created
|
|
||||||
created_str = adjustl(created_str)
|
|
||||||
|
|
||||||
status = sqliteff_open(db_path, connection)
|
|
||||||
|
|
||||||
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 program main
|
end program main
|
||||||
|
|
|
@ -16,6 +16,3 @@ implicit-external = false
|
||||||
implicit-typing = false
|
implicit-typing = false
|
||||||
source-form = "free"
|
source-form = "free"
|
||||||
[dependencies]
|
[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"
|
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
#!/bin/sh
|
#!/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
|
||||||
|
|
Loading…
Reference in New Issue