Skip to content

Commit

Permalink
Merge pull request #131 from CodersGit/ssl-for-pull
Browse files Browse the repository at this point in the history
Added SSL support for websocket
  • Loading branch information
deStrO authored Jul 21, 2017
2 parents 1471a88 + c0e3042 commit 7f016f0
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function run() {
1 => array("file", APP_ROOT . "logs" . DIRECTORY_SEPARATOR . "websocket.log", "a"),
2 => array("file", APP_ROOT . "logs" . DIRECTORY_SEPARATOR . "websocket.error", "a")
);
$webSocketProcess = proc_open($config->getNodeStartupMethod().' ' . APP_ROOT . 'websocket_server.js ' . \eBot\Config\Config::getInstance()->getBot_ip() . ' ' . \eBot\Config\Config::getInstance()->getBot_port(), $descriptorspec, $pipes);
$webSocketProcess = proc_open($config->getNodeStartupMethod() . ' ' . APP_ROOT . 'websocket_server.js ' . \eBot\Config\Config::getInstance()->getBot_ip() . ' ' . \eBot\Config\Config::getInstance()->getBot_port() . ' ' . (\eBot\Config\Config::getInstance()->isSSLEnabled() ? 'TRUE': 'FALSE') . ' ' . \eBot\Config\Config::getInstance()->getSSLCertificatePath() . ' ' . \eBot\Config\Config::getInstance()->getSSLKeyPath(), $descriptorspec, $pipes);
if (is_resource($webSocketProcess)) {
fclose($pipes[0]);
usleep(400000);
Expand Down
5 changes: 4 additions & 1 deletion config/config.ini.smp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ MYSQL_BASE = "ebotv3"
[Config]
BOT_IP = "127.0.0.1"
BOT_PORT = 12360
SSL_ENABLED = false
SSL_CERTIFICATE_PATH = "ssl/cert.pem"
SSL_KEY_PATH = "ssl/key.pem"
EXTERNAL_LOG_IP = "" ; use this in case your server isn't binded with the external IP (behind a NAT)
MANAGE_PLAYER = 1
DELAY_BUSY_SERVER = 120
Expand All @@ -26,7 +29,7 @@ LO3_METHOD = "restart" ; restart or csay or esl
KO3_METHOD = "restart" ; restart or csay or esl
DEMO_DOWNLOAD = true ; true or false :: whether gotv demos will be downloaded from the gameserver after matchend or not
REMIND_RECORD = false ; true will print the 3x "Remember to record your own POV demos if needed!" messages, false will not
DAMAGE_REPORT = true; true will print damage reports at end of round to players, false will not
DAMAGE_REPORT = true ; true will print damage reports at end of round to players, false will not
USE_DELAY_END_RECORD = false ; use the tv_delay to record postpone the tv_stoprecord & upload

[MAPS]
Expand Down
40 changes: 39 additions & 1 deletion src/eBot/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
*/
class Config extends Singleton
{

private $mysql_ip;
private $mysql_port;
private $mysql_user;
private $mysql_pass;
private $mysql_base;
private $bot_ip;
private $bot_port;
private $sslEnabled;
private $sslCertPath;
private $sslKeyPath;
private $messages = array();
private $record_name = "ebot";
private $delay_busy_server = 90;
Expand Down Expand Up @@ -60,6 +62,9 @@ public function __construct()

$this->bot_ip = $config["BOT_IP"];
$this->bot_port = $config["BOT_PORT"];
$this->sslEnabled = $config["SSL_ENABLED"];
$this->sslCertPath = $config["SSL_CERTIFICATE_PATH"];
$this->sslKeyPath = $config["SSL_KEY_PATH"];

$this->delay_busy_server = $config["DELAY_BUSY_SERVER"];

Expand Down Expand Up @@ -232,6 +237,39 @@ public function setBot_port($bot_port)
$this->bot_port = $bot_port;
}

public function isSSLEnabled()
{
return $this->sslEnabled;
}

public function setSSLEnabled($sslEnabled)
{
$this->sslEnabled = $sslEnabled;
return $this;
}

public function getSSLCertificatePath()
{
return $this->sslCertPath;
}

public function setSSLCertificatePath($sslCertificatePath)
{
$this->sslCertPath = $sslCertificatePath;
return $this;
}

public function getSSLKeyPath()
{
return $this->sslKeyPath;
}

public function setSSLKeyPath($sslKeyPath)
{
$this->sslKeyPath = $sslKeyPath;
return $this;
}

public function getMessages()
{
return $this->messages;
Expand Down
3 changes: 1 addition & 2 deletions src/eBot/Match/Match.php
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,8 @@ public function taskExecute($name) {
} elseif ($name == self::STOP_RECORD) {
$this->needDelTask = false;
$this->addLog("Stopping record and pushing demo...");
// $this->rcon->send("tv_stoprecord");
if (\eBot\Config\Config::getInstance()->getDemoDownload()) {
$this->rcon->send('tv_stoprecord; ' . 'csay_tv_demo_push "' . $this->currentRecordName . '.dem" "http://' . \eBot\Config\Config::getInstance()->getLogAddressIp() . ':' . \eBot\Config\Config::getInstance()->getBot_port() . '/upload"');
$this->rcon->send('tv_stoprecord; ' . 'csay_tv_demo_push "' . $this->currentRecordName . '.dem" "' . (\eBot\Config\Config::getInstance()->isSSLEnabled() ? 'https' : 'http') . '://' . \eBot\Config\Config::getInstance()->getLogAddressIp() . ':' . \eBot\Config\Config::getInstance()->getBot_port() . '/upload"');
} else {
$this->rcon->send("tv_stoprecord");
}
Expand Down
15 changes: 13 additions & 2 deletions websocket_server.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var http = require('http');
var https = require('https');
var formidable = require('formidable');
var archiver = require('archiver');
var fs = require('fs');
Expand All @@ -7,14 +8,15 @@ var clientUDP = dgram.createSocket("udp4");

var udp_ip = process.argv[2];
var udp_port = process.argv[3];
var sslEnabled = process.argv[4] === 'TRUE';

var DEMO_PATH = __dirname + "/demos/";

String.prototype.endsWith = function(suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};

var server = http.createServer(function(request, response) {
function requestHandler (request, response) {
switch (request.url) {

case '/upload':
Expand Down Expand Up @@ -87,7 +89,16 @@ var server = http.createServer(function(request, response) {
response.end();
break;
}
});
}
var server;
if (sslEnabled) {
server = https.createServer({
key: fs.readFileSync(process.argv[6] || 'ssl/key.pem'),
cert: fs.readFileSync(process.argv[5] ||'ssl/cert.pem')
},requestHandler);
} else {
server = http.createServer(requestHandler);
}

fs.exists(DEMO_PATH, function(exists) {
if (!exists) {
Expand Down

0 comments on commit 7f016f0

Please sign in to comment.