From 2fb449d28b45bec808f8c50cad56957d463e3a49 Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Wed, 5 May 2021 15:57:22 -0400 Subject: Fixed inquire statements. Added releases support, in theory, to the web handler. --- captain/requtils.f90 | 4 +- captain/web.f90 | 178 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 179 insertions(+), 3 deletions(-) (limited to 'captain') diff --git a/captain/requtils.f90 b/captain/requtils.f90 index 01c4472..23df37a 100644 --- a/captain/requtils.f90 +++ b/captain/requtils.f90 @@ -52,7 +52,7 @@ contains else - inquire(file=actual_filename, exist=exists) + inquire(name=actual_filename, exist=exists) if(exists) then call get_one_line_output_shell_command("mimetype -b "//trim(actual_filename), mimetype) @@ -138,7 +138,7 @@ contains resp%body_filename => get_special_full_filename(trim(category), trim(filename)) - inquire(file=resp%body_filename, exist=exists) + inquire(name=resp%body_filename, exist=exists) if(.not. exists) then resp%code = notfound_code(req) diff --git a/captain/web.f90 b/captain/web.f90 index 0899159..c0fdbf0 100644 --- a/captain/web.f90 +++ b/captain/web.f90 @@ -49,14 +49,190 @@ contains deallocate(script_name) end subroutine build_request_object + + function html_link(link, label) result(res) + implicit none + + character(*), intent(in)::link, label + character(len=:), pointer::res + integer::nl + + + nl = len_trim(link) + len_trim(label) + len('') + allocate(character(len=nl)::res) + res = ''//trim(label)//'' + + end function html_link + + function generate_releases_html(req) result(res) + use utilities + use server_response + use config + implicit none + + type(request), intent(in)::req + character(len=:), pointer::res + character(len=DIR_LIST_STRING_LENGTH), dimension(:), pointer::directories + character(len=DIR_LIST_STRING_LENGTH), dimension(:), pointer::files + + character(1024)::public_path, local_path, subpath + integer::allocation_size, i + character(1)::nl = new_line(' ') + character(4)::folder_icon = char(240)//char(159)//char(147)//char(129) + character(len=:), pointer::one_link + + if(.not. associated(req%query_string)) then + public_path = "/releases" + local_path = release_dir + else + call combine_paths("/releases", req%query_string, public_path) + call combine_paths(release_dir, req%query_string, local_path) + end if + + res => null() + + ! Easy safety check - no relative paths + if(index(local_path, '..') > 0) then + allocate(character(len=64)::res) + res = "None Found" + return + end if + + directories => get_directories_in_directory(local_path) + files => get_files_in_directory(local_path) + + allocation_size = 1024 + if(associated(directories)) then + allocation_size = allocation_size + 2 * size(directories) * (DIR_LIST_STRING_LENGTH+32) + end if + if(associated(files)) then + allocation_size = allocation_size + 2 * size(files) * (DIR_LIST_STRING_LENGTH+32) + end if + allocate(character(len=allocation_size) :: res) + res = "

Listing for "//trim(public_path)//"

"//nl//"