admin-general.vue 19 KB
Newer Older
NGPixel's avatar
NGPixel committed
1
<template lang='pug'>
2
  v-container(fluid, grid-list-lg)
NGPixel's avatar
NGPixel committed
3 4
    v-layout(row wrap)
      v-flex(xs12)
5
        .admin-header
Nick's avatar
Nick committed
6
          img.animated.fadeInUp(src='/svg/icon-categorize.svg', alt='General', style='width: 80px;')
7
          .admin-header-title
Nick's avatar
Nick committed
8
            .headline.primary--text.animated.fadeInLeft {{ $t('admin:general.title') }}
9
            .subtitle-1.grey--text.animated.fadeInLeft {{ $t('admin:general.subtitle') }}
10
          v-spacer
Nick's avatar
Nick committed
11
          v-btn.animated.fadeInDown(color='success', depressed, @click='save', large)
12
            v-icon(left) mdi-check
13
            span {{$t('common:actions.apply')}}
NGPixel's avatar
NGPixel committed
14 15 16
        v-form.pt-3
          v-layout(row wrap)
            v-flex(lg6 xs12)
17
              v-form
18
                v-card.animated.fadeInUp
19
                  v-toolbar(color='primary', dark, dense, flat)
20
                    v-toolbar-title.subtitle-1 {{ $t('admin:general.siteInfo') }}
21
                  .overline.grey--text.pa-4 {{$t('admin:general.general')}}
22
                  .px-3.pb-3
23
                    v-text-field(
24
                      outlined
Nick's avatar
Nick committed
25
                      :label='$t(`admin:general.siteUrl`)'
26 27 28
                      required
                      :counter='255'
                      v-model='config.host'
29
                      prepend-icon='mdi-label-variant-outline'
Nick's avatar
Nick committed
30
                      :hint='$t(`admin:general.siteUrlHint`)'
31 32
                      persistent-hint
                      )
33 34
                    v-text-field.mt-3(
                      outlined
Nick's avatar
Nick committed
35
                      :label='$t(`admin:general.siteTitle`)'
36 37
                      required
                      :counter='50'
38
                      v-model='config.title'
39
                      prepend-icon='mdi-earth'
Nick's avatar
Nick committed
40
                      :hint='$t(`admin:general.siteTitleHint`)'
41
                      persistent-hint
42
                      )
43
                  v-divider
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
                  .overline.grey--text.pa-4 {{$t('admin:general.logo')}}
                  .pt-2.pb-7.pl-10.pr-3
                    .d-flex.align-center
                      v-avatar(size='100', tile)
                        v-img(
                          :src='config.logoUrl'
                          lazy-src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNcWQ8AAdcBKrJda2oAAAAASUVORK5CYII='
                          aspect-ratio='1'
                          )
                      .ml-4(style='flex: 1 1 auto;')
                        v-text-field(
                          outlined
                          :label='$t(`admin:general.logoUrl`)'
                          v-model='config.logoUrl'
                          :hint='$t(`admin:general.logoUrlHint`)'
                          persistent-hint
                          append-icon='mdi-folder-image'
                          @click:append='browseLogo'
                          @keyup.enter='refreshLogo'
                        )
Nick's avatar
Nick committed
64
                  v-divider
65
                  .overline.grey--text.pa-4 {{$t('admin:general.footerCopyright')}}
Nick's avatar
Nick committed
66 67
                  .px-3.pb-3
                    v-text-field(
68
                      outlined
Nick's avatar
Nick committed
69
                      :label='$t(`admin:general.companyName`)'
Nick's avatar
Nick committed
70 71
                      v-model='config.company'
                      :counter='255'
72
                      prepend-icon='mdi-domain'
Nick's avatar
Nick committed
73
                      persistent-hint
Nick's avatar
Nick committed
74
                      :hint='$t(`admin:general.companyNameHint`)'
Nick's avatar
Nick committed
75
                      )
