Pslink/README.md

171 lines
5.8 KiB
Markdown
Raw Normal View History

2021-03-09 14:07:05 +01:00
# Pslink a "Private Short Link page"
The target audience of this tool are small entities that need a url shortener. The shortened urls can be publicly resolved but only registered users can create short urls. Every registered user can see all shorted urls but ownly modify its own. Admin users can invite other accounts and edit everything that can be edited (also urls created by other accounts).
So in general this is more a shared short url bookmark webpage than a shorturl service.
2021-06-17 10:45:28 +02:00
![Screenshot](./doc/img/screenshot.png)
![Screenshot](./doc/img/screenshot_edit.png)
2021-03-09 14:07:05 +01:00
2021-08-12 10:33:11 +02:00
## What users can do
2021-06-20 19:38:45 +02:00
2021-08-12 10:33:11 +02:00
### Guests (no account)
2021-06-20 19:38:45 +02:00
* click on link get redirected to the page
* error on invalid or deleted link
2021-08-12 10:33:11 +02:00
### Users (regular account)
2021-06-20 19:38:45 +02:00
* view all existing links
* modify all own links
* create new links
* download qr-codes of the links
* modify own "profile" settings
2021-08-12 10:33:11 +02:00
### Admins (priviledged account)
2021-06-20 19:38:45 +02:00
* everything from users
* modify all links
* list all users
* modify all profiles
* create new users
* make users administrators
* make administrators normal users
2021-08-12 10:33:11 +02:00
## What the program can do
2021-06-20 19:38:45 +02:00
2021-03-27 11:09:41 +01:00
The Page comes with a basic commandline interface to setup the environment.
2021-03-09 14:07:05 +01:00
2021-08-12 10:33:11 +02:00
### Commandline
2021-06-20 19:38:45 +02:00
* create and read from a `.env` file in the current directory
* create and migrate the database
* create an admin user
* run the webserver
2021-08-12 10:33:11 +02:00
### Service
2021-06-20 19:38:45 +02:00
* admin interface via wasm
* Rest+Json server
* Tracing via Jaeger
2021-03-27 11:09:41 +01:00
## Usage
2021-03-09 14:07:05 +01:00
2021-03-27 11:09:41 +01:00
### install binary
The pslink binary can be downloaded from the latest release at: https://github.com/enaut/pslink/releases
These binaries are selfcontained and should run on any linux 64bit sy"stem. Just put them where you like them to be and make them executable. A sample install might be:
2021-03-27 11:09:41 +01:00
```bash
# mkdir -p /opt/pslink
# wget -o /opt/pslink/pslink https://github.com/enaut/pslink/releases/latest/download/pslink_linux_64bit
2021-03-27 11:09:41 +01:00
# chmod +x /opt/pslink/pslink
```
You could now adjust your `PATH` or setup an alias or just call the binary with the full path `/opt/pslink/pslink`
### Install with cargo
`cargo install pslink` does not (yet) produce a working binary! Use the "install binary" or "build from source" approach
2021-08-12 10:33:11 +02:00
### Build from source
Checkout the git repository and within its root folder issue the following commands. Internet es required and some packages will be installed during the process.
2021-03-27 11:09:41 +01:00
```bash
2021-06-17 10:45:28 +02:00
$ cargo install cargo-make
$ cargo make build_release
2021-07-12 09:31:00 +02:00
# or to immediately start the server after building but
# as you probably do not yet have a .env file or database
# this will fail.
2021-06-17 10:45:28 +02:00
$ cargo make start_release
2021-03-27 11:09:41 +01:00
```
2021-08-12 10:33:11 +02:00
If that succeeds you should now be able to call pslink. The binary is located at `target/release/pslink` and can be moved anywhere you want.
2021-03-27 11:09:41 +01:00
2021-08-12 10:33:11 +02:00
When building manually with cargo you may have to have a sqlite database present or build it in offline mode. So on your first build you will most likely need to call:
2021-03-27 11:09:41 +01:00
```bash
2021-06-17 10:45:28 +02:00
SQLX_OFFLINE=1 cargo make build_release
2021-03-27 11:09:41 +01:00
# or
$ export SQLX_OFFLINE=1
2021-06-17 10:45:28 +02:00
$ cargo make build_release
2021-03-27 11:09:41 +01:00
```
If pslink is built with `cargo make build_standalone` everything is embedded and it should be portable to any 64bit linux system. Otherwise the same or newer version of libc needs to be installed on the target linux system. Note that you need to install `musl-gcc` for this to work using: `sudo dnf install musl-libc musl-gcc` or `sudo apt-get install musl-tools`.
2021-07-12 09:31:00 +02:00
Templates and migrations are allways embedded in the binary so it should run standalone without anything extra.
2021-03-27 11:09:41 +01:00
### Setup
2021-03-09 14:07:05 +01:00
2021-08-14 11:47:51 +02:00
To read the help and documentation of additional options call:
```pslink help```
2021-03-09 14:07:05 +01:00
To get Pslink up and running use the commands in the following order:
2021-03-27 11:09:41 +01:00
1. `pslink generate-env`
this will generate a `.env` file in the curent directory with the default settings. Edit this file to your liking. You can however skip this step and provide all the parameters via commandline or environmentvariable. It is **not** recommended to provide PSLINK_SECRET with commandline parameters as they can be read by every user on the system.
2021-07-12 09:31:00 +02:00
2021-03-27 11:09:41 +01:00
2. `pslink migrate-database`
will create a sqlite database in the location specified.
2021-07-12 09:31:00 +02:00
2021-03-27 11:09:41 +01:00
3. `pslink create-admin`
2021-07-12 09:31:00 +02:00
create an initial admin user. As the page has no "register" function this is required to do anything usefull. The command is interactive so you will be asked the username and password of the new admin user.
2021-03-27 11:09:41 +01:00
4. `pslink runserver`
2021-07-12 09:31:00 +02:00
If everything is set up correctly this command will start the service. You should now be able to go to your url at [http://localhost/app/] and be presented with a login screen.
2021-03-09 14:07:05 +01:00
2021-03-27 11:09:41 +01:00
### Run the service
2021-03-09 14:07:05 +01:00
2021-05-24 14:30:47 +02:00
If everything is correctly set up just do `pslink runserver` to launch the server.
2021-03-09 14:07:05 +01:00
2021-03-27 11:09:41 +01:00
### Update
2021-03-09 14:07:05 +01:00
To update to a newer version execute the commands in the following order
1. stop the service
2021-07-12 09:31:00 +02:00
2. download and install or build the new binary
2021-03-27 11:09:41 +01:00
3. run `pslink migrate-database`
4. run the server again `pslink runserver`
2021-03-09 14:07:05 +01:00
2021-03-27 11:09:41 +01:00
### Help
2021-03-09 14:07:05 +01:00
2021-03-27 11:09:41 +01:00
For a list of options use `pslink help`. If the help does not provide enough clues please file an issue at: https://github.com/enaut/pslink/issues/new
2021-03-09 14:07:05 +01:00
2021-03-27 11:09:41 +01:00
### Systemd service file
2021-03-09 14:07:05 +01:00
2021-03-27 11:09:41 +01:00
If you want to automatically start this with systemd you can adjust the following template unit to your system. In this case a dedicated `pslink` user and group is used with the users home directory at `/var/pslink`. Some additional settings are in place to protect the system a little should anything go wrong.
2021-03-09 14:07:05 +01:00
```systemd
# /etc/systemd/system/pslink.service
[Unit]
Description=Pslink the Urlshortener
Documentation=https://github.com/enaut/Pslink
Wants=network.target
After=network.target
[Service]
User=pslink
Group=pslink
EnvironmentFile=-/var/pslink/.env
ProtectHome=true
ProtectSystem=full
PrivateDevices=true
NoNewPrivileges=true
PrivateTmp=true
InaccessibleDirectories=/root /sys /srv -/opt /media -/lost+found
ReadWriteDirectories=/var/pslink
WorkingDirectory=/var/pslink
ExecStart=/var/pslink/pslink runserver
[Install]
WantedBy=multi-user.target
```