forked from pterodactyl/daemon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
263263a
commit b280991
Showing
17 changed files
with
364 additions
and
55 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,3 @@ | ||
{ | ||
"presets": ["es2015-node4"] | ||
} |
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,5 @@ | ||
# Ignore lib folder since those files are compiled by babel | ||
lib/*.js | ||
|
||
# Ignore JSON Files | ||
**/*.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,7 @@ | ||
{ | ||
"extends": "airbnb", | ||
"rules": { | ||
"indent": [2, 4], | ||
"func-names": 0 | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -1,2 +1,37 @@ | ||
# Daemon | ||
# Pterodactyl Daemon (Wings) | ||
The server control and management daemon built specifically for Pterodactyl Panel. | ||
|
||
# Contributing | ||
Please see `CONTRIBUTING.md` for information needed if you want to contribute to this project. | ||
|
||
# Running Developmental Builds | ||
|
||
## Building Project | ||
In order to run a development build of the daemon you will need to first build the project using Babel. This can be easily accomplished using the commands below. | ||
|
||
``` | ||
npm run-script build | ||
npm start | ||
``` | ||
|
||
This will compile the code in `src/` using Babel and send the output to `lib/`. If you make any changes to the code in `src/` you will need to rebuild before running to have those changes take effect. | ||
|
||
## Building Configuration File | ||
A basic configuration will need to be created in order to run a developmental build. | ||
|
||
``` | ||
{ | ||
"web": { | ||
"listen": 8080, | ||
"ssl": { | ||
"enabled": false, | ||
"certificate": "~/.ssl/public.crt", | ||
"key": "~/.ssl/public.key" | ||
} | ||
}, | ||
"docker": { | ||
"socket": "unix:///var/run/docker.sock" | ||
}, | ||
"logPath": "logs/" | ||
} | ||
``` |
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,47 @@ | ||
{ | ||
"name": "pterodactyl-daemon", | ||
"version": "0.0.1", | ||
"description": "Server management wrapper built for Pterodactyl Panel.", | ||
"main": "index.js", | ||
"directories": { | ||
"test": "tests" | ||
}, | ||
"scripts": { | ||
"start": "node lib/index.js | node_modules/bunyan/bin/bunyan", | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"build": "babel src -d lib" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Pterodactyl/Daemon.git" | ||
}, | ||
"keywords": [ | ||
"pterodactyl", | ||
"daemon", | ||
"wings" | ||
], | ||
"author": "Dane Everitt", | ||
"license": "GPL-3.0", | ||
"bugs": { | ||
"url": "https://github.com/Pterodactyl/Daemon/issues" | ||
}, | ||
"homepage": "https://github.com/Pterodactyl/Daemon#readme", | ||
"devDependencies": { | ||
"babel": "^6.3.13", | ||
"babel-cli": "^6.3.17", | ||
"babel-eslint": "^4.1.6", | ||
"babel-preset-es2015-node4": "^2.0.2", | ||
"eslint": "^1.10.3", | ||
"eslint-config-airbnb": "^2.1.1", | ||
"eslint-plugin-react": "^3.12.0" | ||
}, | ||
"dependencies": { | ||
"async": "^1.5.0", | ||
"bunyan": "^1.5.1", | ||
"dockerode": "^2.2.7", | ||
"fs-extra": "^0.26.3", | ||
"path": "^0.12.7", | ||
"restify": "^4.0.3", | ||
"rfr": "^1.2.3" | ||
} | ||
} |
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,62 @@ | ||
/** | ||
* Pterodactyl Daemon | ||
* Copyright (c) 2015 Dane Everitt <[email protected]> | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
const rfr = require('rfr'); | ||
|
||
const LoadConfig = rfr('lib/helpers/config.js'); | ||
const Dockerode = require('dockerode'); | ||
|
||
const Config = new LoadConfig(); | ||
const DockerController = new Dockerode({ | ||
socketPath: Config.get('docker.socket', 'unix:///var/run/docker.sock'), | ||
}); | ||
|
||
class Docker { | ||
constructor(container) { | ||
this._containerID = container; | ||
this._container = DockerController.getContainer(container); | ||
} | ||
|
||
/** | ||
* Starts a given container and returns a callback when finished. | ||
* @param {Function} next [description] | ||
* @return {[type]} [description] | ||
*/ | ||
start(next) { | ||
this._container.start(function (err) { | ||
return next(err); | ||
}); | ||
} | ||
|
||
/** | ||
* Stops a given container and returns a callback when finished. | ||
* @param {Function} next [description] | ||
* @return {[type]} [description] | ||
*/ | ||
stop(next) { | ||
this._container.stop(function (err) { | ||
return next(err); | ||
}); | ||
} | ||
|
||
/** | ||
* Kills a given container and returns a callback when finished. | ||
* @param {Function} next [description] | ||
* @return {[type]} [description] | ||
*/ | ||
kill(next) { | ||
this._container.kill(function (err) { | ||
return next(err); | ||
}); | ||
} | ||
|
||
rebuild() { | ||
// | ||
} | ||
} | ||
|
||
module.exports = Docker; |
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,24 @@ | ||
/** | ||
* Pterodactyl Daemon | ||
* Copyright (c) 2015 Dane Everitt <[email protected]> | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
class Server { | ||
constructor(json) { | ||
this._json = json; | ||
this._uuid = json.uuid; | ||
} | ||
|
||
/** | ||
* Returns UUID of the given server. | ||
* @return string | ||
*/ | ||
uuid() { | ||
return this._uuid; | ||
} | ||
} | ||
|
||
module.exports = Server; |
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,29 @@ | ||
/** | ||
* Pterodactyl Daemon | ||
* Copyright (c) 2015 Dane Everitt <[email protected]> | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
const rfr = require('rfr'); | ||
|
||
class Config { | ||
|
||
_raw() { | ||
return rfr('config/core.json'); | ||
} | ||
|
||
get(key, defaultResponse) { | ||
const raw = this._raw(); | ||
const getObject = key.split('.').reduce((o, i) => o[i], raw); | ||
|
||
if (typeof getObject !== 'undefined') { | ||
return getObject; | ||
} | ||
|
||
return (typeof defaultResponse !== 'undefined') ? defaultResponse : undefined; | ||
} | ||
|
||
} | ||
|
||
module.exports = Config; |
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,72 @@ | ||
/** | ||
* Pterodactyl Daemon | ||
* Copyright (c) 2015 Dane Everitt <[email protected]> | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
const rfr = require('rfr'); | ||
const Async = require('async'); | ||
const Path = require('path'); | ||
const Util = require('util'); | ||
const Fs = require('fs-extra'); | ||
const Log = rfr('lib/helpers/logger.js'); | ||
|
||
const Server = rfr('lib/controllers/server.js'); | ||
const Servers = {}; | ||
|
||
class Initialize { | ||
constructor() { | ||
// | ||
} | ||
|
||
/** | ||
* Initializes all servers on the system and loads them into memory for NodeJS. | ||
* @param {Function} next [description] | ||
* @return {[type]} [description] | ||
*/ | ||
init(next) { | ||
const self = this; | ||
Fs.readdir('./config/servers/', function (err, files) { | ||
if (err) { | ||
Log.fatal('Unable to load server configration files into memory.'); | ||
} | ||
|
||
Async.each(files, function (file, callback) { | ||
if (Path.extname(file) === '.json') { | ||
Fs.readJson(Util.format('./config/servers/%s', file), function (errJson, json) { | ||
if (errJson) { | ||
Log.warn(err, Util.format('Unable to parse JSON in %s due to an error, skipping...', file)); | ||
return; | ||
} | ||
|
||
// Is this JSON valid enough? | ||
if (typeof json.uuid === 'undefined') { | ||
Log.warn(Util.format('Detected valid JSON, but server was missing a UUID in %s, skipping...', file)); | ||
return; | ||
} | ||
|
||
// Initalize the Server | ||
self.setup(json, callback); | ||
}); | ||
} | ||
}, function () { | ||
return next(Servers); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Performs the setup action for a specific server. | ||
* @param {[type]} json [description] | ||
* @param {Function} next [description] | ||
* @return {[type]} [description] | ||
*/ | ||
setup(json, next) { | ||
Servers[json.uuid] = new Server(json); | ||
Log.info(Util.format('Loaded server configuration and initalized server for UUID:%s', json.uuid)); | ||
return next(); | ||
} | ||
} | ||
|
||
module.exports = Initialize; |
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,35 @@ | ||
/** | ||
* Pterodactyl Daemon | ||
* Copyright (c) 2015 Dane Everitt <[email protected]> | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
const rfr = require('rfr'); | ||
const Bunyan = require('bunyan'); | ||
const Path = require('path'); | ||
const LoadConfig = rfr('lib/helpers/config.js'); | ||
const Config = new LoadConfig(); | ||
|
||
const Log = Bunyan.createLogger({ | ||
name: 'core', | ||
streams: [ | ||
{ | ||
level: 'debug', | ||
stream: process.stdout, | ||
}, | ||
{ | ||
level: 'debug', | ||
type: 'rotating-file', | ||
path: Path.join(Config.get('logPath', '/var/log/pterodactyl-daemon'), 'daily.log'), | ||
period: '1d', | ||
count: 3, | ||
}, | ||
{ | ||
level: 'error', | ||
path: Path.join(Config.get('logPath', '/var/log/pterodactyl-daemon'), 'core-error.log'), | ||
}, | ||
], | ||
}); | ||
|
||
module.exports = Log; |
Oops, something went wrong.