76 77 78 79 80 81 82 83 84 85
                    v-select.mt-3(
                      outlined
                      :label='$t(`admin:general.contentLicense`)'
                      :items='contentLicenses'
                      v-model='config.contentLicense'
                      prepend-icon='mdi-creative-commons'
                      :return-object='false'
                      :hint='$t(`admin:general.contentLicenseHint`)'
                      persistent-hint
                      )
Nick's avatar
Nick committed
86
                  v-divider
87
                  .overline.grey--text.pa-4 SEO
88
                  .px-3.pb-3
89
                    v-text-field(
90
                      outlined
Nick's avatar
Nick committed
91
                      :label='$t(`admin:general.siteDescription`)'
92
                      :counter='255'
93
                      v-model='config.description'
94
                      prepend-icon='mdi-compass'
Nick's avatar
Nick committed
95
                      :hint='$t(`admin:general.siteDescriptionHint`)'
96
                      persistent-hint
97
                      )
98 99
                    v-select.mt-3(
                      outlined
Nick's avatar
Nick committed
100
                      :label='$t(`admin:general.metaRobots`)'
101
                      multiple
102
                      :items='metaRobots'
103
                      v-model='config.robots'
104
                      prepend-icon='mdi-compass'
105
                      :return-object='false'
Nick's avatar
Nick committed
106
                      :hint='$t(`admin:general.metaRobotsHint`)'
107
                      persistent-hint
108
                      )
Nick's avatar
Nick committed
109

NGPixel's avatar
NGPixel committed
110
            v-flex(lg6 xs12)
111
              v-card.animated.fadeInUp.wait-p4s
112
                v-toolbar(color='indigo', dark, dense, flat)
113
                  v-toolbar-title.subtitle-1 Features
Nick's avatar
Nick committed
114
                  v-spacer
115
                  v-chip(label, color='white', small).indigo--text coming soon
116
                v-card-text
Nick's avatar
Nick committed
117
                  v-switch(
118
                    inset
Nick's avatar
Nick committed
119
                    label='Asset Image Optimization'
120
                    color='indigo'
Nick's avatar
Nick committed
121 122 123 124 125 126
                    v-model='config.featureTinyPNG'
                    persistent-hint
                    hint='Image optimization tool to reduce filesize and bandwidth costs.'
                    disabled
                    )
                  v-text-field.mt-3(
127
                    outlined
Nick's avatar
Nick committed
128 129 130
                    label='TinyPNG API Key'
                    :counter='255'
                    v-model='config.description'
131
                    prepend-icon='mdi-subdirectory-arrow-right'
Nick's avatar
Nick committed
132 133 134 135 136 137
                    hint='Get your API key at https://tinypng.com/developers'
                    persistent-hint
                    disabled
                    )

                  v-divider.mt-3
138
                  v-switch(
139
                    inset
140
                    label='Page Ratings'
141
                    color='indigo'
142
                    v-model='config.featurePageRatings'
143 144
                    persistent-hint
                    hint='Allow users to rate pages.'
Nick's avatar
Nick committed
145
                    disabled
146
                    )
Nick's avatar
Nick committed
147

148 149
                  v-divider.mt-3
                  v-switch(
150
                    inset
151
                    label='Page Comments'
152
                    color='indigo'
153 154 155
                    v-model='config.featurePageComments'
                    persistent-hint
                    hint='Allow users to leave comments on pages.'
Nick's avatar
Nick committed
156
                    disabled
157
                    )
Nick's avatar
Nick committed
158

159 160
                  v-divider.mt-3
                  v-switch(
161
                    inset
162
                    label='Personal Wikis'
163
                    color='indigo'
164
                    v-model='config.featurePersonalWikis'
165 166
                    persistent-hint
                    hint='Allow users to have their own personal wiki.'
Nick's avatar
Nick committed
167
                    disabled
168
                    )
NGPixel's avatar
NGPixel committed
169

