+++ /dev/null
-LOCAL_STORAGE=/mnt/data2/purplebirdman/art
-IPV4_WAN=public.purplebirdman.com
FROM httpd:2.4-alpine
+# open htdocs so scripts can write dynamically into there
+RUN chmod 777 /usr/local/apache2/htdocs
+
COPY /httpd.conf /usr/local/apache2/conf/httpd.conf
-COPY /public /root/public
+COPY /lua /usr/local/apache2/lua
services:
web:
build: .
- image: cjpalmer/public:1.1.0
+ image: cjpalmer/public:1.2.0
volumes:
- - ${LOCAL_STORAGE}:/storage
+ - ${SHARE_ROOT}:/storage
- public_data:/usr/local/apache2/htdocs
+ - httpd_users:/usr/local/apache2/auth
environment:
- PUBLIC_ROOT_DIR=/storage
- PUBLIC_LINK_DIR=/usr/local/apache2/htdocs
- - PUBLIC_HTTP_URI=https://${IPV4_WAN}
ports:
- 80:80
volumes:
public_data:
driver: local
+ httpd_users:
+ driver: local
#LoadModule log_debug_module modules/mod_log_debug.so\r
#LoadModule log_forensic_module modules/mod_log_forensic.so\r
#LoadModule logio_module modules/mod_logio.so\r
-#LoadModule lua_module modules/mod_lua.so\r
+LoadModule lua_module modules/mod_lua.so\r
LoadModule env_module modules/mod_env.so\r
#LoadModule mime_magic_module modules/mod_mime_magic.so\r
#LoadModule cern_meta_module modules/mod_cern_meta.so\r
# e-mailed. This address appears on some server-generated pages, such\r
# as error documents. e.g. admin@your-domain.com\r
#\r
-ServerAdmin purplebirdman@mail.purplebirdman.online\r
+ServerAdmin purplebirdman@purplebirdman.com\r
\r
#\r
# ServerName gives the name and port that the server uses to identify itself.\r
Require all denied\r
</Files>\r
\r
+# run lua scripts using ".lua" extension\r
+<Files "*.lua">\r
+ SetHandler lua-script\r
+</Files>\r
+\r
#\r
# ErrorLog: The location of the error log file.\r
# If you do not specify an ErrorLog directive within a <VirtualHost>\r
# directives as to Alias.\r
#\r
ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/"\r
+ ScriptAlias /lua/ "/usr/local/apache2/lua/"\r
\r
</IfModule>\r
\r
Require all granted\r
</Directory>\r
\r
+# more lua stuff\r
+<Directory "/usr/local/apache2/lua">\r
+ AuthType Basic\r
+ AuthName "Restricted Files"\r
+ AuthUserFile "/usr/local/apache2/auth/passwords"\r
+ AllowOverride None\r
+ Options None\r
+ Require valid-user\r
+</Directory>\r
+\r
<IfModule headers_module>\r
#\r
# Avoid passing HTTP_PROXY environment to CGI's on this or any proxied\r
--- /dev/null
+require "apache2"
+
+--[[
+ Dumps all the published links
+--]]
+function dump_files(t, r, dir)
+ for _, f in ipairs(r:get_direntries(dir)) do
+ if f ~= "." and f ~= ".." then
+ local filepath = dir .. "/" .. f
+ local info = r:stat(filepath)
+ if info then
+ -- if this is a file, then add it to the table!
+ if info.filetype == 1 then
+ t[filepath] = info
+ end
+
+ -- if this is a dir, then descend into it
+ if info.filetype == 2 then
+ dump_files(t, r, filepath)
+ end
+ end
+ end
+ end
+end
+
+function handle(r)
+ r.content_type = "text/plain"
+
+ if r.method == 'GET' then
+ local links = {}
+ dump_files(links, r, r.document_root)
+
+ for filepath, info in pairs(links) do
+ r:puts( ("%s\n"):format(
+ filepath:gsub(r.document_root, r.server_name .. ":" ..r.port)
+ ))
+ end
+ else
+ return 501
+ end
+ return apache2.OK
+end
--- /dev/null
+require "apache2"
+
+function publish(dir, pattern)
+ local cmd = ("%s/publish.sh %s"):format(dir, pattern)
+ local handle = io.popen(cmd)
+ local output = handle:read('*a')
+ handle:close()
+
+ return output
+end
+
+function get_form(dir)
+ local handle = io.open(dir .. '/submit.html')
+ local output = handle:read('*a')
+ handle:close()
+
+ return output;
+end
+
+function handle(r)
+ r.content_type = "text/html"
+
+ local args = r:parseargs()
+ local pattern = args.pattern
+
+ if pattern then
+ local nonce = publish(r.context_document_root, pattern)
+ local uri = ("%s://%s:%s/%s"):format(
+ r.is_https and "https" or "http",
+ r.server_name, r.port, nonce)
+ r:puts( ([[<a href="%s">%s</a>]]):format(uri, uri) )
+ else
+ local template = get_form(r.context_document_root)
+ r:puts( template )
+ end
+
+ return apache2.OK
+end
--- /dev/null
+#!/bin/sh
+
+# make sure public root and link dirs are declared
+[[ -z "$PUBLIC_ROOT_DIR" ]] && echo Expected PUBLIC_ROOT_DIR && exit 1
+[[ -z "$PUBLIC_LINK_DIR" ]] && echo Expected PUBLIC_LINK_DIR && exit 1
+
+[[ -z "$1" ]] && echo Expected pattern && exit 1
+
+# if pattern matches files from storage,
+# create nonce directory
+# create symlinks to matching files
+nonce=$(head /dev/urandom | sha1sum -b | awk '{print $1}')
+symlink_dir=$PUBLIC_LINK_DIR/$nonce
+
+find $PUBLIC_ROOT_DIR -type f -name "*$1*" | while read fname
+do
+ [[ -d $symlink_dir ]] || mkdir -p $symlink_dir
+ ln -s $fname $symlink_dir/$(echo $fname | sed 's|^.*/||')
+done
+
+# print nonce directory
+echo $nonce
--- /dev/null
+<html>
+<head>
+<title>Public</title>
+<script>
+function validate() {
+ return( true );
+}
+</script>
+</head>
+<body>
+<form name="get-search-pattern" onsubmit="return(validate());">
+
+<p>
+<h3>What do you want me to publish?</h3>
+<input type="text" name="pattern" />
+</p>
+
+<p>
+<input type="submit" value="submit" />
+</p>
+
+</form>
+</body>
+</html>
+++ /dev/null
-#!/usr/bin/perl
-use strict;
-use warnings;
-
-use File::Spec;
-use File::Path qw/ make_path /;
-
-my $root_dir = $ENV{PUBLIC_ROOT_DIR}
- or die "Need PUBLIC_ROOT_DIR\n";
-my $link_dir = $ENV{PUBLIC_LINK_DIR}
- or die "Need PUBLIC_LINK_DIR\n";
-my $http_uri = $ENV{PUBLIC_HTTP_URI}
- or die "Need PUBLIC_HTTP_URI\n";
-
-
-sub nonce {
- my $n = shift;
- $n = 10 unless $n > 0;
-
- my @chars = ( 'a' .. 'z', 'A' .. 'Z', '0' .. '9' );
- my @path = ();
- push @path, $chars[ rand @chars ] for 1 .. $n;
-
- return join '', @path;
-}
-
-sub makeNonceDir {
- my $nonce = shift;
- my $path = File::Spec->catdir($link_dir, $nonce);
- make_path($path, { chmod => 0777 });
- return $path, ;
-}
-
-sub addFiles {
- # get list of files matching name from root directory
- my $name = shift
- or die "Need filename!\n";
-
- opendir DIR, $root_dir
- or die $!;
- my @files = grep /$name/i, readdir(DIR);
- closedir DIR;
-
- # exit if no files found
- die "No match: $name\n" unless @files;
-
- # create nonce dir and add symbolic links
- my $nonce = nonce(20);
- my $nonce_dir = makeNonceDir($nonce);
-
- for my $file (@files) {
- my $root_filepath = File::Spec->catfile($root_dir, $file);
- my $link_filepath = File::Spec->catfile($nonce_dir, $file);
-
- symlink $root_filepath, $link_filepath
- or die "Unable to create symlink: $root_filepath -> $link_filepath";
-
- my $uri_link = join '/', $http_uri, $nonce, $file;
- print "$uri_link\n";
- }
-}
-
-sub listFiles {
- opendir DIR, $link_dir;
- my @nonces = readdir(DIR);
- closedir DIR;
-
- for my $nonce (@nonces) {
- next if $nonce eq '.';
- next if $nonce eq '..';
-
- # ensure it's a directory
- my $nonce_dir = File::Spec->catdir($link_dir, $nonce);
- next unless -d $nonce_dir;
-
- # make URIs for all the files in the nonce dirs
- opendir DIR, $nonce_dir;
- my @files = readdir(DIR);
- closedir DIR;
-
- for my $file (@files) {
- next if $file eq '.';
- next if $file eq '..';
-
- my $uri_link = join '/', $http_uri, $nonce, $file;
- print "$uri_link\n";
- }
- }
-}
-
-
-# script begins
-if (@ARGV) {
- addFiles($_) for @ARGV;
-}
-else {
- listFiles;
-}
+++ /dev/null
-#!/bin/bash
-service=proxy_public
-
-for f in $(docker service ps -q $service)
-do
- [[ running == $(docker inspect --format '{{.Status.State}}' $f) ]] || continue
- container_id=$(docker inspect --format '{{.Status.ContainerStatus.ContainerID}}' $f)
- echo docker exec $container_id /root/public "$@"
- docker exec $container_id /root/public "$@"
-done
docker stack deploy -c <(docker-compose config) public
```
-### creating a public directory by filename regex
-```
-cliftonpalmer@pop-os:~/swarm/share-public$ ./public.sh simplify
-http://public.purplebirdman.online/1ojxVHOXk9u89u234erso7df/SimplifyPikoPseftis3.jpg
-http://public.purplebirdman.online/1ojxVHOXk9u89u234erso7df/SimplifyPikoPseftis.png
-http://public.purplebirdman.online/1ojxVHOXk9u89u234erso7df/SimplifyPikoPseftis.clip
-http://public.purplebirdman.online/1ojxVHOXk9u89u234erso7df/SimplifyPikoPseftis2.png
-```
+### reaching the services
+
+Must authorize self through ```$hostname```/lua/publish.lua and set up valid users on first deployment
-### listing public directories and contents
```
-cliftonpalmer@pop-os:~/swarm/share-public$ ./public.sh
-http://public.purplebirdman.online/1ojxVHOXk9u89u234erso7df/SimplifyPikoPseftis3.jpg
-http://public.purplebirdman.online/1ojxVHOXk9u89u234erso7df/SimplifyPikoPseftis2.png
-http://public.purplebirdman.online/1ojxVHOXk9u89u234erso7df/SimplifyPikoPseftis.png
-http://public.purplebirdman.online/1ojxVHOXk9u89u234erso7df/SimplifyPikoPseftis.clip
+htpasswd -c passwords $username
```
## todo