Skip to content

Commit

Permalink
in
Browse files Browse the repository at this point in the history
  • Loading branch information
nokonoko committed Jan 1, 2023
1 parent e2c8b57 commit af4b9c4
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 115 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -10,3 +10,4 @@ uguu.sq3
.vscode
composer.phar
composer.lock
docker/uguuForDocker.tar.gz
83 changes: 48 additions & 35 deletions 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/
Expand All @@ -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/
Expand All @@ -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

17 changes: 10 additions & 7 deletions README.md
Expand Up @@ -10,23 +10,27 @@ 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

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.

Expand Down Expand Up @@ -57,7 +61,6 @@ tests.
* S3 Bucket Support
* Azure File Storage Support
* Temporal/RR Support
*

## Credits

Expand Down
83 changes: 42 additions & 41 deletions docker/Dockerfile
@@ -1,26 +1,21 @@
FROM php:8.1-alpine

ARG VERSION


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
FROM --platform=linux/amd64 debian:bullseye-slim

# 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 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/
Expand All @@ -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

# Copy SSL certs
COPY docker/ssl /etc/ssl
#RUN sed -i 's#XXX#$()#g' /var/www/uguu/src/static/scripts/checkfiles.sh

# 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 SSL certs
#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" ]
16 changes: 8 additions & 8 deletions 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
6 changes: 3 additions & 3 deletions 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;
Expand All @@ -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;
Expand All @@ -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)(.*)$;
Expand Down
8 changes: 0 additions & 8 deletions docker_build.sh

This file was deleted.

2 changes: 0 additions & 2 deletions docker_purge.sh

This file was deleted.

7 changes: 3 additions & 4 deletions 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": {
Expand All @@ -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"
}
Expand Down
4 changes: 3 additions & 1 deletion src/config.json
Expand Up @@ -3,7 +3,7 @@
"allowErrors": false
},
"dest": "dist",
"pkgVersion": "1.6.5",
"pkgVersion": "1.6.6",
"pages": [
"index.ejs",
"faq.ejs",
Expand All @@ -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",
Expand Down

0 comments on commit af4b9c4

Please sign in to comment.