170 171 172 173 174 175
              v-card.mt-5.animated.fadeInUp.wait-p5s
                v-toolbar(color='red darken-2', dark, dense, flat)
                  v-toolbar-title.subtitle-1 Security
                v-card-text
                  v-alert(outlined, color='red darken-2', icon='mdi-information-outline').body-2 Make sure to understand the implications before turning on / off a security feature.
                  v-switch.mt-3(
176
                    inset
177 178 179 180 181 182
                    label='Block IFrame Embedding'
                    color='red darken-2'
                    v-model='config.securityIframe'
                    persistent-hint
                    hint='Prevents other websites from embedding your wiki in an iframe. This provides clickjacking protection.'
                    )
183

184 185
                  v-divider.mt-3
                  v-switch(
186
                    inset
187 188 189 190 191 192 193
                    label='Same Origin Referrer Policy'
                    color='red darken-2'
                    v-model='config.securityReferrerPolicy'
                    persistent-hint
                    hint='Limits the referrer header to same origin.'
                    )

194 195 196 197 198 199 200 201 202 203
                  v-divider.mt-3
                  v-switch(
                    inset
                    label='Trust X-Forwarded-* Proxy Headers'
                    color='red darken-2'
                    v-model='config.securityTrustProxy'
                    persistent-hint
                    hint='Should be enabled when using a reverse-proxy like nginx, apache, CloudFlare, etc in front of Wiki.js. Turn off otherwise.'
                    )

NGPixel's avatar
NGPixel committed
204 205 206
                  v-divider.mt-3
                  v-switch(
                    inset
207
                    label='Subresource Integrity (SRI)'
NGPixel's avatar
NGPixel committed
208 209 210 211
                    color='red darken-2'
                    v-model='config.securitySRI'
                    persistent-hint
                    hint='This ensure that resources such as CSS and JS files are not altered during delivery.'
212
                    disabled
NGPixel's avatar
NGPixel committed
213 214
                    )

215 216
                  v-divider.mt-3
                  v-switch(
217
                    inset
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
                    label='Enforce HSTS'
                    color='red darken-2'
                    v-model='config.securityHSTS'
                    persistent-hint
                    hint='This ensures the connection cannot be established through an insecure HTTP connection.'
                    )
                  v-select.mt-5(
                    outlined
                    label='HSTS Max Age'
                    :items='hstsDurations'
                    v-model='config.securityHSTSDuration'
                    prepend-icon='mdi-subdirectory-arrow-right'
                    :disabled='!config.securityHSTS'
                    hide-details
                    style='max-width: 450px;'
                    )
                  .pl-11.mt-3
                    .caption Defines the duration for which the server should only deliver content through HTTPS.
                    .caption It's a good idea to start with small values and make sure that nothing breaks on your wiki before moving to longer values.

                  v-divider.mt-3
                  v-switch(
240
                    inset
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
                    label='Enforce CSP'
                    color='red darken-2'
                    v-model='config.securityCSP'
                    persistent-hint
                    hint='Restricts scripts to pre-approved content sources.'
                    disabled
                    )
                  v-textarea.mt-5(
                    label='CSP Directives'
                    outlined
                    v-model='config.securityCSPDirectives'
                    prepend-icon='mdi-subdirectory-arrow-right'
                    persistent-hint
                    hint='One directive per line.'
                    disabled
                  )
257
    component(:is='activeModal')
258

NGPixel's avatar
NGPixel committed
259 260 261
</template>

<script>
262
import _ from 'lodash'
263
import { get, sync } from 'vuex-pathify'
264
import gql from 'graphql-tag'
265

266 267 268 269 270 271
import editorStore from '../../store/editor'

/* global WIKI */

WIKI.$store.registerModule('editor', editorStore)

