Skip to content

Commit

Permalink
Very basic initial push of code.
Browse files Browse the repository at this point in the history
  • Loading branch information
DaneEveritt committed Dec 22, 2015
1 parent 263263a commit b280991
Show file tree
Hide file tree
Showing 17 changed files with 364 additions and 55 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015-node4"]
}
5 changes: 5 additions & 0 deletions .eslintignore
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
7 changes: 7 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "airbnb",
"rules": {
"indent": [2, 4],
"func-names": 0
}
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

config/**/*.json
lib/*
!lib/.githold
54 changes: 0 additions & 54 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -619,57 +619,3 @@ Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.

END OF TERMS AND CONDITIONS

How to Apply These Terms to Your New Programs

If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.

To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

{one line to give the program's name and a brief idea of what it does.}
Copyright (C) {year} {name of author}

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

Also add information on how to contact you by electronic and paper mail.

If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:

{project} Copyright (C) {year} {fullname}
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.

The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".

You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.

The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

37 changes: 36 additions & 1 deletion README.md
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 added lib/.githold
Empty file.
47 changes: 47 additions & 0 deletions package.json
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 added src/controllers/daemon.js
Empty file.
62 changes: 62 additions & 0 deletions src/controllers/docker.js
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;
24 changes: 24 additions & 0 deletions src/controllers/server.js
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;
29 changes: 29 additions & 0 deletions src/helpers/config.js
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;
72 changes: 72 additions & 0 deletions src/helpers/initialize.js
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;
35 changes: 35 additions & 0 deletions src/helpers/logger.js
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;
Loading

0 comments on commit b280991

Please sign in to comment.