diff options
author | Jeffrey Armstrong <jeff@approximatrix.com> | 2021-03-30 11:23:27 -0400 |
---|---|---|
committer | Jeffrey Armstrong <jeff@approximatrix.com> | 2021-03-30 11:23:27 -0400 |
commit | 8da227ca130355332fc92935cfbabc87bd0db078 (patch) | |
tree | 8831aad73c70663dbcfca6b34bd0916ef16d6337 /captain | |
parent | fbfd194941de48affaa92522ceaff97010abc1c2 (diff) | |
download | levitating-8da227ca130355332fc92935cfbabc87bd0db078.tar.gz levitating-8da227ca130355332fc92935cfbabc87bd0db078.zip |
Storing an example site. Added support for just plain old static files and favicons
Diffstat (limited to 'captain')
-rw-r--r-- | captain/config.f90 | 11 | ||||
-rw-r--r-- | captain/example/levitating.conf | 20 | ||||
-rw-r--r-- | captain/example/levitating.xinetd | 16 | ||||
-rw-r--r-- | captain/example/static/favicon.txt | 1 | ||||
-rw-r--r-- | captain/external.f90 | 21 | ||||
-rw-r--r-- | captain/levitating-captain.prj | 83 | ||||
-rw-r--r-- | captain/response.f90 | 27 |
7 files changed, 145 insertions, 34 deletions
diff --git a/captain/config.f90 b/captain/config.f90 index a56f757..5ab5930 100644 --- a/captain/config.f90 +++ b/captain/config.f90 @@ -28,6 +28,11 @@ implicit none character(*), parameter::UPLOAD_DIRECTORY_VARIABLE = "upload-directory" character(1024)::upload_dir + character(*), parameter::RESULTS_DIRECTORY_VARIABLE = "results-directory" + character(1024)::results_dir + + character(*), parameter::STATIC_DIRECTORY_VARIABLE = "static-directory" + character(1024)::static_dir contains @@ -98,6 +103,12 @@ contains else if(cvariable == UPLOAD_DIRECTORY_VARIABLE) then upload_dir = cvalue + + else if(cvariable == RESULTS_DIRECTORY_VARIABLE) then + results_dir = cvalue + + else if(cvariable == STATIC_DIRECTORY_VARIABLE) then + static_dir = cvalue end if diff --git a/captain/example/levitating.conf b/captain/example/levitating.conf new file mode 100644 index 0000000..a43ea8d --- /dev/null +++ b/captain/example/levitating.conf @@ -0,0 +1,20 @@ + +template-directory = /home/jeff/Workspace/levitating/captain/templates + +database = /home/jeff/Workspace/levitating/captain/example/store.db + +log-filename = /tmp/levitating.log + +project = misc-build + +description = A builder for stuff + +public-cert = /home/jeff/Workspace/levitating/captain/example/pub.crt + +private-cert = /home/jeff/Workspace/levitating/captain/example/priv.key + +uploads-directory = /home/jeff/Workspace/levitating/captain/example/uploads + +results-directory = /home/jeff/Workspace/levitating/captain/example/results + +static-directory = /home/jeff/Workspace/levitating/captain/example/static diff --git a/captain/example/levitating.xinetd b/captain/example/levitating.xinetd new file mode 100644 index 0000000..3c78286 --- /dev/null +++ b/captain/example/levitating.xinetd @@ -0,0 +1,16 @@ +# default: off +# description: An internal xinetd service, listing active services. + +service gemini +{ + type = UNLISTED + port = 1965 + socket_type = stream + protocol = tcp + wait = no + user = jeff + disable = no + only_from = 127.0.0.1 + server = /home/jeff/Workspace/levitating/captain/levitating-captain + server_args = -g -c /home/jeff/Workspace/levitating/captain/example/levitating.conf +} diff --git a/captain/example/static/favicon.txt b/captain/example/static/favicon.txt new file mode 100644 index 0000000..0c5326b --- /dev/null +++ b/captain/example/static/favicon.txt @@ -0,0 +1 @@ +🎈 diff --git a/captain/external.f90 b/captain/external.f90 index 146060f..5e64bab 100644 --- a/captain/external.f90 +++ b/captain/external.f90 @@ -108,6 +108,7 @@ contains function is_request_static(req) use server_response + use logging implicit none class(request), intent(in)::req @@ -116,7 +117,13 @@ contains call req%path_component(1, first) - is_request_static = ((first == "releases") .or. (first == "uploads")) + call write_log("Static check: "//trim(first)) + + is_request_static = ((trim(first) == "releases") .or. & + (trim(first) == "uploads") .or. & + (trim(first) == "results") .or. & + (trim(first) == "static") .or. & + (trim(first) == "favicon.txt")) end function is_request_static @@ -138,17 +145,29 @@ contains call req%path_component(1, category) call req%last_component(filename) + call write_log("Catgeory: "//trim(category)//" File: "//trim(filename)) + if(category == "releases") then allocate(character(len=(len_trim(release_dir)+len_trim(filename)+1)) :: resp%body_filename) call combine_paths(release_dir, filename, resp%body_filename) else if(category == "uploads") then allocate(character(len=(len_trim(release_dir)+len_trim(filename)+1)) :: resp%body_filename) call combine_paths(release_dir, filename, resp%body_filename) + else if(category == "results") then + allocate(character(len=(len_trim(results_dir)+len_trim(filename)+1)) :: resp%body_filename) + call combine_paths(results_dir, filename, resp%body_filename) + else if(category == "static") then + allocate(character(len=(len_trim(static_dir)+len_trim(filename)+1)) :: resp%body_filename) + call combine_paths(static_dir, filename, resp%body_filename) + else if(category == "favicon.txt") then + allocate(character(len=(len_trim(static_dir)+len_trim(filename)+1)) :: resp%body_filename) + call combine_paths(static_dir, filename, resp%body_filename) end if inquire(file=resp%body_filename, exist=exists) if(.not. exists) then resp%code = GEMINI_CODE_PERMFAIL + call write_log("File did not exist: "//resp%body_filename) else resp%code = GEMINI_CODE_SUCCESS diff --git a/captain/levitating-captain.prj b/captain/levitating-captain.prj index 8618272..1fe6cc8 100644 --- a/captain/levitating-captain.prj +++ b/captain/levitating-captain.prj @@ -4,67 +4,96 @@ "Folders":[], "Name":"+common", "Files":[{ - "filename":"..\\common\\jessl.f90", + "filename":"../common/jessl.f90", "enabled":"1" },{ - "filename":"..\\common\\network.F90", + "filename":"../common/network.F90", "enabled":"1" },{ - "filename":"..\\common\\protocol.f90", + "filename":"../common/protocol.f90", "enabled":"1" },{ - "filename":"..\\common\\request.f90", + "filename":"../common/request.f90", "enabled":"1" },{ - "filename":"..\\common\\utilities.F90", - "enabled":"1" + "filename":"../common/utilities.F90", + "enabled":"1", + "panel":1, + "open":"1" },{ - "filename":"..\\common\\wsa.f90", + "filename":"../common/wsa.f90", "enabled":"0" }] },{ "Folders":[], + "Name":"+example", + "Files":[{ + "filename":"example/levitating.conf", + "enabled":"1", + "panel":1, + "open":"1" + }] + },{ + "Folders":[], "Name":"+sql", "Files":[{ - "filename":".\\sql\\create.sql", + "filename":"sql/create.sql", "enabled":"1" }] },{ "Folders":[], "Name":"+templates", "Files":[{ - "filename":".\\templates\\index.gmi", - "enabled":"1" + "filename":"templates/index.gmi", + "enabled":"1", + "panel":1, + "open":"1" }] }], "Name":"+levitating-captain (levitating-captain)", "Files":[{ - "filename":".\\captian.f90", - "enabled":"1" + "filename":"captian.f90", + "enabled":"1", + "panel":1, + "open":"1" },{ - "filename":".\\config.f90", - "enabled":"1" + "filename":"config.f90", + "enabled":"1", + "panel":1, + "open":"1" },{ - "filename":".\\db.f90", - "enabled":"1" + "filename":"db.f90", + "enabled":"1", + "panel":1, + "open":"1" },{ - "filename":".\\external.f90", - "enabled":"1" + "filename":"external.f90", + "enabled":"1", + "panel":1, + "open":"1" },{ - "filename":".\\gemini.f90", - "enabled":"1" + "filename":"gemini.f90", + "enabled":"1", + "panel":1, + "open":"1" },{ - "filename":".\\log.f90", - "enabled":"1" + "filename":"log.f90", + "enabled":"1", + "panel":1, + "open":"1" },{ - "filename":".\\response.f90", - "enabled":"1" + "filename":"response.f90", + "enabled":"1", + "panel":1, + "open":"1" },{ - "filename":".\\sqlite.f90", + "filename":"sqlite.f90", "enabled":"1" },{ - "filename":".\\template.f90", - "enabled":"1" + "filename":"template.f90", + "enabled":"1", + "panel":1, + "open":"1" }] }, "Name":"levitating-captain (levitating-captain)", diff --git a/captain/response.f90 b/captain/response.f90 index efc8655..5463978 100644 --- a/captain/response.f90 +++ b/captain/response.f90 @@ -90,6 +90,7 @@ contains end subroutine request_init subroutine request_component(self, i_component, res) + use logging implicit none class(request) :: self @@ -107,8 +108,10 @@ contains do while(i /= i_last .and. j < i_component) j = j + 1 + call write_log("RC: "//self%location(i:n)) + i_last = i - i = index(self%location(i_last:n), "/") + i = index(self%location(i_last+1:n), "/") i = i_last + i end do @@ -116,6 +119,7 @@ contains if(j == i_component) then if(i == i_last) then res = self%location(i_last+1:n) + call write_log("Last! "//trim(res)) else res = self%location(i_last+1:i-1) end if @@ -129,14 +133,25 @@ contains class(request) :: self character(*), intent(out)::res - integer::i - - i = index(self%location, "/", back=.true.) + integer::i, n - if(i == len_trim(self%location)) then + n = len_trim(self%location) + if(n == 1) then res = "/" else - res = self%location((i+1):len_trim(res)) + + i = index(self%location, "/", back=.true.) + + if(i == n) then + i = index(self%location(1:n-1), "/", back=.true.) + if(i > 0) then + res = self%location(i+1:n-1) + else + res = "/" + end if + else + res = self%location((i+1):n) + end if end if end subroutine request_last_component |