-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added support for Redhats openshift cloud hosting
- Loading branch information
Showing
7 changed files
with
212 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "Starting creation of a new Nodepot app named $1" | ||
|
||
rhc app create $1 nodejs-0.10 --from-code=http://github.com/schmalle/nodepot.git | ||
rhc add-cartridge http://cartreflect-claytondev.rhcloud.com/reflect?github=smarterclayton/openshift-redis-cart --app $1 | ||
|
||
echo "Finished..." | ||
|
||
|
||
|
||
|
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,39 @@ | ||
var redis = require("redis"); | ||
|
||
var port = process.env.OPENSHIFT_REDIS_PORT; | ||
|
||
function initClient() | ||
{ | ||
var openShiftIP = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1"; | ||
if (openShiftIP != undefined) | ||
{ | ||
console.log("Starting DB client with ip/port server " + port + " : " + process.env.OPENSHIFT_REDIS_HOST + " on openshift"); | ||
|
||
var client = redis.createClient(port, process.env.OPENSHIFT_REDIS_HOST); | ||
client.auth(process.env.REDIS_PASSWORD); | ||
return client; | ||
|
||
} | ||
else | ||
{ | ||
console.log("Starting DB without special parameters outside of OpenShift environment ..."); | ||
var client = redis.createClient(); | ||
return client; | ||
} | ||
|
||
} | ||
|
||
var client = initClient(); | ||
console.log("Starting after initclient..."); | ||
|
||
if (client != undefined) | ||
{ | ||
console.log("client after initClient is defined"); | ||
} | ||
else | ||
{ | ||
console.log("client after initClient is not defined"); | ||
} | ||
|
||
module.exports = client; | ||
exports.initClient = initClient; |
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,14 @@ | ||
#!/usr/bin/env bash | ||
cd $HOME/app-root/data | ||
mkdir html | ||
mkdir dl | ||
mkdir download | ||
mkdir logs | ||
mkdir log | ||
cp ./../repo/template/config.js . | ||
cp ./../repo/html/* ./html/ | ||
|
||
|
||
|
||
|
||
|
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 @@ | ||
#!/usr/bin/env bash | ||
/bin/sh $HOME/app-root/repo/openshift/openshift.sh; cd $HOME/app-root/repo; node ./app.js |
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,129 @@ | ||
var http = require("http"); | ||
var url = require("url"); | ||
var fs = require("fs"); | ||
var path = require('path'); | ||
var ana = require("./analyzer"); | ||
var S = require('string'); | ||
var twitter = require("./twitter"); | ||
var moment = require("moment"); | ||
var config = "test"; | ||
|
||
|
||
|
||
var mimeTypes = { | ||
"html": "text/html", | ||
"jpeg": "image/jpeg", | ||
"jpg": "image/jpeg", | ||
"png": "image/png", | ||
"js": "text/javascript", | ||
"css": "text/css"}; | ||
|
||
|
||
/** | ||
* retrive the correct path for the stored html data | ||
* @param config | ||
* @param openShiftDataDir | ||
* @returns {string} | ||
*/ | ||
function getHtmlPath(config, openShiftDataDir) { | ||
|
||
var openShiftDataDir = process.env.OPENSHIFT_DATA_DIR; | ||
|
||
|
||
var configuredHtmlPath = config.html; | ||
if (openShiftDataDir != undefined) | ||
{ | ||
configuredHtmlPath = openShiftDataDir + '/html/'; | ||
} | ||
else | ||
{ | ||
configuredHtmlPath = config.html; | ||
} | ||
|
||
return configuredHtmlPath; | ||
} | ||
|
||
|
||
function start(configName) { | ||
|
||
config = require(configName); | ||
|
||
function onRequest(request, response) { | ||
|
||
|
||
/* set the correct content type */ | ||
response.writeHead(200, {"Content-Type": "text/html"}); | ||
|
||
var query = request.url; | ||
var ip = request.connection.remoteAddress; | ||
|
||
// get data directory for OpenShift (easy check, if we run in Openshift) | ||
var openShiftDataDir = process.env.OPENSHIFT_DATA_DIR; | ||
var logPath = "/var/log/nodepot.log"; | ||
|
||
var configuredHtmlPath = getHtmlPath(config, openShiftDataDir); | ||
|
||
if (openShiftDataDir != undefined) | ||
{ | ||
logPath = openShiftDataDir + "/log/nodepot.log" | ||
} | ||
|
||
|
||
// admin check (query and IP range) | ||
if ((query == "/admin" || query == "admin") && (S(ip).contains("127.0.0.1") || S(ip).contains(config.home_ip))) | ||
{ | ||
// show UI | ||
|
||
var defaultTemplateStart = fs.readFileSync(configuredHtmlPath + '/adminstart.html', 'utf8'); | ||
var learnedStuff = fs.readFileSync(logPath, 'utf8'); | ||
var defaultTemplateEnd = fs.readFileSync(configuredHtmlPath + '/adminend.html', 'utf8'); | ||
response.write(defaultTemplateStart); | ||
response.write(learnedStuff); | ||
response.write(defaultTemplateEnd); | ||
|
||
} | ||
else | ||
{ /* default analyze case */ | ||
|
||
/* check if the request contains an .. code */ | ||
statusAnalyze = ana.analyze(request, response, config); | ||
|
||
|
||
|
||
|
||
var defaultTemplate = fs.readFileSync(configuredHtmlPath + '/demo.html', 'utf8'); | ||
var learnedStuff = fs.readFileSync(configuredHtmlPath + '/dork.html', 'utf8'); | ||
|
||
response.write(defaultTemplate); | ||
response.write(learnedStuff); | ||
|
||
if (config.twitter.verbose == "yes" && statusAnalyze != null) | ||
{ | ||
twitter.tweet(moment().format('MMMM Do YYYY, h:mm:ss a') + "(Nodepot): Found request from ip " + ip, config); | ||
} | ||
|
||
|
||
} | ||
response.end(); | ||
} | ||
|
||
var openShiftIP = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1"; | ||
var port = process.env.OPENSHIFT_NODEJS_PORT; | ||
|
||
if (port != undefined) { | ||
console.log(moment().format('MMMM Do YYYY, h:mm:ss a') + " Server tries to start on port " + port); | ||
} | ||
|
||
if (openShiftIP != undefined) | ||
{ | ||
http.createServer(onRequest).listen(process.env.OPENSHIFT_NODEJS_PORT, openShiftIP); | ||
} | ||
else | ||
{ | ||
http.createServer(onRequest).listen(config.port); | ||
} | ||
|
||
console.log(moment().format('MMMM Do YYYY, h:mm:ss a') + " Server has started."); | ||
} | ||
|
||
exports.start = 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 @@ | ||
console.log("Dummy start"); |