Permalink
Please
sign in to comment.
Showing
with
2,889 additions
and 733 deletions.
- +2 −1 .env.example
- +3 −2 .gitignore
- +4 −4 README.md
- +0 −2 bin/.htaccess
- +73 −0 bin/generate
- +0 −74 bin/generate.php
- +0 −9 composer.json
- +13 −0 dist/graphjs-theme.less
- +0 −4 generate/.htaccess
- +70 −0 generate/index.js
- +0 −74 generate/index.php
- +58 −0 index.js
- +0 −29 index.php
- +169 −0 lib/FileGeneration.js
- +0 −166 lib/FileGeneration.php
- +7 −0 lib/asyncMiddleware.js
- +35 −0 lib/functions.js
- +33 −0 lib/init.js
- +0 −32 lib/init.php
- +2,162 −0 package-lock.json
- +13 −0 package.json
- +35 −0 server.js
- +9 −0 site/templates/account.njk
- +0 −20 site/templates/account.php
- +9 −0 site/templates/create-group.njk
- +0 −20 site/templates/create-group.php
- +8 −20 site/templates/{error.php → error.njk}
- +14 −0 site/templates/feed.njk
- +0 −25 site/templates/feed.php
- +9 −0 site/templates/forum.njk
- +0 −20 site/templates/forum.php
- +14 −0 site/templates/group.njk
- +0 −25 site/templates/group.php
- +9 −0 site/templates/groups.njk
- +0 −20 site/templates/groups.php
- +35 −0 site/templates/home.njk
- +0 −47 site/templates/home.php
- +30 −24 site/templates/layout/{base.php → base.njk}
- +10 −0 site/templates/layout/template_generate.njk
- +0 −9 site/templates/layout/template_generate.php
- +23 −0 site/templates/layout/template_show.njk
- +0 −20 site/templates/layout/template_show.php
- +9 −0 site/templates/members.njk
- +0 −20 site/templates/members.php
- +9 −0 site/templates/messages.njk
- +0 −20 site/templates/messages.php
- +14 −0 site/templates/profile.njk
- +0 −25 site/templates/profile.php
- +9 −20 site/templates/{settings.php → settings.njk}
- +1 −1 site/vendor/graphjs/graph.js
- BIN site/vendor/graphjs/graph.js.gz
@@ -1,2 +1,3 @@ | ||
SALT= | ||
BACKUP_SCRIPT=/usr/local/bin/groups-backup.sh | ||
BACKUP_SCRIPT=/usr/local/bin/groups-backup.sh | ||
REDIRECT= |
@@ -1,3 +1,4 @@ | ||
/node_modules | ||
.env | ||
.DS_Store | ||
composer.lock | ||
/vendor | ||
|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/env node | ||
|
||
const path = require('path'); | ||
const cmd = require('commander'); | ||
const FileGeneration = require('../lib/FileGeneration'); | ||
|
||
const dir = path.dirname(__dirname) + '/site/templates'; | ||
|
||
cmd.description('Generates static social network frontend'); | ||
cmd.arguments('<name> <title>', 'Name'); | ||
cmd.option('-d, --description, <description>', 'Group Description (may contain spaces or special chars)'); | ||
cmd.option('-g, --git, <git>', 'Git Remote Url'); | ||
cmd.option('-i, --id, <id>', 'GraphJS ID'); | ||
cmd.option('-h, --host, <host>', 'GraphJS Server Hostname'); | ||
cmd.option('-s, --stream_host, <stream_host>', 'Stream Server Hostname'); | ||
cmd.option('-p, --primary_color, <primary_color>', 'Primary Color'); | ||
cmd.option('-t, --text_color, <text_color>', 'Text Color'); | ||
cmd.option('-b, --background_color, <background_color>', 'Background Color'); | ||
cmd.option('-t, --theme, <theme>', 'Theme (light or dark)'); | ||
cmd.option('-m, --modules, <modules>', 'List of extra modules to enable; forum, groups'); | ||
cmd.option('-xh, --extra_head, <extra_head>', 'Extra code to inject in HEAD'); | ||
|
||
let args = []; | ||
let name; | ||
let title; | ||
|
||
cmd.action(function (argName, argTitle) { | ||
args = Array.from(arguments); | ||
name = argName; | ||
title = argTitle; | ||
}); | ||
|
||
cmd.parse(process.argv); | ||
|
||
if (args.length === 0) { | ||
console.error('ERROR: <name> and <title> must be specified'); | ||
process.exit(1); | ||
} | ||
|
||
const publicId = cmd.id || null; | ||
const theme = cmd.theme || 'light'; | ||
const textColor = cmd.text_color || null; | ||
const backgroundColor = cmd.background_color || null; | ||
const primaryColor = cmd.primary_color || null; | ||
const host = cmd.host || null; | ||
const streamHost = cmd.stream_host || null; | ||
const description = (cmd.hasOwnProperty('description') && cmd.description) || ''; | ||
const remoteUrl = cmd.git || ''; | ||
const modules = cmd.modules.split(",") || ''; | ||
const extraHead = (cmd.hasOwnProperty('extra_head') && cmd.description) || ''; | ||
|
||
var moduleForum = "off"; | ||
var moduleGroups = "off"; | ||
|
||
for(let i=0;i<modules.length;i++) { | ||
switch(modules[i].trim()) { | ||
case "forum": | ||
moduleForum = "on"; | ||
break; | ||
case "groups": | ||
moduleGroups = "on"; | ||
break; | ||
} | ||
} | ||
|
||
(new FileGeneration( | ||
dir, name, title, theme, publicId, primaryColor, | ||
textColor, backgroundColor, host, streamHost, | ||
remoteUrl, description, extraHead, moduleForum, moduleGroups | ||
)).generate().catch(function (error) { | ||
console.error(error); | ||
}); | ||
|
@@ -0,0 +1,70 @@ | ||
const path = require('path'); | ||
const crypto = require('crypto'); | ||
const fs = require('fs'); | ||
const executable = require('executable'); | ||
const child_process = require('child_process'); | ||
const FileGeneration = require('../lib/FileGeneration'); | ||
const fn = require('../lib/functions'); | ||
|
||
module.exports = async function (req, res) { | ||
|
||
const rootPath = path.dirname(__dirname); | ||
const dir = rootPath + '/site/templates'; | ||
const body = req.body; | ||
const q = req.query; | ||
|
||
const name = q.name || body.name || null; | ||
const title = q.title || body.title || null; | ||
const description = q.description || body.description || ''; | ||
const remoteUrl = q.git || body.git || ''; | ||
const publicId = q.public_id || body.public_id || null; | ||
const theme = q.theme || body.theme || null; | ||
const textColor = q.text_color || body.text_color || null; | ||
const backgroundColor = q.background_color || body.background_color || null; | ||
const primaryColor = q.primary_color || body.primary_color || null; | ||
const host = q.host || body.host || null; | ||
const streamHost = q.stream_host || body.stream_host || null; | ||
const secret = q.secret || body.secret || null; | ||
const regen = q.regen || body.regen || false; | ||
const moduleForum = q.module_forum || body.module_forum || false; | ||
const moduleGroups = q.module_groups || body.module_groups || false; | ||
const extraHead = q.extra_head || body.extra_head || ''; | ||
|
||
if (! name || ! title || ! publicId) { | ||
res.setHeader('Content-Type', 'application/json'); | ||
return res.send(JSON.stringify({ | ||
success: false, | ||
message: 'name, title, public_id are required', | ||
})); | ||
} | ||
|
||
if (crypto.createHash('md5').update(name + process.env.SALT).digest('hex') != secret) { | ||
res.setHeader('Content-Type', 'application/json'); | ||
return res.send(JSON.stringify({ | ||
success: false, | ||
message: 'not authorized', | ||
})); | ||
} | ||
|
||
const backupScript = process.env.BACKUP_SCRIPT; | ||
if ( | ||
backupScript | ||
&& await fn.fs.exists(backupScript) | ||
&& await executable(backupScript) | ||
) { | ||
await fn.child_process.execFile(backupScript); | ||
} | ||
|
||
// actual file generation takes place here. | ||
await (new FileGeneration( | ||
dir, name, title, theme, publicId, primaryColor, | ||
textColor, backgroundColor, host, streamHost, | ||
remoteUrl, description, extraHead, moduleForum, moduleGroups | ||
)).generate(regen); | ||
|
||
res.setHeader('Content-Type', 'application/json'); | ||
res.send(JSON.stringify({ | ||
success: true, | ||
message: 'Generated', | ||
})); | ||
}; |

Oops, something went wrong.
0 comments on commit
4efb600