Compare commits

...

15 Commits

Author SHA1 Message Date
Coluzzi Andrea 16b50df550
Italian Translations v4 (#524)
* IT translations: fix old PR comments

* IT translations: WIP v4 tokens

* IT translations: WIP v4 tokens

* IT translations: added v4 tokens
2022-08-03 07:18:36 +01:00
Martin Kleinschrodt 16b1a1a1e0
Merge pull request #522 from padloc/chore/update-translation-files
Update translation files with latest strings
2022-08-02 10:51:18 +02:00
Martin Kleinschrodt f639d24341 Exclude translations and word lists from prettier checks 2022-08-02 10:19:13 +02:00
Martin Kleinschrodt 00a282c632 Update translation files with latest strings 2022-08-02 10:14:52 +02:00
Martin Kleinschrodt 08b8ce4511
Merge pull request #520 from coluzziandrea/feature/italian-translations
Italian translations
2022-08-02 10:07:13 +02:00
Martin Kleinschrodt 12b027b37c
Merge pull request #521 from padloc/chore/update-simplewebauthn
Update SimpeWebAuthn dependency to latest
2022-08-02 08:22:16 +02:00
Martin Kleinschrodt e0834e72cb Update SimpeWebAuthn dependency to latest 2022-08-02 08:11:40 +02:00
Andrea Coluzzi 22fbde7502 Added italian translations 2022-08-02 00:43:36 +02:00
Martin Kleinschrodt f2b7846072
Merge pull request #515 from padloc/feature/better-error-reports-2
Provide better information in error reports. Also added postgres logger
2022-07-29 18:23:20 +02:00
Martin Kleinschrodt e2d8dc21ce Actually, using time stamps as an id prefix is probably a better idea 2022-07-29 18:06:33 +02:00
Martin Kleinschrodt 3736fac4c5 Forgot to generate id for log events 2022-07-29 17:58:49 +02:00
Martin Kleinschrodt cc092fae03 Implement postgres logger 2022-07-29 17:30:53 +02:00
Martin Kleinschrodt a7c58f693d Fix type error 2022-07-29 17:15:20 +02:00
Martin Kleinschrodt 9640a66f09 Apparently prettier doesn't like <pre></pre> inside <p></p> 2022-07-29 16:49:40 +02:00
Martin Kleinschrodt 01dd5eaf2a Provide better information in error reports by printing the stack trace and message of the original error instead of the Err wrapper 2022-07-29 16:36:32 +02:00
24 changed files with 25287 additions and 13516 deletions

View File

@ -13,3 +13,4 @@ packages/pwa/dist/**/*
package-lock.json
cypress/fixtures/**/*
.flatpak-builder/**/*
packages/locale/res/**/*

View File

@ -1,7 +0,0 @@
<p>The following error occurred at {{ time }}:</p>
<p>
Code: {{ code }} <br />
Message: {{ message }} <br />
Event ID: {{ eventId }}`
</p>

View File

@ -1,5 +0,0 @@
The following error occurred at {{ time }}:
Code: {{ code }}
Message: {{ message }}
Event ID: {{ eventId }}`

3
assets/email/plain.html Normal file
View File

@ -0,0 +1,3 @@
<pre>
{{ message }}
</pre>

1
assets/email/plain.txt Normal file
View File

@ -0,0 +1 @@
{{ message }}

View File

@ -184,6 +184,22 @@
# PL_LOGGING_MONGODB_MAX_SIZE=""
# PL_LOGGING_MONGODB_MAX_DOCUMENTS=""
# -----------------------------------------------------------------------------
# POSTGRES
#
# Use postgresql as log storage: https://www.npmjs.com/package/pg
# -----------------------------------------------------------------------------
# PL_LOGGING_BACKEND=postgres
# PL_LOGGING_POSTGRES_HOST=localhost
# PL_LOGGING_POSTGRES_PORT=5432
# PL_LOGGING_POSTGRES_DATABASE=padloc
# PL_LOGGING_POSTGRES_USER=padloc
# PL_LOGGING_POSTGRES_PASSWORD=""
# PL_LOGGING_POSTGRES_TLS=false
# PL_LOGGING_POSTGRES_TLS_CAFILE=""
# PL_LOGGING_POSTGRES_TLS_REJECT_UNAUTHORIZED=true
# -----------------------------------------------------------------------------
# MIXPANEL
#

File diff suppressed because it is too large Load Diff

View File

@ -22,8 +22,8 @@
"dependencies": {
"@padloc/core": "4.0.0",
"@padloc/locale": "4.0.0",
"@simplewebauthn/browser": "4.0.0",
"@simplewebauthn/typescript-types": "4.0.0",
"@simplewebauthn/browser": "5.4.0",
"@simplewebauthn/typescript-types": "5.4.0",
"@tiptap/core": "2.0.0-beta.182",
"@tiptap/starter-kit": "2.0.0-beta.191",
"@types/autosize": "4.0.1",

View File

@ -99,8 +99,10 @@ export class Err extends Error {
}
toString() {
return `Time: ${this.time.toISOString()}\nError Code: ${this.code}:\nError Message: ${
this.message
}\nStack Trace:\n${this.originalError ? this.originalError.stack : this.stack}`;
return `Time: ${this.time.toISOString()}
Error Code: ${this.code}
Error Message: ${this.message}
Stack Trace:\n${this.originalError ? this.originalError.stack : this.stack}
`;
}
}

View File

@ -60,8 +60,8 @@ export class JoinOrgInviteCompletedMessage extends Message<{ orgName: string; op
}
}
export class ErrorMessage extends Message<{ code: string; message: string; time: string; eventId: string }> {
template = "error";
export class PlainMessage extends Message<{ message: string }> {
template = "plain";
get title() {
return "Padloc Error Notification";

View File

@ -44,7 +44,7 @@ import { Org, OrgID, OrgMember, OrgMemberStatus, OrgRole, ScimSettings } from ".
import { Invite } from "./invite";
import {
ConfirmMembershipInviteMessage,
ErrorMessage,
PlainMessage,
JoinOrgInviteAcceptedMessage,
JoinOrgInviteCompletedMessage,
JoinOrgInviteMessage,
@ -2078,8 +2078,6 @@ export class Server {
}
private async _handleError(error: Error, req: Request, res: Response, context: Context) {
console.error(error);
const e =
error instanceof Err
? error
@ -2096,6 +2094,8 @@ export class Server {
};
if (e.report) {
console.error(error);
const evt = this.log("error", context, {
error: e.toRaw(),
request: {
@ -2108,13 +2108,12 @@ export class Server {
try {
await this.messenger.send(
this.config.reportErrors,
new ErrorMessage({
time: e.time.toISOString(),
code: e.code,
message: `Endpoint: ${req.method}\nMessage: ${e.message}\nDevice Info:\n${
new PlainMessage({
message: `The following error occured at ${e.time.toISOString()}:\n\nEndpoint: ${
req.method
}\nDevice Info:\n${
req.device && JSON.stringify(req.device?.toRaw(), null, 4)
}\nStack Trace:\n${e.stack}`,
eventId: evt.id,
}\n${e.toString()}${evt?.id ? `Event ID: ${evt.id}` : ""}`,
})
);
} catch (e) {}

View File

@ -21,6 +21,18 @@ export async function uuid(): Promise<string> {
].join("-");
}
/**
* Generates a random UUID v4
* NOT CRYPTOGRAPHICALLY SAFE!
*/
export function unsafeUUID(): string {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
var r = (Math.random() * 16) | 0,
v = c == "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}
/** Caracters, by category */
export const chars = {
numbers: "0123456789",

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -24,7 +24,7 @@
"@aws-sdk/types": "3.25.0",
"@padloc/core": "4.0.0",
"@padloc/locale": "4.0.0",
"@simplewebauthn/server": "4.0.0",
"@simplewebauthn/server": "5.4.0",
"@types/fs-extra": "9.0.11",
"@types/mixpanel": "2.14.3",
"@types/node": "15.6.1",

View File

@ -82,7 +82,7 @@ export class LoggingConfig extends Config {
}
@ConfigParam()
backend: "void" | "mongodb" | "mixpanel" = "void";
backend: "void" | "mongodb" | "postgres" | "mixpanel" = "void";
@ConfigParam()
secondaryBackend?: "mongodb" | "mixpanel";
@ -90,6 +90,9 @@ export class LoggingConfig extends Config {
@ConfigParam(MongoDBStorageConfig)
mongodb?: MongoDBStorageConfig;
@ConfigParam(PostgresConfig)
postgres?: PostgresConfig;
@ConfigParam(MixpanelConfig)
mixpanel?: MixpanelConfig;
}

View File

@ -11,7 +11,7 @@ import { AuthServer, AuthType } from "@padloc/core/src/auth";
import { WebAuthnConfig, WebAuthnServer } from "./auth/webauthn";
import { SMTPSender } from "./email/smtp";
import { MongoDBStorage } from "./storage/mongodb";
import { ConsoleMessenger, ErrorMessage } from "@padloc/core/src/messenger";
import { ConsoleMessenger, PlainMessage } from "@padloc/core/src/messenger";
import { FSAttachmentStorage, FSAttachmentStorageConfig } from "./attachments/fs";
import {
AttachmentStorageConfig,
@ -33,11 +33,11 @@ import { resolve, join } from "path";
import { MongoDBLogger } from "./logging/mongodb";
import { MixpanelLogger } from "./logging/mixpanel";
import { PostgresStorage } from "./storage/postgres";
import { ErrorCode } from "@padloc/core/src/error";
import { stripPropertiesRecursive } from "@padloc/core/src/util";
import { DirectoryProvisioner } from "./provisioning/directory";
import { ScimServer, ScimServerConfig } from "./scim";
import { DirectoryProvider, DirectorySync } from "@padloc/core/src/directory";
import { PostgresLogger } from "./logging/postgres";
const rootDir = resolve(__dirname, "../../..");
const assetsDir = resolve(rootDir, process.env.PL_ASSETS_DIR || "assets");
@ -75,7 +75,7 @@ async function initDataStorage(config: DataStorageConfig) {
}
}
async function initLogger({ backend, secondaryBackend, mongodb, mixpanel }: LoggingConfig) {
async function initLogger({ backend, secondaryBackend, mongodb, postgres, mixpanel }: LoggingConfig) {
let primaryLogger: Logger;
switch (backend) {
@ -83,9 +83,15 @@ async function initLogger({ backend, secondaryBackend, mongodb, mixpanel }: Logg
if (!mongodb) {
throw "PL_LOGGING_BACKEND was set to 'mongodb', but no related configuration was found!";
}
const storage = new MongoDBStorage(mongodb);
await storage.init();
primaryLogger = new MongoDBLogger(storage);
const mongoStorage = new MongoDBStorage(mongodb);
await mongoStorage.init();
primaryLogger = new MongoDBLogger(mongoStorage);
break;
case "postgres":
if (!postgres) {
throw "PL_LOGGING_BACKEND was set to 'postgres', but no related configuration was found!";
}
primaryLogger = new PostgresLogger(new PostgresStorage(postgres));
break;
case "void":
primaryLogger = new VoidLogger();
@ -302,11 +308,10 @@ async function init(config: PadlocConfig) {
try {
await emailSender.send(
config.server.reportErrors,
new ErrorMessage({
code: ErrorCode.UNKNOWN_ERROR,
message: `${err.message}\n${err.stack}`,
time: new Date().toISOString(),
eventId: "",
new PlainMessage({
message: `An uncaught exception occured at ${new Date().toISOString()}:\n${err.message}\n${
err.stack
}`,
})
);
} catch (e) {}

View File

@ -0,0 +1,17 @@
import { Logger, LogEvent } from "@padloc/core/src/logging";
import { PostgresStorage } from "../storage/postgres";
export class PostgresLogger implements Logger {
constructor(private _storage: PostgresStorage) {}
log(type: string, data?: any) {
const event = new LogEvent(type, data);
event.id = `${event.time.toISOString()}_${Math.floor(Math.random() * 1e6)}`;
(async () => {
try {
this._storage.save(event);
} catch (e) {}
})();
return event;
}
}