Skip to content

Commit

Permalink
Merge pull request #45
Browse files Browse the repository at this point in the history
Linguard service and improved build and install processes
  • Loading branch information
joseantmazonsb authored Sep 22, 2021
2 parents e27ae05 + abc42a3 commit 89be13d
Show file tree
Hide file tree
Showing 16 changed files with 295 additions and 208 deletions.
37 changes: 0 additions & 37 deletions .github/workflows/dev-git-install.yaml

This file was deleted.

25 changes: 22 additions & 3 deletions .github/workflows/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
- "**.js"
- "**.yml"
- "**.yaml"
- "**.sh"
- "poetry.lock"
- "pyproject.toml"

Expand Down Expand Up @@ -43,7 +44,7 @@ jobs:
run: |
wget https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py
python3 install-poetry.py
poetry config virtualenvs.create false
poetry config virtualenvs.in-project true
poetry install --no-interaction
- name: Install linux dependencies
Expand All @@ -57,7 +58,25 @@ jobs:
poetry run coverage run -m pytest && poetry run coverage xml
- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v2
if: always()
with:
files: coverage.xml
files: coverage.xml

- name: Build release
run: |
chmod +x build.sh
./build.sh
- name: Install release
run: |
cd dist
tar -xf *.tar.gz
chmod +x install.sh
sudo ./install.sh
- name: Briefly test uwgsi (can't use service here)
run: |
sudo -u linguard /usr/bin/uwsgi --yaml /etc/linguard/config/uwsgi.yaml &
sleep 2s
sudo pkill -f uwsgi
29 changes: 0 additions & 29 deletions .github/workflows/git-install.yaml

This file was deleted.

18 changes: 18 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,21 @@ jobs:
if: always()
with:
files: coverage.xml

- name: Build release
run: |
chmod +x build.sh
./build.sh
- name: Install release
run: |
cd dist
tar -xf *.tar.gz
chmod +x install.sh
sudo ./install.sh
- name: Briefly test uwgsi (can't use service here)
run: |
sudo -u linguard /usr/bin/uwsgi --yaml /etc/linguard/config/uwsgi.yaml &
sleep 2s
sudo pkill -f uwsgi
25 changes: 9 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,26 @@ Check out [the wiki](https://github.com/joseantmazonsb/linguard/wiki) for additi

## Table of contents
- [Installation](#installation)
- [Screenshots](#screenshots)
- [Git](#git)
- [Debian package](#debian-package)
- [Release](#release)
- [Docker](#docker)
- [Screenshots](#screenshots)
- [Contributing](#contributing)

## Installation

### Git
### Release

1. Download the installation script and run it. You must supply the installation directory (for instance, `/var/www/linguard`) and (optionally) the tag to check out.
1. Download [any release](https://github.com/joseantmazonsb/linguard/releases).

2. Extract it and run the installation script:
```bash
wget -q https://raw.githubusercontent.com/joseantmazonsb/linguard/main/scripts/install.sh
chmod +x install.sh
sudo ./install.sh <install_folder> [git_branch]
sudo ./install.sh
```
2. Edit the configuration files located in `/var/www/linguard/config` to fit your needs.
3. Start linguard:
3. Run Linguard:
```bash
sudo -u linguard /var/www/linguard/scripts/run.sh
sudo systemctl start linguard.service
```
or, if you renamed the uwsgi configuration file:
```bash
sudo -u linguard uwsgi --yaml /path/to/uwsgi/config/file
```

### Debian package

### Docker

Expand Down
79 changes: 79 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash

source ./scripts/log.sh

if [[ $# -gt 0 ]]; then
fatal "Invalid arguments."
info "Usage: $0"
exit 1
fi

OUT_DIR=$(pwd)
DIST_DIR="$OUT_DIR/dist"

info "Creating dist folder in '$DIST_DIR'..."

if [[ -d "$DIST_DIR" ]]; then
while true; do
warn -n "'$DIST_DIR' already exists. Shall I overwrite it? [y/n] "
read yn
case $yn in
[Yy]* )
rm -rf "$DIST_DIR";
if [ $? -ne 0 ]; then
fatal "Unable to overwrite '$DIST_DIR'."
exit 1
fi
break;;
[Nn]* )
info "Aborting...";
exit;;
* ) echo "Please answer yes or no.";;
esac
done
if [ $? -ne 0 ]; then
fatal "Unable to overwrite '$DIST_DIR'."
exit 1
fi
fi
mkdir -p "$DIST_DIR"

info "Copying source code..."
CODE_DIR="$DIST_DIR/linguard"
mkdir "$CODE_DIR"
cp -r linguard/common "$CODE_DIR/common"
cp -r linguard/core "$CODE_DIR/core"
cp -r linguard/web "$CODE_DIR/web"
cp linguard/__main__.py "$CODE_DIR"
cp linguard/__init__.py "$CODE_DIR"

info "Copying configuration files..."
cp -r systemd/ "$DIST_DIR"
CONFIG_DIR="$DIST_DIR/config"
mkdir "$CONFIG_DIR"
find config -type f | grep -E "[^.]+\.sample\.yaml" | xargs -i cp {} "$CONFIG_DIR"

info "Exporting python requirements..."
poetry export --without-hashes -f requirements.txt -o requirements.txt
if [ $? -ne 0 ]; then
fatal "Unable to export requirements."
exit 1
fi
mv requirements.txt "$DIST_DIR"

info "Copying scripts..."
cp scripts/install.sh "$DIST_DIR"
cp scripts/log.sh "$DIST_DIR"

version=$(poetry version -s)
zip_name="linguard-$version.tar.gz"

info "Compressing package into '$zip_name'..."
cd "$DIST_DIR"
tar -czf "$zip_name" *
mv "$zip_name" ..
cd - > /dev/null
rm -rf "$DIST_DIR"
mkdir -p "$DIST_DIR"
mv "$zip_name" "$DIST_DIR"
info "Done!"
10 changes: 5 additions & 5 deletions config/linguard.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ wireguard: !yamlable/wireguard
private_key: 4Ob32NhyhwIXbj7od6L5ASWle3vbOjn9g80at/dxPm0=
public_key: 7NTAVIucHQJsS9Z8eT3lUV8VUoTSFrB6J272F9ox5RQ=
uuid: 39a855187c4c4ca694d8c3f215e76cdc
interfaces_folder: /var/www/linguard/interfaces
interfaces_folder: /etc/linguard/interfaces
iptables_bin: /usr/sbin/iptables
wg_bin: /usr/bin/wg
wg_quick_bin: /usr/bin/wg-quick
logger: !yamlable/logger
level: debug
logfile: /var/www/linguard/linguard.log
level: info
logfile: /var/log/linguard/linguard.log
overwrite: false
traffic: !yamlable/traffic
driver: !yamlable/traffic_storage_driver_json
filepath: /var/www/linguard/traffic.json
filepath: /etc/linguard/traffic.json
timestamp_format: '%d/%m/%Y %H:%M:%S'
enabled: true
web: !yamlable/web
credentials_file: /var/www/linguard/credentials.yaml
credentials_file: /etc/linguard/credentials.yaml
login_attempts: 0
secret_key: G,XhSEIu{>TFu$y?4-kMy+<MN%T*J@/[
4 changes: 3 additions & 1 deletion config/uwsgi.sample.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
uwsgi:
master: true
enable-threads: true
processes: 1
threads: 1
chdir: /var/www/linguard
venv: venv
wsgi-file: linguard/__main__.py
pyargv: config/linguard.sample.yaml
pyargv: /etc/linguard/config/linguard.yaml
need-plugin: python3
callable: app
die-on-term: true
Expand Down
17 changes: 7 additions & 10 deletions linguard/web/controllers/RestController.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
from http.client import NO_CONTENT, INTERNAL_SERVER_ERROR
from logging import debug

from flask import Response, send_file, url_for, redirect, abort
from flask import Response, url_for, redirect, abort
from flask_login import login_user
from werkzeug.wsgi import FileWrapper

from linguard.common.models.user import users, User
from linguard.common.utils.logs import log_exception
Expand Down Expand Up @@ -109,15 +110,11 @@ def download_iface(self, iface: Interface) -> Response:

@staticmethod
def send_text_as_file(filename: str, text: str):
proxy = io.StringIO()
proxy.writelines(text)
# Creating the byteIO object from the StringIO Object
mem = io.BytesIO()
mem.write(proxy.getvalue().encode())
# seeking was necessary. Python 3.5.2, Flask 0.12.2
mem.seek(0)
proxy.close()
return send_file(mem, as_attachment=True, attachment_filename=filename, mimetype="text/plain")
wrapper = FileWrapper(io.BytesIO(text.encode()))
headers = {
'Content-Disposition': f'attachment; filename={filename}'
}
return Response(wrapper, mimetype='text/plain', direct_passthrough=True, headers=headers)

@staticmethod
def save_settings(form):
Expand Down
2 changes: 1 addition & 1 deletion linguard/web/templates/web/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ <h1 class="my-4">{{ title }}</h1>
<div class="card mb-4">
<div class="card-header">
<i class="fas fa-cog mr-1"></i>
{{ app_name }}
Wireguard
</div>
<div class="card-body">
<div id="alerts">
Expand Down
Loading

0 comments on commit 89be13d

Please sign in to comment.