|
@@ -2,6 +2,8 @@ const loggerFactory = require('@alias/logger');
|
|
|
|
|
|
|
|
const logger = loggerFactory('growi:routes:apiv3:app-settings');
|
|
const logger = loggerFactory('growi:routes:apiv3:app-settings');
|
|
|
|
|
|
|
|
|
|
+const debug = require('debug')('growi:routes:admin');
|
|
|
|
|
+
|
|
|
const express = require('express');
|
|
const express = require('express');
|
|
|
|
|
|
|
|
const router = express.Router();
|
|
const router = express.Router();
|
|
@@ -20,6 +22,13 @@ const validator = {
|
|
|
siteUrlSetting: [
|
|
siteUrlSetting: [
|
|
|
body('siteUrl').trim(),
|
|
body('siteUrl').trim(),
|
|
|
],
|
|
],
|
|
|
|
|
+ mailSetting: [
|
|
|
|
|
+ body('fromAddress').trim(),
|
|
|
|
|
+ body('smtpHost').trim(),
|
|
|
|
|
+ body('smtpPort').trim(),
|
|
|
|
|
+ body('smtpUser').trim(),
|
|
|
|
|
+ body('smtpPassword').trim(),
|
|
|
|
|
+ ],
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
@@ -49,12 +58,33 @@ const validator = {
|
|
|
* fileUpload:
|
|
* fileUpload:
|
|
|
* type: boolean
|
|
* type: boolean
|
|
|
* description: enable upload file except image file
|
|
* description: enable upload file except image file
|
|
|
|
|
+ * SiteUrlSettingParams:
|
|
|
|
|
+ * type: object
|
|
|
|
|
+ * properties:
|
|
|
* siteUrl:
|
|
* siteUrl:
|
|
|
* type: String
|
|
* type: String
|
|
|
* description: Site URL. e.g. https://example.com, https://example.com:8080
|
|
* description: Site URL. e.g. https://example.com, https://example.com:8080
|
|
|
* envSiteUrl:
|
|
* envSiteUrl:
|
|
|
* type: String
|
|
* type: String
|
|
|
* description: environment variable 'APP_SITE_URL'
|
|
* description: environment variable 'APP_SITE_URL'
|
|
|
|
|
+ * MailSettingParams:
|
|
|
|
|
+ * type: object
|
|
|
|
|
+ * properties:
|
|
|
|
|
+ * fromAddress:
|
|
|
|
|
+ * type: String
|
|
|
|
|
+ * description: e-mail address used as from address of mail which sent from GROWI app
|
|
|
|
|
+ * smtpHost:
|
|
|
|
|
+ * type: String
|
|
|
|
|
+ * description: host name of client's smtp server
|
|
|
|
|
+ * smtpPort:
|
|
|
|
|
+ * type: String
|
|
|
|
|
+ * description: port of client's smtp server
|
|
|
|
|
+ * smtpUser:
|
|
|
|
|
+ * type: String
|
|
|
|
|
+ * description: user name of client's smtp server
|
|
|
|
|
+ * smtpPassword:
|
|
|
|
|
+ * type: String
|
|
|
|
|
+ * description: password of client's smtp server
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
module.exports = (crowi) => {
|
|
module.exports = (crowi) => {
|
|
@@ -80,35 +110,25 @@ module.exports = (crowi) => {
|
|
|
* application/json:
|
|
* application/json:
|
|
|
* schema:
|
|
* schema:
|
|
|
* properties:
|
|
* properties:
|
|
|
- * title:
|
|
|
|
|
- * type: String
|
|
|
|
|
- * description: site name show on page header and tilte of HTML
|
|
|
|
|
- * confidential:
|
|
|
|
|
- * type: String
|
|
|
|
|
- * description: confidential show on page header
|
|
|
|
|
- * globalLang:
|
|
|
|
|
- * type: String
|
|
|
|
|
- * description: language set when create user
|
|
|
|
|
- * fileUpload:
|
|
|
|
|
- * type: boolean
|
|
|
|
|
- * description: enable upload file except image file
|
|
|
|
|
- * siteUrl:
|
|
|
|
|
- * type: String
|
|
|
|
|
- * description: Site URL. e.g. https://example.com, https://example.com:8080
|
|
|
|
|
- * envSiteUrl:
|
|
|
|
|
- * type: String
|
|
|
|
|
- * description: environment variable 'APP_SITE_URL'
|
|
|
|
|
|
|
+ * appSettingsParams:
|
|
|
|
|
+ * type: object
|
|
|
|
|
+ * description: app settings params
|
|
|
*/
|
|
*/
|
|
|
router.get('/', accessTokenParser, loginRequired, adminRequired, async(req, res) => {
|
|
router.get('/', accessTokenParser, loginRequired, adminRequired, async(req, res) => {
|
|
|
- const appSettingParams = {
|
|
|
|
|
|
|
+ const appSettingsParams = {
|
|
|
title: crowi.configManager.getConfig('crowi', 'app:title'),
|
|
title: crowi.configManager.getConfig('crowi', 'app:title'),
|
|
|
confidential: crowi.configManager.getConfig('crowi', 'app:confidential'),
|
|
confidential: crowi.configManager.getConfig('crowi', 'app:confidential'),
|
|
|
globalLang: crowi.configManager.getConfig('crowi', 'app:globalLang'),
|
|
globalLang: crowi.configManager.getConfig('crowi', 'app:globalLang'),
|
|
|
fileUpload: crowi.configManager.getConfig('crowi', 'app:fileUpload'),
|
|
fileUpload: crowi.configManager.getConfig('crowi', 'app:fileUpload'),
|
|
|
siteUrl: crowi.configManager.getConfig('crowi', 'app:siteUrl'),
|
|
siteUrl: crowi.configManager.getConfig('crowi', 'app:siteUrl'),
|
|
|
envSiteUrl: crowi.configManager.getConfigFromEnvVars('crowi', 'app:siteUrl'),
|
|
envSiteUrl: crowi.configManager.getConfigFromEnvVars('crowi', 'app:siteUrl'),
|
|
|
|
|
+ fromAddress: crowi.configManager.getConfig('crowi', 'mail:from'),
|
|
|
|
|
+ smtpHost: crowi.configManager.getConfig('crowi', 'mail:smtpHost'),
|
|
|
|
|
+ smtpPort: crowi.configManager.getConfig('crowi', 'mail:smtpPort'),
|
|
|
|
|
+ smtpUser: crowi.configManager.getConfig('crowi', 'mail:smtpUser'),
|
|
|
|
|
+ smtpPassword: crowi.configManager.getConfig('crowi', 'mail:smtpPassword'),
|
|
|
};
|
|
};
|
|
|
- return res.apiv3({ appSettingParams });
|
|
|
|
|
|
|
+ return res.apiv3({ appSettingsParams });
|
|
|
|
|
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -125,29 +145,14 @@ module.exports = (crowi) => {
|
|
|
* content:
|
|
* content:
|
|
|
* application/json:
|
|
* application/json:
|
|
|
* schema:
|
|
* schema:
|
|
|
- * type: object
|
|
|
|
|
- * properties:
|
|
|
|
|
- * title:
|
|
|
|
|
- * type: String
|
|
|
|
|
- * description: site name show on page header and tilte of HTML
|
|
|
|
|
- * confidential:
|
|
|
|
|
- * type: String
|
|
|
|
|
- * description: confidential show on page header
|
|
|
|
|
- * globalLang:
|
|
|
|
|
- * type: String
|
|
|
|
|
- * description: language set when create user
|
|
|
|
|
- * fileUpload:
|
|
|
|
|
- * type: boolean
|
|
|
|
|
- * description: enable upload file except image file
|
|
|
|
|
|
|
+ * $ref: '#/components/schemas/AppSettingParams'
|
|
|
* responses:
|
|
* responses:
|
|
|
* 200:
|
|
* 200:
|
|
|
* description: Succeeded to update app setting
|
|
* description: Succeeded to update app setting
|
|
|
* content:
|
|
* content:
|
|
|
* application/json:
|
|
* application/json:
|
|
|
* schema:
|
|
* schema:
|
|
|
- * properties:
|
|
|
|
|
- * status:
|
|
|
|
|
- * $ref: '#/components/schemas/appSettingParams'
|
|
|
|
|
|
|
+ * $ref: '#/components/schemas/AppSettingParams'
|
|
|
*/
|
|
*/
|
|
|
router.put('/app-setting', loginRequiredStrictly, adminRequired, csrf, validator.appSetting, ApiV3FormValidator, async(req, res) => {
|
|
router.put('/app-setting', loginRequiredStrictly, adminRequired, csrf, validator.appSetting, ApiV3FormValidator, async(req, res) => {
|
|
|
const requestAppSettingParams = {
|
|
const requestAppSettingParams = {
|
|
@@ -176,32 +181,26 @@ module.exports = (crowi) => {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * @swagger
|
|
|
|
|
- *
|
|
|
|
|
- * /app-settings/site-url-setting:
|
|
|
|
|
- * put:
|
|
|
|
|
- * tags: [AppSettings]
|
|
|
|
|
- * description: Update site url setting
|
|
|
|
|
- * requestBody:
|
|
|
|
|
- * required: true
|
|
|
|
|
- * content:
|
|
|
|
|
- * application/json:
|
|
|
|
|
- * schema:
|
|
|
|
|
- * type: object
|
|
|
|
|
- * properties:
|
|
|
|
|
- * siteUrl:
|
|
|
|
|
- * type: String
|
|
|
|
|
- * description: Site URL. e.g. https://example.com, https://example.com:8080
|
|
|
|
|
- * responses:
|
|
|
|
|
- * 200:
|
|
|
|
|
- * description: Succeeded to update site url setting
|
|
|
|
|
- * content:
|
|
|
|
|
- * application/json:
|
|
|
|
|
- * schema:
|
|
|
|
|
- * properties:
|
|
|
|
|
- * status:
|
|
|
|
|
- * $ref: '#/components/schemas/appSettingParams'
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ * @swagger
|
|
|
|
|
+ *
|
|
|
|
|
+ * /app-settings/site-url-setting:
|
|
|
|
|
+ * put:
|
|
|
|
|
+ * tags: [AppSettings]
|
|
|
|
|
+ * description: Update site url setting
|
|
|
|
|
+ * requestBody:
|
|
|
|
|
+ * required: true
|
|
|
|
|
+ * content:
|
|
|
|
|
+ * application/json:
|
|
|
|
|
+ * schema:
|
|
|
|
|
+ * $ref: '#/components/schemas/SiteUrlSettingParams'
|
|
|
|
|
+ * responses:
|
|
|
|
|
+ * 200:
|
|
|
|
|
+ * description: Succeeded to update site url setting
|
|
|
|
|
+ * content:
|
|
|
|
|
+ * application/json:
|
|
|
|
|
+ * schema:
|
|
|
|
|
+ * $ref: '#/components/schemas/SiteUrlSettingParams'
|
|
|
|
|
+ */
|
|
|
router.put('/site-url-setting', loginRequiredStrictly, adminRequired, csrf, validator.siteUrlSetting, ApiV3FormValidator, async(req, res) => {
|
|
router.put('/site-url-setting', loginRequiredStrictly, adminRequired, csrf, validator.siteUrlSetting, ApiV3FormValidator, async(req, res) => {
|
|
|
|
|
|
|
|
const requestSiteUrlSettingParams = {
|
|
const requestSiteUrlSettingParams = {
|
|
@@ -210,10 +209,10 @@ module.exports = (crowi) => {
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestSiteUrlSettingParams);
|
|
await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestSiteUrlSettingParams);
|
|
|
- const appSettingParams = {
|
|
|
|
|
|
|
+ const siteUrlSettingParams = {
|
|
|
siteUrl: crowi.configManager.getConfig('crowi', 'app:siteUrl'),
|
|
siteUrl: crowi.configManager.getConfig('crowi', 'app:siteUrl'),
|
|
|
};
|
|
};
|
|
|
- return res.apiv3({ appSettingParams });
|
|
|
|
|
|
|
+ return res.apiv3({ siteUrlSettingParams });
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
|
const msg = 'Error occurred in updating site url setting';
|
|
const msg = 'Error occurred in updating site url setting';
|
|
@@ -223,6 +222,113 @@ module.exports = (crowi) => {
|
|
|
|
|
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * send mail (Promise wrapper)
|
|
|
|
|
+ */
|
|
|
|
|
+ async function sendMailPromiseWrapper(smtpClient, options) {
|
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
|
+ smtpClient.sendMail(options, (err, res) => {
|
|
|
|
|
+ if (err) {
|
|
|
|
|
+ reject(err);
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ resolve(res);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * validate mail setting send test mail
|
|
|
|
|
+ */
|
|
|
|
|
+ async function validateMailSetting(req) {
|
|
|
|
|
+ const mailer = crowi.mailer;
|
|
|
|
|
+ const option = {
|
|
|
|
|
+ host: req.body.smtpHost,
|
|
|
|
|
+ port: req.body.smtpPort,
|
|
|
|
|
+ };
|
|
|
|
|
+ if (req.body.smtpUser && req.body.smtpPassword) {
|
|
|
|
|
+ option.auth = {
|
|
|
|
|
+ user: req.body.smtpUser,
|
|
|
|
|
+ pass: req.body.smtpPassword,
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+ if (option.port === 465) {
|
|
|
|
|
+ option.secure = true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const smtpClient = mailer.createSMTPClient(option);
|
|
|
|
|
+ debug('mailer setup for validate SMTP setting', smtpClient);
|
|
|
|
|
+
|
|
|
|
|
+ const mailOptions = {
|
|
|
|
|
+ from: req.body.fromAddress,
|
|
|
|
|
+ to: req.user.email,
|
|
|
|
|
+ subject: 'Wiki管理設定のアップデートによるメール通知',
|
|
|
|
|
+ text: 'このメールは、WikiのSMTP設定のアップデートにより送信されています。',
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ await sendMailPromiseWrapper(smtpClient, mailOptions);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @swagger
|
|
|
|
|
+ *
|
|
|
|
|
+ * /app-settings/site-url-setting:
|
|
|
|
|
+ * put:
|
|
|
|
|
+ * tags: [AppSettings]
|
|
|
|
|
+ * description: Update site url setting
|
|
|
|
|
+ * requestBody:
|
|
|
|
|
+ * required: true
|
|
|
|
|
+ * content:
|
|
|
|
|
+ * application/json:
|
|
|
|
|
+ * schema:
|
|
|
|
|
+ * $ref: '#/components/schemas/MailSettingParams'
|
|
|
|
|
+ * responses:
|
|
|
|
|
+ * 200:
|
|
|
|
|
+ * description: Succeeded to update site url setting
|
|
|
|
|
+ * content:
|
|
|
|
|
+ * application/json:
|
|
|
|
|
+ * schema:
|
|
|
|
|
+ * $ref: '#/components/schemas/MailSettingParams'
|
|
|
|
|
+ */
|
|
|
|
|
+ router.put('/mail-setting', loginRequiredStrictly, adminRequired, csrf, validator.mailSetting, ApiV3FormValidator, async(req, res) => {
|
|
|
|
|
+ // テストメール送信によるバリデート
|
|
|
|
|
+ try {
|
|
|
|
|
+ await validateMailSetting(req);
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (err) {
|
|
|
|
|
+ const msg = 'SMTPを利用したテストメール送信に失敗しました。設定をみなおしてください。';
|
|
|
|
|
+ logger.error('Error', err);
|
|
|
|
|
+ debug('Error validate mail setting: ', err);
|
|
|
|
|
+ return res.apiv3Err(new ErrorV3(msg, 'update-mailSetting-failed'));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ const requestMailSettingParams = {
|
|
|
|
|
+ 'mail:from': req.body.fromAddress,
|
|
|
|
|
+ 'mail:smtpHost': req.body.smtpHost,
|
|
|
|
|
+ 'mail:smtpPort': req.body.smtpPort,
|
|
|
|
|
+ 'mail:smtpUser': req.body.smtpUser,
|
|
|
|
|
+ 'mail:smtpPassword': req.body.smtpPassword,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestMailSettingParams);
|
|
|
|
|
+ const mailSettingParams = {
|
|
|
|
|
+ fromAddress: crowi.configManager.getConfig('crowi', 'mail:from'),
|
|
|
|
|
+ smtpHost: crowi.configManager.getConfig('crowi', 'mail:smtpHost'),
|
|
|
|
|
+ smtpPort: crowi.configManager.getConfig('crowi', 'mail:smtpPort'),
|
|
|
|
|
+ smtpUser: crowi.configManager.getConfig('crowi', 'mail:smtpUser'),
|
|
|
|
|
+ smtpPassword: crowi.configManager.getConfig('crowi', 'mail:smtpPassword'),
|
|
|
|
|
+ };
|
|
|
|
|
+ return res.apiv3({ mailSettingParams });
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (err) {
|
|
|
|
|
+ const msg = 'Error occurred in updating mail setting';
|
|
|
|
|
+ logger.error('Error', err);
|
|
|
|
|
+ return res.apiv3Err(new ErrorV3(msg, 'update-mailSetting-failed'));
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
return router;
|
|
return router;
|
|
|
};
|
|
};
|