From 8c76b976bb737821d05cbd744a045d8e09fcf41d Mon Sep 17 00:00:00 2001 From: zongor Date: Sat, 2 Sep 2023 19:16:55 -0400 Subject: [PATCH] Update html, get rid of libraries, add args --- common/html/index.html | 28 +++++++- common/sql/test.db3 | Bin 8192 -> 0 bytes fortran/www/app/main.f90 | 145 ++++++++++++++++++++------------------- fortran/www/fpm.toml | 3 - fortran/www/test.sh | 2 +- 5 files changed, 99 insertions(+), 79 deletions(-) delete mode 100644 common/sql/test.db3 diff --git a/common/html/index.html b/common/html/index.html index 609620c..2d19955 100644 --- a/common/html/index.html +++ b/common/html/index.html @@ -1,4 +1,4 @@ - + @@ -6,12 +6,34 @@ MMO Testing Game diff --git a/common/sql/test.db3 b/common/sql/test.db3 deleted file mode 100644 index d3e3473bb7e8bc6d02debd31ee863a6f72ea259f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8192 zcmeI#KT88K7zXg92u@X9-fQqSp*|kP>@uC2+kvl88F$H})HtI}GCF ztUNFI!;`#Z_-$F-&TU}Yv~Ftx9gDG$Qk)S9A!MARI8*g`Cxy88`L~kd=;UKBcFFyT zhyw)y2tWV=5P$##AOHafKmY;|_=5s(r*b#TGWmWV%tOsjo}C|-(X>>BR-}vbxuW5S z4s69uup7&cX4hI>sFH5V*;P?4=~6AJSWNSwwJ}>Jt?qPAo$>y;b=6liUB}Ke>va9H z>RO*3%jxxJtc?$=x_z|Gcgxzb30$Rv!~Sm`Km8~OKmY;|fB*y_009U<00Izz00jQA Fz$ab(MXdk; diff --git a/fortran/www/app/main.f90 b/fortran/www/app/main.f90 index f456984..884d6bf 100644 --- a/fortran/www/app/main.f90 +++ b/fortran/www/app/main.f90 @@ -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 diff --git a/fortran/www/fpm.toml b/fortran/www/fpm.toml index f1ad55f..619d2ce 100644 --- a/fortran/www/fpm.toml +++ b/fortran/www/fpm.toml @@ -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" diff --git a/fortran/www/test.sh b/fortran/www/test.sh index 298f003..2cfcf9f 100755 --- a/fortran/www/test.sh +++ b/fortran/www/test.sh @@ -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