Преглед на файлове

fix: setup https support + various fixes

Nick преди 6 години
родител
ревизия
358e79d7f5

+ 4 - 4
client/components/setup.vue

@@ -171,8 +171,8 @@
             v-card.text-xs-center(flat)
               template(v-if='loading')
                 .mt-3(style='width: 64px; display:inline-block;')
-                  atom-spinner(
-                    :animation-duration='800'
+                  breeding-rhombus-spinner(
+                    :animation-duration='2000'
                     :size='64'
                     color='#1976d2'
                     )
@@ -199,11 +199,11 @@
 <script>
 import axios from 'axios'
 import _ from 'lodash'
-import { AtomSpinner } from 'epic-spinners'
+import { BreedingRhombusSpinner } from 'epic-spinners'
 
 export default {
   components: {
-    AtomSpinner
+    BreedingRhombusSpinner
   },
   props: {
     telemetryId: {

+ 12 - 12
client/themes/default/components/page.vue

@@ -83,18 +83,18 @@
                     v-list-tile-title.pl-3.caption {{tocSubItem.title}}
                   v-divider(inset, v-if='tocIdx < toc.length - 1')
             v-divider
-          v-list.grey(dense, :class='darkMode ? `darken-3` : `lighten-4`')
-            v-subheader.pl-4.yellow--text.text--darken-4 Rating
-            .text-xs-center
-              v-rating(
-                v-model='rating'
-                color='yellow darken-3'
-                background-color='grey lighten-1'
-                half-increments
-                hover
-              )
-              .pb-2.caption.grey--text 5 votes
-          v-divider
+          //- v-list.grey(dense, :class='darkMode ? `darken-3` : `lighten-4`')
+          //-   v-subheader.pl-4.yellow--text.text--darken-4 Rating
+          //-   .text-xs-center
+          //-     v-rating(
+          //-       v-model='rating'
+          //-       color='yellow darken-3'
+          //-       background-color='grey lighten-1'
+          //-       half-increments
+          //-       hover
+          //-     )
+          //-     .pb-2.caption.grey--text 5 votes
+          //- v-divider
           template(v-if='tags.length')
             v-list.grey(dense, :class='darkMode ? `darken-3-d3` : `lighten-3`')
               v-subheader.pl-4.teal--text Tags

+ 3 - 4
server/core/auth.js

@@ -130,7 +130,7 @@ module.exports = {
 
       // JWT is NOT valid, set as guest
       if (!user) {
-        if (true || WIKI.auth.guest.cacheExpiration.isSameOrBefore(moment.utc())) {
+        if (WIKI.auth.guest.cacheExpiration.isSameOrBefore(moment.utc())) {
           WIKI.auth.guest = await WIKI.models.users.getGuestUser()
           WIKI.auth.guest.cacheExpiration = moment.utc().add(1, 'm')
         }
@@ -176,9 +176,7 @@ module.exports = {
       user.groups.forEach(grp => {
         const grpId = _.isObject(grp) ? _.get(grp, 'id', 0) : grp
         _.get(WIKI.auth.groups, `${grpId}.pageRules`, []).forEach(rule => {
-          console.info(page.path)
-          console.info(rule)
-          switch(rule.match) {
+          switch (rule.match) {
             case 'START':
               if (_.startsWith(`/${page.path}`, `/${rule.path}`)) {
                 checkState = this._applyPageRuleSpecificity({ rule, checkState, higherPriority: ['END', 'REGEX', 'EXACT'] })
@@ -194,6 +192,7 @@ module.exports = {
               if (reg.test(page.path)) {
                 checkState = this._applyPageRuleSpecificity({ rule, checkState, higherPriority: ['EXACT'] })
               }
+              break
             case 'EXACT':
               if (`/${page.path}` === `/${rule.path}`) {
                 checkState = this._applyPageRuleSpecificity({ rule, checkState, higherPriority: [] })

+ 1 - 1
server/graph/resolvers/authentication.js

@@ -60,7 +60,7 @@ module.exports = {
     },
     async register(obj, args, context) {
       try {
-        await WIKI.models.users.register({...args, verify: true }, context)
+        await WIKI.models.users.register({ ...args, verify: true }, context)
         return {
           responseResult: graphHelper.generateSuccess('Registration success')
         }

+ 0 - 15
server/middlewares/flash.js

@@ -1,15 +0,0 @@
-'use strict'
-
-/**
- * Flash middleware
- *
- * @param      {Express Request}   req     Express Request object
- * @param      {Express Response}  res     Express Response object
- * @param      {Function}          next    Next callback function
- * @return     {any}               void
- */
-module.exports = (req, res, next) => {
-  res.locals.flash = req.flash('alert')
-
-  next()
-}

+ 2 - 2
server/middlewares/seo.js

@@ -1,7 +1,7 @@
-'use strict'
-
 const _ = require('lodash')
 
+/* global WIKI */
+
 /**
  * SEO Middleware
  *

+ 42 - 20
server/setup.js

@@ -1,5 +1,18 @@
 const path = require('path')
 const uuid = require('uuid/v4')
+const bodyParser = require('body-parser')
+const compression = require('compression')
+const express = require('express')
+const favicon = require('serve-favicon')
+const http = require('http')
+const https = require('https')
+const Promise = require('bluebird')
+const fs = require('fs-extra')
+const _ = require('lodash')
+const cfgHelper = require('./helpers/config')
+const crypto = Promise.promisifyAll(require('crypto'))
+const pem2jwk = require('pem-jwk').pem2jwk
+const semver = require('semver')
 
 /* global WIKI */
 
@@ -11,23 +24,6 @@ module.exports = () => {
 
   WIKI.system = require('./core/system')
 
-  // ----------------------------------------
-  // Load modules
-  // ----------------------------------------
-
-  const bodyParser = require('body-parser')
-  const compression = require('compression')
-  const express = require('express')
-  const favicon = require('serve-favicon')
-  const http = require('http')
-  const Promise = require('bluebird')
-  const fs = require('fs-extra')
-  const _ = require('lodash')
-  const cfgHelper = require('./helpers/config')
-  const crypto = Promise.promisifyAll(require('crypto'))
-  const pem2jwk = require('pem-jwk').pem2jwk
-  const semver = require('semver')
-
   // ----------------------------------------
   // Define Express App
   // ----------------------------------------
@@ -138,8 +134,8 @@ module.exports = () => {
       WIKI.telemetry.sendEvent('setup', 'install-start')
 
       // Basic checks
-      if (!semver.satisfies(process.version, '>=10.14')) {
-        throw new Error('Node.js 10.14.x or later required!')
+      if (!semver.satisfies(process.version, '>=10.12')) {
+        throw new Error('Node.js 10.12.x or later required!')
       }
 
       // Upgrade from WIKI.js 1.x?
@@ -356,7 +352,33 @@ module.exports = () => {
   WIKI.logger.info(`HTTP Server on port: [ ${WIKI.config.port} ]`)
 
   app.set('port', WIKI.config.port)
-  WIKI.server = http.createServer(app)
+
+  if (WIKI.config.ssl.enabled) {
+    WIKI.logger.info(`HTTPS Server on port: [ ${WIKI.config.port} ]`)
+    const tlsOpts = {}
+    try {
+      if (WIKI.config.ssl.format === 'pem') {
+        tlsOpts.key = fs.readFileSync(WIKI.config.ssl.key)
+        tlsOpts.cert = fs.readFileSync(WIKI.config.ssl.cert)
+      } else {
+        tlsOpts.pfx = fs.readFileSync(WIKI.config.ssl.pfx)
+      }
+      if (!_.isEmpty(WIKI.config.ssl.passphrase)) {
+        tlsOpts.passphrase = WIKI.config.ssl.passphrase
+      }
+      if (!_.isEmpty(WIKI.config.ssl.dhparam)) {
+        tlsOpts.dhparam = WIKI.config.ssl.dhparam
+      }
+    } catch (err) {
+      WIKI.logger.error('Failed to setup HTTPS server parameters:')
+      WIKI.logger.error(err)
+      return process.exit(1)
+    }
+    WIKI.server = https.createServer(tlsOpts, app)
+  } else {
+    WIKI.logger.info(`HTTP Server on port: [ ${WIKI.config.port} ]`)
+    WIKI.server = http.createServer(app)
+  }
   WIKI.server.listen(WIKI.config.port, WIKI.config.bindIP)
 
   var openConnections = []