From af4b9c424600265fbc2f155f16e6424bc08a1ab9 Mon Sep 17 00:00:00 2001 From: "Go Johansson (neku)" Date: Sun, 1 Jan 2023 09:45:39 +0100 Subject: [PATCH] in --- .gitignore | 1 + Makefile | 83 +++++++++++++++----------- README.md | 17 +++--- docker/Dockerfile | 79 ++++++++++++------------ docker/docker-entrypoint.sh | 16 ++--- docker/nginx/uguu.conf | 6 +- docker_build.sh | 8 --- docker_purge.sh | 2 - package.json | 7 +-- src/config.json | 4 +- src/static/dbSchemas/sqlite_schema.sql | 6 -- 11 files changed, 116 insertions(+), 113 deletions(-) delete mode 100755 docker_build.sh delete mode 100755 docker_purge.sh diff --git a/.gitignore b/.gitignore index c5b018d..d82fc8c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ uguu.sq3 .vscode composer.phar composer.lock +docker/uguuForDocker.tar.gz diff --git a/Makefile b/Makefile index d43db37..20a5a86 100644 --- a/Makefile +++ b/Makefile @@ -1,45 +1,50 @@ -MAKE="make" -INSTALL="install" -TAR="tar" -GREP="grep" -NODE="node" -NPM="npm" -NODEJQ="node_modules/node-jq/bin/jq" -SQLITE="sqlite3" -CONF="src/config.json" -PHP="php" -CURL="curl" +MAKE = "make" +INSTALL = "install" +TAR = "tar" +GREP = "grep" +NODE = "node" +NPM = "npm" +NODEJQ = "node_modules/node-jq/bin/jq" +SQLITE = "sqlite3" +CONF = "src/config.json" +PHP = "php" +CURL = "curl" DESTDIR = $(shell $(CURDIR)/$(NODEJQ) -r ".dest" $(CURDIR)/$(CONF)) -NPX="npx" +SITEDOMAIN = $(shell $(CURDIR)/$(NODEJQ) -r ".DOMAIN" $(CURDIR)/$(CONF)) +FILESDOMAIN = $(shell $(CURDIR)/$(NODEJQ) -r ".FILE_DOMAIN" $(CURDIR)/$(CONF)) +CONTACT_EMAIL = $(shell $(CURDIR)/$(NODEJQ) -r ".infoContact" $(CURDIR)/$(CONF)) PKG_VERSION = $(shell $(CURDIR)/$(NODEJQ) -r ".version" $(CURDIR)/package.json) TMPDIR = $(shell mktemp -d) DOCKER_IMAGE = "$(shell basename $(CURDIR) | tr [:upper:] [:lower:])" -DOCKER_TAG="$(DOCKER_TAG)" -CONTAINER_NAME="$(CONTAINER_NAME)" +DOCKER_TAG = "$(DOCKER_TAG)" +CONTAINER_NAME = "$(CONTAINER_NAME)" # default modules MODULES="php" pageList = $(shell $(CURDIR)/$(NODEJQ) -r ".pages[]" $(CURDIR)/$(CONF)) noExt = $(shell echo $(i) | cut -d '.' -f1) -all: builddirs npm_dependencies ejs minify-all copy-img copy-php +all: builddirs npm_dependencies ejs "node_modules/minify/bin/minify.js"-all copy-img copy-php ejs: $(foreach i,$(pageList), \ - $(NPX) ejs -f $(CURDIR)/$(CONF) $(CURDIR)/src/templates/$(i) -o $(CURDIR)/build/html/unmin/$(noExt).html;) + "node_modules/ejs/bin/cli.js" -f $(CURDIR)/$(CONF) $(CURDIR)/src/templates/$(i) -o $(CURDIR)/build/html/unmin/$(noExt).html;) -minify-all: - $(NPX) minify-all-cli -s $(CURDIR)/src/static/js -d $(CURDIR)/build/js - $(NPX) minify-all-cli -s $(CURDIR)/src/static/css -d $(CURDIR)/build/css - $(NPX) minify-all-cli -s $(CURDIR)/build/html/unmin/ -d $(CURDIR)/build/html/min/ -h +"node_modules/minify/bin/minify.js"-all: + "node_modules/minify/bin/minify.js" $(CURDIR)/src/static/js/uguu.js > $(CURDIR)/build/js/uguu.min.js + "node_modules/minify/bin/minify.js" $(CURDIR)/src/static/css/uguu.css > $(CURDIR)/build/css/uguu.min.css + "node_modules/minify/bin/minify.js" $(CURDIR)/build/html/unmin/faq.html > $(CURDIR)/build/html/min/faq.html + "node_modules/minify/bin/minify.js" $(CURDIR)/build/html/unmin/tools.html > $(CURDIR)/build/html/min/index.html + "node_modules/minify/bin/minify.js" $(CURDIR)/build/html/unmin/tools.html > $(CURDIR)/build/html/min/tools.html installdirs: mkdir -p $(DESTDIR)/ $(DESTDIR)/img mkdir -p $(DESTDIR)/ $(DESTDIR)/img/grills copy-img: - $(NPX) imagemin $(CURDIR)/src/static/img/*.png -o=$(CURDIR)/build/img/ - $(NPX) imagemin $(CURDIR)/src/static/img/grills/*.png --plugin=pngquant -o=$(CURDIR)/build/img/grills/ + "node_modules/imagemin-cli/cli.js" $(CURDIR)/src/static/img/*.png -o=$(CURDIR)/build/img/ + "node_modules/imagemin-cli/cli.js" $(CURDIR)/src/static/img/grills/*.png --plugin=pngquant -o=$(CURDIR)/build/img/grills/ + copy-php: cp -v $(CURDIR)/src/static/php/*.php $(CURDIR)/build/php/ @@ -56,8 +61,6 @@ install: installdirs rm -rf $(DESTDIR)/css rm -rf $(DESTDIR)/js rm -rf $(DESTDIR)/php - mv $(DESTDIR)/public/uguu.css $(DESTDIR)/public/uguu.min.css - mv $(DESTDIR)/public/uguu.js $(DESTDIR)/public/uguu.min.js mv $(DESTDIR)/img $(DESTDIR)/public/ mv $(DESTDIR)/grill.php $(DESTDIR)/public/ mv $(DESTDIR)/upload.php $(DESTDIR)/public/ @@ -72,33 +75,43 @@ dist: install $(TAR) cJf uguu-$(PKG_VERSION).tar.xz $(DESTDIR) rm -rf $(TMPDIR) - + clean: - rm -rvf $(CURDIR)/node_modules + rm -rvf $(CURDIR)/node_modules rm -rvf $(CURDIR)/build - + uninstall: rm -rvf $(DESTDIR)/ - + npm_dependencies: $(NPM) install -build-image: - tar --exclude='./uguuForDocker.tar.gz' --exclude='./vendor' --exclude='./node_modules' -czf uguuForDocker.tar.gz . +build-container-no-cache: + tar --exclude='./uguuForDocker.tar.gz' --exclude='./vendor' --exclude='./node_modules' --exclude='./build' --exclude='./dist' --exclude='./.git' -czf uguuForDocker.tar.gz . mv uguuForDocker.tar.gz docker/ - docker build -f docker/Dockerfile --build-arg VERSION=$(UGUU_RELEASE_VER) --no-cache -t $(DOCKER_IMAGE):$(DOCKER_TAG) . + docker build -f docker/Dockerfile --build-arg VERSION=$(PKG_VERSION) --no-cache -t uguu:$(PKG_VERSION) . + +build-container: + tar --exclude='./uguuForDocker.tar.gz' --exclude='./vendor' --exclude='./node_modules' --exclude='./build' --exclude='./dist' --exclude='./.git' -czf uguuForDocker.tar.gz . + mv uguuForDocker.tar.gz docker/ + docker build -f docker/Dockerfile --build-arg DOMAIN=$(SITEDOMAIN) --build-arg FILE_DOMAIN=$(FILESDOMAIN) --build-arg CONTACT_EMAIL=$(FILESDOMAIN) -t uguu:$(PKG_VERSION) . run-container: - docker run --name $(CONTAINER_NAME) -d -p 8080:80 -p 8081:443 $(DOCKER_IMAGE):$(DOCKER_TAG) + docker run --name uguu -d -p 8080:80 -p 8081:443 uguu:$(PKG_VERSION) + docker exec -it uguu /bin/bash service nginx start + docker exec -it uguu /bin/bash service php8.1-fpm start -purge-container: - if docker images | grep $(DOCKER_IMAGE); then \ - docker rm -f $(CONTAINER_NAME) && docker rmi $(DOCKER_IMAGE):$(DOCKER_TAG) || true;\ +purge-containers: + if docker images | grep uguu; then \ + docker rm -f uguu && docker rmi uguu:$(PKG_VERSION) || true;\ fi; +remove-container: + docker rm -f uguu + builddirs: mkdir -p $(CURDIR)/build $(CURDIR)/build/img $(CURDIR)/build/html $(CURDIR)/build/html/min $(CURDIR)/build/html/unmin $(CURDIR)/build/js $(CURDIR)/build/css $(CURDIR)/build/php $(CURDIR)/build/php/Classes $(CURDIR)/build/public diff --git a/README.md b/README.md index 575b5db..c6d7fcb 100644 --- a/README.md +++ b/README.md @@ -10,15 +10,19 @@ Uguu is a simple lightweight temporary file hosting and sharing platform, but ca ## Features -- One click uploading, no registration required -- A minimal, modern web interface -- Drag & Drop & Paste supported -- Upload API with multiple response choices +- One click uploading, no registration required. +- A minimal, modern web interface. +- Drag & Drop & Paste supported. +- Upload API with multiple response choices: - JSON - HTML - Text - CSV -- Supports [ShareX](https://getsharex.com/) and other screenshot tools +- Supports [ShareX](https://getsharex.com/) and other screenshot tools. +- File extension & MIME black/whitelisting. +- Upload rate limiting. +- File (hash) blacklisting. +- Run bare or as a container. ### Demo @@ -26,7 +30,7 @@ See the real world site at [uguu.se](https://uguu.se). ## Requirements -Tested and working with Nginx + PHP-8.0/8.1 + SQLite/MySQL. +Tested and working with Nginx + PHP-8.1 + SQLite/MySQL. Node is used to compile Uguu, after that it runs on PHP. @@ -57,7 +61,6 @@ tests. * S3 Bucket Support * Azure File Storage Support * Temporal/RR Support -* ## Credits diff --git a/docker/Dockerfile b/docker/Dockerfile index 368cf65..0aa09d7 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,26 +1,21 @@ -FROM php:8.1-alpine +FROM --platform=linux/amd64 debian:bullseye-slim -ARG VERSION +# Install needed software +RUN apt-get update - -RUN apk add --no-cache $PHPIZE_DEPS \ - php-fpm zlib-dev libzip-dev libgomp; \ - docker-php-ext-install intl pcntl gd exif zip pdo mysql dom; \ - apk del $PHPIZE_DEPS; \ - rm -rf /tmp/pear; - -# Install the needed software -RUN apk add --no-cache sqlite nodejs git npm bash build-base supervisor curl wget nginx -#php8-fileinfo php8-pdo php8-tokenizer php8-dom php8-iconv php8-xml php8-simplexml \ -#php8-sqlite3 php8-opcache php8-mbstring php8-phar php8-openssl - -# Create the www-data user and group -#RUN set -x ; \ -# addgroup -g 82 -S www-data ; \ -# adduser -u 82 -D -S -G www-data www-data && exit 0 ; exit 1 - -# Copy supervisor conf file -COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf +RUN apt-get install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2 curl cron socat +RUN echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/sury-php.list +RUN curl -fsSL https://packages.sury.org/php/apt.gpg| gpg --dearmor -o /etc/apt/trusted.gpg.d/sury-keyring.gpg +RUN apt-get update +RUN apt-get upgrade -y +RUN curl -o nodejssetup.sh https://deb.nodesource.com/setup_19.x +RUN chmod a+x nodejssetup.sh +RUN ./nodejssetup.sh +RUN apt-get install -y nodejs gcc g++ make +RUN apt-get install -y build-essential nginx-full php8.1-fpm php8.1 sqlite3 php8.1-sqlite3 \ + php8.1-curl php8.1-cli php8.1-lz4 \ + php8.1-mcrypt php8.1-mysql php8.1-xdebug php8.1-zip \ + php8.1-common php8.1-readline php8.1-bcmath php8.1-common php8.1-xml # Set default workdir WORKDIR /var/www/ @@ -37,45 +32,51 @@ RUN mkdir /var/www/files && \ mkdir /var/www/db # Create the Sqlite DB -RUN sqlite3 /var/www/db/uguu.sq3 -init /var/www/uguu/src/static/dbSchemas/sqlite_schema.sql && \ +RUN sqlite3 /var/www/db/uguuDB.sq3 -init /var/www/uguu/src/static/dbSchemas/sqlite_schema.sql "" && \ chown -R www-data:www-data /var/www && \ chmod -R 775 /var/www/ +# Add scripts to cron +RUN echo "0,30 * * * * bash /var/www/uguu/src/static/scripts/checkfiles.sh" >> /var/spool/cron/crontabs/www-data && \ + echo "0,30 * * * * bash /var/www/uguu/src/static/scripts/checkdb.sh" >> /var/spool/cron/crontabs/www-data + # Fix script paths RUN chmod a+x /var/www/uguu/src/static/scripts/checkdb.sh && \ chmod a+x /var/www/uguu/src/static/scripts/checkfiles.sh && \ sed -i 's#/path/to/files/#/var/www/uguu/files/#g' /var/www/uguu/src/static/scripts/checkfiles.sh && \ sed -i 's#/path/to/db/uguu.sq3#/var/www/db/uguu.sq3#g' /var/www/uguu/src/static/scripts/checkdb.sh -# Add scripts to cron -RUN echo "0,30 * * * * bash /var/www/uguu/src/static/scripts/checkfiles.sh" >> /var/spool/cron/crontabs/www-data && \ - echo "0,30 * * * * bash /var/www/uguu/src/static/scripts/checkdb.sh" >> /var/spool/cron/crontabs/www-data - # Copy Nginx Server conf -COPY docker/nginx/uguu.conf /etc/nginx/http.d/ +COPY docker/nginx/uguu.conf /etc/nginx/sites-enabled/uguu.conf + +#RUN sed -i 's#XXX#$()#g' /var/www/uguu/src/static/scripts/checkfiles.sh # Copy SSL certs -COPY docker/ssl /etc/ssl - -# Copy PHP config -COPY docker/php/php.ini /etc/php8/ -COPY docker/php/www.conf /etc/php8/php-fpm.d/ -RUN mkdir /var/run/php +#COPY docker/ssl /etc/ssl # Copy Uguu config COPY src/config.json /var/www/uguu/config.json -# Give permissions to www-data -RUN chown -R www-data:www-data /run /var/lib/nginx /var/log/nginx /etc/nginx /etc/php8 /var/log/php8 /var/run/php - -# Change user to www-data -USER www-data - # Expose port 80 from the container EXPOSE 80 # Expose port 443 from the container EXPOSE 443 +#RUN service nginx restart +# Change user to www-data +#USER www-data + +#RUN cd /var/www/uguu && make && make install + +ARG DOMAIN +ENV DOMAIN=$DOMAIN +ARG FILE_DOMAIN +ENV FILE_DOMAIN=$FILE_DOMAIN +ARG CONTACT_EMAIL +ENV CONTACT_EMAIL=$CONTACT_EMAIL +RUN curl -o acmeinstall.sh https://get.acme.sh +RUN chmod a+x acmeinstall.sh +RUN ./acmeinstall.sh # Load entrypoint ENTRYPOINT [ "bash", "/var/www/docker-entrypoint.sh" ] \ No newline at end of file diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 76e1ae6..2c8c003 100644 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -1,11 +1,11 @@ #!/bin/bash -cd /var/www/uguu/ +cd /var/www/uguu +npm install make make install -php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" -php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" -php composer-setup.php -php -r "unlink('composer-setup.php');" -php composer.phar install -php composer.phar update -/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf +/root/.acme.sh/acme.sh --set-default-ca --server letsencrypt +/root/.acme.sh/acme.sh --issue -d $DOMAIN -w /var/www/uguu/dist/public/ +/root/.acme.sh/acme.sh --issue -d $FILE_DOMAIN -w /var/www/files/ +service nginx start +service php8.1-fpm start +tail -f /var/log/nginx/access.log \ No newline at end of file diff --git a/docker/nginx/uguu.conf b/docker/nginx/uguu.conf index 9732b6c..af13672 100644 --- a/docker/nginx/uguu.conf +++ b/docker/nginx/uguu.conf @@ -1,7 +1,7 @@ server{ listen 80; - server_name 192.168.240.9; + server_name XXX; #ssl on; #ssl_certificate /etc/nginx/ssl/fullchain.pem; #ssl_certificate_key /etc/nginx/ssl/privkey.pem; @@ -12,7 +12,7 @@ server{ root /var/www/uguu/dist/public/; autoindex on; access_log on; - index index.html index.php; + index index.html; location ~* \.(css|js|jpg|jpeg|gif|png|ico|xml|eot|woff|woff2|ttf|svg|otf|x-icon|avif|webp|apng)$ { expires 30d; @@ -26,7 +26,7 @@ server{ gzip_types text/css text/js text/javascript application/javascript application/x-javascript; location ~* \.php$ { - fastcgi_pass unix:/var/run/php/php8.0-fpm.sock; + fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; fastcgi_intercept_errors on; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(.*)$; diff --git a/docker_build.sh b/docker_build.sh deleted file mode 100755 index 7b4d91d..0000000 --- a/docker_build.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -echo ">>> BUILDING UGUU CONTAINER <<<" -make UGUU_RELEASE_VER="$(cat package.json | grep version | cut -d '"' -f4)" DOCKER_TAG="$(cat package.json | grep version | cut -d '"' -f4)" build-image -echo ">>> DONE! <<<" - -echo ">>> Starting Uguu container! <<<" -make DOCKER_TAG="$(cat package.json | grep version | cut -d '"' -f4)" CONTAINER_NAME=uguu run-container -echo ">>> DONE! <<<" diff --git a/docker_purge.sh b/docker_purge.sh deleted file mode 100755 index f87fe5c..0000000 --- a/docker_purge.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -make DOCKER_TAG="$(cat package.json | grep version | cut -d '"' -f4)" CONTAINER_NAME=uguu purge-container diff --git a/package.json b/package.json index 394fe4c..a54fbf1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "uguu", - "version": "1.6.5", + "version": "1.6.6", "description": "Uguu is a simple lightweight temporary file host with support for drop, paste, click and API uploading.", "homepage": "https://uguu.se", "repository": { @@ -17,10 +17,9 @@ "url": "https://github.com/nokonoko/uguu/issues" }, "devDependencies": { + "minify": "^9.1.0", "ejs": "^3.1.8", - "minify-all-cli": "^1.0.13", - "node-jq": "^2.3.3", - "npx": "^10.2.2", + "node-jq": "^2.3.4", "imagemin-cli": "^7.0.0", "imagemin-pngquant": "^9.0.2" } diff --git a/src/config.json b/src/config.json index 39f5839..9759b69 100755 --- a/src/config.json +++ b/src/config.json @@ -3,7 +3,7 @@ "allowErrors": false }, "dest": "dist", - "pkgVersion": "1.6.5", + "pkgVersion": "1.6.6", "pages": [ "index.ejs", "faq.ejs", @@ -13,6 +13,8 @@ "expireTime": "48H", "siteName": "Uguu", "subTitle": "wahooo", + "DOMAIN": "domain.com", + "FILE_DOMAIN": "files.domain.com", "siteUrl": "https://domain.com", "abuseContact": "abuse@example.com", "infoContact": "info@example.com", diff --git a/src/static/dbSchemas/sqlite_schema.sql b/src/static/dbSchemas/sqlite_schema.sql index f26b65b..9354ab4 100644 --- a/src/static/dbSchemas/sqlite_schema.sql +++ b/src/static/dbSchemas/sqlite_schema.sql @@ -28,10 +28,4 @@ CREATE TABLE `ratelimit` ( , `time` integer default NULL , `files` integer default NULL ); -CREATE TABLE `ratelimit`( - `id` integer NOT NULL PRIMARY KEY AUTOINCREMENT -, `iphash` char(40) default NULL -, `files` integer default NULL -, `time` integer default NULL -); END TRANSACTION;