-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from pkrll/dev/0.2.1
0.2.1
- Loading branch information
Showing
73 changed files
with
2,381 additions
and
786 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.PHONY: build | ||
|
||
build: | ||
npm run build | ||
|
||
run: | ||
npm run start:server | ||
|
||
clean: | ||
rm -rf dist/* | ||
rm -f tmp/info.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
|
||
const express = require('express'); | ||
const app = express(); | ||
const server = require('http').Server(app); | ||
const winston = require('winston'); | ||
|
||
require('./helpers/config.js')(app); | ||
require('./helpers/socket.js')(server); | ||
require('./app/router')(app); | ||
|
||
server.listen(app.get('port'), () => winston.loggers.get('logger').info('Server started. Listening on port ' + app.get('port'))); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict' | ||
const Raspy = require('../models/Raspy.js'); | ||
|
||
exports.update = (callback) => { | ||
Raspy.update(callback); | ||
} | ||
|
||
exports.install = (callback) => { | ||
Raspy.install(callback); | ||
} | ||
|
||
exports.restart = (callback) => { | ||
Raspy.restart(callback); | ||
} | ||
|
||
exports.stop = (callback) => { | ||
Raspy.stop(callback); | ||
} | ||
|
||
exports.shutdown = (callback) => { | ||
Raspy.shutdown(callback); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict' | ||
const System = require('../models/System.js'); | ||
|
||
exports.isNodeAppRunning = (appName, callback) => { | ||
System.isNodeAppRunning(appName).then(response => { | ||
callback(response); | ||
}).catch(error => { | ||
callback(error); | ||
}); | ||
} | ||
|
||
exports.getLogHistory = (options, callback) => { | ||
System.getLogHistory(options).then(response => { | ||
callback(response); | ||
}).catch(error => { | ||
callback(error); | ||
}); | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict' | ||
|
||
exports.update = callback => execute('cd ../ && make update', callback); | ||
exports.install = callback => execute('cd ../ && make install', callback); | ||
exports.restart = callback => execute('cd ../ && make restart', callback); | ||
exports.stop = callback => execute('cd ../ && make stop', callback); | ||
exports.shutdown = callback => execute('cd ../ && make shutdown', callback); | ||
|
||
function execute(process, callback) { | ||
const spawn = require('child_process').spawn; | ||
const command = spawn(process, { shell: true }); | ||
|
||
let history = ''; | ||
|
||
command.stdout.on('data', function (data) { | ||
history += data.toString(); | ||
callback({ | ||
status: 1, | ||
result: data.toString() | ||
}); | ||
}); | ||
|
||
command.stderr.on('data', function (data) { | ||
history += data.toString(); | ||
callback({ | ||
status: 0, | ||
error: { message: data.toString() } | ||
}); | ||
}); | ||
|
||
command.on('exit', function (code) { | ||
const winston = require('winston').loggers.get('command-logger'); | ||
winston.log('info', history); | ||
callback({ status: -1 }); | ||
}); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict' | ||
|
||
exports.isNodeAppRunning = appName => { | ||
const psNode = require('ps-node'); | ||
|
||
return new Promise( (resolve, reject) => { | ||
psNode.lookup({ | ||
command: 'node', | ||
arguments: appName | ||
}, function(error, result) { | ||
if (error) { | ||
reject({status: 0, error: error}); | ||
} else { | ||
let isRunning = (result.length > 0); | ||
resolve({status: 1, running: isRunning, arguments: process.arguments, pid: process.pid}); | ||
} | ||
}) | ||
}); | ||
}; | ||
|
||
exports.getLogHistory = options => { | ||
const winston = require('winston').loggers.get('command-logger'); | ||
|
||
return new Promise( (resolve, reject) => { | ||
winston.query(options, (error, results) => { | ||
if (error) { | ||
reject({status: 0, error: error}); | ||
} else { | ||
let result = (results.file) ? results.file.reverse() : []; | ||
resolve({status: 1, result: result}); | ||
} | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict' | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const path = require('path'); | ||
|
||
module.exports = function (app) { | ||
|
||
app.use(express.static(app.get('dist'))); | ||
|
||
app.get('*', function(req, res) { | ||
let file = path.join(app.get('dist'), '/index.html'); | ||
res.sendFile(file); | ||
}); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use strict' | ||
const winston = require('winston').loggers.get('command-logger'); | ||
const System = require('../controllers/SystemController.js'); | ||
const Raspy = require('../controllers/RaspyController.js'); | ||
|
||
module.exports = socket => { | ||
|
||
socket.on('client:status', () => { | ||
System.isNodeAppRunning('server.js', response => { | ||
socket.emit('status', response); | ||
}); | ||
}); | ||
|
||
socket.on('client:perform', request => { | ||
winston.log('info', '$ ' + request.command); | ||
|
||
switch (request.command) { | ||
case 'update': | ||
Raspy.update(message => socket.emit('command', message)); | ||
break; | ||
case 'install': | ||
Raspy.install(message => socket.emit('command', message)); | ||
break; | ||
case 'restart': | ||
Raspy.restart(message => socket.emit('command', message)); | ||
break; | ||
case 'stop': | ||
Raspy.stop(message => socket.emit('command', message)); | ||
break; | ||
case 'shutdown': | ||
Raspy.shutdown(message => socket.emit('command', message)); | ||
break; | ||
default: | ||
socket.emit('command', { | ||
status: 0, | ||
error: { message: 'Unrecognized command ' + request.command } | ||
}); | ||
break; | ||
} | ||
}); | ||
|
||
socket.on('client:history', () => { | ||
const options = { | ||
from: new Date - 24 * 60 * 60 * 1000 * 7, | ||
until: new Date, | ||
limit: 20, | ||
start: 0, | ||
order: 'desc', | ||
fields: ['message', 'level'] | ||
}; | ||
|
||
System.getLogHistory(options, response => socket.emit('history', response)); | ||
}); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
dev: { | ||
port: 5001, | ||
databasePath: 'db.json' | ||
}, | ||
prod: { | ||
port: 5001, | ||
databasePath: 'db.json' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
const express = require('express'); | ||
const path = require('path'); | ||
const config = require('../config/') | ||
const winston = require('winston'); | ||
|
||
module.exports = function(app) { | ||
const isDebugMode = (process.env.NODE_ENV != 'production'); | ||
const defaultPort = (isDebugMode) ? config.dev.port : config.port.port; | ||
const databasePath = (isDebugMode) ? config.dev.databasePath : config.port.databasePath; | ||
|
||
app.set('databasePath', databasePath); | ||
app.set('port', process.env.PORT || defaultPort); | ||
app.set('dist', path.join(__dirname, '../dist')); | ||
|
||
winston.loggers.add('command-logger', { | ||
console: { | ||
level: 'info', | ||
colorize: true, | ||
label: 'Command history' | ||
}, | ||
file: { filename: 'tmp/commands.log' } | ||
}); | ||
|
||
winston.loggers.add('logger', { | ||
console: { | ||
level: 'info', | ||
colorize: true, | ||
label: 'Logger' | ||
}, | ||
file: { filename: 'tmp/info.log' } | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict' | ||
const socketioAuth = require("socketio-auth"); | ||
const socketEvents = require('../app/router/socket.js'); | ||
|
||
const authenticate = async (socket, data, callback) => { | ||
var username = data.username; | ||
var password = data.password; | ||
var check = (username == 'admin' && password == 'secret'); | ||
|
||
console.log("Authentication attempt: " + ((check) ? 'success' : 'failure')); | ||
|
||
return callback(null, check); | ||
} | ||
|
||
const disconnected = socket => { | ||
console.log("Socket with id " + socket.id + " disconnected."); | ||
} | ||
|
||
module.exports = function (server) { | ||
const socketio = require('socket.io')(server); | ||
socketioAuth(socketio, { | ||
authenticate: authenticate, | ||
disconnect: disconnected, | ||
postAuthenticate: socketEvents, | ||
timeout: "none" | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"ignore": [ | ||
".git", "node_modules/**/node_modules", "*.json", "config/*", "web/*", "nodemon.json", "Makefile", "tmp" | ||
], | ||
"events": { | ||
"restart": "", | ||
"start": "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "raspy-bootstrapper", | ||
"version": "1.0.0", | ||
"description": "Bootstrapper for Raspy", | ||
"private": true, | ||
"scripts": { | ||
"dev": "nodemon app.js", | ||
"start:client": "cd web && npm start", | ||
"start:server": "npm run dev", | ||
"build": "node web/build/build.js" | ||
}, | ||
"dependencies": { | ||
"express": "^4.16.3", | ||
"express-basic-auth": "^1.1.5", | ||
"ps-node": "^0.1.6", | ||
"socket.io": "^2.1.1", | ||
"socketio-auth": "^0.1.1", | ||
"winston": "^2.4.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"presets": [ | ||
["env", { | ||
"modules": false, | ||
"targets": { | ||
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"] | ||
} | ||
}], | ||
"stage-2" | ||
], | ||
"plugins": ["transform-vue-jsx", "transform-runtime"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.DS_Store | ||
node_modules/ | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Editor directories and files | ||
.idea | ||
.vscode | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// https://github.com/michael-ciniawsky/postcss-load-config | ||
|
||
module.exports = { | ||
"plugins": { | ||
"postcss-import": {}, | ||
"postcss-url": {}, | ||
// to edit target browsers: use "browserslist" field in package.json | ||
"autoprefixer": {} | ||
} | ||
} |
Oops, something went wrong.