Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: knora upload scripts and configs #174

Merged
merged 18 commits into from
Jun 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ COPY . /sipi
RUN cd /sipi/build && \
make install && \
mkdir /sipi/images && \
mkdir /sipi/images/knora && \
mkdir /sipi/cache && \
rm -rf /sipi/vendor && \
rm -rf /sipi/build && \
Expand Down
9 changes: 9 additions & 0 deletions config/sipi.config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ sipi = {
--
subdir_levels = 1,

--
-- if subdir_levels is > 0 and if prefix_as_path is true, all prefixes will be
-- regarded as directories under imgroot. Thus, the subdirs 'A'-'Z' will be
-- created in these directories for the prefixes. However, it may make sense
-- for certain prefixes *not* to use subdirs. A list of these prefix-directories
-- can be given with this configuration parameter.
--
subdir_excludes = { "tmp", "thumb"},

--
-- Lua script which is executed on initialization of the Lua interpreter
--
Expand Down
102 changes: 54 additions & 48 deletions config/sipi.init-knora-test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,65 +62,71 @@ function pre_flight(prefix,identifier,cookie)
end


-- comment this in if you do not want to do a preflight request
-- print("ignoring permissions")
-- do return 'allow', filepath end
if prefix == "knora" then

knora_cookie_header = nil
knora_cookie_header = nil

if cookie ~='' then
if cookie ~='' then

-- tries to extract the Knora session id from the cookie:
-- gets the digits between "sid=" and the closing ";" (only given in case of several key value pairs)
-- returns nil if it cannot find it
session_id = get_session_id(cookie)
-- tries to extract the Knora session id from the cookie:
-- gets the digits between "sid=" and the closing ";" (only given in case of several key value pairs)
-- returns nil if it cannot find it
session_id = get_session_id(cookie)

if session_id == nil then
-- no session_id could be extracted
print("cookie key is invalid")
else
knora_cookie_header = { Cookie = "KnoraAuthentication=" .. session_id }
if session_id == nil then
-- no session_id could be extracted
print("cookie key is invalid: " .. cookie)
else
knora_cookie_header = { Cookie = "KnoraAuthentication=" .. session_id }
end
end
end

knora_url = 'http://' .. config.knora_path .. ':' .. config.knora_port .. '/v1/files/' .. identifier
knora_url = 'http://' .. config.knora_path .. ':' .. config.knora_port .. '/v1/files/' .. identifier

success, result = server.http("GET", knora_url, knora_cookie_header, 5000)
if not success then
server.log("server.http() failed: " .. result, server.loglevel.LOG_ERR)
return 'deny'
end
--print("knora_url: " .. knora_url)

if result.status_code ~= 200 then
server.log("Knora returned HTTP status code " .. result.status_code)
server.log(result.body)
return 'deny'
end
success, result = server.http("GET", knora_url, knora_cookie_header, 5000)

success, response_json = server.json_to_table(result.body)
if not success then
server.log("server.json_to_table() failed: " .. response_json, server.loglevel.LOG_ERR)
return 'deny'
end
-- check HTTP request was successful
if not success then
server.log("Server.http() failed: " .. result, server.loglevel.LOG_ERR)
return 'deny'
end

if response_json.status ~= 0 then
-- something went wrong with the request, Knora returned a non zero status
return 'deny'
end
if result.status_code ~= 200 then
server.log("Knora returned HTTP status code " .. result.status_code)
server.log(result.body)
return 'deny'
end

if response_json.permissionCode == 0 then
-- no view permission on file
return 'deny'
elseif response_json.permissionCode == 1 then
-- restricted view permission on file
-- either watermark or size (depends on project, should be returned with permission code by Sipi responder)
return 'restrict:size=' .. config.thumb_size, filepath
elseif response_json.permissionCode >= 2 then
-- full view permissions on file
return 'allow', filepath
else
-- invalid permission code
return 'deny'
success, response_json = server.json_to_table(result.body)
if not success then
server.log("Server.http() failed: " .. response_json, server.loglevel.LOG_ERR)
return 'deny'
end

--print("status: " .. response_json.status)
--print("permission code: " .. response_json.permissionCode)

if response_json.status ~= 0 then
-- something went wrong with the request, Knora returned a non zero status
return 'deny'
end

if response_json.permissionCode == 0 then
-- no view permission on file
return 'deny'
elseif response_json.permissionCode == 1 then
-- restricted view permission on file
-- either watermark or size (depends on project, should be returned with permission code by Sipi responder)
return 'restrict:size=' .. config.thumb_size, filepath
elseif response_json.permissionCode >= 2 then
-- full view permissions on file
return 'allow', filepath
else
-- invalid permission code
return 'deny'
end
end

end
Expand Down
105 changes: 52 additions & 53 deletions config/sipi.init-knora.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,72 +56,71 @@ function pre_flight(prefix, identifier, cookie)
end


-- comment this in if you do not want to do a preflight request
-- print("ignoring permissions")
-- do return 'allow', filepath end
if prefix == "knora" then

knora_cookie_header = nil
knora_cookie_header = nil

if cookie ~='' then
if cookie ~='' then

-- tries to extract the Knora session id from the cookie:
-- gets the digits between "sid=" and the closing ";" (only given in case of several key value pairs)
-- returns nil if it cannot find it
session_id = get_session_id(cookie)
-- tries to extract the Knora session id from the cookie:
-- gets the digits between "sid=" and the closing ";" (only given in case of several key value pairs)
-- returns nil if it cannot find it
session_id = get_session_id(cookie)

if session_id == nil then
-- no session_id could be extracted
print("cookie key is invalid: " .. cookie)
else
knora_cookie_header = { Cookie = "KnoraAuthentication=" .. session_id }
if session_id == nil then
-- no session_id could be extracted
print("cookie key is invalid: " .. cookie)
else
knora_cookie_header = { Cookie = "KnoraAuthentication=" .. session_id }
end
end
end

knora_url = 'http://' .. config.knora_path .. ':' .. config.knora_port .. '/v1/files/' .. identifier
--print("knora_url: " .. knora_url)
knora_url = 'http://' .. config.knora_path .. ':' .. config.knora_port .. '/v1/files/' .. identifier

success, result = server.http("GET", knora_url, knora_cookie_header, 5000)
--print("knora_url: " .. knora_url)

-- check HTTP request was successful
if not success then
server.log("Server.http() failed: " .. result, server.loglevel.LOG_ERR)
return 'deny'
end
success, result = server.http("GET", knora_url, knora_cookie_header, 5000)

if result.status_code ~= 200 then
server.log("Knora returned HTTP status code " .. result.status_code)
server.log(result.body)
return 'deny'
end
-- check HTTP request was successful
if not success then
server.log("Server.http() failed: " .. result, server.loglevel.LOG_ERR)
return 'deny'
end

success, response_json = server.json_to_table(result.body)
if not success then
server.log("Server.http() failed: " .. response_json, server.loglevel.LOG_ERR)
return 'deny'
end
if result.status_code ~= 200 then
server.log("Knora returned HTTP status code " .. result.status_code)
server.log(result.body)
return 'deny'
end

success, response_json = server.json_to_table(result.body)
if not success then
server.log("Server.http() failed: " .. response_json, server.loglevel.LOG_ERR)
return 'deny'
end

--print("status: " .. response_json.status)
--print("permission code: " .. response_json.permissionCode)
--print("status: " .. response_json.status)
--print("permission code: " .. response_json.permissionCode)

if response_json.status ~= 0 then
-- something went wrong with the request, Knora returned a non zero status
return 'deny'
end
if response_json.status ~= 0 then
-- something went wrong with the request, Knora returned a non zero status
return 'deny'
end

if response_json.permissionCode == 0 then
-- no view permission on file
return 'deny'
elseif response_json.permissionCode == 1 then
-- restricted view permission on file
-- either watermark or size (depends on project, should be returned with permission code by Sipi responder)
return 'restrict:size=' .. config.thumb_size, filepath
elseif response_json.permissionCode >= 2 then
-- full view permissions on file
return 'allow', filepath
else
-- invalid permission code
return 'deny'
if response_json.permissionCode == 0 then
-- no view permission on file
return 'deny'
elseif response_json.permissionCode == 1 then
-- restricted view permission on file
-- either watermark or size (depends on project, should be returned with permission code by Sipi responder)
return 'restrict:size=' .. config.thumb_size, filepath
elseif response_json.permissionCode >= 2 then
-- full view permissions on file
return 'allow', filepath
else
-- invalid permission code
return 'deny'
end
end

end
-------------------------------------------------------------------------------
32 changes: 31 additions & 1 deletion config/sipi.knora-config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,25 @@ sipi = {
--
prefix_as_path = true,

--
-- In order not to accumulate to many files into one diretory (which slows down file
-- access considerabely), the images are stored in recursive subdirectories 'A'-'Z'.
-- If subdir_levels is equal 0, no subdirectories are used. The maximum is 6.
-- The recommandeation is that on average there should not me more than a few
-- thousand files in a unix directory (your mileage may vay depending on the
-- file system used).
--
subdir_levels = 1,

--
-- if subdir_levels is > 0 and if prefix_as_path is true, all prefixes will be
-- regarded as directories under imgroot. Thus, the subdirs 'A'-'Z' will be
-- created in these directories for the prefixes. However, it may make sense
-- for certain prefixes *not* to use subdirs. A list of these prefix-directories
-- can be given with this configuration parameter.
--
subdir_excludes = { "tmp", "thumbs"},

--
-- Lua script which is executed on initialization of the Lua interpreter
--
Expand Down Expand Up @@ -107,13 +126,24 @@ sipi = {
--
-- Port of Knora Application
--
knora_port = '3333'
knora_port = '3333',

--
-- loglevel, one of "EMERGENCY", "ALERT", "CRITICAL", "ERROR", "WARNING", "NOTICE", "INFORMATIONAL", "DEBUG"
--
loglevel = "DEBUG"
}


fileserver = {
--
-- directory where the documents for the normal webserver are located
--
docroot = './server',

--
-- route under which the normal webserver shouöd respond to requests
--
wwwroute = '/server'
}

Expand Down
19 changes: 18 additions & 1 deletion config/sipi.knora-docker-config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ sipi = {
--
prefix_as_path = true,

--
-- In order not to accumulate to many files into one diretory (which slows down file
-- access considerabely), the images are stored in recursive subdirectories 'A'-'Z'.
-- If subdir_levels is equal 0, no subdirectories are used. The maximum is 6.
-- The recommandeation is that on average there should not me more than a few
-- thousand files in a unix directory (your mileage may vay depending on the
-- file system used).
--
subdir_levels = 1,

--
-- Lua script which is executed on initialization of the Lua interpreter
--
Expand Down Expand Up @@ -113,8 +123,15 @@ sipi = {


fileserver = {
--
-- directory where the documents for the normal webserver are located
--
docroot = '/sipi/server',
docroute = '/server'

--
-- route under which the normal webserver shouöd respond to requests
--
wwwroute = '/server'
}

--
Expand Down
Loading