Skip to content

Commit

Permalink
Merge branch 'tdjsnelling:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Klaiment authored Mar 7, 2024
2 parents ccf97db + 5e1e955 commit c9385c2
Show file tree
Hide file tree
Showing 21 changed files with 1,086 additions and 364 deletions.
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ The sqtracker client service provides the modern, responsive web interface that

The HTTP proxy allows the client, API, and BitTorrent tracker to all be accessible via a single endpoint.

Traefik is recommended and is configured by default. An Nginx config file is also provided for those that prefer it and the `docker-compose.yml` file contains an Nginx block that can be enabled.

### Deploying with Docker compose

The sqtracker platform is designed to be deployed via Docker. Once a configuration file is created, deploying is as simple as running `docker compose up -d` at the root of the project.
Expand Down Expand Up @@ -116,16 +118,20 @@ To add a new translation in your own language, create a new JSON file with your

The best place to start is to copy the `en.json` file and work through it, translating each English string.

There is also an [inlang project](https://fink.inlang.com/github.com/tdjsnelling/sqtracker) to aid with translation.

### Existing translations

| Language | Complete (estimate) | Contributed by |
|--------------------|---------------------|----------------------------------------------------|
| English | 100% | |
| Russian | 100% | [@smlinux](https://github.com/smlinux) |
| Esperanto | 100% | [@smlinux](https://github.com/smlinux) |
| German | 100% | [@EchterAlsFake](https://github.com/EchterAlsFake) |
| Simplified Chinese | 95% | [@0EAC](https://github.com/0EAC) |
| French | 100% | [@Klaiment](https://github.com/Klaiment) |
| Language | Contributed by |
|--------------------|------------------------------------------------------|
| English | |
| Russian | [@smlinux](https://github.com/smlinux) |
| Esperanto | [@smlinux](https://github.com/smlinux) |
| German | [@EchterAlsFake](https://github.com/EchterAlsFake) |
| Simplified Chinese | [@0EAC](https://github.com/0EAC) |
| French | [@Klaiment](https://github.com/Klaiment) |
| Spanish | [@CerealKillerjs](https://github.com/CerealKillerjs) |
| Italian | [@NotLugozzi](https://github.com/NotLugozzi) |

## Screenshots

Expand Down
2 changes: 1 addition & 1 deletion api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16-alpine
FROM node:16
ENV NODE_ENV=production
ENV SENTRY_DSN="https://[email protected]/4504645996576768"
LABEL org.opencontainers.image.source=https://github.com/tdjsnelling/sqtracker
Expand Down
76 changes: 42 additions & 34 deletions api/src/controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const register = (mail) => async (req, res, next) => {
role,
invitedBy: invite?.invitingUser,
remainingInvites: 0,
emailVerified: false,
emailVerified: process.env.SQ_DISABLE_EMAIL,
bonusPoints: 0,
totp: {
enabled: false,
Expand All @@ -125,19 +125,21 @@ export const register = (mail) => async (req, res, next) => {

const createdUser = await newUser.save();

const emailVerificationValidUntil = created + 48 * 60 * 60 * 1000;
const emailVerificationToken = jwt.sign(
{
user: req.body.email,
validUntil: emailVerificationValidUntil,
},
process.env.SQ_JWT_SECRET
);
await sendVerificationEmail(
mail,
req.body.email,
emailVerificationToken
);
if (!process.env.SQ_DISABLE_EMAIL) {
const emailVerificationValidUntil = created + 48 * 60 * 60 * 1000;
const emailVerificationToken = jwt.sign(
{
user: req.body.email,
validUntil: emailVerificationValidUntil,
},
process.env.SQ_JWT_SECRET
);
await sendVerificationEmail(
mail,
req.body.email,
emailVerificationToken
);
}

if (createdUser) {
if (req.body.invite) {
Expand Down Expand Up @@ -293,14 +295,16 @@ export const generateInvite = (mail) => async (req, res, next) => {
const createdInvite = await invite.save();

if (createdInvite) {
await mail.sendMail({
from: `"${process.env.SQ_SITE_NAME}" <${process.env.SQ_MAIL_FROM_ADDRESS}>`,
to: email,
subject: "Invite",
text: `You have been invited to join ${process.env.SQ_SITE_NAME}. Please follow the link below to register.
if (!process.env.SQ_DISABLE_EMAIL) {
await mail.sendMail({
from: `"${process.env.SQ_SITE_NAME}" <${process.env.SQ_MAIL_FROM_ADDRESS}>`,
to: email,
subject: "Invite",
text: `You have been invited to join ${process.env.SQ_SITE_NAME}. Please follow the link below to register.
${process.env.SQ_BASE_URL}/register?token=${createdInvite.token}`,
});
});
}
res.send(createdInvite);
}
} else {
Expand Down Expand Up @@ -343,18 +347,20 @@ export const changePassword = (mail) => async (req, res, next) => {
{ $set: { password: hash } }
);

await mail.sendMail({
from: `"${process.env.SQ_SITE_NAME}" <${process.env.SQ_MAIL_FROM_ADDRESS}>`,
to: user.email,
subject: "Your password was changed",
text: `Your password was updated successfully at ${new Date().toISOString()} from ${
req.ip
}.
if (!process.env.SQ_DISABLE_EMAIL) {
await mail.sendMail({
from: `"${process.env.SQ_SITE_NAME}" <${process.env.SQ_MAIL_FROM_ADDRESS}>`,
to: user.email,
subject: "Your password was changed",
text: `Your password was updated successfully at ${new Date().toISOString()} from ${
req.ip
}.
If you did not perform this action, follow the link below immediately to reset your password. If this was you, no action is required.
${process.env.SQ_BASE_URL}/reset-password/initiate`,
});
});
}

res.sendStatus(200);
} catch (e) {
Expand Down Expand Up @@ -388,14 +394,16 @@ export const initiatePasswordReset = (mail) => async (req, res, next) => {
process.env.SQ_JWT_SECRET
);

await mail.sendMail({
from: `"${process.env.SQ_SITE_NAME}" <${process.env.SQ_MAIL_FROM_ADDRESS}>`,
to: user.email,
subject: "Password reset",
text: `Please follow the link below to reset your password.
if (!process.env.SQ_DISABLE_EMAIL) {
await mail.sendMail({
from: `"${process.env.SQ_SITE_NAME}" <${process.env.SQ_MAIL_FROM_ADDRESS}>`,
to: user.email,
subject: "Password reset",
text: `Please follow the link below to reset your password.
${process.env.SQ_BASE_URL}/reset-password/finalise?token=${token}`,
});
});
}

res.sendStatus(200);
} catch (e) {
Expand Down
22 changes: 13 additions & 9 deletions api/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,19 @@ validateConfig(config).then(() => {
});
}

const mail = nodemailer.createTransport({
host: process.env.SQ_SMTP_HOST,
port: process.env.SQ_SMTP_PORT,
secure: process.env.SQ_SMTP_SECURE,
auth: {
user: process.env.SQ_SMTP_USER,
pass: process.env.SQ_SMTP_PASS,
},
});
let mail;

if (!process.env.SQ_DISABLE_EMAIL) {
mail = nodemailer.createTransport({
host: process.env.SQ_SMTP_HOST,
port: process.env.SQ_SMTP_PORT,
secure: process.env.SQ_SMTP_SECURE,
auth: {
user: process.env.SQ_SMTP_USER,
pass: process.env.SQ_SMTP_PASS,
},
});
}

const connectToDb = () => {
console.log("[sq] initiating db connection...");
Expand Down
29 changes: 16 additions & 13 deletions api/src/setup/createAdminUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const createAdminUser = async (mail) => {
password: hash,
created,
remainingInvites: Number.MAX_SAFE_INTEGER,
emailVerified: process.env.SQ_DISABLE_EMAIL,
});
adminUser.uid = crypto
.createHash("sha256")
Expand All @@ -35,19 +36,21 @@ const createAdminUser = async (mail) => {

await adminUser.save();

const emailVerificationValidUntil = created + 48 * 60 * 60 * 1000;
const emailVerificationToken = jwt.sign(
{
user: process.env.SQ_ADMIN_EMAIL,
validUntil: emailVerificationValidUntil,
},
process.env.SQ_JWT_SECRET
);
await sendVerificationEmail(
mail,
process.env.SQ_ADMIN_EMAIL,
emailVerificationToken
);
if (!process.env.SQ_DISABLE_EMAIL) {
const emailVerificationValidUntil = created + 48 * 60 * 60 * 1000;
const emailVerificationToken = jwt.sign(
{
user: process.env.SQ_ADMIN_EMAIL,
validUntil: emailVerificationValidUntil,
},
process.env.SQ_JWT_SECRET
);
await sendVerificationEmail(
mail,
process.env.SQ_ADMIN_EMAIL,
emailVerificationToken
);
}

console.log("[sq] created initial admin user");
}
Expand Down
44 changes: 38 additions & 6 deletions api/src/utils/validateConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,37 @@ const configSchema = yup
grey: yup.string().matches(hexRegex),
}),
SQ_EXTENSION_BLACKLIST: yup.array().of(yup.string()).min(0),
SQ_SITE_DEFAULT_LOCALE: yup
.string()
.oneOf(["en", "es", "it", "ru", "de", "zh", "eo", "fr"]),
SQ_BASE_URL: yup.string().matches(httpRegex).required(),
SQ_API_URL: yup.string().matches(httpRegex).required(),
SQ_MONGO_URL: yup.string().matches(mongoRegex).required(),
SQ_MAIL_FROM_ADDRESS: yup.string().email().required(),
SQ_SMTP_HOST: yup.string().required(),
SQ_SMTP_PORT: yup.number().integer().min(1).max(65535).required(),
SQ_SMTP_SECURE: yup.boolean().required(),
SQ_DISABLE_EMAIL: yup.boolean(),
SQ_MAIL_FROM_ADDRESS: yup
.string()
.email()
.when("SQ_DISABLE_EMAIL", {
is: (val) => val !== true,
then: (schema) => schema.required(),
}),
SQ_SMTP_HOST: yup.string().when("SQ_DISABLE_EMAIL", {
is: (val) => val !== true,
then: (schema) => schema.required(),
}),
SQ_SMTP_PORT: yup
.number()
.integer()
.min(1)
.max(65535)
.when("SQ_DISABLE_EMAIL", {
is: (val) => val !== true,
then: (schema) => schema.required(),
}),
SQ_SMTP_SECURE: yup.boolean().when("SQ_DISABLE_EMAIL", {
is: (val) => val !== true,
then: (schema) => schema.required(),
}),
})
.strict()
.noUnknown()
Expand All @@ -66,8 +90,16 @@ const configSchema = yup
SQ_JWT_SECRET: yup.string().required(),
SQ_SERVER_SECRET: yup.string().required(),
SQ_ADMIN_EMAIL: yup.string().email().required(),
SQ_SMTP_USER: yup.string().required(),
SQ_SMTP_PASS: yup.string().required(),
SQ_SMTP_USER: yup.string(),
SQ_SMTP_PASS: yup.string(),
})
.when("envs.SQ_DISABLE_EMAIL", {
is: (val) => val !== true,
then: (schema) => {
schema.fields.SQ_SMTP_USER = yup.string().required();
schema.fields.SQ_SMTP_PASS = yup.string().required();
return schema;
},
})
.strict()
.noUnknown()
Expand Down
2 changes: 1 addition & 1 deletion client/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16-alpine AS builder
FROM node:16 AS builder
ARG SENTRY_AUTH_TOKEN
ENV NODE_ENV=production
ENV SENTRY_ORG=tdjsnelling
Expand Down
9 changes: 6 additions & 3 deletions client/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,24 @@
"accEnable2FA": "Enable 2FA",
"accEveryRequestYouFulfill": "for every request you fulfill, or",
"accForEveryGBYouUpload": "for every GB you upload",
"accIfYouAreAlsUploaderAcceptTorrent": "if you are als the uploader of the accepted torrent",
"accIfYouAreAlsUploaderAcceptTorrent": "if you are also the uploader of the accepted torrent",
"accInviteLinkCopiedClipboard": "Invite link copied to clipboard",
"accInvites": "Invites",
"accRemaining": "remaining",
"accRoleUser": "Role: user",
"accRoleAdmin": "Role: admin",
"accInviteSentSuccess": "Invite sent successfully",
"accInviteSentSuccessNoEmail": "Invite created successfully",
"accInviteText1": "Enter an email address to send an invite. The invited user will need to sign up with the same email address. Once the invite is generated, you can also copy a direct invite link.",
"accInviteText1NoEmail": "Enter an email address to generate an invite. The invited user will need to sign up with the same email address. This tracker has email sending disabled, so you will need to copy and send the invite link yourself.",
"accItemsPurchasedSuccess": "Items purchased successfully",
"accMyAccount": "My account",
"accPassChangedSuccess": "Password changed successfully",
"accPurchaseInvites": "Purchase invites",
"accPurchaseUpload1GB": "Purchase upload (1 GB)",
"accRole": "Role",
"accSendInvite": "Send invite",
"accSendInviteNoEmail": "Create invite",
"accThisIsAdminAcc": "This is an admin account.",
"accValidUntil": "Valid until",
"accYouCurrentlyHave": "You currently have",
Expand Down Expand Up @@ -279,8 +282,8 @@
"userUploaded": "Uploaded",
"userMyUploads": "My uploads",
"usernameRules": "Can only consist of letters, numbers, and “.”",
"userUnban": "unban",
"userBan": "ban",
"userUnban": "Unban",
"userBan": "Ban",
"userUnbanned": "unbanned",
"userBanned": "banned",
"userAdmin": "Admin",
Expand Down
Loading

0 comments on commit c9385c2

Please sign in to comment.