wiki plugin

This commit is contained in:
jysperm
2014-09-07 15:20:21 +08:00
parent c26a7a0864
commit 3b3e04f79e
8 changed files with 71 additions and 33 deletions

View File

@@ -43,6 +43,7 @@ RootPanel 是一个高度插件化的,基于 Linux 的虚拟服务销售平台
配置文件示例(sample 目录):
core.config.coffee # 仅核心模块
shadowsocks.config.coffee # ShadowSocks 代理服务
full.config.coffee # 全功能虚拟主机
php-vhost.config.coffee # PHP/MySQL 虚拟主机

View File

@@ -20,7 +20,7 @@ module.exports =
billing:
currency: 'CNY'
taobao_item_id: '38370649858'
taobao_item_id: '41040606505'
force_unsubscribe:
when_balance_below: 0

View File

@@ -18,6 +18,9 @@ exports.hooks =
view:
layout:
# object(href, target, body)
menu_bar: []
# path
styles: []
exports.initializePlugins = (callback) ->

View File

@@ -1,30 +0,0 @@
exports.checkHomeFilePath = (account, path) ->
home_dir = "/home/#{account.username}/"
unless /^[/A-Za-z0-9_\-\.]+\/?$/.test path
return false
unless path.slice(0, home_dir.length) == home_dir
return false
unless path.length < 512
return false
unless path.slice(-3) != '/..'
return false
unless path.indexOf('/../') == -1
return false
return true
exports.checkHomeUnixSocket = (account, path) ->
fastcgi_prefix = 'unix://'
unless path.slice(0, fastcgi_prefix.length) == fastcgi_prefix
return false
unless exports.checkHomeFilePath account, path.slice fastcgi_prefix.length
return false
return true

View File

@@ -33,3 +33,34 @@ exports.randomString = (length) ->
exports.hashPassword = (password, password_salt) ->
return exports.sha256(password_salt + exports.sha256(password))
exports.checkHomeFilePath = (account, path) ->
home_dir = "/home/#{account.username}/"
unless /^[/A-Za-z0-9_\-\.]+\/?$/.test path
return false
unless path.slice(0, home_dir.length) == home_dir
return false
unless path.length < 512
return false
unless path.slice(-3) != '/..'
return false
unless path.indexOf('/../') == -1
return false
return true
exports.checkHomeUnixSocket = (account, path) ->
fastcgi_prefix = 'unix://'
unless path.slice(0, fastcgi_prefix.length) == fastcgi_prefix
return false
unless exports.checkHomeFilePath account, path.slice fastcgi_prefix.length
return false
return true

33
plugin/wiki/index.coffee Normal file
View File

@@ -0,0 +1,33 @@
markdown = require('markdown').markdown
path = require 'path'
fs = require 'fs'
{pluggable} = app
{renderAccount} = app.middleware
module.exports =
name: 'wiki'
type: 'extension'
pluggable.hooks.view.layout.menu_bar.push
href: '/wiki/'
body: '用户手册'
app.use '/wiki', renderAccount, (req, res) ->
url = req.url.substr '/wiki'.length
unless url
url = 'README.md'
filename = path.resolve path.join __dirname, '../../WIKI', url
baseDir = path.resolve path.join __dirname, '../../WIKI'
unless filename[0 .. baseDir.length - 1] == baseDir
return res.status(403).end()
fs.readFile filename, (err, data) ->
if err
return res.status(404).send err.toString()
res.render 'wiki',
title: url
content: markdown.toHTML data.toString()

View File

@@ -1,4 +1,4 @@
extends layout
extends ../../../core/view/layout
prepend head
title #{title} | #{config.web.name}

View File

@@ -17,7 +17,7 @@ module.exports =
available_services: ['shadowsocks']
billing:
taobao_item_id: '40711140727'
taobao_item_id: '41040606505'
force_unsubscribe:
when_balance_below: 0