This commit is contained in:
Go Johansson (neku) 2023-01-01 09:45:39 +01:00
parent e2c8b5721d
commit af4b9c4246
11 changed files with 116 additions and 113 deletions

1
.gitignore vendored
View File

@ -10,3 +10,4 @@ uguu.sq3
.vscode .vscode
composer.phar composer.phar
composer.lock composer.lock
docker/uguuForDocker.tar.gz

View File

@ -1,45 +1,50 @@
MAKE="make" MAKE = "make"
INSTALL="install" INSTALL = "install"
TAR="tar" TAR = "tar"
GREP="grep" GREP = "grep"
NODE="node" NODE = "node"
NPM="npm" NPM = "npm"
NODEJQ="node_modules/node-jq/bin/jq" NODEJQ = "node_modules/node-jq/bin/jq"
SQLITE="sqlite3" SQLITE = "sqlite3"
CONF="src/config.json" CONF = "src/config.json"
PHP="php" PHP = "php"
CURL="curl" CURL = "curl"
DESTDIR = $(shell $(CURDIR)/$(NODEJQ) -r ".dest" $(CURDIR)/$(CONF)) 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) PKG_VERSION = $(shell $(CURDIR)/$(NODEJQ) -r ".version" $(CURDIR)/package.json)
TMPDIR = $(shell mktemp -d) TMPDIR = $(shell mktemp -d)
DOCKER_IMAGE = "$(shell basename $(CURDIR) | tr [:upper:] [:lower:])" DOCKER_IMAGE = "$(shell basename $(CURDIR) | tr [:upper:] [:lower:])"
DOCKER_TAG="$(DOCKER_TAG)" DOCKER_TAG = "$(DOCKER_TAG)"
CONTAINER_NAME="$(CONTAINER_NAME)" CONTAINER_NAME = "$(CONTAINER_NAME)"
# default modules # default modules
MODULES="php" MODULES="php"
pageList = $(shell $(CURDIR)/$(NODEJQ) -r ".pages[]" $(CURDIR)/$(CONF)) pageList = $(shell $(CURDIR)/$(NODEJQ) -r ".pages[]" $(CURDIR)/$(CONF))
noExt = $(shell echo $(i) | cut -d '.' -f1) 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: ejs:
$(foreach i,$(pageList), \ $(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: "node_modules/minify/bin/minify.js"-all:
$(NPX) minify-all-cli -s $(CURDIR)/src/static/js -d $(CURDIR)/build/js "node_modules/minify/bin/minify.js" $(CURDIR)/src/static/js/uguu.js > $(CURDIR)/build/js/uguu.min.js
$(NPX) minify-all-cli -s $(CURDIR)/src/static/css -d $(CURDIR)/build/css "node_modules/minify/bin/minify.js" $(CURDIR)/src/static/css/uguu.css > $(CURDIR)/build/css/uguu.min.css
$(NPX) minify-all-cli -s $(CURDIR)/build/html/unmin/ -d $(CURDIR)/build/html/min/ -h "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: installdirs:
mkdir -p $(DESTDIR)/ $(DESTDIR)/img mkdir -p $(DESTDIR)/ $(DESTDIR)/img
mkdir -p $(DESTDIR)/ $(DESTDIR)/img/grills mkdir -p $(DESTDIR)/ $(DESTDIR)/img/grills
copy-img: copy-img:
$(NPX) imagemin $(CURDIR)/src/static/img/*.png -o=$(CURDIR)/build/img/ "node_modules/imagemin-cli/cli.js" $(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/grills/*.png --plugin=pngquant -o=$(CURDIR)/build/img/grills/
copy-php: copy-php:
cp -v $(CURDIR)/src/static/php/*.php $(CURDIR)/build/php/ cp -v $(CURDIR)/src/static/php/*.php $(CURDIR)/build/php/
@ -56,8 +61,6 @@ install: installdirs
rm -rf $(DESTDIR)/css rm -rf $(DESTDIR)/css
rm -rf $(DESTDIR)/js rm -rf $(DESTDIR)/js
rm -rf $(DESTDIR)/php 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)/img $(DESTDIR)/public/
mv $(DESTDIR)/grill.php $(DESTDIR)/public/ mv $(DESTDIR)/grill.php $(DESTDIR)/public/
mv $(DESTDIR)/upload.php $(DESTDIR)/public/ mv $(DESTDIR)/upload.php $(DESTDIR)/public/
@ -72,33 +75,43 @@ dist:
install install
$(TAR) cJf uguu-$(PKG_VERSION).tar.xz $(DESTDIR) $(TAR) cJf uguu-$(PKG_VERSION).tar.xz $(DESTDIR)
rm -rf $(TMPDIR) rm -rf $(TMPDIR)
clean: clean:
rm -rvf $(CURDIR)/node_modules rm -rvf $(CURDIR)/node_modules
rm -rvf $(CURDIR)/build rm -rvf $(CURDIR)/build
uninstall: uninstall:
rm -rvf $(DESTDIR)/ rm -rvf $(DESTDIR)/
npm_dependencies: npm_dependencies:
$(NPM) install $(NPM) install
build-image: build-container-no-cache:
tar --exclude='./uguuForDocker.tar.gz' --exclude='./vendor' --exclude='./node_modules' -czf uguuForDocker.tar.gz . 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/ 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: 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: purge-containers:
if docker images | grep $(DOCKER_IMAGE); then \ if docker images | grep uguu; then \
docker rm -f $(CONTAINER_NAME) && docker rmi $(DOCKER_IMAGE):$(DOCKER_TAG) || true;\ docker rm -f uguu && docker rmi uguu:$(PKG_VERSION) || true;\
fi; fi;
remove-container:
docker rm -f uguu
builddirs: 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 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

View File

@ -10,15 +10,19 @@ Uguu is a simple lightweight temporary file hosting and sharing platform, but ca
## Features ## Features
- One click uploading, no registration required - One click uploading, no registration required.
- A minimal, modern web interface - A minimal, modern web interface.
- Drag & Drop & Paste supported - Drag & Drop & Paste supported.
- Upload API with multiple response choices - Upload API with multiple response choices:
- JSON - JSON
- HTML - HTML
- Text - Text
- CSV - 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 ### Demo
@ -26,7 +30,7 @@ See the real world site at [uguu.se](https://uguu.se).
## Requirements ## 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. Node is used to compile Uguu, after that it runs on PHP.
@ -57,7 +61,6 @@ tests.
* S3 Bucket Support * S3 Bucket Support
* Azure File Storage Support * Azure File Storage Support
* Temporal/RR Support * Temporal/RR Support
*
## Credits ## Credits

View File

@ -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 apt-get install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2 curl cron socat
RUN apk add --no-cache $PHPIZE_DEPS \ RUN echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/sury-php.list
php-fpm zlib-dev libzip-dev libgomp; \ RUN curl -fsSL https://packages.sury.org/php/apt.gpg| gpg --dearmor -o /etc/apt/trusted.gpg.d/sury-keyring.gpg
docker-php-ext-install intl pcntl gd exif zip pdo mysql dom; \ RUN apt-get update
apk del $PHPIZE_DEPS; \ RUN apt-get upgrade -y
rm -rf /tmp/pear; RUN curl -o nodejssetup.sh https://deb.nodesource.com/setup_19.x
RUN chmod a+x nodejssetup.sh
# Install the needed software RUN ./nodejssetup.sh
RUN apk add --no-cache sqlite nodejs git npm bash build-base supervisor curl wget nginx RUN apt-get install -y nodejs gcc g++ make
#php8-fileinfo php8-pdo php8-tokenizer php8-dom php8-iconv php8-xml php8-simplexml \ RUN apt-get install -y build-essential nginx-full php8.1-fpm php8.1 sqlite3 php8.1-sqlite3 \
#php8-sqlite3 php8-opcache php8-mbstring php8-phar php8-openssl php8.1-curl php8.1-cli php8.1-lz4 \
php8.1-mcrypt php8.1-mysql php8.1-xdebug php8.1-zip \
# Create the www-data user and group php8.1-common php8.1-readline php8.1-bcmath php8.1-common php8.1-xml
#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
# Set default workdir # Set default workdir
WORKDIR /var/www/ WORKDIR /var/www/
@ -37,45 +32,51 @@ RUN mkdir /var/www/files && \
mkdir /var/www/db mkdir /var/www/db
# Create the Sqlite 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 && \ chown -R www-data:www-data /var/www && \
chmod -R 775 /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 # Fix script paths
RUN chmod a+x /var/www/uguu/src/static/scripts/checkdb.sh && \ RUN chmod a+x /var/www/uguu/src/static/scripts/checkdb.sh && \
chmod a+x /var/www/uguu/src/static/scripts/checkfiles.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/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 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 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 SSL certs
COPY docker/ssl /etc/ssl #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 Uguu config # Copy Uguu config
COPY src/config.json /var/www/uguu/config.json 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 port 80 from the container
EXPOSE 80 EXPOSE 80
# Expose port 443 from the container # Expose port 443 from the container
EXPOSE 443 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 # Load entrypoint
ENTRYPOINT [ "bash", "/var/www/docker-entrypoint.sh" ] ENTRYPOINT [ "bash", "/var/www/docker-entrypoint.sh" ]

View File

@ -1,11 +1,11 @@
#!/bin/bash #!/bin/bash
cd /var/www/uguu/ cd /var/www/uguu
npm install
make make
make install make install
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" /root/.acme.sh/acme.sh --set-default-ca --server letsencrypt
php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" /root/.acme.sh/acme.sh --issue -d $DOMAIN -w /var/www/uguu/dist/public/
php composer-setup.php /root/.acme.sh/acme.sh --issue -d $FILE_DOMAIN -w /var/www/files/
php -r "unlink('composer-setup.php');" service nginx start
php composer.phar install service php8.1-fpm start
php composer.phar update tail -f /var/log/nginx/access.log
/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf

View File

@ -1,7 +1,7 @@
server{ server{
listen 80; listen 80;
server_name 192.168.240.9; server_name XXX;
#ssl on; #ssl on;
#ssl_certificate /etc/nginx/ssl/fullchain.pem; #ssl_certificate /etc/nginx/ssl/fullchain.pem;
#ssl_certificate_key /etc/nginx/ssl/privkey.pem; #ssl_certificate_key /etc/nginx/ssl/privkey.pem;
@ -12,7 +12,7 @@ server{
root /var/www/uguu/dist/public/; root /var/www/uguu/dist/public/;
autoindex on; autoindex on;
access_log 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)$ { location ~* \.(css|js|jpg|jpeg|gif|png|ico|xml|eot|woff|woff2|ttf|svg|otf|x-icon|avif|webp|apng)$ {
expires 30d; expires 30d;
@ -26,7 +26,7 @@ server{
gzip_types text/css text/js text/javascript application/javascript application/x-javascript; gzip_types text/css text/js text/javascript application/javascript application/x-javascript;
location ~* \.php$ { 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_intercept_errors on;
fastcgi_index index.php; fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_split_path_info ^(.+\.php)(.*)$;

View File

@ -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! <<<"

View File

@ -1,2 +0,0 @@
#!/bin/bash
make DOCKER_TAG="$(cat package.json | grep version | cut -d '"' -f4)" CONTAINER_NAME=uguu purge-container

View File

@ -1,6 +1,6 @@
{ {
"name": "uguu", "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.", "description": "Uguu is a simple lightweight temporary file host with support for drop, paste, click and API uploading.",
"homepage": "https://uguu.se", "homepage": "https://uguu.se",
"repository": { "repository": {
@ -17,10 +17,9 @@
"url": "https://github.com/nokonoko/uguu/issues" "url": "https://github.com/nokonoko/uguu/issues"
}, },
"devDependencies": { "devDependencies": {
"minify": "^9.1.0",
"ejs": "^3.1.8", "ejs": "^3.1.8",
"minify-all-cli": "^1.0.13", "node-jq": "^2.3.4",
"node-jq": "^2.3.3",
"npx": "^10.2.2",
"imagemin-cli": "^7.0.0", "imagemin-cli": "^7.0.0",
"imagemin-pngquant": "^9.0.2" "imagemin-pngquant": "^9.0.2"
} }

View File

@ -3,7 +3,7 @@
"allowErrors": false "allowErrors": false
}, },
"dest": "dist", "dest": "dist",
"pkgVersion": "1.6.5", "pkgVersion": "1.6.6",
"pages": [ "pages": [
"index.ejs", "index.ejs",
"faq.ejs", "faq.ejs",
@ -13,6 +13,8 @@
"expireTime": "48H", "expireTime": "48H",
"siteName": "Uguu", "siteName": "Uguu",
"subTitle": "wahooo", "subTitle": "wahooo",
"DOMAIN": "domain.com",
"FILE_DOMAIN": "files.domain.com",
"siteUrl": "https://domain.com", "siteUrl": "https://domain.com",
"abuseContact": "abuse@example.com", "abuseContact": "abuse@example.com",
"infoContact": "info@example.com", "infoContact": "info@example.com",

View File

@ -28,10 +28,4 @@ CREATE TABLE `ratelimit` (
, `time` integer default NULL , `time` integer default NULL
, `files` 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; END TRANSACTION;