NGPixel's avatar
NGPixel committed
272
export default {
273 274 275 276
  i18nOptions: { namespaces: 'editor' },
  components: {
    editorModalMedia: () => import(/* webpackChunkName: "editor", webpackMode: "lazy" */ '../editor/editor-modal-media.vue')
  },
NGPixel's avatar
NGPixel committed
277
  data() {
278
    return {
279 280
      analyticsServices: [
        { text: 'None', value: '' },
281
        { text: 'Elasticsearch APM RUM', value: 'elk' },
282
        { text: 'Google Analytics', value: 'ga' },
Nick's avatar
Nick committed
283
        { text: 'Google Tag Manager', value: 'gtm' }
284
      ],
285 286 287 288 289
      config: {
        host: '',
        title: '',
        description: '',
        robots: [],
290 291
        analyticsService: '',
        analyticsId: '',
292
        company: '',
293
        contentLicense: '',
294
        logoUrl: '',
Nick's avatar
Nick committed
295
        featureAnalytics: false,
296 297
        featurePageRatings: false,
        featurePageComments: false,
Nick's avatar
Nick committed
298
        featurePersonalWikis: false,
299 300 301
        featureTinyPNG: false,
        securityIframe: true,
        securityReferrerPolicy: true,
302
        securityTrustProxy: true,
NGPixel's avatar
NGPixel committed
303
        securitySRI: true,
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
        securityHSTS: false,
        securityHSTSDuration: 0,
        securityCSP: false,
        securityCSPDirectives: ''
      },
      hstsDurations: [
        { value: 300, text: '5 minutes' },
        { value: 86400, text: '1 day' },
        { value: 604800, text: '1 week' },
        { value: 2592000, text: '1 month' },
        { value: 31536000, text: '1 year' },
        { value: 63072000, text: '2 years' }
      ],
      metaRobots: [
        { text: 'Index', value: 'index' },
        { text: 'Follow', value: 'follow' },
        { text: 'No Index', value: 'noindex' },
        { text: 'No Follow', value: 'nofollow' }
      ]
323
    }
324 325
  },
  computed: {
326
    darkMode: get('site/dark'),
327
    siteTitle: sync('site/title'),
328 329
    logoUrl: sync('site/logoUrl'),
    company: sync('site/company'),
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
    contentLicense: sync('site/contentLicense'),
    activeModal: sync('editor/activeModal'),
    contentLicenses () {
      return [
        { value: '', text: this.$t('common:license.none') },
        { value: 'alr', text: this.$t('common:license.alr') },
        { value: 'cc0', text: this.$t('common:license.cc0') },
        { value: 'ccby', text: this.$t('common:license.ccby') },
        { value: 'ccbysa', text: this.$t('common:license.ccbysa') },
        { value: 'ccbynd', text: this.$t('common:license.ccbynd') },
        { value: 'ccbync', text: this.$t('common:license.ccbync') },
        { value: 'ccbyncsa', text: this.$t('common:license.ccbyncsa') },
        { value: 'ccbyncnd', text: this.$t('common:license.ccbyncnd') }
      ]
    }
345 346 347
  },
  methods: {
    async save () {
348 349
      try {
        await this.$apollo.mutate({
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
          mutation: gql`
            mutation (
              $host: String!
              $title: String!
              $description: String!
              $robots: [String]!
              $analyticsService: String!
              $analyticsId: String!
              $company: String!
              $contentLicense: String!
              $logoUrl: String!
              $featurePageRatings: Boolean!
              $featurePageComments: Boolean!
              $featurePersonalWikis: Boolean!
              $securityIframe: Boolean!
              $securityReferrerPolicy: Boolean!
              $securityTrustProxy: Boolean!
              $securitySRI: Boolean!
              $securityHSTS: Boolean!
              $securityHSTSDuration: Int!
              $securityCSP: Boolean!
              $securityCSPDirectives: String!
            ) {
              site {
                updateConfig(
                  host: $host,
                  title: $title,
                  description: $description,
                  robots: $robots,
                  analyticsService: $analyticsService,
                  analyticsId: $analyticsId,
                  company: $company,
                  contentLicense: $contentLicense,
                  logoUrl: $logoUrl,
                  featurePageRatings: $featurePageRatings,
                  featurePageComments: $featurePageComments,
                  featurePersonalWikis: $featurePersonalWikis,
                  securityIframe: $securityIframe,
                  securityReferrerPolicy: $securityReferrerPolicy,
                  securityTrustProxy: $securityTrustProxy,
                  securitySRI: $securitySRI,
                  securityHSTS: $securityHSTS,
                  securityHSTSDuration: $securityHSTSDuration,
                  securityCSP: $securityCSP,
                  securityCSPDirectives: $securityCSPDirectives
                ) {
                  responseResult {
                    succeeded
                    errorCode
                    slug
                    message
                  }
                }
              }
            }
          `,
406
          variables: {
407 408 409 410 411 412 413
            host: _.get(this.config, 'host', ''),
            title: _.get(this.config, 'title', ''),
            description: _.get(this.config, 'description', ''),
            robots: _.get(this.config, 'robots', []),
            analyticsService: _.get(this.config, 'analyticsService', ''),
            analyticsId: _.get(this.config, 'analyticsId', ''),
            company: _.get(this.config, 'company', ''),
414
            contentLicense: _.get(this.config, 'contentLicense', ''),
415
            logoUrl: _.get(this.config, 'logoUrl', ''),
416 417 418 419 420
            featurePageRatings: _.get(this.config, 'featurePageRatings', false),
            featurePageComments: _.get(this.config, 'featurePageComments', false),
            featurePersonalWikis: _.get(this.config, 'featurePersonalWikis', false),
            securityIframe: _.get(this.config, 'securityIframe', false),
            securityReferrerPolicy: _.get(this.config, 'securityReferrerPolicy', false),
421
            securityTrustProxy: _.get(this.config, 'securityTrustProxy', false),
NGPixel's avatar
NGPixel committed
422
            securitySRI: _.get(this.config, 'securitySRI', false),
423 424 425 426
            securityHSTS: _.get(this.config, 'securityHSTS', false),
            securityHSTSDuration: _.get(this.config, 'securityHSTSDuration', 0),
            securityCSP: _.get(this.config, 'securityCSP', false),
            securityCSPDirectives: _.get(this.config, 'securityCSPDirectives', '')
427 428 429 430 431 432 433 434 435 436 437 438
          },
          watchLoading (isLoading) {
            this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-site-update')
          }
        })
        this.$store.commit('showNotification', {
          style: 'success',
          message: 'Configuration saved successfully.',
          icon: 'check'
        })
        this.siteTitle = this.config.title
        this.company = this.config.company
439
        this.contentLicense = this.config.contentLicense
440
        this.logoUrl = this.config.logoUrl
441
      } catch (err) {
442
        this.$store.commit('pushGraphError', err)
443
      }
444 445 446 447 448 449 450
    },
    browseLogo () {
      this.$store.set('editor/editorKey', 'common')
      this.activeModal = 'editorModalMedia'
    },
    refreshLogo () {
      this.$forceUpdate()
451 452
    }
  },
453 454 455 456 457 458 459 460
  mounted () {
    this.$root.$on('editorInsert', opts => {
      this.config.logoUrl = opts.path
    })
  },
  beforeDestroy() {
    this.$root.$off('editorInsert')
  },
461 462
  apollo: {
    config: {
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
      query: gql`
        {
          site {
            config {
              host
              title
              description
              robots
              analyticsService
              analyticsId
              company
              contentLicense
              logoUrl
              featurePageRatings
              featurePageComments
              featurePersonalWikis
              securityIframe
              securityReferrerPolicy
              securityTrustProxy
              securitySRI
              securityHSTS
              securityHSTSDuration
              securityCSP
              securityCSPDirectives
            }
          }
        }
      `,
491 492 493 494 495
      fetchPolicy: 'network-only',
      update: (data) => _.cloneDeep(data.site.config),
      watchLoading (isLoading) {
        this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-site-refresh')
      }
496
    }
NGPixel's avatar
NGPixel committed
497 498 499 500 501 502 503
  }
}
</script>

<style lang='scss'>

</style>