Add allowlist functionality, rudimentary
This commit is contained in:
parent
99667caac8
commit
760646efd7
1
Gemfile
1
Gemfile
@ -7,6 +7,7 @@ gemspec
|
|||||||
|
|
||||||
gem "rake", "~> 13.0"
|
gem "rake", "~> 13.0"
|
||||||
gem "rackup"
|
gem "rackup"
|
||||||
|
gem "rubytree"
|
||||||
|
|
||||||
gem "rspec", "~> 3.0"
|
gem "rspec", "~> 3.0"
|
||||||
|
|
||||||
|
@ -53,6 +53,8 @@ GEM
|
|||||||
rubocop (>= 1.7.0, < 2.0)
|
rubocop (>= 1.7.0, < 2.0)
|
||||||
rubocop-ast (>= 0.4.0)
|
rubocop-ast (>= 0.4.0)
|
||||||
ruby-progressbar (1.13.0)
|
ruby-progressbar (1.13.0)
|
||||||
|
rubytree (2.0.2)
|
||||||
|
json (~> 2.0, > 2.3.1)
|
||||||
standard (1.30.1)
|
standard (1.30.1)
|
||||||
language_server-protocol (~> 3.17.0.2)
|
language_server-protocol (~> 3.17.0.2)
|
||||||
lint_roller (~> 1.0)
|
lint_roller (~> 1.0)
|
||||||
@ -75,6 +77,7 @@ DEPENDENCIES
|
|||||||
rackup
|
rackup
|
||||||
rake (~> 13.0)
|
rake (~> 13.0)
|
||||||
rspec (~> 3.0)
|
rspec (~> 3.0)
|
||||||
|
rubytree
|
||||||
skeksis!
|
skeksis!
|
||||||
standard (~> 1.3)
|
standard (~> 1.3)
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
require 'skeksis'
|
require 'skeksis'
|
||||||
|
require 'rubytree'
|
||||||
|
|
||||||
class SkeksisApp
|
class SkeksisApp
|
||||||
def initialize
|
def initialize
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "yaml"
|
require "yaml"
|
||||||
|
require "tree"
|
||||||
|
|
||||||
require_relative "skeksis/version"
|
require_relative "skeksis/version"
|
||||||
require_relative "skeksis/parser"
|
require_relative "skeksis/parser"
|
||||||
@ -39,9 +40,44 @@ module Skeksis
|
|||||||
config = YAML.load(File.read("config.yml"))
|
config = YAML.load(File.read("config.yml"))
|
||||||
@gemini_uri = config['skeksis_config']['gemini_uri']
|
@gemini_uri = config['skeksis_config']['gemini_uri']
|
||||||
@serve_dir = config['skeksis_config']['serve_dir']
|
@serve_dir = config['skeksis_config']['serve_dir']
|
||||||
|
@allowlist = Tree::TreeNode.new("ROOT", false)
|
||||||
|
|
||||||
|
build_allowlist(@allowlist, @serve_dir)
|
||||||
|
|
||||||
|
puts @allowlist.to_h
|
||||||
|
end
|
||||||
|
|
||||||
|
def build_allowlist(tree, path)
|
||||||
|
Dir.each_child(path) do |child|
|
||||||
|
full_path = Pathname.new(path).join(child)
|
||||||
|
|
||||||
|
if child == ".serve_ok"
|
||||||
|
tree.content = true
|
||||||
|
end
|
||||||
|
|
||||||
|
serve_ok = false
|
||||||
|
if Dir.exist?(full_path)
|
||||||
|
Dir.each_child(full_path) do |subchild|
|
||||||
|
if subchild == ".serve_ok"
|
||||||
|
serve_ok = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
child_node = Tree::TreeNode.new(child, serve_ok)
|
||||||
|
tree << child_node
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def query(path, env)
|
def query(path, env)
|
||||||
|
query_path = Pathname.new(path).each_filename.to_a
|
||||||
|
|
||||||
|
@allowlist.children do |child|
|
||||||
|
if child.name == query_path[0] and child.content == false
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Chomps the first / and builds path
|
# Chomps the first / and builds path
|
||||||
full_path = Pathname.new(@serve_dir) + path[1..-1]
|
full_path = Pathname.new(@serve_dir) + path[1..-1]
|
||||||
puts full_path.to_s
|
puts full_path.to_s
|
||||||
@ -83,12 +119,19 @@ module Skeksis
|
|||||||
end
|
end
|
||||||
|
|
||||||
listing = Dir.each_child(path).map do |i|
|
listing = Dir.each_child(path).map do |i|
|
||||||
if i == ".directory-listing-ok"
|
if i == ".directory-listing-ok" or i == ".serve_ok"
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
path = Pathname.new(env['PATH_INFO']).join(i)
|
child_path = Pathname.new(path).join(i)
|
||||||
uri = URI::HTTP.build(host: http.host, port: http.port, path: path.to_s)
|
puts child_path
|
||||||
|
|
||||||
|
if Dir.exist?(child_path) and not Dir.each_child(child_path).include?('.serve_ok')
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
uri_path = Pathname.new(env['PATH_INFO']).join(i)
|
||||||
|
uri = URI::HTTP.build(host: http.host, port: http.port, path: uri_path.to_s)
|
||||||
"<a href=\"#{uri.to_s}\">#{i}</a><br>"
|
"<a href=\"#{uri.to_s}\">#{i}</a><br>"
|
||||||
end.join("\n")
|
end.join("\n")
|
||||||
[Header + listing + Footer]
|
[Header + listing + Footer]
|
||||||
|
Loading…
Reference in New Issue
Block a user