diff --git a/Dockerfile b/Dockerfile index 3fe401e..8d34291 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,7 @@ ARG CODENAME=bionic FROM ${REGISTRY_PREFIX}ubuntu:${CODENAME} as builder +ARG DEBIAN_FRONTEND=noninteractive RUN set -x \ && apt update \ && apt upgrade -y \ @@ -17,7 +18,9 @@ RUN set -x \ uuid-dev \ wget \ libconfig-dev \ - libpam0g-dev + libpam0g-dev \ + nginx \ + fcgiwrap ARG PARALLELMFLAGS=-j2 @@ -138,8 +141,11 @@ RUN set -x \ && cd /usr/local/src/www \ && npm update --no-save \ && npm run build \ + && rm -rf /tmp/npm-* \ + && rm -rf /tmp/v8-* \ && mkdir -p /var/www \ - && cp -r ./dist/. /var/www/ + && cp -r ./dist/. /var/www/ \ + && chmod +x /var/www/cgi-bin/* ARG USERID=1000 RUN set -x \ diff --git a/README.md b/README.md index 0df7c3d..d53d896 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,9 @@ Example of webfuse. --device /dev/fuse --cap-add SYS_ADMIN --security-opt apparmor:unconfined \ webfuse -Open a webbrowser and visit http://localhost:8080 and establish a connection. +Open a webbrowser, visit http://localhost:8080 and follow the instruction on the screen. -Once connected, you can display the provided filesystem inside the container. +Once connected, you can also display the provided filesystem inside the container. cat /tmp/test/hello.txt diff --git a/etc/nginx/fcgi.conf b/etc/nginx/fcgi.conf new file mode 100644 index 0000000..c2f509a --- /dev/null +++ b/etc/nginx/fcgi.conf @@ -0,0 +1,21 @@ +fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; +fastcgi_param QUERY_STRING $query_string; +fastcgi_param REQUEST_METHOD $request_method; +fastcgi_param CONTENT_TYPE $content_type; +fastcgi_param CONTENT_LENGTH $content_length; +fastcgi_param SCRIPT_NAME $fastcgi_script_name; +fastcgi_param REQUEST_URI $request_uri; +fastcgi_param DOCUMENT_URI $document_uri; +fastcgi_param DOCUMENT_ROOT $document_root; +fastcgi_param SERVER_PROTOCOL $server_protocol; +fastcgi_param GATEWAY_INTERFACE CGI/1.1; +fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; +fastcgi_param REMOTE_ADDR $remote_addr; +fastcgi_param REMOTE_PORT $remote_port; +fastcgi_param SERVER_ADDR $server_addr; +fastcgi_param SERVER_PORT $server_port; +fastcgi_param SERVER_NAME $server_name; + +fastcgi_index index.php; + +fastcgi_param REDIRECT_STATUS 200; \ No newline at end of file diff --git a/etc/nginx/mime.types b/etc/nginx/mime.types new file mode 100644 index 0000000..62bd4b6 --- /dev/null +++ b/etc/nginx/mime.types @@ -0,0 +1,48 @@ +types { + text/html html htm shtml; + text/css css; + text/xml xml rss; + image/gif gif; + image/jpeg jpeg jpg; + application/x-javascript js; + text/plain txt; + text/x-component htc; + text/mathml mml; + image/png png; + image/x-icon ico; + image/x-jng jng; + image/vnd.wap.wbmp wbmp; + application/java-archive jar war ear; + application/mac-binhex40 hqx; + application/pdf pdf; + application/x-cocoa cco; + application/x-java-archive-diff jardiff; + application/x-java-jnlp-file jnlp; + application/x-makeself run; + application/x-perl pl pm; + application/x-pilot prc pdb; + application/x-rar-compressed rar; + application/x-redhat-package-manager rpm; + application/x-sea sea; + application/x-shockwave-flash swf; + application/x-stuffit sit; + application/x-tcl tcl tk; + application/x-x509-ca-cert der pem crt; + application/x-xpinstall xpi; + application/zip zip; + application/octet-stream deb; + application/octet-stream bin exe dll; + application/octet-stream dmg; + application/octet-stream eot; + application/octet-stream iso img; + application/octet-stream msi msp msm; + audio/mpeg mp3; + audio/x-realaudio ra; + video/mpeg mpeg mpg; + video/quicktime mov; + video/x-flv flv; + video/x-msvideo avi; + video/x-ms-wmv wmv; + video/x-ms-asf asx asf; + video/x-mng mng; +} \ No newline at end of file diff --git a/etc/nginx/nginx.conf b/etc/nginx/nginx.conf new file mode 100644 index 0000000..a09e7df --- /dev/null +++ b/etc/nginx/nginx.conf @@ -0,0 +1,37 @@ +user user user; +worker_processes 1; + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + server { + listen 8080; + server_name localhost; + + root /var/www; + + location / { + index index.html; + } + + location /webfuse-api { + proxy_pass http://localhost:8081; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_set_header Host $host; + } + + location /cgi-bin/ { + fastcgi_intercept_errors on; + include fcgi.conf; + + fastcgi_pass unix:/tmp/fcgi.sock; + } + } +} \ No newline at end of file diff --git a/etc/services.d/fcgi/run b/etc/services.d/fcgi/run new file mode 100644 index 0000000..dba5b21 --- /dev/null +++ b/etc/services.d/fcgi/run @@ -0,0 +1,4 @@ +#!/usr/bin/execlineb -P + +s6-setuidgid user +/usr/sbin/fcgiwrap -s unix:/tmp/fcgi.sock \ No newline at end of file diff --git a/etc/services.d/nginx/run b/etc/services.d/nginx/run new file mode 100644 index 0000000..577e02f --- /dev/null +++ b/etc/services.d/nginx/run @@ -0,0 +1,3 @@ +#!/usr/bin/execlineb -P + +nginx -g "daemon off;" diff --git a/etc/webfused.conf b/etc/webfused.conf index 8062fb9..29868d0 100644 --- a/etc/webfused.conf +++ b/etc/webfused.conf @@ -5,8 +5,8 @@ version = { major = 1, minor = 0 } server: { vhost_name = "localhost" - port = 8080 - document_root = "/var/www" + port = 8081 + # document_root = "/var/www" } filesystems: diff --git a/www/src/cgi-bin/get-contents b/www/src/cgi-bin/get-contents new file mode 100755 index 0000000..3a24407 --- /dev/null +++ b/www/src/cgi-bin/get-contents @@ -0,0 +1,12 @@ +#!/bin/sh + +echo "Content-Type: text/plain" +echo "" + +if [ -f /tmp/test/hello.txt ] ; then +cat /tmp/test/hello.txt +exit 0 +else +echo "File Not Found" +exit 1 +fi diff --git a/www/src/cgi-bin/list-dir b/www/src/cgi-bin/list-dir new file mode 100755 index 0000000..3a487e4 --- /dev/null +++ b/www/src/cgi-bin/list-dir @@ -0,0 +1,7 @@ +#!/bin/sh + +echo "Content-Type: text/plain" +echo "" + +ls -1a /tmp/test +exit 0 \ No newline at end of file diff --git a/www/src/connection_view.js b/www/src/connection_view.js index 31576ae..1084ef9 100644 --- a/www/src/connection_view.js +++ b/www/src/connection_view.js @@ -16,7 +16,7 @@ export class ConnectionView { this.urlTextbox = document.createElement("input"); this.urlTextbox.type = "text"; - this.urlTextbox.value = window.location.href.replace(/^http/, "ws"); + this.urlTextbox.value = window.location.href.replace(/^http/, "ws") + 'webfuse-api'; connectBox.appendChild(this.urlTextbox); this.connectButton = document.createElement("input"); @@ -25,8 +25,8 @@ export class ConnectionView { this.connectButton.addEventListener("click", () => { this._onConnectButtonClicked(); }); connectBox.appendChild(this.connectButton); - const authenticateBox = document.createElement("div"); + authenticateBox.classList.add('hidden'); this.element.appendChild(authenticateBox); const authLabel = document.createElement("span"); diff --git a/www/src/index.html b/www/src/index.html index ce665e3..6fbfef8 100644 --- a/www/src/index.html +++ b/www/src/index.html @@ -12,6 +12,31 @@
Connection
+ +
+
Info
+
+

Please connect to start providing files. This page updates every 5 seconds.

+

There are two files provided in this example: +

+

+

To display the files, see /tmp/test directory inside the container.

+
+
+ +
+
/tmp/test
+
+
+ +
+
/tmp/test/hello.txt
+
+
+ <%= htmlWebpackPlugin.tags.bodyTage %> diff --git a/www/src/index.js b/www/src/index.js index 0632653..81955c7 100644 --- a/www/src/index.js +++ b/www/src/index.js @@ -7,6 +7,22 @@ function mode(value) { return parseInt(value, 8); } +function updateContents() { + const directory = document.getElementById('directory'); + fetch("cgi-bin/list-dir").then(response => response.text()).then((text) => { + directory.textContent = text; + }) + .catch(() => { directory.innerHTML = ''; }); + + const contents = document.getElementById('contents'); + fetch("cgi-bin/get-contents").then(response => response.text()).then((text) => { + contents.textContent = text; + }) + .catch(() => { contents.innerHTML = ''; }); + + window.setTimeout(updateContents, 5 * 1000); +} + function startup() { const provider = new FileSystemProvider({ inode: 1, @@ -20,6 +36,7 @@ function startup() { const client = new Client(); const connectionView = new ConnectionView(client, provider); document.getElementById('connection').appendChild(connectionView.element); + updateContents(); } window.onload = startup; diff --git a/www/src/style/main.css b/www/src/style/main.css index 399bfd1..e8a6c7c 100644 --- a/www/src/style/main.css +++ b/www/src/style/main.css @@ -15,7 +15,7 @@ html, body { border-radius: 5px; padding: 10px; margin-bottom: 25px; - color: white; + color: #c0c0c0; } .window .title { @@ -45,3 +45,11 @@ html, body { text-align: center; } +.hidden { + display: none; + visibility: hidden; +} + +#contents, #directory { + white-space: pre; +} diff --git a/www/webpack.config.js b/www/webpack.config.js index bb7234f..02f3931 100644 --- a/www/webpack.config.js +++ b/www/webpack.config.js @@ -18,7 +18,8 @@ module.exports = { template: "./src/index.html" }), new CopyWebpackPlugin([ - { from: './src/style', to: 'style' } + { from: './src/style', to: 'style' }, + { from: './src/cgi-bin', to: 'cgi-bin', copyPermissions: true } ]) ], resolve: {