aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2021-05-06 11:47:53 -0400
committerJeffrey Armstrong <jeff@approximatrix.com>2021-05-06 11:47:53 -0400
commit13a08c508005b9c3b280c05459e943a268b5ccc5 (patch)
tree246029b796ea10d7da11b7032970501bfa605589
parentb9cac9bb26fe388abff34fa4fc562b0804cabb2e (diff)
downloadlevitating-13a08c508005b9c3b280c05459e943a268b5ccc5.tar.gz
levitating-13a08c508005b9c3b280c05459e943a268b5ccc5.zip
Fixed static file handler to allow subdirectories properly. Fixed directory file listing under Linux. Release listing now works through CGI.
-rw-r--r--captain/requtils.f902
-rw-r--r--captain/response.f9050
-rw-r--r--captain/template.f902
-rw-r--r--captain/templates/index.html4
-rw-r--r--captain/web.f9013
-rw-r--r--common/utilities.F9011
6 files changed, 74 insertions, 8 deletions
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 @@
+<!DOCTYPE html>
<html>
<head>
+ <meta charset="utf-8"/>
<title>{{ title }} - I'm Levitating!</title>
<link rel="stylsheet" href="/static/style.css" />
</head>
@@ -22,7 +24,7 @@
<div class="content">
- {{ content }}
+ {{ contents }}
</div>
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//"<li>"//one_link//"</li>"
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//"<li>"//one_link//"</li>"
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//"<li>"//one_link//"</li>"
deallocate(one_link)
end do
diff --git a/common/utilities.F90 b/common/utilities.F90
index 670d48f..e8bceff 100644
--- a/common/utilities.F90
+++ b/common/utilities.F90
@@ -391,6 +391,7 @@ contains
end function get_directories_in_directory
function get_files_in_directory(directory) result(res)
+ use logging
implicit none
character(*), intent(in)::directory
@@ -398,6 +399,7 @@ contains
character(80)::line
character(len=:), pointer::tempfile
+ logical::skip_first
logical, dimension(:), allocatable::is_real_file
integer::unum, ierr, i, n, j
@@ -428,6 +430,8 @@ contains
i = i + 1
if(len_trim(line) > 0 .and. line(1:1) == '-' .and. line(1:6) /= "total ") then
is_real_file(i) = .TRUE.
+ else if(line(1:6) == "total ") then
+ skip_first = .TRUE.
end if
read(unum, '(A)', iostat=ierr) line
end do
@@ -448,7 +452,12 @@ contains
! Now we can read files
i = 0
- j = 0
+ if(skip_first) then
+ j = 1
+ else
+ j = 0
+ end if
+
read(unum, '(A)', iostat=ierr) line
do while(ierr == 0 .and. i < n)
j = j + 1