mizozobu 6 лет назад
Родитель
Сommit
22ddec7393

+ 3 - 3
src/server/crowi/express-init.js

@@ -64,12 +64,12 @@ module.exports = function(crowi, app) {
     const Config = crowi.model('Config');
     app.set('tzoffset', tzoffset);
 
-    req.config = config;
+    // req.config = config;
     req.csrfToken = null;
 
     res.locals.req = req;
     res.locals.baseUrl = configManager.getSiteUrl();
-    res.locals.config = config;
+    // res.locals.config = config;
     res.locals.env = env;
     res.locals.now = now;
     res.locals.tzoffset = tzoffset;
@@ -80,7 +80,7 @@ module.exports = function(crowi, app) {
       restrictGuestMode: Config.getRestrictGuestModeLabels(),
       registrationMode: Config.getRegistrationModeLabels(),
     };
-    res.locals.local_config = Config.getLocalconfig(config); // config for browser context
+    res.locals.local_config = Config.getLocalconfig(); // config for browser context
 
     next();
   });

+ 17 - 17
src/server/models/config.js

@@ -611,7 +611,7 @@ module.exports = function(crowi) {
     return (!!config.notification['slack:token']);
   };
 
-  configSchema.statics.getLocalconfig = function(config) {
+  configSchema.statics.getLocalconfig = function() { // CONF.RF: これも別のメソッドにする
     const Config = this;
     const env = process.env;
 
@@ -621,20 +621,20 @@ module.exports = function(crowi) {
         url: crowi.configManager.getSiteUrl(),
       },
       upload: {
-        image: Config.isUploadable(config),
-        file: Config.fileUploadEnabled(config),
+        image: crowi.configManager.getIsUploadable(),
+        file: crowi.configManager.getConfig('crowi', 'app:fileUpload'),
       },
-      behaviorType: Config.behaviorType(config),
-      layoutType: Config.layoutType(config),
-      isEnabledLinebreaks: Config.isEnabledLinebreaks(config),
-      isEnabledLinebreaksInComments: Config.isEnabledLinebreaksInComments(config),
-      isEnabledXssPrevention: Config.isEnabledXssPrevention(config),
-      xssOption: Config.xssOption(config),
-      tagWhiteList: Config.tagWhiteList(config),
-      attrWhiteList: Config.attrWhiteList(config),
-      highlightJsStyleBorder: Config.highlightJsStyleBorder(config),
-      isSavedStatesOfTabChanges: Config.isSavedStatesOfTabChanges(config),
-      hasSlackConfig: Config.hasSlackConfig(config),
+      behaviorType: crowi.configManager.getConfig('crowi', 'customize:behavior'),
+      layoutType: crowi.configManager.getConfig('crowi', 'customize:layout'),
+      isEnabledLinebreaks: crowi.configManager.getConfig('markdown', 'markdown:isEnabledLinebreaks'),
+      isEnabledLinebreaksInComments: crowi.configManager.getConfig('markdown', 'markdown:isEnabledLinebreaksInComments'),
+      isEnabledXssPrevention: crowi.configManager.getConfig('markdown', 'markdown:xss:isEnabledPrevention'),
+      xssOption: crowi.configManager.getConfig('markdown', 'markdown:xss:option'),
+      tagWhiteList: crowi.configManager.getTagWhiteList(),
+      attrWhiteList: crowi.configManager.getAttrWhiteList(),
+      highlightJsStyleBorder: crowi.configManager.getConfig('crowi', 'customize:highlightJsStyleBorder'),
+      isSavedStatesOfTabChanges: crowi.configManager.getConfig('crowi', 'customize:isSavedStatesOfTabChanges'),
+      hasSlackConfig: crowi.configManager.getConfig('crowi', 'customize:behavior'), // change
       env: {
         PLANTUML_URI: env.PLANTUML_URI || null,
         BLOCKDIAG_URI: env.BLOCKDIAG_URI || null,
@@ -642,9 +642,9 @@ module.exports = function(crowi) {
         MATHJAX: env.MATHJAX || null,
         NO_CDN: env.NO_CDN || null,
       },
-      recentCreatedLimit: Config.showRecentCreatedNumber(config),
-      isAclEnabled: !Config.isPublicWikiOnly(config),
-      globalLang: Config.globalLang(config),
+      recentCreatedLimit: crowi.configManager.getConfig('crowi', 'customize:showRecentCreatedNumber'),
+      isAclEnabled: !crowi.configManager.getIsPublicWikiOnly(),
+      globalLang: crowi.configManager.getConfig('crowi', 'app:globalLang'),
     };
 
     return localConfig;

+ 106 - 0
src/server/service/config-manager.js

@@ -92,6 +92,112 @@ class ConfigManager {
   }
   /* eslint-enable no-else-return */
 
+  getIsUploadable() {
+    const method = process.env.FILE_UPLOAD || 'aws';
+
+    if (method === 'aws' && (
+      !this.getConfig('crowi', 'aws:accessKeyId')
+        || !this.getConfig('crowi', 'aws:secretAccessKey')
+        || !this.getConfig('crowi', 'aws:region')
+        || !this.getConfig('crowi', 'aws:bucket'))) {
+      return false;
+    }
+
+    return method !== 'none';
+  }
+
+  getTagWhiteList() {
+    const { tags } = require('@commons/service/xss/recommended-whitelist');
+    const isEnabledXssPrevention = this.getConfig('markdown', 'markdown:xss:isEnabledPrevention');
+    const xssOpiton = this.getConfig('markdown', 'markdown:xss:option');
+
+    if (isEnabledXssPrevention) {
+      switch (xssOpiton) {
+        case 1: // ignore all: use default option
+          return [];
+
+        case 2: // recommended
+          return tags;
+
+        case 3: // custom white list
+          return this.getConfig('markdown', 'markdown:xss:tagWhiteList');
+
+        default:
+          return [];
+      }
+    }
+    else {
+      return [];
+    }
+  }
+
+  getAttrWhiteList() {
+    const { attrs } = require('@commons/service/xss/recommended-whitelist');
+    const isEnabledXssPrevention = this.getConfig('markdown', 'markdown:xss:isEnabledPrevention');
+    const xssOpiton = this.getConfig('markdown', 'markdown:xss:option');
+
+    if (isEnabledXssPrevention) {
+      switch (xssOpiton) {
+        case 1: // ignore all: use default option
+          return [];
+
+        case 2: // recommended
+          return attrs;
+
+        case 3: // custom white list
+          return this.getConfig('markdown', 'markdown:xss:attrWhiteList');
+
+        default:
+          return [];
+      }
+    }
+    else {
+      return [];
+    }
+  }
+
+  hasSlackConfig() {
+    let hasSlackToken = false;
+    let hasSlackIwhUrl = false;
+
+    if (this.configObject.notification) {
+      hasSlackToken = !!this.configObject.notification['slack:token'];
+      hasSlackIwhUrl = !!this.configObject.notification['slack:incomingWebhookUrl'];
+    }
+
+    return hasSlackToken || hasSlackIwhUrl;
+  }
+
+  getIsPublicWikiOnly() {
+    // CONF.RF save PUBLIC_WIKI_ONLY in mongodb?
+    const publicWikiOnly = process.env.PUBLIC_WIKI_ONLY;
+    if (publicWikiOnly === 'true' || publicWikiOnly === 1) {
+      return true;
+    }
+    return false;
+  }
+
+  getIsGuestAllowedToRead() {
+    const SECURITY_RESTRICT_GUEST_MODE_DENY = 'Deny';
+    const SECURITY_RESTRICT_GUEST_MODE_READONLY = 'Readonly';
+    const SECURITY_REGISTRATION_MODE_OPEN = 'Open';
+    const SECURITY_REGISTRATION_MODE_RESTRICTED = 'Resricted';
+    const SECURITY_REGISTRATION_MODE_CLOSED = 'Closed';
+
+    // return true if puclic wiki mode
+    if (this.getIsPublicWikiOnly()) {
+      return true;
+    }
+
+    // return false if undefined
+    const isRestrictGuestMode = this.getConfig('crowi', 'security:restrictGuestMode');
+    if (isRestrictGuestMode) {
+      return false;
+    }
+
+    return SECURITY_RESTRICT_GUEST_MODE_READONLY === isRestrictGuestMode;
+  }
+
   /**
    * update configs in the same namespace
    *

+ 3 - 4
src/server/util/middlewares.js

@@ -207,16 +207,15 @@ module.exports = (crowi, app) => {
    * @param {boolean} isStrictly whethere strictly restricted (default true)
    */
   middlewares.loginRequired = function(isStrictly = true) {
+    const isGuestAllowedToRead = crowi.configManager.getIsGuestAllowedToRead();
+
     return function(req, res, next) {
       const User = crowi.model('User');
 
       // when the route is not strictly restricted
       if (!isStrictly) {
-        const config = req.config;
-        const Config = crowi.model('Config');
-
         // when allowed to read
-        if (Config.isGuestAllowedToRead(config)) {
+        if (isGuestAllowedToRead) {
           return next();
         }
       }