diff --git a/Procfile b/Procfile index 16e3a033..8ae78557 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: node ./backend/index.js --Client-authenticationRequired=false +web: node ./backend/index.js --Client-authenticationRequired=false --Client-Sharing-enabled=false diff --git a/backend/middlewares/AdminMWs.ts b/backend/middlewares/AdminMWs.ts index 0c5fc393..4f8b608f 100644 --- a/backend/middlewares/AdminMWs.ts +++ b/backend/middlewares/AdminMWs.ts @@ -136,6 +136,9 @@ export class AdminMWs { // only updating explicitly set config (not saving config set by the diagnostics) const original = Config.original(); original.Client.authenticationRequired = req.body.settings; + if (original.Client.authenticationRequired === false) { + original.Client.Sharing.enabled = false; + } original.save(); await ConfigDiagnostics.runDiagnostics(); Logger.info(LOG_TAG, 'new config:'); diff --git a/backend/model/ConfigDiagnostics.ts b/backend/model/ConfigDiagnostics.ts index 925d61d0..1099605b 100644 --- a/backend/model/ConfigDiagnostics.ts +++ b/backend/model/ConfigDiagnostics.ts @@ -104,6 +104,10 @@ export class ConfigDiagnostics { config.Server.database.type === DatabaseType.memory) { throw new Error('Memory Database do not support sharing'); } + if (sharing.enabled === true && + config.Client.authenticationRequired === false) { + throw new Error('In case of no authentication, sharing is not supported'); + } } static async testMapConfig(map: ClientConfig.MapConfig) { @@ -118,10 +122,11 @@ export class ConfigDiagnostics { if (Config.Server.database.type !== DatabaseType.memory) { try { await ConfigDiagnostics.testDatabase(Config.Server.database); - } catch (err) { - Logger.warn(LOG_TAG, '[SQL error]', err); + } catch (ex) { + const err: Error = ex; + Logger.warn(LOG_TAG, '[SQL error]', err.toString()); Logger.warn(LOG_TAG, 'Error during initializing SQL falling back temporally to memory DB'); - NotificationManager.warning('Error during initializing SQL falling back temporally to memory DB', err); + NotificationManager.warning('Error during initializing SQL falling back temporally to memory DB', err.toString()); Config.setDatabaseType(DatabaseType.memory); } } @@ -129,11 +134,12 @@ export class ConfigDiagnostics { if (Config.Server.thumbnail.processingLibrary !== ThumbnailProcessingLib.Jimp) { try { await ConfigDiagnostics.testThumbnailLib(Config.Server.thumbnail.processingLibrary); - } catch (err) { + } catch (ex) { + const err: Error = ex; NotificationManager.warning('Thumbnail hardware acceleration is not possible.' + ' \'' + ThumbnailProcessingLib[Config.Server.thumbnail.processingLibrary] + '\' node module is not found.' + - ' Falling back temporally to JS based thumbnail generation', err); - Logger.warn(LOG_TAG, '[Thumbnail hardware acceleration] module error: ', err); + ' Falling back temporally to JS based thumbnail generation', err.toString()); + Logger.warn(LOG_TAG, '[Thumbnail hardware acceleration] module error: ', err.toString()); Logger.warn(LOG_TAG, 'Thumbnail hardware acceleration is not possible.' + ' \'' + ThumbnailProcessingLib[Config.Server.thumbnail.processingLibrary] + '\' node module is not found.' + ' Falling back temporally to JS based thumbnail generation'); @@ -143,51 +149,57 @@ export class ConfigDiagnostics { try { await ConfigDiagnostics.testThumbnailFolder(Config.Server.thumbnail.folder); - } catch (err) { - NotificationManager.error('Thumbnail folder error', err); - Logger.error(LOG_TAG, 'Thumbnail folder error', err); + } catch (ex) { + const err: Error = ex; + NotificationManager.error('Thumbnail folder error', err.toString()); + Logger.error(LOG_TAG, 'Thumbnail folder error', err.toString()); } try { await ConfigDiagnostics.testImageFolder(Config.Server.imagesFolder); - } catch (err) { - NotificationManager.error('Images folder error', err); - Logger.error(LOG_TAG, 'Images folder error', err); + } catch (ex) { + const err: Error = ex; + NotificationManager.error('Images folder error', err.toString()); + Logger.error(LOG_TAG, 'Images folder error', err.toString()); } try { await ConfigDiagnostics.testClientThumbnailConfig(Config.Client.Thumbnail); - } catch (err) { - NotificationManager.error('Thumbnail settings error', err); - Logger.error(LOG_TAG, 'Thumbnail settings error', err); + } catch (ex) { + const err: Error = ex; + NotificationManager.error('Thumbnail settings error', err.toString()); + Logger.error(LOG_TAG, 'Thumbnail settings error', err.toString()); } try { await ConfigDiagnostics.testSearchConfig(Config.Client.Search, Config); - } catch (err) { + } catch (ex) { + const err: Error = ex; NotificationManager.warning('Search is not supported with these settings. Disabling temporally. ' + - 'Please adjust the config properly.', err); - Logger.warn(LOG_TAG, 'Search is not supported with these settings, switching off..', err); + 'Please adjust the config properly.', err.toString()); + Logger.warn(LOG_TAG, 'Search is not supported with these settings, switching off..', err.toString()); Config.Client.Search.enabled = false; } try { await ConfigDiagnostics.testSharingConfig(Config.Client.Sharing, Config); - } catch (err) { + } catch (ex) { + const err: Error = ex; NotificationManager.warning('Sharing is not supported with these settings. Disabling temporally. ' + - 'Please adjust the config properly.', err); - Logger.warn(LOG_TAG, 'Sharing is not supported with these settings, switching off..', err); + 'Please adjust the config properly.', err.toString()); + Logger.warn(LOG_TAG, 'Sharing is not supported with these settings, switching off..', err.toString()); Config.Client.Sharing.enabled = false; } try { await ConfigDiagnostics.testMapConfig(Config.Client.Map); - } catch (err) { + } catch (ex) { + const err: Error = ex; NotificationManager.warning('Maps is not supported with these settings. Disabling temporally. ' + - 'Please adjust the config properly.', err); + 'Please adjust the config properly.', err.toString()); Logger.warn(LOG_TAG, 'Maps is not supported with these settings. Disabling temporally. ' + - 'Please adjust the config properly.', err); + 'Please adjust the config properly.', err.toString()); Config.Client.Map.enabled = false; } diff --git a/backend/routes/SharingRouter.ts b/backend/routes/SharingRouter.ts index 8fc5f7a2..05511ea5 100644 --- a/backend/routes/SharingRouter.ts +++ b/backend/routes/SharingRouter.ts @@ -2,9 +2,10 @@ import {AuthenticationMWs} from '../middlewares/user/AuthenticationMWs'; import {UserRoles} from '../../common/entities/UserDTO'; import {RenderingMWs} from '../middlewares/RenderingMWs'; import {SharingMWs} from '../middlewares/SharingMWs'; +import * as express from 'express'; export class SharingRouter { - public static route(app: any) { + public static route(app: express.Express) { this.addShareLogin(app); this.addGetSharing(app); @@ -12,7 +13,7 @@ export class SharingRouter { this.addUpdateSharing(app); } - private static addShareLogin(app) { + private static addShareLogin(app: express.Express) { app.post('/api/share/login', AuthenticationMWs.inverseAuthenticate, AuthenticationMWs.shareLogin, @@ -20,7 +21,7 @@ export class SharingRouter { ); } - private static addGetSharing(app) { + private static addGetSharing(app: express.Express) { app.get('/api/share/:sharingKey', AuthenticationMWs.authenticate, AuthenticationMWs.authorise(UserRoles.LimitedGuest), @@ -29,7 +30,7 @@ export class SharingRouter { ); } - private static addCreateSharing(app) { + private static addCreateSharing(app: express.Express) { app.post(['/api/share/:directory(*)', '/api/share/', '/api/share//'], AuthenticationMWs.authenticate, AuthenticationMWs.authorise(UserRoles.User), @@ -38,7 +39,7 @@ export class SharingRouter { ); } - private static addUpdateSharing(app) { + private static addUpdateSharing(app: express.Express) { app.put(['/api/share/:directory(*)', '/api/share/', '/api/share//'], AuthenticationMWs.authenticate, AuthenticationMWs.authorise(UserRoles.User), diff --git a/backend/server.ts b/backend/server.ts index 4195ac8c..76aa4a20 100644 --- a/backend/server.ts +++ b/backend/server.ts @@ -27,7 +27,7 @@ const LOG_TAG = '[server]'; export class Server { - private app: any; + private app: _express.Express; private server: any; /** diff --git a/frontend/app/settings/share/share.settings.service.ts b/frontend/app/settings/share/share.settings.service.ts index c78f5d3f..338c267a 100644 --- a/frontend/app/settings/share/share.settings.service.ts +++ b/frontend/app/settings/share/share.settings.service.ts @@ -15,7 +15,8 @@ export class ShareSettingsService extends AbstractSettingsService { diff --git a/package.json b/package.json index c87c3a5a..eda87427 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "winston": "2.4.2" }, "devDependencies": { - "@agm/core": "1.0.0-beta.2", + "@agm/core": "1.0.0-beta.3", "@angular-devkit/build-angular": "~0.6.3", "@angular/animations": "6.0.3", "@angular/cli": "6.0.3",