From 13a08c508005b9c3b280c05459e943a268b5ccc5 Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Thu, 6 May 2021 11:47:53 -0400 Subject: Fixed static file handler to allow subdirectories properly. Fixed directory file listing under Linux. Release listing now works through CGI. --- captain/requtils.f90 | 2 +- captain/response.f90 | 50 ++++++++++++++++++++++++++++++++++++++++++++ captain/template.f90 | 2 ++ captain/templates/index.html | 4 +++- captain/web.f90 | 13 +++++++----- 5 files changed, 64 insertions(+), 7 deletions(-) (limited to 'captain') diff --git a/captain/requtils.f90 b/captain/requtils.f90 index 01c4472..04ef6cf 100644 --- a/captain/requtils.f90 +++ b/captain/requtils.f90 @@ -134,7 +134,7 @@ contains resp%temporary_file = .false. call req%path_component(1, category) - call req%path_component(2, filename) + call req%path_starting_with_component(2, filename) resp%body_filename => get_special_full_filename(trim(category), trim(filename)) diff --git a/captain/response.f90 b/captain/response.f90 index 3982f1e..a4fe24e 100644 --- a/captain/response.f90 +++ b/captain/response.f90 @@ -70,6 +70,7 @@ implicit none procedure :: last_component => request_last_component procedure :: path_component => request_component procedure :: path_component_int => request_component_int + procedure :: path_starting_with_component => request_component_starting_with procedure :: component => request_component_func end type request @@ -169,6 +170,37 @@ contains end subroutine request_init + function request_component_start_location(self, i_component) result(res) + implicit none + + class(request) :: self + integer, intent(in)::i_component + integer::res + + integer::i, j, i_last, n + + res = -1 + + n = len_trim(self%location) + + i_last = 0 + j = 0 + i = index(self%location, "/") + do while(i /= i_last .and. j < i_component) + j = j + 1 + + i_last = i + i = index(self%location(i_last+1:n), "/") + i = i_last + i + end do + + ! Found + if(j == i_component) then + res = i_last + 1 + end if + + end function request_component_start_location + subroutine request_component(self, i_component, res) use logging implicit none @@ -205,6 +237,24 @@ contains end subroutine request_component + subroutine request_component_starting_with(self, i_component, res) + implicit none + + class(request) :: self + integer, intent(in)::i_component + character(*), intent(out)::res + + integer::string_index_component + + string_index_component = request_component_start_location(self, i_component) + + if(string_index_component > 0) then + res = self%location(string_index_component:len_trim(self%location)) + else + res = " " + end if + + end subroutine request_component_starting_with function request_component_int(self, i) result(res) implicit none diff --git a/captain/template.f90 b/captain/template.f90 index 9ababb2..f3f6db1 100644 --- a/captain/template.f90 +++ b/captain/template.f90 @@ -281,6 +281,8 @@ contains call self%variables(i)%assign(name, value) + call write_log(name//"=|||"//trim(value)//"|||", LOG_INFO) + end subroutine template_assign_string subroutine template_assign_logical(self, name, value) diff --git a/captain/templates/index.html b/captain/templates/index.html index 1bbf8f4..6a41d0d 100644 --- a/captain/templates/index.html +++ b/captain/templates/index.html @@ -1,5 +1,7 @@ + + {{ title }} - I'm Levitating! @@ -22,7 +24,7 @@
- {{ content }} + {{ contents }}
diff --git a/captain/web.f90 b/captain/web.f90 index ec91d88..e466c63 100644 --- a/captain/web.f90 +++ b/captain/web.f90 @@ -84,6 +84,9 @@ contains if(.not. associated(req%query_string)) then public_path = "/releases" local_path = release_dir + else if(len_trim(req%query_string) == 0) 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) @@ -115,9 +118,9 @@ contains if(trim(public_path) /= "/releases") then i = index(req%query_string, "/", back=.true.) if(i > 0) then - one_link = html_link("/releases.html?"//req%query_string(1:(i-1)), "Up a directory") + one_link => html_link("releases.html?"//req%query_string(1:(i-1)), "Up a directory") else - one_link = html_link("/releases.html", "Up a directory") + one_link => html_link("releases.html", "Up a directory") end if res = trim(res)//nl//"
  • "//one_link//"
  • " deallocate(one_link) @@ -133,7 +136,7 @@ contains subpath = trim(directories(i)) end if - one_link = html_link("/releases.html?"//trim(subpath), folder_icon//" "//trim(directories(i))) + one_link => html_link("releases.html?"//trim(subpath), folder_icon//" "//trim(directories(i))) res = trim(res)//nl//"
  • "//one_link//"
  • " deallocate(one_link) @@ -146,8 +149,8 @@ contains if(associated(files)) then do i = 1, size(files) - call combine_paths(public_path, trim(files(i)), subpath) - one_link = html_link("/releases.html?"//trim(subpath), trim(files(i))) + call combine_paths(public_path(2:len_trim(public_path)), trim(files(i)), subpath) + one_link => html_link(trim(subpath), trim(files(i))) res = trim(res)//nl//"
  • "//one_link//"
  • " deallocate(one_link) end do -- cgit v1.2.3