Merge branch 'master' into feat/captchaVerify

This commit is contained in:
Madeline
2022-08-06 10:48:21 +10:00
committed by GitHub
97 changed files with 2006 additions and 234 deletions
-1
View File
@@ -1 +0,0 @@
MONGO_URL=mongodb://db:27017/fosscord?readPreference=secondaryPreferred
-2
View File
@@ -1,2 +0,0 @@
node_modules/
db/
+4 -1
View File
@@ -9,4 +9,7 @@ files/
config.json
.vscode/settings.json
api/assets/plugins/*.js
api/assets/plugins/*.js
.idea/
*.code-workspace
+7 -25
View File
@@ -1,8 +1,6 @@
FROM node:alpine
# env vars
ENV WORK_DIR="/srv/fosscord-server"
ENV DEV_MODE=0
ENV HTTP_PORT=3001
ENV WS_PORT=3002
ENV CDN_PORT=3003
@@ -13,28 +11,12 @@ ENV ADMIN_PORT=3005
EXPOSE ${HTTP_PORT}/tcp ${WS_PORT}/tcp ${CDN_PORT}/tcp ${RTC_PORT}/tcp ${ADMIN_PORT}/tcp
# install required apps
RUN apk add --no-cache --update git python2 py-pip make build-base
RUN apk add --no-cache --update git python3 py-pip make build-base
RUN ln -s /usr/bin/python3 /usr/bin/python
# optionl: packages for debugging/development
RUN apk add --no-cache sqlite
# Run as non-root user
# RUN adduser -D fosscord
# USER fosscord
# download fosscord-server
WORKDIR $WORK_DIR/src
RUN git clone https://github.com/fosscord/fosscord-server.git .
# setup and run
WORKDIR $WORK_DIR/src/bundle
RUN npm run setup
RUN npm install @yukikaze-bot/erlpack
# RUN npm install mysql --save
# create update script
RUN printf '#!/bin/sh\n\ngit -C $WORK_DIR/src/ checkout master\ngit -C $WORK_DIR/src/ reset --hard HEAD\ngit -C $WORK_DIR/src/ pull\ncd $WORK_DIR/src/bundle/\nnpm run setup\n' > $WORK_DIR/update.sh
RUN chmod +x $WORK_DIR/update.sh
# configure entrypoint file
RUN printf '#!/bin/sh\n\nDEV_MODE=${DEV_MODE:-0}\n\nif [ "$DEV_MODE" -eq 1 ]; then\n tail -f /dev/null\nelse\n cd $WORK_DIR/src/bundle/\n npm run start:bundle\nfi\n' > $WORK_DIR/entrypoint.sh
RUN chmod +x $WORK_DIR/entrypoint.sh
WORKDIR $WORK_DIR
ENTRYPOINT ["./entrypoint.sh"]
WORKDIR /srv/fosscord-server/bundle
ENTRYPOINT ["npm", "run", "start:bundle"]
+1343 -7
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -7,6 +7,7 @@
<link rel="stylesheet" href="/assets/fosscord.css" />
<link id="logincss" rel="stylesheet" href="/assets/fosscord-login.css" />
<link id="customcss" rel="stylesheet" href="/assets/user.css" />
<!-- inline plugin marker -->
<!-- preload plugin marker -->
</head>
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+12 -10
View File
@@ -1,16 +1,18 @@
{
"login": {
"INVALID_LOGIN": "מייל או מספר טלפון לא נמצאים במאגר",
"INVALID_PASSWORD": "סיסמא שגויה",
"ACCOUNT_DISABLED": "משתמש זה חסום / מבוטל"
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "לא ניתן לאפשר רישום משתמשים חדשים",
"INVITE_ONLY": "עליך להיות מוזמן בכדי להרשם",
"EMAIL_INVALID": "מייל שגוי",
"EMAIL_ALREADY_REGISTERED": "מייל זה כבר רשום",
"DATE_OF_BIRTH_UNDERAGE": "{{years}} עלייך להיות מעל גיל",
"CONSENT_REQUIRED": ".עליך להסכים לתנאי השירות ולמדיניות הפרטיות",
"USERNAME_TOO_MANY_USERS": "ליותר מדי משתמשים יש שם משתמש זהה, אנא נסה אחר"
"REGISTRATION_DISABLED": "New user registration is disabled",
"INVITE_ONLY": "You must be invited to register",
"EMAIL_INVALID": "Invalid Email",
"EMAIL_ALREADY_REGISTERED": "Email is already registered",
"DATE_OF_BIRTH_UNDERAGE": "You need to be {{years}} years or older",
"CONSENT_REQUIRED": "You must agree to the Terms of Service and Privacy Policy.",
"USERNAME_TOO_MANY_USERS": "Too many users have this username, please try another"
}
}
+11 -11
View File
@@ -1,18 +1,18 @@
{
"field": {
"BASE_TYPE_REQUIRED": "שדה זה חובה",
"BASE_TYPE_STRING": "שדה זה חייב להיות כטקסט",
"BASE_TYPE_NUMBER": "שדה זה חייב להיות מספר",
"BASE_TYPE_BIGINT": "השדה הזה חייב להיות ביגינט",
"BASE_TYPE_BOOLEAN": "השדה הזה חייב להיות בוליאני",
"BASE_TYPE_CHOICES": "({{types}}) שדה זה חייב להיות אחד מ",
"BASE_TYPE_CLASS": "{{type}} מסוג instance שדה זה חייב להיות",
"BASE_TYPE_REQUIRED": "This field is required",
"BASE_TYPE_STRING": "This field must be a string",
"BASE_TYPE_NUMBER": "This field must be a number",
"BASE_TYPE_BIGINT": "This field must be a bigint",
"BASE_TYPE_BOOLEAN": "This field must be a boolean",
"BASE_TYPE_CHOICES": "This field must be one of ({{types}})",
"BASE_TYPE_CLASS": "This field must be an instance of {{type}}",
"BASE_TYPE_OBJECT": "שדה זה חייב להיות אובייקט",
"BASE_TYPE_ARRAY": "שדה זה חייב להיות מערך",
"UNKOWN_FIELD": "{{key}} :מפתח לא ידוע",
"BASE_TYPE_CONSTANT": "{{value}} שדה זה חייב להיות",
"UNKOWN_FIELD": "מפתח לא ידוע: {{key}}",
"BASE_TYPE_CONSTANT": "שדה זה להיות {{value}}",
"EMAIL_TYPE_INVALID_EMAIL": "כתובת דואר אלקטרוני לא חוקית",
"DATE_TYPE_PARSE": "ISO8601 אמור להיות {{date}} לא ניתן לאתר",
"BASE_TYPE_BAD_LENGTH": "{{length}} האורך חייב להיות בין"
"DATE_TYPE_PARSE": "לא ניתן לנתח {{date}}. צריך להיות ISO8601",
"BASE_TYPE_BAD_LENGTH": "האורך חייב להיות בין {{length}}"
}
}
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-mail lub numer telefonu nie został znaleziony",
"INVALID_PASSWORD": "Nieprawidłowe hasło",
"ACCOUNT_DISABLED": "To konto jest nieaktywne"
"ACCOUNT_DISABLED": "To konto jest nieaktywne",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "Rejestracja nowych użytkowników jest wyłączona",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "Данный адрес электронной почты или телефона не найден",
"INVALID_PASSWORD": "Неверный пароль",
"ACCOUNT_DISABLED": "Этот аккаунт отключён"
"ACCOUNT_DISABLED": "Этот аккаунт отключён",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "Регистрация новых пользователей отключена",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-post eller telefon hittades inte",
"INVALID_PASSWORD": "Ogiltigt lösenord",
"ACCOUNT_DISABLED": "Detta konto är inaktiverat"
"ACCOUNT_DISABLED": "Detta konto är inaktiverat",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "Registrering av nya användare är inaktiverat",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-posta veya Telefon Numarası bulunamadı",
"INVALID_PASSWORD": "Geçersiz Şifre",
"ACCOUNT_DISABLED": "Bu hesap devre dışı bırakıldı"
"ACCOUNT_DISABLED": "Bu hesap devre dışı bırakıldı",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "Yeni kullanıcı alımı devre dışı bırakıldı",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+3 -1
View File
@@ -2,7 +2,9 @@
"login": {
"INVALID_LOGIN": "E-Mail or Phone not found",
"INVALID_PASSWORD": "Invalid Password",
"ACCOUNT_DISABLED": "This account is disabled"
"ACCOUNT_DISABLED": "This account is disabled",
"INVALID_TOTP_CODE": "Invalid two-factor code.",
"INVALID_TOTP_SECRET": "Invalid two-factor secret."
},
"register": {
"REGISTRATION_DISABLED": "New user registration is disabled",
+2 -1
View File
@@ -48,7 +48,7 @@
"@types/jsonwebtoken": "^8.5.0",
"@types/morgan": "^1.9.3",
"@types/multer": "^1.4.5",
"@types/node": "^14.17.9",
"@types/node": "^14.18.22",
"@types/node-fetch": "^2.5.5",
"@types/supertest": "^2.0.11",
"@zerollup/ts-transform-paths": "^1.7.18",
@@ -86,6 +86,7 @@
"missing-native-js-functions": "^1.2.18",
"morgan": "^1.10.0",
"multer": "^1.4.2",
"node-2fa": "^2.0.3",
"node-fetch": "^2.6.2",
"patch-package": "^6.4.7",
"picocolors": "^1.0.0",
+1
View File
@@ -7,6 +7,7 @@ export const NO_AUTHORIZATION_ROUTES = [
"/auth/login",
"/auth/register",
"/auth/location-metadata",
"/auth/mfa/totp",
// Routes with a seperate auth system
"/webhooks/",
// Public information endpoints
+105 -65
View File
@@ -1,54 +1,46 @@
import express, { Request, Response, Application } from "express";
import fs from "fs";
import fs, { writeFile } from "fs";
import path from "path";
import fetch, { Response as FetchResponse } from "node-fetch";
import fetch, { Response as FetchResponse, Headers } from "node-fetch";
import ProxyAgent from 'proxy-agent';
import { Config } from "@fosscord/util";
import { AssetCacheItem } from "../util/entities/AssetCacheItem"
import { FileLogger } from "typeorm";
export default function TestClient(app: Application) {
const agent = new ProxyAgent();
const assetCache = new Map<string, { response: FetchResponse; buffer: Buffer }>();
const indexHTML = fs.readFileSync(path.join(__dirname, "..", "..", "client_test", "index.html"), { encoding: "utf8" });
var html = indexHTML;
const CDN_ENDPOINT = (Config.get().cdn.endpointClient || Config.get()?.cdn.endpointPublic || process.env.CDN || "").replace(
/(https?)?(:\/\/?)/g,
""
);
const GATEWAY_ENDPOINT = Config.get().gateway.endpointClient || Config.get()?.gateway.endpointPublic || process.env.GATEWAY || "";
if (CDN_ENDPOINT) {
html = html.replace(/CDN_HOST: .+/, `CDN_HOST: \`${CDN_ENDPOINT}\`,`);
}
if (GATEWAY_ENDPOINT) {
html = html.replace(/GATEWAY_ENDPOINT: .+/, `GATEWAY_ENDPOINT: \`${GATEWAY_ENDPOINT}\`,`);
}
// inline plugins
var files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "preload-plugins"));
var plugins = "";
files.forEach(x =>{if(x.endsWith(".js")) plugins += `<script>${fs.readFileSync(path.join(__dirname, "..", "..", "assets", "preload-plugins", x))}</script>\n`; });
html = html.replaceAll("<!-- preload plugin marker -->", plugins);
// plugins
files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "plugins"));
plugins = "";
files.forEach(x =>{if(x.endsWith(".js")) plugins += `<script src='/assets/plugins/${x}'></script>\n`; });
html = html.replaceAll("<!-- plugin marker -->", plugins);
//preload plugins
files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "preload-plugins"));
plugins = "";
files.forEach(x =>{if(x.endsWith(".js")) plugins += `<script>${fs.readFileSync(path.join(__dirname, "..", "..", "assets", "preload-plugins", x))}</script>\n`; });
html = html.replaceAll("<!-- preload plugin marker -->", plugins);
app.use("/assets", express.static(path.join(__dirname, "..", "..", "assets")));
//build client page
let html = fs.readFileSync(path.join(__dirname, "..", "..", "client_test", "index.html"), { encoding: "utf8" });
html = applyEnv(html);
html = applyInlinePlugins(html);
html = applyPlugins(html);
html = applyPreloadPlugins(html);
//load asset cache
let newAssetCache: Map<string, AssetCacheItem> = new Map<string, AssetCacheItem>();
if(!fs.existsSync(path.join(__dirname, "..", "..", "assets", "cache"))) {
fs.mkdirSync(path.join(__dirname, "..", "..", "assets", "cache"));
}
if(fs.existsSync(path.join(__dirname, "..", "..", "assets", "cache", "index.json"))) {
let rawdata = fs.readFileSync(path.join(__dirname, "..", "..", "assets", "cache", "index.json"));
newAssetCache = new Map<string, AssetCacheItem>(Object.entries(JSON.parse(rawdata.toString())));
}
app.use("/assets", express.static(path.join(__dirname, "..", "..", "assets")));
app.get("/assets/:file", async (req: Request, res: Response) => {
delete req.headers.host;
var response: FetchResponse;
var buffer: Buffer;
const cache = assetCache.get(req.params.file);
if (!cache) {
let response: FetchResponse;
let buffer: Buffer;
let assetCacheItem: AssetCacheItem = new AssetCacheItem(req.params.file);
if(newAssetCache.has(req.params.file)){
assetCacheItem = newAssetCache.get(req.params.file)!;
assetCacheItem.Headers.forEach((value: any, name: any) => {
res.set(name, value);
});
}
else {
console.log(`CACHE MISS! Asset file: ${req.params.file}`);
response = await fetch(`https://discord.com/assets/${req.params.file}`, {
agent,
// @ts-ignore
@@ -56,34 +48,24 @@ export default function TestClient(app: Application) {
...req.headers
}
});
buffer = await response.buffer();
} else {
response = cache.response;
buffer = cache.buffer;
//set cache info
assetCacheItem.Headers = Object.fromEntries(stripHeaders(response.headers));
assetCacheItem.FilePath = path.join(__dirname, "..", "..", "assets", "cache", req.params.file);
assetCacheItem.Key = req.params.file;
//add to cache and save
newAssetCache.set(req.params.file, assetCacheItem);
fs.writeFileSync(path.join(__dirname, "..", "..", "assets", "cache", "index.json"), JSON.stringify(Object.fromEntries(newAssetCache), null, 4));
//download file
fs.writeFileSync(assetCacheItem.FilePath, await response.buffer());
}
response.headers.forEach((value, name) => {
if (
[
"content-length",
"content-security-policy",
"strict-transport-security",
"set-cookie",
"transfer-encoding",
"expect-ct",
"access-control-allow-origin",
"content-encoding"
].includes(name.toLowerCase())
) {
return;
}
assetCacheItem.Headers.forEach((value: string, name: string) => {
res.set(name, value);
});
assetCache.set(req.params.file, { buffer, response });
return res.send(buffer);
return res.send(fs.readFileSync(assetCacheItem.FilePath));
});
app.get("/developers*", (req: Request, res: Response) => {
app.get("/developers*", (_req: Request, res: Response) => {
const { useTestClient } = Config.get().client;
res.set("Cache-Control", "public, max-age=" + 60 * 60 * 24);
res.set("content-type", "text/html");
@@ -104,4 +86,62 @@ export default function TestClient(app: Application) {
res.send(html);
});
}
function applyEnv(html: string): string {
const CDN_ENDPOINT = (Config.get().cdn.endpointClient || Config.get()?.cdn.endpointPublic || process.env.CDN || "").replace(
/(https?)?(:\/\/?)/g,
""
);
const GATEWAY_ENDPOINT = Config.get().gateway.endpointClient || Config.get()?.gateway.endpointPublic || process.env.GATEWAY || "";
if (CDN_ENDPOINT) {
html = html.replace(/CDN_HOST: .+/, `CDN_HOST: \`${CDN_ENDPOINT}\`,`);
}
if (GATEWAY_ENDPOINT) {
html = html.replace(/GATEWAY_ENDPOINT: .+/, `GATEWAY_ENDPOINT: \`${GATEWAY_ENDPOINT}\`,`);
}
return html;
}
function applyPlugins(html: string): string {
// plugins
let files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "plugins"));
let plugins = "";
files.forEach(x =>{if(x.endsWith(".js")) plugins += `<script src='/assets/plugins/${x}'></script>\n`; });
return html.replaceAll("<!-- plugin marker -->", plugins);
}
function applyInlinePlugins(html: string): string{
// inline plugins
let files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "inline-plugins"));
let plugins = "";
files.forEach(x =>{if(x.endsWith(".js")) plugins += `<script src='/assets/inline-plugins/${x}'></script>\n\n`; });
return html.replaceAll("<!-- inline plugin marker -->", plugins);
}
function applyPreloadPlugins(html: string): string{
//preload plugins
let files = fs.readdirSync(path.join(__dirname, "..", "..", "assets", "preload-plugins"));
let plugins = "";
files.forEach(x =>{if(x.endsWith(".js")) plugins += `<script>${fs.readFileSync(path.join(__dirname, "..", "..", "assets", "preload-plugins", x))}</script>\n`; });
return html.replaceAll("<!-- preload plugin marker -->", plugins);
}
function stripHeaders(headers: Headers): Headers {
[
"content-length",
"content-security-policy",
"strict-transport-security",
"set-cookie",
"transfer-encoding",
"expect-ct",
"access-control-allow-origin",
"content-encoding"
].forEach(headerName => {
headers.delete(headerName);
});
return headers;
}
+16 -1
View File
@@ -2,6 +2,7 @@ import { Request, Response, Router } from "express";
import { route, getIpAdress, verifyCaptcha } from "@fosscord/api";
import bcrypt from "bcrypt";
import { Config, User, generateToken, adjustEmail, FieldErrors } from "@fosscord/util";
import crypto from "crypto";
const router: Router = Router();
export default router;
@@ -45,7 +46,7 @@ router.post("/", route({ body: "LoginSchema" }), async (req: Request, res: Respo
const user = await User.findOneOrFail({
where: [{ phone: login }, { email: login }],
select: ["data", "id", "disabled", "deleted", "settings"]
select: ["data", "id", "disabled", "deleted", "settings", "totp_secret", "mfa_enabled"]
}).catch((e) => {
throw FieldErrors({ login: { message: req.t("auth:login.INVALID_LOGIN"), code: "INVALID_LOGIN" } });
});
@@ -65,6 +66,20 @@ router.post("/", route({ body: "LoginSchema" }), async (req: Request, res: Respo
throw FieldErrors({ password: { message: req.t("auth:login.INVALID_PASSWORD"), code: "INVALID_PASSWORD" } });
}
if (user.mfa_enabled) {
// TODO: This is not a discord.com ticket. I'm not sure what it is but I'm lazy
const ticket = crypto.randomBytes(40).toString("hex");
await User.update({ id: user.id }, { totp_last_ticket: ticket });
return res.json({
ticket: ticket,
mfa: true,
sms: false, // TODO
token: null,
})
}
const token = await generateToken(user.id);
// Notice this will have a different token structure, than discord
+49
View File
@@ -0,0 +1,49 @@
import { Router, Request, Response } from "express";
import { route } from "@fosscord/api";
import { BackupCode, FieldErrors, generateToken, User } from "@fosscord/util";
import { verifyToken } from "node-2fa";
import { HTTPError } from "lambert-server";
const router = Router();
export interface TotpSchema {
code: string,
ticket: string,
gift_code_sku_id?: string | null,
login_source?: string | null,
}
router.post("/", route({ body: "TotpSchema" }), async (req: Request, res: Response) => {
const { code, ticket, gift_code_sku_id, login_source } = req.body as TotpSchema;
const user = await User.findOneOrFail({
where: {
totp_last_ticket: ticket,
},
select: [
"id",
"totp_secret",
"settings",
],
});
const backup = await BackupCode.findOne({ code: code, expired: false, consumed: false, user: { id: user.id }});
if (!backup) {
const ret = verifyToken(user.totp_secret!, code);
if (!ret || ret.delta != 0)
throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008);
}
else {
backup.consumed = true;
await backup.save();
}
await User.update({ id: user.id }, { totp_last_ticket: "" });
return res.json({
token: await generateToken(user.id),
user_settings: user.settings,
});
});
export default router;
+2 -1
View File
@@ -7,7 +7,8 @@ import { GuildCreateSchema } from "../index";
const router = Router();
export interface GuildUpdateSchema extends Omit<GuildCreateSchema, "channels"> {
export interface GuildUpdateSchema extends Omit<GuildCreateSchema, "channels" | "name"> {
name?: string;
banner?: string | null;
splash?: string | null;
description?: string;
+1
View File
@@ -11,6 +11,7 @@ export interface UserModifySchema {
* @maxLength 100
*/
username?: string;
discriminator?: string;
avatar?: string | null;
/**
* @maxLength 1024
+48
View File
@@ -0,0 +1,48 @@
import { Router, Request, Response } from "express";
import { route } from "@fosscord/api";
import { BackupCode, Config, FieldErrors, generateMfaBackupCodes, User } from "@fosscord/util";
import bcrypt from "bcrypt";
const router = Router();
export interface MfaCodesSchema {
password: string;
regenerate?: boolean;
}
// TODO: This route is replaced with users/@me/mfa/codes-verification in newer clients
router.post("/", route({ body: "MfaCodesSchema" }), async (req: Request, res: Response) => {
const { password, regenerate } = req.body as MfaCodesSchema;
const user = await User.findOneOrFail({ id: req.user_id }, { select: ["data"] });
if (!await bcrypt.compare(password, user.data.hash || "")) {
throw FieldErrors({ password: { message: req.t("auth:login.INVALID_PASSWORD"), code: "INVALID_PASSWORD" } });
}
var codes: BackupCode[];
if (regenerate && Config.get().security.twoFactor.generateBackupCodes) {
await BackupCode.update(
{ user: { id: req.user_id } },
{ expired: true }
);
codes = generateMfaBackupCodes(req.user_id);
await Promise.all(codes.map(x => x.save()));
}
else {
codes = await BackupCode.find({
user: {
id: req.user_id,
},
expired: false,
});
}
return res.json({
backup_codes: codes.map(x => ({ ...x, expired: undefined })),
})
});
export default router;
@@ -0,0 +1,45 @@
import { Router, Request, Response } from "express";
import { route } from "@fosscord/api";
import { verifyToken } from 'node-2fa';
import { HTTPError } from "lambert-server";
import { User, generateToken, BackupCode } from "@fosscord/util";
const router = Router();
export interface TotpDisableSchema {
code: string;
}
router.post("/", route({ body: "TotpDisableSchema" }), async (req: Request, res: Response) => {
const body = req.body as TotpDisableSchema;
const user = await User.findOneOrFail({ id: req.user_id }, { select: ["totp_secret"] });
const backup = await BackupCode.findOne({ code: body.code });
if (!backup) {
const ret = verifyToken(user.totp_secret!, body.code);
if (!ret || ret.delta != 0)
throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008);
}
await User.update(
{ id: req.user_id },
{
mfa_enabled: false,
totp_secret: "",
},
);
await BackupCode.update(
{ user: { id: req.user_id } },
{
expired: true,
}
);
return res.json({
token: await generateToken(user.id),
});
});
export default router;
@@ -0,0 +1,54 @@
import { Router, Request, Response } from "express";
import { User, generateToken, BackupCode, generateMfaBackupCodes, Config } from "@fosscord/util";
import { route } from "@fosscord/api";
import bcrypt from "bcrypt";
import { HTTPError } from "lambert-server";
import { verifyToken } from 'node-2fa';
const router = Router();
export interface TotpEnableSchema {
password: string;
code?: string;
secret?: string;
}
router.post("/", route({ body: "TotpEnableSchema" }), async (req: Request, res: Response) => {
const body = req.body as TotpEnableSchema;
const user = await User.findOneOrFail({ where: { id: req.user_id }, select: ["data"] });
// TODO: Are guests allowed to enable 2fa?
if (user.data.hash) {
if (!await bcrypt.compare(body.password, user.data.hash)) {
throw new HTTPError(req.t("auth:login.INVALID_PASSWORD"));
}
}
if (!body.secret)
throw new HTTPError(req.t("auth:login.INVALID_TOTP_SECRET"), 60005);
if (!body.code)
throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008);
if (verifyToken(body.secret, body.code)?.delta != 0)
throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008);
let backup_codes: BackupCode[] = [];
if (Config.get().security.twoFactor.generateBackupCodes) {
backup_codes = generateMfaBackupCodes(req.user_id);
await Promise.all(backup_codes.map(x => x.save()));
}
await User.update(
{ id: req.user_id },
{ mfa_enabled: true, totp_secret: body.secret }
);
res.send({
token: await generateToken(user.id),
backup_codes: backup_codes.map(x => ({ ...x, expired: undefined })),
});
});
export default router;
+32 -11
View File
@@ -1,37 +1,58 @@
import { Request, Response, Router } from "express";
import { route } from "@fosscord/api";
import { User, emitEvent } from "@fosscord/util";
import { User, Note, emitEvent, Snowflake } from "@fosscord/util";
const router: Router = Router();
router.get("/:id", route({}), async (req: Request, res: Response) => {
const { id } = req.params;
const user = await User.findOneOrFail({ where: { id: req.user_id }, select: ["notes"] });
const note = user.notes[id];
const note = await Note.findOneOrFail({
where: {
owner: { id: req.user_id },
target: { id: id },
}
});
return res.json({
note: note,
note: note?.content,
note_user_id: id,
user_id: user.id,
user_id: req.user_id,
});
});
router.put("/:id", route({}), async (req: Request, res: Response) => {
const { id } = req.params;
const user = await User.findOneOrFail({ where: { id: req.user_id } });
const noteUser = await User.findOneOrFail({ where: { id: id }}); //if noted user does not exist throw
const owner = await User.findOneOrFail({ where: { id: req.user_id } });
const target = await User.findOneOrFail({ where: { id: id } }); //if noted user does not exist throw
const { note } = req.body;
await User.update({ id: req.user_id }, { notes: { ...user.notes, [noteUser.id]: note } });
if (note && note.length) {
// upsert a note
if (await Note.findOne({ owner: { id: owner.id }, target: { id: target.id } })) {
Note.update(
{ owner: { id: owner.id }, target: { id: target.id } },
{ owner, target, content: note }
);
}
else {
Note.insert(
{ id: Snowflake.generate(), owner, target, content: note }
);
}
}
else {
await Note.delete({ owner: { id: owner.id }, target: { id: target.id } });
}
await emitEvent({
event: "USER_NOTE_UPDATE",
data: {
note: note,
id: noteUser.id
id: target.id
},
user_id: user.id,
})
user_id: owner.id,
});
return res.status(204);
});
+3
View File
@@ -0,0 +1,3 @@
export class AssetCacheItem {
constructor(public Key: string, public FilePath: string = "", public Headers: any = null as any) {}
}
+2 -1
View File
@@ -6,4 +6,5 @@ export * from "./utility/RandomInviteID";
export * from "./handlers/route";
export * from "./utility/String";
export * from "./handlers/Voice";
export * from "./utility/captcha";
export * from "./utility/captcha";
export * from "./entities/AssetCacheItem";
BIN
View File
Binary file not shown.
+4 -3
View File
@@ -79,7 +79,7 @@
"exif-be-gone": "^1.2.0",
"express": "^4.17.1",
"express-async-errors": "^3.1.1",
"file-type": "^16.5.0",
"file-type": "^16.5.4",
"form-data": "^4.0.0",
"fs-extra": "^10.0.0",
"i18next": "^19.9.2",
@@ -109,6 +109,7 @@
"typescript": "^4.1.2",
"typescript-cached-transpile": "^0.0.6",
"typescript-json-schema": "^0.50.1",
"ws": "^7.4.2"
"ws": "^7.4.2",
"node-2fa": "^2.0.3"
}
}
}
BIN
View File
Binary file not shown.
+1 -1
View File
@@ -44,7 +44,7 @@
"exif-be-gone": "^1.2.0",
"express": "^4.17.1",
"express-async-errors": "^3.1.1",
"file-type": "^16.5.0",
"file-type": "^16.5.4",
"form-data": "^4.0.0",
"fs-extra": "^10.0.0",
"image-size": "^1.0.0",
+6
View File
@@ -0,0 +1,6 @@
version: '3.9'
services:
fosscord:
entrypoint: [ "npm", "run", "setup" ]
+3 -25
View File
@@ -1,46 +1,24 @@
version: '3.8'
version: '3.9'
services:
fosscord:
container_name: fosscord
image: fosscord
restart: on-failure:5
# depends_on: mariadb
build: .
ports:
- '3001-3005:3001-3005'
volumes:
# - ./data/:${WORK_DIR:-/srv/fosscord-server}/data/
- data:${WORK_DIR:-/srv/fosscord-server}/
- ./:/srv/fosscord-server/
environment:
WORK_DIR: ${WORK_DIR:-/srv/fosscord-server}
DEV_MODE: ${DEV_MODE:-0}
THREADS: ${THREADS:-1}
DATABASE: ${DATABASE:-../../data/database.db}
STORAGE_LOCATION: ${STORAGE_LOCATION:-../../data/files/}
HTTP_PORT: 3001
WS_PORT: 3002
CDN_PORT: 3003
RTC_PORT: 3004
ADMIN_PORT: 3005
# mariadb:
# image: mariadb:latest
# restart: on-failure:5
# environment:
# MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-secr3tpassw0rd}
# MYSQL_DATABASE: ${MYSQL_DATABASE:-fosscord}
# MYSQL_USER: ${MYSQL_USER:-fosscord}
# MYSQL_PASSWORD: ${MYSQL_PASSWORD:-password1}
# networks:
# - default
# volumes:
# - mariadb:/var/lib/mysql
volumes:
data:
# mariadb:
networks:
default:
name: fosscord
+1 -2
View File
@@ -24,6 +24,5 @@
{
"path": "webrtc"
}
],
"settings": {}
]
}
BIN
View File
Binary file not shown.
+35
View File
@@ -0,0 +1,35 @@
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import { User } from "./User";
import crypto from "crypto";
@Entity("backup_codes")
export class BackupCode extends BaseClass {
@JoinColumn({ name: "user_id" })
@ManyToOne(() => User, { onDelete: "CASCADE" })
user: User;
@Column()
code: string;
@Column()
consumed: boolean;
@Column()
expired: boolean;
}
export function generateMfaBackupCodes(user_id: string) {
let backup_codes: BackupCode[] = [];
for (let i = 0; i < 10; i++) {
const code = BackupCode.create({
user: { id: user_id },
code: crypto.randomBytes(4).toString("hex"), // 8 characters
consumed: false,
expired: false,
});
backup_codes.push(code);
}
return backup_codes;
}
+6
View File
@@ -121,6 +121,9 @@ export interface ConfigValue {
secret: string | null;
};
ipdataApiKey: string | null;
twoFactor: {
generateBackupCodes: boolean;
};
};
login: {
requireCaptcha: boolean;
@@ -312,6 +315,9 @@ export const DefaultConfigOptions: ConfigValue = {
secret: null,
},
ipdataApiKey: "eca677b284b3bac29eb72f5e496aa9047f26543605efe99ff2ce35c9",
twoFactor: {
generateBackupCodes: true,
},
},
login: {
requireCaptcha: false,
+18
View File
@@ -0,0 +1,18 @@
import { Column, Entity, JoinColumn, ManyToOne, Unique } from "typeorm";
import { BaseClass } from "./BaseClass";
import { User } from "./User";
@Entity("notes")
@Unique(["owner", "target"])
export class Note extends BaseClass {
@JoinColumn({ name: "owner_id" })
@ManyToOne(() => User, { onDelete: "CASCADE" })
owner: User;
@JoinColumn({ name: "target_id" })
@ManyToOne(() => User, { onDelete: "CASCADE" })
target: User;
@Column()
content: string;
}
+8 -4
View File
@@ -1,10 +1,11 @@
import { Column, Entity, FindOneOptions, JoinColumn, ManyToMany, OneToMany, RelationId } from "typeorm";
import { Column, Entity, FindOneOptions, JoinColumn, OneToMany } from "typeorm";
import { BaseClass } from "./BaseClass";
import { BitField } from "../util/BitField";
import { Relationship } from "./Relationship";
import { ConnectedAccount } from "./ConnectedAccount";
import { Config, FieldErrors, Snowflake, trimSpecial } from "..";
import { Member, Session } from ".";
import { Note } from "./Note";
export enum PublicUserEnum {
username,
@@ -108,6 +109,12 @@ export class User extends BaseClass {
@Column({ select: false })
mfa_enabled: boolean; // if multi factor authentication is enabled
@Column({ select: false, nullable: true })
totp_secret?: string;
@Column({ nullable: true, select: false })
totp_last_ticket?: string;
@Column()
created_at: Date; // registration date
@@ -168,9 +175,6 @@ export class User extends BaseClass {
@Column({ type: "simple-json", select: false })
extended_settings: string;
@Column({ type: "simple-json" })
notes: { [key: string]: string }; //key is ID of user
toPublicUser() {
const user: any = {};
PublicUserProjection.forEach((x) => {
+3 -1
View File
@@ -27,4 +27,6 @@ export * from "./Template";
export * from "./User";
export * from "./VoiceState";
export * from "./Webhook";
export * from "./ClientRelease";
export * from "./ClientRelease";
export * from "./BackupCodes";
export * from "./Note";