Skip to content

Commit be5de23

Browse files
authored
Merge pull request #589 from geekyd/master
Adds enable/disable PDF export via config
2 parents c794412 + f7d2ef9 commit be5de23

File tree

7 files changed

+30
-10
lines changed

7 files changed

+30
-10
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,10 @@ Environment variables (will overwrite other server configs)
145145
| HMD_LDAP_SEARCHFILTER | `(uid={{username}})` | LDAP filter to search with |
146146
| HMD_LDAP_SEARCHATTRIBUTES | no example | LDAP attributes to search with |
147147
| HMD_LDAP_TLS_CA | `server-cert.pem, root.pem` | Root CA for LDAP TLS in PEM format (use comma to separate) |
148-
| HMD_LDAP_PROVIDERNAME | `My institution` | Optional name to be displayed at login form indicating the LDAP provider |
148+
| HMD_LDAP_PROVIDERNAME | `My institution` | Optional name to be displayed at login form indicating the LDAP provider |
149149
| HMD_IMGUR_CLIENTID | no example | Imgur API client id |
150150
| HMD_EMAIL | `true` or `false` | set to allow email signin |
151+
| HMD_ALLOW_PDF_EXPORT | `true` or `false` | Enable or disable PDF exports |
151152
| HMD_ALLOW_EMAIL_REGISTER | `true` or `false` | set to allow email register (only applied when email is set, default is `true`) |
152153
| HMD_IMAGE_UPLOAD_TYPE | `imgur`, `s3` or `filesystem` | Where to upload image. For S3, see our [S3 Image Upload Guide](docs/guides/s3-image-upload.md) |
153154
| HMD_S3_ACCESS_KEY_ID | no example | AWS access key id |

app.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@
127127
"HMD_IMGUR_CLIENTID": {
128128
"description": "Imgur API client id",
129129
"required": false
130+
},
131+
"HMD_ALLOW_PDF_EXPORT": {
132+
"description": "Enable or disable PDF exports",
133+
"required": false
130134
}
131135
},
132136
"addons": [

lib/config/default.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,6 @@ module.exports = {
9494
tlsca: undefined
9595
},
9696
email: true,
97-
allowemailregister: true
97+
allowemailregister: true,
98+
allowpdfexport: true
9899
}

lib/config/environment.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,6 @@ module.exports = {
6969
tlsca: process.env.HMD_LDAP_TLS_CA
7070
},
7171
email: toBooleanConfig(process.env.HMD_EMAIL),
72-
allowemailregister: toBooleanConfig(process.env.HMD_ALLOW_EMAIL_REGISTER)
72+
allowemailregister: toBooleanConfig(process.env.HMD_ALLOW_EMAIL_REGISTER),
73+
allowpdfexport: toBooleanConfig(process.env.HMD_ALLOW_PDF_EXPORT)
7374
}

lib/config/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
'use strict'
23

34
const fs = require('fs')
@@ -90,6 +91,7 @@ config.isEmailEnable = config.email
9091
config.isGitHubEnable = config.github.clientID && config.github.clientSecret
9192
config.isGitLabEnable = config.gitlab.clientID && config.gitlab.clientSecret
9293
config.isLDAPEnable = config.ldap.url
94+
config.isPDFExportEnable = config.allowpdfexport
9395

9496
// generate correct path
9597
config.sslcapath = path.join(appRootPath, config.sslcapath)
@@ -106,7 +108,7 @@ config.errorpath = path.join(appRootPath, config.errorpath)
106108
config.prettypath = path.join(appRootPath, config.prettypath)
107109
config.slidepath = path.join(appRootPath, config.slidepath)
108110

109-
// maek config readonly
111+
// make config readonly
110112
config = deepFreeze(config)
111113

112114
module.exports = config

lib/response.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ function showIndex (req, res, next) {
6969
ldap: config.isLDAPEnable,
7070
email: config.isEmailEnable,
7171
allowemailregister: config.allowemailregister,
72+
allowpdfexport: config.allowpdfexport,
7273
signin: req.isAuthenticated(),
7374
infoMessage: req.flash('info'),
7475
errorMessage: req.flash('error')
@@ -98,7 +99,8 @@ function responseHackMD (res, note) {
9899
google: config.isGoogleEnable,
99100
ldap: config.isLDAPEnable,
100101
email: config.isEmailEnable,
101-
allowemailregister: config.allowemailregister
102+
allowemailregister: config.allowemailregister,
103+
allowpdfexport: config.allowpdfexport
102104
})
103105
}
104106

@@ -382,7 +384,12 @@ function noteActions (req, res, next) {
382384
actionInfo(req, res, note)
383385
break
384386
case 'pdf':
385-
actionPDF(req, res, note)
387+
if (config.allowpdfexport) {
388+
actionPDF(req, res, note)
389+
} else {
390+
logger.error('PDF export failed: Disabled by config. Set "allowpdfexport: true" to enable. Check the documentation for details')
391+
response.errorForbidden(res)
392+
}
386393
break
387394
case 'gist':
388395
actionGist(req, res, note)

public/views/hackmd/header.ejs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@
7070
</li>
7171
<li role="presentation"><a role="menuitem" class="ui-download-raw-html" tabindex="-1" href="#" target="_self"><i class="fa fa-file-code-o fa-fw"></i> <%= __('Raw HTML') %></a>
7272
</li>
73-
<li role="presentation"><a role="menuitem" class="ui-download-pdf-beta" tabindex="-1" href="#" target="_self"><i class="fa fa-file-pdf-o fa-fw"></i> PDF (Beta)</a>
74-
</li>
73+
<% if(allowpdfexport) {%>
74+
<li role="presentation"><a role="menuitem" class="ui-download-pdf-beta" tabindex="-1" href="#" target="_self"><i class="fa fa-file-pdf-o fa-fw"></i> PDF (Beta)</a>
75+
</li>
76+
<% } %>
7577
<li class="divider"></li>
7678
<li role="presentation"><a role="menuitem" class="ui-help" href="#" data-toggle="modal" data-target=".help-modal"><i class="fa fa-question-circle fa-fw"></i> Help</a>
7779
</li>
@@ -169,8 +171,10 @@
169171
</li>
170172
<li role="presentation"><a role="menuitem" class="ui-download-raw-html" tabindex="-1" href="#" target="_self"><i class="fa fa-file-code-o fa-fw"></i> <%= __('Raw HTML') %></a>
171173
</li>
172-
<li role="presentation"><a role="menuitem" class="ui-download-pdf-beta" tabindex="-1" href="#" target="_self"><i class="fa fa-file-pdf-o fa-fw"></i> PDF (Beta)</a>
173-
</li>
174+
<% if(allowpdfexport) {%>
175+
<li role="presentation"><a role="menuitem" class="ui-download-pdf-beta" tabindex="-1" href="#" target="_self"><i class="fa fa-file-pdf-o fa-fw"></i> PDF (Beta)</a>
176+
</li>
177+
<% } %>
174178
</ul>
175179
</li>
176180
</ul>

0 commit comments

Comments
 (0)