function arguments still need care

This commit is contained in:
Dominic Bosch 2014-04-19 03:49:48 +02:00
parent a68b27c0c7
commit 0e8ce1233c
28 changed files with 1350 additions and 1008 deletions

View file

@ -14,6 +14,8 @@ Components Manager
db = require './persistence'
# - [Dynamic Modules](dynamic-modules.html)
dynmod = require './dynamic-modules'
# - [Encryption](encryption.html)
encryption = require './encryption'
# - Node.js Modules: [fs](http://nodejs.org/api/fs.html),
# [path](http://nodejs.org/api/path.html) and
@ -159,40 +161,109 @@ getModuleParams = ( user, oPayload, dbMod, callback ) ->
answ.message = oPayload
callback answ
getModuleUserParams = ( user, oPayload, dbMod, callback ) ->
answ = hasRequiredParams [ 'id' ], oPayload
if answ.code isnt 200
callback answ
else
dbMod.getUserParams oPayload.id, user.username, ( err, str ) ->
oParams = JSON.parse str
for name, oParam of oParams
if not oParam.shielded
oParam.value = encryption.decrypt oParam.value
answ.message = JSON.stringify oParams
callback answ
getModuleUserArguments = ( user, oPayload, dbMod, callback ) ->
answ = hasRequiredParams [ 'ruleId' ,'moduleId' ], oPayload
if answ.code isnt 200
callback answ
else
dbMod.getAllModuleUserArguments user.username, oPayload.ruleId, oPayload.moduleId, ( err, oPayload ) ->
answ.message = oPayload
callback answ
forgeModule = ( user, oPayload, dbMod, callback ) =>
answ = hasRequiredParams [ 'id', 'params', 'lang', 'data' ], oPayload
if answ.code isnt 200
callback answ
else
i = 0
dbMod.getModule oPayload.id, ( err, mod ) =>
if mod
answ.code = 409
answ.message = 'Module name already existing: ' + oPayload.id
callback answ
else
src = oPayload.data
dynmod.compileString src, user.username, 'dummyRule', oPayload.id, oPayload.lang, null, ( cm ) =>
answ = cm.answ
if answ.code is 200
funcs = []
funcs.push name for name, id of cm.module
@log.info "CM | Storing new module with functions #{ funcs.join( ', ' ) }"
answ.message =
" Module #{ oPayload.id } successfully stored! Found following function(s): #{ funcs }"
oPayload.functions = JSON.stringify funcs
oPayload.functionArgs = JSON.stringify cm.funcParams
dbMod.storeModule user.username, oPayload
if oPayload.public is 'true'
dbMod.publish oPayload.id
if oPayload.overwrite
storeModule user, oPayload, dbMod, callback
else
dbMod.getModule oPayload.id, ( err, mod ) =>
if mod
answ.code = 409
answ.message = 'Module name already existing: ' + oPayload.id
callback answ
else
storeModule user, oPayload, dbMod, callback
storeModule = ( user, oPayload, dbMod, callback ) =>
src = oPayload.data
dynmod.compileString src, user.username, 'dummyRule', oPayload.id, oPayload.lang, null, ( cm ) =>
answ = cm.answ
if answ.code is 200
funcs = []
funcs.push name for name, id of cm.module
@log.info "CM | Storing new module with functions #{ funcs.join( ', ' ) }"
answ.message =
" Module #{ oPayload.id } successfully stored! Found following function(s): #{ funcs }"
oPayload.functions = JSON.stringify funcs
oPayload.functionArgs = JSON.stringify cm.funcParams
dbMod.storeModule user.username, oPayload
if oPayload.public is 'true'
dbMod.publish oPayload.id
callback answ
storeRule = ( user, oPayload, callback ) =>
# This is how a rule is stored in the database
rule =
id: oPayload.id
event: oPayload.event
event_interval: oPayload.event_interval
conditions: oPayload.conditions
actions: oPayload.actions
strRule = JSON.stringify rule
# store the rule
db.storeRule rule.id, strRule
# link the rule to the user
db.linkRule rule.id, user.username
# activate the rule
db.activateRule rule.id, user.username
# if event module parameters were send, store them
if oPayload.event_params
epModId = rule.event.split( ' -> ' )[ 0 ]
db.eventPollers.storeUserParams epModId, user.username, JSON.stringify oPayload.event_params
# if action module params were send, store them
oParams = oPayload.action_params
for id, params of oParams
db.actionInvokers.storeUserParams id, user.username, JSON.stringify params
oParams = oPayload.action_functions
# if action function arguments were send, store them
for id, params of oParams
arr = id.split ' -> '
db.actionInvokers.storeUserArguments user.username, rule.id, arr[ 0 ], arr[ 1 ], JSON.stringify params
# Initialize the rule log
db.resetLog user.username, rule.id
db.appendLog user.username, rule.id, "INIT", "Rule '#{ rule.id }' initialized"
# Inform everbody about the new rule
eventEmitter.emit 'rule',
event: 'new'
user: user.username
rule: rule
callback
code: 200
message: "Rule '#{ rule.id }' stored and activated!"
commandFunctions =
get_public_key: ( user, oPayload, callback ) ->
callback
code: 200
message: dynmod.getPublicKey()
message: encryption.getPublicKey()
# EVENT POLLERS
# -------------
@ -208,6 +279,12 @@ commandFunctions =
get_event_poller_params: ( user, oPayload, callback ) ->
getModuleParams user, oPayload, db.eventPollers, callback
get_event_poller_user_params: ( user, oPayload, callback ) ->
getModuleUserParams user, oPayload, db.eventPollers, callback
get_event_poller_user_arguments: ( user, oPayload, callback ) ->
getModuleUserArguments user, oPayload, db.eventPollers, callback
forge_event_poller: ( user, oPayload, callback ) ->
forgeModule user, oPayload, db.eventPollers, callback
@ -239,7 +316,13 @@ commandFunctions =
get_action_invoker_params: ( user, oPayload, callback ) ->
getModuleParams user, oPayload, db.actionInvokers, callback
get_action_invoker_function_params: ( user, oPayload, callback ) ->
get_action_invoker_user_params: ( user, oPayload, callback ) ->
getModuleUserParams user, oPayload, db.actionInvokers, callback
get_action_invoker_user_arguments: ( user, oPayload, callback ) ->
getModuleUserArguments user, oPayload, db.actionInvokers, callback
get_action_invoker_function_arguments: ( user, oPayload, callback ) ->
answ = hasRequiredParams [ 'id' ], oPayload
if answ.code isnt 200
callback answ
@ -270,6 +353,16 @@ commandFunctions =
code: 200
message: obj
get_rule: ( user, oPayload, callback ) ->
answ = hasRequiredParams [ 'id' ], oPayload
if answ.code isnt 200
callback answ
else
db.getRule oPayload.id, ( err, obj ) ->
callback
code: 200
message: obj
get_rule_log: ( user, oPayload, callback ) ->
answ = hasRequiredParams [ 'id' ], oPayload
if answ.code isnt 200
@ -291,54 +384,16 @@ commandFunctions =
if answ.code isnt 200
callback answ
else
db.getRule oPayload.id, ( err, oExisting ) ->
if oExisting isnt null
answ =
code: 409
message: 'Rule name already existing!'
else
# This is how a rule is stored in the database
rule =
id: oPayload.id
event: oPayload.event
event_interval: oPayload.event_interval
conditions: oPayload.conditions
actions: oPayload.actions
strRule = JSON.stringify rule
# store the rule
db.storeRule rule.id, strRule
# link the rule to the user
db.linkRule rule.id, user.username
# activate the rule
db.activateRule rule.id, user.username
# if event module parameters were send, store them
if oPayload.event_params
epModId = rule.event.split( ' -> ' )[0]
db.eventPollers.storeUserParams epModId, user.username, oPayload.event_params
# if action module params were send, store them
oParams = oPayload.action_params
for id, params of oParams
db.actionInvokers.storeUserParams id, user.username, JSON.stringify params
oParams = oPayload.action_functions
# if action function arguments were send, store them
for id, params of oParams
arr = id.split ' -> '
db.actionInvokers.storeUserArguments user.username, rule.id, arr[ 0 ], arr[ 1 ], JSON.stringify params
# Initialize the rule log
db.resetLog user.username, rule.id
db.appendLog user.username, rule.id, "INIT", "Rule '#{ rule.id }' initialized"
# Inform everbody about the new rule
eventEmitter.emit 'rule',
event: 'new'
user: user.username
rule: rule
answ =
code: 200
message: "Rule '#{ rule.id }' stored and activated!"
callback answ
if oPayload.overwrite
storeRule user, oPayload, callback
else
db.getRule oPayload.id, ( err, mod ) =>
if mod
answ.code = 409
answ.message = 'Rule name already existing: ' + oPayload.id
callback answ
else
storeRule user, oPayload, callback
delete_rule: ( user, oPayload, callback ) ->
answ = hasRequiredParams [ 'id' ], oPayload

View file

@ -10,6 +10,8 @@ Dynamic Modules
# - [Persistence](persistence.html)
db = require './persistence'
# - [Encryption](encryption.html)
encryption = require './encryption'
# - Node.js Modules: [vm](http://nodejs.org/api/vm.html) and
# [events](http://nodejs.org/api/events.html)
@ -18,11 +20,9 @@ needle = require 'needle'
request = require 'request'
# - External Modules: [coffee-script](http://coffeescript.org/),
# [cryptico](https://github.com/wwwtyro/cryptico),
# [crypto-js](https://www.npmjs.org/package/crypto-js) and
# [import-io](https://www.npmjs.org/package/import-io)
cs = require 'coffee-script'
cryptico = require 'my-cryptico'
cryptoJS = require 'crypto-js'
importio = require( 'import-io' ).client
@ -37,21 +37,9 @@ Initializes the dynamic module handler.
###
exports = module.exports = ( args ) =>
@log = args.logger
# FIXME this can't come through the arguments
if not @strPublicKey and args[ 'keygen' ]
db args
passPhrase = args[ 'keygen' ]
numBits = 1024
@oPrivateRSAkey = cryptico.generateRSAKey passPhrase, numBits
@strPublicKey = cryptico.publicKeyString @oPrivateRSAkey
@log.info "DM | Public Key generated: #{ @strPublicKey }"
db args
module.exports
exports.getPublicKey = () =>
@strPublicKey
logFunction = ( uId, rId, mId ) ->
( msg ) ->
db.appendLog uId, rId, mId, msg
@ -61,7 +49,7 @@ getFunctionParamNames = ( fName, func, oFuncs ) ->
fnStr = func.toString().replace regexpComments, ''
result = fnStr.slice( fnStr.indexOf( '(' ) + 1, fnStr.indexOf( ')' ) ).match /([^\s,]+)/g
if not result
result = []
result = []
oFuncs[fName] = result
###
@ -93,13 +81,14 @@ exports.compileString = ( src, userId, ruleId, modId, lang, dbMod, cb ) =>
if dbMod
dbMod.getUserParams modId, userId, ( err, obj ) =>
try
oDecrypted = cryptico.decrypt obj, @oPrivateRSAkey
obj = JSON.parse oDecrypted.plaintext
oParams = {}
for name, oParam of JSON.parse obj
oParams[ name ] = encryption.decrypt oParam.value
@log.info "DM | Loaded user defined params for #{ userId }, #{ ruleId }, #{ modId }"
catch err
@log.warn "DM | Error during parsing of user defined params for #{ userId }, #{ ruleId }, #{ modId }"
@log.warn err
fTryToLoadModule userId, ruleId, modId, src, dbMod, obj, cb
fTryToLoadModule userId, ruleId, modId, src, dbMod, oParams, cb
else
fTryToLoadModule userId, ruleId, modId, src, dbMod, null, cb
@ -156,8 +145,7 @@ fTryToLoadModule = ( userId, ruleId, modId, src, dbMod, params, cb ) =>
dbMod.getUserArguments userId, ruleId, modId, func, ( err, obj ) =>
if obj
try
oDecrypted = cryptico.decrypt obj, @oPrivateRSAkey
oFuncArgs[ func ] = JSON.parse oDecrypted.plaintext
oFuncArgs[ func ] = JSON.parse encryption.decrypt obj
@log.info "DM | Found and attached user-specific arguments to #{ userId }, #{ ruleId }, #{ modId }"
catch err
@log.warn "DM | Error during parsing of user-specific arguments for #{ userId }, #{ ruleId }, #{ modId }"

29
coffee/encryption.coffee Normal file
View file

@ -0,0 +1,29 @@
###
Encryption
===============
> Handles RSA encryption and decryption of user specific parameters.
###
# **Loads Modules:**
# - [cryptico](https://github.com/wwwtyro/cryptico)
cryptico = require 'my-cryptico'
exports = module.exports = ( args ) =>
@log = args.logger
@oPrivateRSAkey = cryptico.generateRSAKey args[ 'keygen' ], 1024
@strPublicKey = cryptico.publicKeyString @oPrivateRSAkey
@log.info "DM | Public Key generated: #{ @strPublicKey }"
module.exports
exports.getPublicKey = () =>
@strPublicKey
exports.encrypt = ( plainText ) =>
oEncrypted = cryptico.encrypt plainText, @strPublicKey
oEncrypted.cipher
exports.decrypt = ( strEncrypted ) =>
oDecrypted = cryptico.decrypt strEncrypted, @oPrivateRSAkey
oDecrypted.plaintext

View file

@ -8,11 +8,13 @@ Dynamic Modules
# **Loads Modules:**
# - [Logging](logging.html), [Persistence](persistence.html)
# - [Logging](logging.html), [Persistence](persistence.html),
# [Encryption](encryption.html)
# and [Dynamic Modules](dynamic-modules.html)
logger = require './logging'
db = require './persistence'
dynmod = require './dynamic-modules'
encryption = require './encryption'
# If we do not receive all required arguments we shut down immediately
if process.argv.length < 8
@ -33,6 +35,9 @@ log.info 'EP | Event Poller starts up'
db logger: log
dynmod
logger: log
encryption
logger: log
keygen: process.argv[ 7 ]
# Initialize module local variables and

View file

@ -345,6 +345,22 @@ class IndexedModules
@log.info "DB | (IdxedMods) #{ @setname }.getUserArgumentsFunctions( #{ userId }, #{ ruleId }, #{ mId } )"
@db.get "#{ @setname }:#{ userId }:#{ ruleId }:#{ mId }:functions", cb
getAllModuleUserArguments: ( userId, ruleId, mId, cb ) =>
@log.info "DB | (IdxedMods) #{ @setname }.getAllModuleUserArguments( #{ userId }, #{ ruleId }, #{ mId } )"
@db.smembers "#{ @setname }:#{ userId }:#{ ruleId }:#{ mId }:functions", ( err, obj ) =>
sem = obj.length
console.log 'getAllModuleUserArguments'
console.log obj
oAnswer = {}
for func in obj
fRegisterFunction = ( func ) =>
( err, obj ) =>
if obj
oAnswer[ func ] = obj
if --sem is 0
cb null, oAnswer
@db.get "#{ @setname }:#{ userId }:#{ ruleId }:#{ mId }:function:#{ func }", fRegisterFunction func
getUserArguments: ( userId, ruleId, mId, funcId, cb ) =>
@log.info "DB | (IdxedMods) #{ @setname }.getUserArguments( #{ userId }, #{ ruleId }, #{ mId }, #{ funcId } )"
@db.get "#{ @setname }:#{ userId }:#{ ruleId }:#{ mId }:function:#{ funcId }", cb

View file

@ -30,6 +30,9 @@ engine = require './engine'
# - [HTTP Listener](http-listener.html)
http = require './http-listener'
# - [Encryption](encryption.html)
encryption = require './encryption'
# - [Event Poller](event-poller.html) *(will be forked into a child process)*
nameEP = 'event-poller'
@ -134,6 +137,8 @@ init = =>
#FIXME this has to come from user input for security reasons:
args[ 'keygen' ] = conf.getKeygenPassphrase()
args[ 'webhooks' ] = conf.fetchProp 'webhooks'
encryption args
@log.info 'RS | Initialzing DB'
db args

View file

@ -10,12 +10,14 @@ Components Manager
*/
(function() {
var commandFunctions, db, dynmod, eventEmitter, events, exports, forgeModule, fs, getModuleParams, getModules, hasRequiredParams, path;
var commandFunctions, db, dynmod, encryption, eventEmitter, events, exports, forgeModule, fs, getModuleParams, getModuleUserArguments, getModuleUserParams, getModules, hasRequiredParams, path, storeModule, storeRule;
db = require('./persistence');
dynmod = require('./dynamic-modules');
encryption = require('./encryption');
fs = require('fs');
path = require('path');
@ -221,54 +223,140 @@ Components Manager
}
};
getModuleUserParams = function(user, oPayload, dbMod, callback) {
var answ;
answ = hasRequiredParams(['id'], oPayload);
if (answ.code !== 200) {
return callback(answ);
} else {
return dbMod.getUserParams(oPayload.id, user.username, function(err, str) {
var name, oParam, oParams;
oParams = JSON.parse(str);
for (name in oParams) {
oParam = oParams[name];
if (!oParam.shielded) {
oParam.value = encryption.decrypt(oParam.value);
}
}
answ.message = JSON.stringify(oParams);
return callback(answ);
});
}
};
getModuleUserArguments = function(user, oPayload, dbMod, callback) {
var answ;
answ = hasRequiredParams(['ruleId', 'moduleId'], oPayload);
if (answ.code !== 200) {
return callback(answ);
} else {
return dbMod.getAllModuleUserArguments(user.username, oPayload.ruleId, oPayload.moduleId, function(err, oPayload) {
answ.message = oPayload;
return callback(answ);
});
}
};
forgeModule = (function(_this) {
return function(user, oPayload, dbMod, callback) {
var answ, i;
var answ;
answ = hasRequiredParams(['id', 'params', 'lang', 'data'], oPayload);
if (answ.code !== 200) {
return callback(answ);
} else {
i = 0;
return dbMod.getModule(oPayload.id, function(err, mod) {
var src;
if (mod) {
answ.code = 409;
answ.message = 'Module name already existing: ' + oPayload.id;
return callback(answ);
} else {
src = oPayload.data;
return dynmod.compileString(src, user.username, 'dummyRule', oPayload.id, oPayload.lang, null, function(cm) {
var funcs, id, name, _ref;
answ = cm.answ;
if (answ.code === 200) {
funcs = [];
_ref = cm.module;
for (name in _ref) {
id = _ref[name];
funcs.push(name);
}
_this.log.info("CM | Storing new module with functions " + (funcs.join(', ')));
answ.message = " Module " + oPayload.id + " successfully stored! Found following function(s): " + funcs;
oPayload.functions = JSON.stringify(funcs);
oPayload.functionArgs = JSON.stringify(cm.funcParams);
dbMod.storeModule(user.username, oPayload);
if (oPayload["public"] === 'true') {
dbMod.publish(oPayload.id);
}
}
if (oPayload.overwrite) {
return storeModule(user, oPayload, dbMod, callback);
} else {
return dbMod.getModule(oPayload.id, function(err, mod) {
if (mod) {
answ.code = 409;
answ.message = 'Module name already existing: ' + oPayload.id;
return callback(answ);
});
}
});
} else {
return storeModule(user, oPayload, dbMod, callback);
}
});
}
}
};
})(this);
storeModule = (function(_this) {
return function(user, oPayload, dbMod, callback) {
var src;
src = oPayload.data;
return dynmod.compileString(src, user.username, 'dummyRule', oPayload.id, oPayload.lang, null, function(cm) {
var answ, funcs, id, name, _ref;
answ = cm.answ;
if (answ.code === 200) {
funcs = [];
_ref = cm.module;
for (name in _ref) {
id = _ref[name];
funcs.push(name);
}
_this.log.info("CM | Storing new module with functions " + (funcs.join(', ')));
answ.message = " Module " + oPayload.id + " successfully stored! Found following function(s): " + funcs;
oPayload.functions = JSON.stringify(funcs);
oPayload.functionArgs = JSON.stringify(cm.funcParams);
dbMod.storeModule(user.username, oPayload);
if (oPayload["public"] === 'true') {
dbMod.publish(oPayload.id);
}
}
return callback(answ);
});
};
})(this);
storeRule = (function(_this) {
return function(user, oPayload, callback) {
var arr, epModId, id, oParams, params, rule, strRule;
rule = {
id: oPayload.id,
event: oPayload.event,
event_interval: oPayload.event_interval,
conditions: oPayload.conditions,
actions: oPayload.actions
};
strRule = JSON.stringify(rule);
db.storeRule(rule.id, strRule);
db.linkRule(rule.id, user.username);
db.activateRule(rule.id, user.username);
if (oPayload.event_params) {
epModId = rule.event.split(' -> ')[0];
db.eventPollers.storeUserParams(epModId, user.username, JSON.stringify(oPayload.event_params));
}
oParams = oPayload.action_params;
for (id in oParams) {
params = oParams[id];
db.actionInvokers.storeUserParams(id, user.username, JSON.stringify(params));
}
oParams = oPayload.action_functions;
for (id in oParams) {
params = oParams[id];
arr = id.split(' -> ');
db.actionInvokers.storeUserArguments(user.username, rule.id, arr[0], arr[1], JSON.stringify(params));
}
db.resetLog(user.username, rule.id);
db.appendLog(user.username, rule.id, "INIT", "Rule '" + rule.id + "' initialized");
eventEmitter.emit('rule', {
event: 'new',
user: user.username,
rule: rule
});
return callback({
code: 200,
message: "Rule '" + rule.id + "' stored and activated!"
});
};
})(this);
commandFunctions = {
get_public_key: function(user, oPayload, callback) {
return callback({
code: 200,
message: dynmod.getPublicKey()
message: encryption.getPublicKey()
});
},
get_event_pollers: function(user, oPayload, callback) {
@ -285,6 +373,12 @@ Components Manager
get_event_poller_params: function(user, oPayload, callback) {
return getModuleParams(user, oPayload, db.eventPollers, callback);
},
get_event_poller_user_params: function(user, oPayload, callback) {
return getModuleUserParams(user, oPayload, db.eventPollers, callback);
},
get_event_poller_user_arguments: function(user, oPayload, callback) {
return getModuleUserArguments(user, oPayload, db.eventPollers, callback);
},
forge_event_poller: function(user, oPayload, callback) {
return forgeModule(user, oPayload, db.eventPollers, callback);
},
@ -321,7 +415,13 @@ Components Manager
get_action_invoker_params: function(user, oPayload, callback) {
return getModuleParams(user, oPayload, db.actionInvokers, callback);
},
get_action_invoker_function_params: function(user, oPayload, callback) {
get_action_invoker_user_params: function(user, oPayload, callback) {
return getModuleUserParams(user, oPayload, db.actionInvokers, callback);
},
get_action_invoker_user_arguments: function(user, oPayload, callback) {
return getModuleUserArguments(user, oPayload, db.actionInvokers, callback);
},
get_action_invoker_function_arguments: function(user, oPayload, callback) {
var answ;
answ = hasRequiredParams(['id'], oPayload);
if (answ.code !== 200) {
@ -359,6 +459,20 @@ Components Manager
});
});
},
get_rule: function(user, oPayload, callback) {
var answ;
answ = hasRequiredParams(['id'], oPayload);
if (answ.code !== 200) {
return callback(answ);
} else {
return db.getRule(oPayload.id, function(err, obj) {
return callback({
code: 200,
message: obj
});
});
}
},
get_rule_log: function(user, oPayload, callback) {
var answ;
answ = hasRequiredParams(['id'], oPayload);
@ -379,54 +493,21 @@ Components Manager
if (answ.code !== 200) {
return callback(answ);
} else {
return db.getRule(oPayload.id, function(err, oExisting) {
var arr, epModId, id, oParams, params, rule, strRule;
if (oExisting !== null) {
answ = {
code: 409,
message: 'Rule name already existing!'
if (oPayload.overwrite) {
return storeRule(user, oPayload, callback);
} else {
return db.getRule(oPayload.id, (function(_this) {
return function(err, mod) {
if (mod) {
answ.code = 409;
answ.message = 'Rule name already existing: ' + oPayload.id;
return callback(answ);
} else {
return storeRule(user, oPayload, callback);
}
};
} else {
rule = {
id: oPayload.id,
event: oPayload.event,
event_interval: oPayload.event_interval,
conditions: oPayload.conditions,
actions: oPayload.actions
};
strRule = JSON.stringify(rule);
db.storeRule(rule.id, strRule);
db.linkRule(rule.id, user.username);
db.activateRule(rule.id, user.username);
if (oPayload.event_params) {
epModId = rule.event.split(' -> ')[0];
db.eventPollers.storeUserParams(epModId, user.username, oPayload.event_params);
}
oParams = oPayload.action_params;
for (id in oParams) {
params = oParams[id];
db.actionInvokers.storeUserParams(id, user.username, JSON.stringify(params));
}
oParams = oPayload.action_functions;
for (id in oParams) {
params = oParams[id];
arr = id.split(' -> ');
db.actionInvokers.storeUserArguments(user.username, rule.id, arr[0], arr[1], JSON.stringify(params));
}
db.resetLog(user.username, rule.id);
db.appendLog(user.username, rule.id, "INIT", "Rule '" + rule.id + "' initialized");
eventEmitter.emit('rule', {
event: 'new',
user: user.username,
rule: rule
});
answ = {
code: 200,
message: "Rule '" + rule.id + "' stored and activated!"
};
}
return callback(answ);
});
})(this));
}
}
},
delete_rule: function(user, oPayload, callback) {

View file

@ -9,10 +9,12 @@ Dynamic Modules
*/
(function() {
var cryptico, cryptoJS, cs, db, exports, fTryToLoadModule, getFunctionParamNames, importio, logFunction, needle, regexpComments, request, vm;
var cryptoJS, cs, db, encryption, exports, fTryToLoadModule, getFunctionParamNames, importio, logFunction, needle, regexpComments, request, vm;
db = require('./persistence');
encryption = require('./encryption');
vm = require('vm');
needle = require('needle');
@ -21,8 +23,6 @@ Dynamic Modules
cs = require('coffee-script');
cryptico = require('my-cryptico');
cryptoJS = require('crypto-js');
importio = require('import-io').client;
@ -38,26 +38,12 @@ Dynamic Modules
exports = module.exports = (function(_this) {
return function(args) {
var numBits, passPhrase;
_this.log = args.logger;
if (!_this.strPublicKey && args['keygen']) {
db(args);
passPhrase = args['keygen'];
numBits = 1024;
_this.oPrivateRSAkey = cryptico.generateRSAKey(passPhrase, numBits);
_this.strPublicKey = cryptico.publicKeyString(_this.oPrivateRSAkey);
_this.log.info("DM | Public Key generated: " + _this.strPublicKey);
}
db(args);
return module.exports;
};
})(this);
exports.getPublicKey = (function(_this) {
return function() {
return _this.strPublicKey;
};
})(this);
logFunction = function(uId, rId, mId) {
return function(msg) {
return db.appendLog(uId, rId, mId, msg);
@ -110,17 +96,21 @@ Dynamic Modules
_this.log.info("DM | Trying to fetch user specific module '" + modId + "' paramters for user '" + userId + "'");
if (dbMod) {
return dbMod.getUserParams(modId, userId, function(err, obj) {
var oDecrypted;
var name, oParam, oParams, _ref;
try {
oDecrypted = cryptico.decrypt(obj, _this.oPrivateRSAkey);
obj = JSON.parse(oDecrypted.plaintext);
oParams = {};
_ref = JSON.parse(obj);
for (name in _ref) {
oParam = _ref[name];
oParams[name] = encryption.decrypt(oParam.value);
}
_this.log.info("DM | Loaded user defined params for " + userId + ", " + ruleId + ", " + modId);
} catch (_error) {
err = _error;
_this.log.warn("DM | Error during parsing of user defined params for " + userId + ", " + ruleId + ", " + modId);
_this.log.warn(err);
}
return fTryToLoadModule(userId, ruleId, modId, src, dbMod, obj, cb);
return fTryToLoadModule(userId, ruleId, modId, src, dbMod, oParams, cb);
});
} else {
return fTryToLoadModule(userId, ruleId, modId, src, dbMod, null, cb);
@ -174,11 +164,9 @@ Dynamic Modules
oFuncArgs = {};
for (func in oFuncParams) {
dbMod.getUserArguments(userId, ruleId, modId, func, function(err, obj) {
var oDecrypted;
if (obj) {
try {
oDecrypted = cryptico.decrypt(obj, _this.oPrivateRSAkey);
oFuncArgs[func] = JSON.parse(oDecrypted.plaintext);
oFuncArgs[func] = JSON.parse(encryption.decrypt(obj));
return _this.log.info("DM | Found and attached user-specific arguments to " + userId + ", " + ruleId + ", " + modId);
} catch (_error) {
err = _error;

47
js/encryption.js Normal file
View file

@ -0,0 +1,47 @@
// Generated by CoffeeScript 1.7.1
/*
Encryption
===============
> Handles RSA encryption and decryption of user specific parameters.
*/
(function() {
var cryptico, exports;
cryptico = require('my-cryptico');
exports = module.exports = (function(_this) {
return function(args) {
_this.log = args.logger;
_this.oPrivateRSAkey = cryptico.generateRSAKey(args['keygen'], 1024);
_this.strPublicKey = cryptico.publicKeyString(_this.oPrivateRSAkey);
_this.log.info("DM | Public Key generated: " + _this.strPublicKey);
return module.exports;
};
})(this);
exports.getPublicKey = (function(_this) {
return function() {
return _this.strPublicKey;
};
})(this);
exports.encrypt = (function(_this) {
return function(plainText) {
var oEncrypted;
oEncrypted = cryptico.encrypt(plainText, _this.strPublicKey);
return oEncrypted.cipher;
};
})(this);
exports.decrypt = (function(_this) {
return function(strEncrypted) {
var oDecrypted;
oDecrypted = cryptico.decrypt(strEncrypted, _this.oPrivateRSAkey);
return oDecrypted.plaintext;
};
})(this);
}).call(this);

View file

@ -9,7 +9,7 @@ Dynamic Modules
*/
(function() {
var db, dynmod, fCallFunction, fCheckAndRun, fLoadModule, isRunning, listUserModules, log, logconf, logger, pollLoop;
var db, dynmod, encryption, fCallFunction, fCheckAndRun, fLoadModule, isRunning, listUserModules, log, logconf, logger, pollLoop;
logger = require('./logging');
@ -17,6 +17,8 @@ Dynamic Modules
dynmod = require('./dynamic-modules');
encryption = require('./encryption');
if (process.argv.length < 8) {
console.error('Not all arguments have been passed!');
process.exit();
@ -42,6 +44,10 @@ Dynamic Modules
});
dynmod({
logger: log
});
encryption({
logger: log,
keygen: process.argv[7]
});

View file

@ -257,6 +257,7 @@ Persistence
this.log = log;
this.deleteUserArguments = __bind(this.deleteUserArguments, this);
this.getUserArguments = __bind(this.getUserArguments, this);
this.getAllModuleUserArguments = __bind(this.getAllModuleUserArguments, this);
this.getUserArgumentsFunctions = __bind(this.getUserArgumentsFunctions, this);
this.storeUserArguments = __bind(this.storeUserArguments, this);
this.deleteUserParams = __bind(this.deleteUserParams, this);
@ -438,6 +439,35 @@ Persistence
return this.db.get("" + this.setname + ":" + userId + ":" + ruleId + ":" + mId + ":functions", cb);
};
IndexedModules.prototype.getAllModuleUserArguments = function(userId, ruleId, mId, cb) {
this.log.info("DB | (IdxedMods) " + this.setname + ".getAllModuleUserArguments( " + userId + ", " + ruleId + ", " + mId + " )");
return this.db.smembers("" + this.setname + ":" + userId + ":" + ruleId + ":" + mId + ":functions", (function(_this) {
return function(err, obj) {
var fRegisterFunction, func, oAnswer, sem, _i, _len, _results;
sem = obj.length;
console.log('getAllModuleUserArguments');
console.log(obj);
oAnswer = {};
_results = [];
for (_i = 0, _len = obj.length; _i < _len; _i++) {
func = obj[_i];
fRegisterFunction = function(func) {
return function(err, obj) {
if (obj) {
oAnswer[func] = obj;
}
if (--sem === 0) {
return cb(null, oAnswer);
}
};
};
_results.push(_this.db.get("" + _this.setname + ":" + userId + ":" + ruleId + ":" + mId + ":function:" + func, fRegisterFunction(func)));
}
return _results;
};
})(this));
};
IndexedModules.prototype.getUserArguments = function(userId, ruleId, mId, funcId, cb) {
this.log.info("DB | (IdxedMods) " + this.setname + ".getUserArguments( " + userId + ", " + ruleId + ", " + mId + ", " + funcId + " )");
return this.db.get("" + this.setname + ":" + userId + ":" + ruleId + ":" + mId + ":function:" + funcId, cb);

View file

@ -13,7 +13,7 @@ WebAPI-ECA Engine
*/
(function() {
var argv, cm, conf, cp, db, engine, fs, http, init, logconf, logger, nameEP, opt, optimist, path, procCmds, shutDown, usage;
var argv, cm, conf, cp, db, encryption, engine, fs, http, init, logconf, logger, nameEP, opt, optimist, path, procCmds, shutDown, usage;
logger = require('./logging');
@ -27,6 +27,8 @@ WebAPI-ECA Engine
http = require('./http-listener');
encryption = require('./encryption');
nameEP = 'event-poller';
fs = require('fs');
@ -147,6 +149,7 @@ WebAPI-ECA Engine
args['db-port'] = parseInt(argv.d || conf.getDbPort());
args['keygen'] = conf.getKeygenPassphrase();
args['webhooks'] = conf.fetchProp('webhooks');
encryption(args);
_this.log.info('RS | Initialzing DB');
db(args);
return db.isConnected(function(err) {

View file

@ -11,14 +11,16 @@ fOnLoad = () ->
if err.status is 401
window.location.href = 'forge?page=edit_modules'
else
if err.responseText is ''
msg = 'No Response from Server!'
else
try
oErr = JSON.parse err.responseText
msg = oErr.message
$( '#info' ).text errMsg + msg
$( '#info' ).attr 'class', 'error'
fDelayed = () ->
if err.responseText is ''
msg = 'No Response from Server!'
else
try
oErr = JSON.parse err.responseText
msg = oErr.message
$( '#info' ).text errMsg + msg
$( '#info' ).attr 'class', 'error'
setTimeout fDelayed, 500
fFetchModules = () ->
if $( '#module_type' ).val() is 'Event Poller'
@ -56,9 +58,8 @@ fOnLoad = () ->
cmd = 'delete_action_invoker'
data =
command: cmd
payload:
payload: JSON.stringify
id: modName
data.payload = JSON.stringify data.payload
$.post( '/usercommand', data )
.done fFetchModules
.fail fErrHandler 'Could not delete module! '
@ -66,8 +67,8 @@ fOnLoad = () ->
$( '#tableModules' ).on 'click', 'img.log', () ->
modName = encodeURIComponent $( 'div', $( this ).closest( 'tr' )).text()
if $( '#module_type' ).val() is 'Event Poller'
window.location.href = 'forge?page=forge_event_poller&id=' + modName
window.location.href = 'forge?page=forge_module&type=event_poller&id=' + modName
else
window.location.href = 'forge?page=forge_action_invoker&id=' + modName
window.location.href = 'forge?page=forge_module&type=action_invoker&id=' + modName
window.addEventListener 'load', fOnLoad, true

View file

@ -50,9 +50,8 @@ fOnLoad = () ->
$( '#log_col' ).text ""
data =
command: 'delete_rule'
payload:
payload: JSON.stringify
id: ruleName
data.payload = JSON.stringify data.payload
$.post( '/usercommand', data )
.done fFetchRules
.fail fErrHandler 'Could not delete rule! '
@ -65,47 +64,12 @@ fOnLoad = () ->
ruleName = $( 'div', $( this ).closest( 'tr' )).text()
data =
command: 'get_rule_log'
payload:
payload: JSON.stringify
id: ruleName
data.payload = JSON.stringify data.payload
$.post( '/usercommand', data )
.done ( data ) ->
log = data.message.replace new RegExp("\n", 'g'), "<br>"
$( '#log_col' ).html "<h3>#{ ruleName } Log:</h3>#{ log }"
.fail fErrHandler 'Could not get rule log! '
# Add parameter list functionality
fChangeInputVisibility = () ->
$( '#tableParams tr' ).each ( id ) ->
if $( this ).is ':last-child' or $( this ).is ':only-child'
$( 'img', this ).hide()
$( 'input[type=checkbox]', this ).hide()
else
$( 'img', this ).show()
$( 'input[type=checkbox]', this ).show()
$( '#tableParams' ).on 'click', 'img', () ->
par = $( this ).closest 'tr'
if not par.is ':last-child'
par.remove()
fChangeInputVisibility()
$( '#tableParams' ).on 'keyup', 'input', ( e ) ->
code = e.keyCode or e.which
if code isnt 9
par = $( this ).closest 'tr'
if par.is ':last-child'
tr = $ '<tr>'
img = $( '<img>' ).attr( 'title', 'Remove?').attr 'src', 'red_cross_small.png'
cb = $( '<input>' ).attr( 'type', 'checkbox' ).attr 'title', 'Password shielded input?'
inp = $( '<input>' ).attr( 'type', 'text' ).attr 'class', 'textinput'
tr.append $( '<td>' ).append img
tr.append $( '<td>' ).append cb
tr.append $( '<td>' ).append inp
par.parent().append tr
fChangeInputVisibility()
else if $( this ).val() is '' and not par.is ':only-child'
par.remove()
fChangeInputVisibility()
window.addEventListener 'load', fOnLoad, true

View file

@ -1,110 +0,0 @@
fOnLoad = () ->
document.title = 'Forge Action Invoker'
$( '#pagetitle' ).text "{{{user.username}}}, forge your custom action invoker!"
# Setup the ACE editor
editor = ace.edit "editor"
editor.setTheme "ace/theme/monokai"
editor.getSession().setMode "ace/mode/coffee"
editor.setShowPrintMargin false
editor.session.setUseSoftTabs false
$( '#editor_mode' ).change ( el ) ->
if $( this ).val() is 'CoffeeScript'
editor.getSession().setMode "ace/mode/coffee"
else
editor.getSession().setMode "ace/mode/javascript"
# Add parameter list functionality
fChangeInputVisibility = () ->
$( '#tableParams tr' ).each ( id ) ->
if $( this ).is ':last-child' or $( this ).is ':only-child'
$( 'img', this ).hide()
$( 'input[type=checkbox]', this ).hide()
else
$( 'img', this ).show()
$( 'input[type=checkbox]', this ).show()
$( '#tableParams' ).on 'click', 'img', () ->
par = $( this ).closest 'tr'
if not par.is ':last-child'
par.remove()
fChangeInputVisibility()
$( '#tableParams' ).on 'keyup', 'input', ( e ) ->
code = e.keyCode or e.which
if code isnt 9
par = $( this ).closest( 'tr' )
if par.is ':last-child'
tr = $ '<tr>'
img = $( '<img>' ).attr( 'title', 'Remove?').attr 'src', 'red_cross_small.png'
cb = $( '<input>' ).attr( 'type', 'checkbox' ).attr 'title', 'Password shielded input?'
inp = $( '<input>' ).attr( 'type', 'text' ).attr 'class', 'textinput'
tr.append( $( '<td>' ).append img )
tr.append( $( '<td>' ).append cb )
tr.append( $( '<td>' ).append inp )
par.parent().append tr
fChangeInputVisibility()
else if $( this ).val() is '' and not par.is ':only-child'
par.remove()
fChangeInputVisibility()
# Add submit button logic
$( '#but_submit' ).click () ->
if $( '#input_id' ).val() is ''
alert 'Please enter an action invoker name!'
else
listParams = {}
$( '#tableParams tr' ).each () ->
val = $( 'input.textinput', this ).val()
shld = $( 'input[type=checkbox]', this ).is ':checked'
if val isnt ""
listParams[val] = shld
true
obj =
command: 'forge_action_invoker'
payload:
id: $( '#input_id' ).val()
lang: $( '#editor_mode' ).val()
public: $( '#is_public' ).is ':checked'
data: editor.getValue()
params: JSON.stringify listParams
obj.payload = JSON.stringify obj.payload
window.scrollTo 0, 0
$.post( '/usercommand', obj )
.done ( data ) ->
$( '#info' ).text data.message
$( '#info' ).attr 'class', 'success'
.fail ( err ) ->
if err.status is 401
window.location.href = 'forge?page=forge_action_invoker'
else
fDelayed = () ->
if err.responseText is ''
msg = 'No Response from Server!'
else
try
oErr = JSON.parse err.responseText
msg = oErr.message
$( '#info' ).text 'Action Invoker not stored! ' + msg
$( '#info' ).attr 'class', 'error'
setTimeout fDelayed, 500
# EDIT MODULES
arrParams = window.location.search.substring(1).split '&'
id = ''
for param in arrParams
arrKV = param.split '='
if arrKV[ 0 ] is 'id'
id = decodeURIComponent arrKV[ 1 ]
if id isnt ''
# TODO we have an idea so we want to edit this module!
console.log id
window.addEventListener 'load', fOnLoad, true

View file

@ -1,95 +0,0 @@
fOnLoad = () ->
document.title = 'Forge Event Poller'
$( '#pagetitle' ).text "{{{user.username}}}, forge your custom event poller!"
# Setup the ACE editor
editor = ace.edit "editor"
editor.setTheme "ace/theme/monokai"
editor.getSession().setMode "ace/mode/coffee"
editor.setShowPrintMargin false
$( '#editor_mode' ).change ( el ) ->
if $( this ).val() is 'CoffeeScript'
editor.getSession().setMode "ace/mode/coffee"
else
editor.getSession().setMode "ace/mode/javascript"
# Add parameter list functionality
fChangeInputVisibility = () ->
$( '#tableParams tr' ).each ( id ) ->
if $( this ).is ':last-child' or $( this ).is ':only-child'
$( 'img', this ).hide()
$( 'input[type=checkbox]', this ).hide()
else
$( 'img', this ).show()
$( 'input[type=checkbox]', this ).show()
$( '#tableParams' ).on 'click', 'img', () ->
par = $( this ).closest 'tr'
if not par.is ':last-child'
par.remove()
fChangeInputVisibility()
$( '#tableParams' ).on 'keyup', 'input', ( e ) ->
code = e.keyCode or e.which
if code isnt 9
par = $( this ).closest( 'tr' )
if par.is ':last-child'
tr = $ '<tr>'
img = $( '<img>' ).attr( 'title', 'Remove?').attr 'src', 'red_cross_small.png'
cb = $( '<input>' ).attr( 'type', 'checkbox' ).attr 'title', 'Password shielded input?'
inp = $( '<input>' ).attr( 'type', 'text' ).attr 'class', 'textinput'
tr.append( $( '<td>' ).append img )
tr.append( $( '<td>' ).append cb )
tr.append( $( '<td>' ).append inp )
tr.append $( '<td>' )
par.parent().append tr
fChangeInputVisibility()
else if $( this ).val() is '' and not par.is ':only-child'
par.remove()
fChangeInputVisibility()
# Add submit button logic
$( '#but_submit' ).click () ->
if $( '#input_id' ).val() is ''
alert 'Please enter an event poller name!'
else
listParams = {}
$( '#tableParams tr' ).each () ->
val = $( 'input.textinput', this ).val()
shld = $( 'input[type=checkbox]', this ).is ':checked'
if val isnt ""
listParams[val] = shld
true
obj =
command: 'forge_event_poller'
payload:
id: $( '#input_id' ).val()
lang: $( '#editor_mode' ).val()
public: $( '#is_public' ).is ':checked'
data: editor.getValue()
params: JSON.stringify listParams
obj.payload = JSON.stringify obj.payload
window.scrollTo 0, 0
$.post( '/usercommand', obj )
.done ( data ) ->
$( '#info' ).text data.message
$( '#info' ).attr 'class', 'success'
.fail ( err ) ->
if err.status is 401
window.location.href = 'forge?page=forge_event_poller'
else
fDelayed = () ->
if err.responseText is ''
msg = 'No Response from Server!'
else
try
oErr = JSON.parse err.responseText
msg = oErr.message
$( '#info' ).text 'Event Poller not stored! ' + msg
$( '#info' ).attr 'class', 'error'
setTimeout fDelayed, 500
window.addEventListener 'load', fOnLoad, true

View file

@ -0,0 +1,175 @@
# Fetch the search string and transform it into an object for easy access
arrParams = window.location.search.substring(1).split '&'
oParams = {}
for param in arrParams
arrKV = param.split '='
oParams[ arrKV[ 0 ] ] = arrKV[ 1 ]
if oParams.type is 'event_poller'
moduleName = 'Event Poller'
else
moduleName = 'Action Invoker'
oParams.type = 'action_invoker'
if oParams.id
oParams.id = decodeURIComponent oParams.id
fErrHandler = ( errMsg ) ->
( err ) ->
if err.status is 401
window.location.href = "forge?page=forge_module?type=#{ oParams.type }"
else
$( '#log_col' ).text ""
fDelayed = () ->
if err.responseText is ''
msg = 'No Response from Server!'
else
try
oErr = JSON.parse err.responseText
msg = oErr.message
$( '#info' ).text errMsg + msg
$( '#info' ).attr 'class', 'error'
setTimeout fDelayed, 500
fOnLoad = () ->
document.title = "Forge #{ moduleName }"
$( '#pagetitle' ).text "{{{user.username}}}, forge your custom #{ moduleName }!"
# Setup the ACE editor
editor = ace.edit "editor"
editor.setTheme "ace/theme/monokai"
editor.getSession().setMode "ace/mode/coffee"
editor.setShowPrintMargin false
editor.session.setUseSoftTabs false
$( '#editor_mode' ).change ( el ) ->
if $( this ).val() is 'CoffeeScript'
editor.getSession().setMode "ace/mode/coffee"
else
editor.getSession().setMode "ace/mode/javascript"
# Add parameter list functionality
fChangeInputVisibility = () ->
$( '#tableParams tr' ).each ( id ) ->
if $( this ).is ':last-child' or $( this ).is ':only-child'
$( 'img', this ).hide()
$( 'input[type=checkbox]', this ).hide()
else
$( 'img', this ).show()
$( 'input[type=checkbox]', this ).show()
fAddInputRow = ( tag ) ->
tr = $ '<tr>'
img = $( '<img>' ).attr( 'title', 'Remove?').attr 'src', 'red_cross_small.png'
cb = $( '<input>' ).attr( 'type', 'checkbox' ).attr 'title', 'Password shielded input?'
inp = $( '<input>' ).attr( 'type', 'text' ).attr 'class', 'textinput'
tr.append( $( '<td>' ).append img )
tr.append( $( '<td>' ).append cb )
tr.append( $( '<td>' ).append inp )
tag.append tr
fChangeInputVisibility()
tr
$( '#tableParams' ).on 'click', 'img', () ->
par = $( this ).closest 'tr'
if not par.is ':last-child'
par.remove()
fChangeInputVisibility()
$( '#tableParams' ).on 'keyup', 'input', ( e ) ->
code = e.keyCode or e.which
if code isnt 9
par = $( this ).closest( 'tr' )
if par.is ':last-child'
fAddInputRow par.parent()
else if $( this ).val() is '' and not par.is ':only-child'
par.remove()
fChangeInputVisibility()
# Add submit button logic
$( '#but_submit' ).click () ->
if $( '#input_id' ).val() is ''
alert "Please enter an #{ moduleName } name!"
else
listParams = {}
$( '#tableParams tr' ).each () ->
val = $( 'input.textinput', this ).val()
shld = $( 'input[type=checkbox]', this ).is ':checked'
if val isnt ""
listParams[val] = shld
true
obj =
command: "forge_#{ oParams.type }"
payload: JSON.stringify
id: $( '#input_id' ).val()
lang: $( '#editor_mode' ).val()
public: $( '#is_public' ).is ':checked'
data: editor.getValue()
params: JSON.stringify listParams
fCheckOverwrite = ( obj ) ->
( err ) ->
if err.status is 409
if confirm 'Are you sure you want to overwrite the existing module?'
payl = JSON.parse obj.payload
payl.overwrite = true
obj.payload = JSON.stringify payl
$.post( '/usercommand', obj )
.done ( data ) ->
$( '#info' ).text data.message
$( '#info' ).attr 'class', 'success'
alert "You need to update the rules that use this module in
order for the changes to be applied to them!"
.fail fErrHandler "#{ moduleName } not stored!"
else
fErrHandler( "#{ moduleName } not stored!" ) err
window.scrollTo 0, 0
$.post( '/usercommand', obj )
.done ( data ) ->
$( '#info' ).text data.message
$( '#info' ).attr 'class', 'success'
.fail fCheckOverwrite obj
# EDIT MODULES
fAddUserParam = ( param, shielded ) ->
tr = fAddInputRow $( '#tableParams' )
$( 'input.textinput', tr ).val param
if shielded
$( 'input[type=checkbox]', tr ).prop 'checked', true
if oParams.id
obj =
command: "get_full_#{ oParams.type }"
payload: JSON.stringify
id: oParams.id
$.post( '/usercommand', obj )
.done ( data ) ->
oMod = JSON.parse data.message
if oMod
fAddUserParam param, shielded for param, shielded of JSON.parse oMod.params
$( '#input_id' ).val oMod.id
$( '#editor_mode' ).val oMod.lang
if oMod.public is 'true'
$( '#is_public' ).prop 'checked', true
editor.setValue oMod.data
editor.moveCursorTo 0, 0
fAddUserParam '', false
.fail fErrHandler "Could not get module #{ oParams.id }!"
else
# We add the standard template, params and names
editor.setValue $( "#template_#{ oParams.type }" ).text()
editor.moveCursorTo 0, 0
if oParams.type is 'event_poller'
$( '#input_id' ).val 'EmailYak'
fAddUserParam 'apikey', true
fAddUserParam '', false
else
$( '#input_id' ).val 'ProBinder'
fAddUserParam 'username', false
fAddUserParam 'password', true
fAddUserParam '', false
window.addEventListener 'load', fOnLoad, true

View file

@ -1,5 +1,14 @@
strPublicKey = ''
# Fetch the search string and transform it into an object for easy access
arrParams = window.location.search.substring(1).split '&'
oParams = {}
for param in arrParams
arrKV = param.split '='
oParams[ arrKV[ 0 ] ] = arrKV[ 1 ]
if oParams.id
oParams.id = decodeURIComponent oParams.id
strPublicKey = ''
fPlaceAndPaintInterval = () ->
$( '#input_interval' ).html 'Interval:
<input id="event_interval" type="text" />
@ -40,9 +49,8 @@ fOnLoad = () ->
arr = name.split ' -> '
obj =
command: 'get_event_poller_params'
payload:
id: arr[0]
obj.payload = JSON.stringify( obj.payload );
payload: JSON.stringify
id: arr[ 0 ]
$.post( '/usercommand', obj )
.done ( data ) ->
if data.message
@ -54,7 +62,7 @@ fOnLoad = () ->
tr = $( '<tr>' )
tr.append $( '<td>' ).css 'width', '20px'
tr.append $( '<td>' ).attr( 'class', 'key' ).text name
inp = $( '<input>' ).attr 'id', "#{ name }"
inp = $( '<input>' )
if shielded
inp.attr( 'type', 'password' )
tr.append $( '<td>' ).text( ' : ' ).append inp
@ -97,6 +105,7 @@ fOnLoad = () ->
else
fPlaceAndPaintInterval()
# Init Action Invoker
obj =
command: 'get_action_invokers'
@ -110,16 +119,16 @@ fOnLoad = () ->
return
fAppendActions = ( module, actions ) ->
for act in actions
$( '#select_actions' ).append $( '<option>' ).text module + ' -> ' + act
if $( "#action_params div:contains(#{ module } -> #{ act })" ).length is 0
$( '#select_actions' ).append $( '<option>' ).text module + ' -> ' + act
fAppendActions module, actions for module, actions of oAis
.fail fFailedRequest 'Error fetching event poller'
fFetchActionParams = ( div, modName ) ->
obj =
command: 'get_action_invoker_params'
payload:
payload: JSON.stringify
id: modName
obj.payload = JSON.stringify( obj.payload );
$.post( '/usercommand', obj )
.done ( data ) ->
if data.message
@ -127,11 +136,10 @@ fOnLoad = () ->
table = $ '<table>'
div.append table
fAppendActionParam = ( name, shielded ) ->
#TODO check if already stored, if yes, indicate no entry is required
tr = $( '<tr>' )
tr.append $( '<td>' ).css 'width', '20px'
tr.append $( '<td>' ).attr( 'class', 'key').text name
inp = $( '<input>' ).attr 'id', "#{ name }"
inp = $( '<input>' )
if shielded
inp.attr( 'type', 'password' )
else
@ -143,10 +151,9 @@ fOnLoad = () ->
fFetchActionFunctionParams = ( tag, arrName ) ->
obj =
command: 'get_action_invoker_function_params'
payload:
command: 'get_action_invoker_function_arguments'
payload: JSON.stringify
id: arrName[ 0 ]
obj.payload = JSON.stringify( obj.payload );
$.post( '/usercommand', obj )
.done ( data ) ->
if data.message
@ -167,10 +174,8 @@ fOnLoad = () ->
.attr 'title', 'js-select expression to be resolved on event?'
.fail fFailedRequest 'Error fetching action invoker function params'
$( '#select_actions' ).on 'change', () ->
opt = $ 'option:selected', this
arrName = opt.text().split ' -> '
fAddSelectedAction = ( name ) ->
arrName = name.split ' -> '
arrEls = $( "#action_params div.modName" ).map( () ->
$( this ).text()
).get()
@ -178,7 +183,7 @@ fOnLoad = () ->
tr = $( '<tr>' ).appendTo table
img = $( '<img>' ).attr 'src', 'red_cross_small.png'
tr.append $( '<td>' ).css( 'width', '20px' ).append img
tr.append $( '<td>' ).attr( 'class', 'title').text opt.val()
tr.append $( '<td>' ).attr( 'class', 'title').text name
td = $( '<td>' ).attr( 'class', 'funcMappings').appendTo tr
fFetchActionFunctionParams td, arrName
if arrName[ 0 ] not in arrEls
@ -187,8 +192,12 @@ fOnLoad = () ->
subdiv.append $( '<div>' )
.attr( 'class', 'modName underlined' ).text arrName[ 0 ]
fFetchActionParams div, arrName[ 0 ]
opt.remove()
$( "#select_actions option:contains(#{ name })" ).remove()
$( '#select_actions' ).on 'change', () ->
opt = $ 'option:selected', this
fAddSelectedAction opt.text()
$( '#selected_actions' ).on 'click', 'img', () ->
act = $( this ).closest( 'td' ).siblings( '.title' ).text()
arrName = act.split ' -> '
@ -197,13 +206,13 @@ fOnLoad = () ->
# Check whether we're the only function left that was selected from this module
$( "#selected_actions td.title" ).each () ->
arrNm = $( this ).text().split ' -> '
nMods++ if arrNm[0] is arrName[0]
nMods++ if arrNm[ 0 ] is arrName[ 0 ]
if nMods is 1
$('#action_params > div').each () ->
if $( this ).children( 'div.modName' ).text() is arrName[ 0 ]
$( this ).remove()
opt = $( '<option>' ).text arrName[ 0 ]
opt = $( '<option>' ).text act
$( '#select_actions' ).append opt
$( this ).closest( 'tr' ).remove()
@ -223,13 +232,19 @@ fOnLoad = () ->
ep = {}
$( "#event_poller_params tr" ).each () ->
key = $( this ).children( '.key' ).text()
val = $( 'input', this ).val()
name = $( this ).children( '.key' ).text()
if val is ''
$( 'input', this ).focus()
throw new Error "Please enter a value for '#{ name }' in the event module!"
ep[name] = val
throw new Error "Please enter a value for '#{ key }' in the event module!"
shielded = $( 'input', this ).attr( 'type' ) is 'password'
ep[ key ] =
shielded: shielded
if $( 'input', this ).attr( 'unchanged' ) is 'true'
ep[ key ].value = val
else
encryptedParam = cryptico.encrypt val, strPublicKey
ep[ key ].value = encryptedParam.cipher
if $( '#selected_actions tr' ).length is 0
throw new Error 'Please select at least one action or create one!'
@ -241,24 +256,37 @@ fOnLoad = () ->
$( 'tr', this ).each () ->
key = $( '.key', this ).text()
val = $( 'input', this ).val()
shielded = $( 'input', this ).attr( 'type' ) is 'password'
if val is ''
$( 'input', this ).focus()
throw new Error "'#{ key }' missing for '#{ modName }'"
params[key] = val
encryptedParams = cryptico.encrypt JSON.stringify( params ), strPublicKey
ap[modName] = encryptedParams.cipher
params[ key ] =
shielded: shielded
if $( 'input', this ).attr( 'unchanged' ) is 'true'
params[ key ].value = val
else
encryptedParam = cryptico.encrypt val, strPublicKey
params[ key ].value = encryptedParam.cipher
ap[ modName ] = params
acts = []
actParams = {}
$( '#selected_actions' ).each () ->
actionName = $( '.title', this ).text()
$( '#selected_actions td.title' ).each () ->
actionName = $( this ).text()
actParams[ actionName ] = []
acts.push actionName
$( '.funcMappings tr' ).each () ->
tmp =
argument: $( 'div.funcarg', this ).val()
par = $( this ).parent()
$( '.funcMappings tr', par ).each () ->
# No need to encrypt this, right?
# tmp =
# argument: $( 'div.funcarg', this ).val()
# value: $( 'input[type=text]', this ).val()
# regexp: $( 'input[type=checkbox]', this ).is( ':checked' )
# tmp = cryptico.encrypt JSON.stringify( tmp ), strPublicKey
# actParams[ actionName ] = tmp.cipher
actParams[ actionName ].push
argument: $( 'div.funcarg', this ).text()
value: $( 'input[type=text]', this ).val()
regexp: $( 'input[type=checkbox]', this ).is( ':checked' )
tmp = cryptico.encrypt JSON.stringify( tmp ), strPublicKey
actParams[ actionName ] = tmp.cipher
try
conds = JSON.parse editor.getValue()
@ -284,55 +312,141 @@ fOnLoad = () ->
txtInterval = $( '#event_interval' ).val()
arrInp = txtInterval.split ' '
# There's only one string entered, either day or hour
if arrInp.length is 1
mins = fParseTime txtInterval
if not txtInterval
mins = 1
else
d = parseInt( arrInp[ 0 ] ) || 0
mins = d * 24 * 60 + fParseTime arrInp[ 1 ], true
arrInp = txtInterval.split ' '
# There's only one string entered, either day or hour
if arrInp.length is 1
mins = fParseTime txtInterval
else
d = parseInt( arrInp[ 0 ] ) || 0
mins = d * 24 * 60 + fParseTime arrInp[ 1 ], true
# We have to limit this to 24 days because setTimeout only takes integer values
# until we implement a scheduler that deals with larger intervals
mins = Math.min mins, 35700
encryptedParams = cryptico.encrypt JSON.stringify( ep ), strPublicKey
fCheckOverwrite = ( obj ) ->
( err ) ->
if err.status is 409
if confirm 'Are you sure you want to overwrite the existing rule?'
payl = JSON.parse obj.payload
payl.overwrite = true
obj.payload = JSON.stringify payl
$.post( '/usercommand', obj )
.done ( data ) ->
$( '#info' ).text data.message
$( '#info' ).attr 'class', 'success'
.fail fFailedRequest "#{ obj.id } not stored!"
else
fFailedRequest( "#{ obj.id } not stored!" ) err
obj =
command: 'forge_rule'
payload:
payload: JSON.stringify
id: $( '#input_id' ).val()
event: $( '#input_event' ).val()
event_params: encryptedParams.cipher
event_params: ep
event_interval: mins
conditions: conds
actions: acts
action_params: ap
action_functions: actParams
obj.payload = JSON.stringify obj.payload
$.post( '/usercommand', obj )
.done ( data ) ->
$( '#info' ).text data.message
$( '#info' ).attr 'class', 'success'
.fail ( err ) ->
if err.responseText is ''
msg = 'No Response from Server!'
else
try
msg = JSON.parse( err.responseText ).message
fFailedRequest( 'Error in upload: ' + msg ) err
.fail fCheckOverwrite obj
catch err
console.log err
$( '#info' ).text 'Error in upload: ' + err.message
$( '#info' ).attr 'class', 'error'
alert err.message
throw err
arrParams = window.location.search.substring(1).split '&'
id = ''
for param in arrParams
arrKV = param.split '='
if arrKV[ 0 ] is 'id'
id = decodeURIComponent arrKV[ 1 ]
if id isnt ''
console.log id
if oParams.id
obj =
command: 'get_rule'
payload: JSON.stringify
id: oParams.id
$.post( '/usercommand', obj )
.done ( data ) ->
oRule = JSON.parse data.message
if oRule
$( '#input_id' ).val oRule.id
# Event
$( '#select_event' ).val oRule.event
if $( '#select_event' ).val() isnt ''
fFetchEventParams oRule.event
fPlaceAndPaintInterval()
obj =
command: 'get_event_poller_user_params'
payload: JSON.stringify
id: oRule.event.split( ' -> ' )[ 0 ]
$.post( '/usercommand', obj )
.done ( data ) ->
oParams = JSON.parse data.message
for param, oParam of oParams
par = $( "#event_poller_params tr:contains(#{ param })" ).parent()
$( 'input', par ).val oParam.value
$( 'input', par ).attr 'unchanged', 'true'
$( 'input', par ).change () ->
$( this ).attr 'unchanged', 'false'
$( '#input_event' ).val oRule.event
$( '#event_interval' ).val oRule.event_interval
# Conditions
editor.setValue JSON.stringify oRule.conditions
# Actions
oActions = {}
for action in oRule.actions
fAddSelectedAction action
arrName = action.split ' -> '
if not oActions[ arrName[ 0 ] ]
oActions[ arrName[ 0 ] ] = []
oActions[ arrName[ 0 ] ].push arrName[ 1 ]
fAddActionModuleParams = ( name ) ->
( data ) ->
oParams = JSON.parse data.message
domMod = $( "#action_params div.modName:contains(#{ name })" ).parent()
for param, oParam of oParams
par = $( "td.key:contains(#{ param })", domMod ).parent()
$( 'input', par ).val oParam.value
$( 'input', par ).attr 'unchanged', 'true'
$( 'input', par ).change () ->
$( this ).attr 'unchanged', 'false'
fAddActionModuleArgs = ( name ) ->
( data ) ->
for key, arrFuncs of data.message
par = $( "#selected_actions td.title:contains(#{ name } -> #{ key })" ).parent()
for oFunc in JSON.parse arrFuncs
tr = $( ".funcarg:contains(#{ oFunc.argument })", par ).parent().parent()
$( "input[type=text]", tr ).val oFunc.value
$( "input[type=checkbox]", tr ).prop 'checked', oFunc.regexp
for mod, arrMod of oActions
obj =
command: 'get_action_invoker_user_params'
payload: JSON.stringify
id: mod
$.post( '/usercommand', obj )
.done fAddActionModuleParams mod
obj.command = 'get_action_invoker_user_arguments'
obj.payload = JSON.stringify
ruleId: oRule.id
moduleId: mod
$.post( '/usercommand', obj )
.done fAddActionModuleArgs mod
.fail ( err ) ->
if err.responseText is ''
msg = 'No Response from Server!'
else
try
msg = JSON.parse( err.responseText ).message
fFailedRequest( 'Error in upload: ' + msg ) err
window.addEventListener 'load', fOnLoad, true

View file

@ -11,20 +11,24 @@
});
fErrHandler = function(errMsg) {
return function(err) {
var msg, oErr;
var fDelayed;
if (err.status === 401) {
return window.location.href = 'forge?page=edit_modules';
} else {
if (err.responseText === '') {
msg = 'No Response from Server!';
} else {
try {
oErr = JSON.parse(err.responseText);
msg = oErr.message;
} catch (_error) {}
}
$('#info').text(errMsg + msg);
return $('#info').attr('class', 'error');
fDelayed = function() {
var msg, oErr;
if (err.responseText === '') {
msg = 'No Response from Server!';
} else {
try {
oErr = JSON.parse(err.responseText);
msg = oErr.message;
} catch (_error) {}
}
$('#info').text(errMsg + msg);
return $('#info').attr('class', 'error');
};
return setTimeout(fDelayed, 500);
}
};
};
@ -68,11 +72,10 @@
}
data = {
command: cmd,
payload: {
payload: JSON.stringify({
id: modName
}
})
};
data.payload = JSON.stringify(data.payload);
return $.post('/usercommand', data).done(fFetchModules).fail(fErrHandler('Could not delete module! '));
}
});
@ -80,9 +83,9 @@
var modName;
modName = encodeURIComponent($('div', $(this).closest('tr')).text());
if ($('#module_type').val() === 'Event Poller') {
return window.location.href = 'forge?page=forge_event_poller&id=' + modName;
return window.location.href = 'forge?page=forge_module&type=event_poller&id=' + modName;
} else {
return window.location.href = 'forge?page=forge_action_invoker&id=' + modName;
return window.location.href = 'forge?page=forge_module&type=action_invoker&id=' + modName;
}
});
};

View file

@ -3,7 +3,7 @@
var fOnLoad;
fOnLoad = function() {
var fChangeInputVisibility, fErrHandler, fFetchRules, fUpdateRuleList;
var fErrHandler, fFetchRules, fUpdateRuleList;
document.title = 'Edit Rules';
$('#pagetitle').text("{{{user.username}}}, edit your Rules!");
fErrHandler = function(errMsg) {
@ -63,11 +63,10 @@
$('#log_col').text("");
data = {
command: 'delete_rule',
payload: {
payload: JSON.stringify({
id: ruleName
}
})
};
data.payload = JSON.stringify(data.payload);
return $.post('/usercommand', data).done(fFetchRules).fail(fErrHandler('Could not delete rule! '));
}
});
@ -76,62 +75,21 @@
ruleName = $('div', $(this).closest('tr')).text();
return window.location.href = 'forge?page=forge_rule&id=' + encodeURIComponent(ruleName);
});
$('#tableRules').on('click', 'img.log', function() {
return $('#tableRules').on('click', 'img.log', function() {
var data, ruleName;
ruleName = $('div', $(this).closest('tr')).text();
data = {
command: 'get_rule_log',
payload: {
payload: JSON.stringify({
id: ruleName
}
})
};
data.payload = JSON.stringify(data.payload);
return $.post('/usercommand', data).done(function(data) {
var log;
log = data.message.replace(new RegExp("\n", 'g'), "<br>");
return $('#log_col').html("<h3>" + ruleName + " Log:</h3>" + log);
}).fail(fErrHandler('Could not get rule log! '));
});
fChangeInputVisibility = function() {
return $('#tableParams tr').each(function(id) {
if ($(this).is(':last-child' || $(this).is(':only-child'))) {
$('img', this).hide();
return $('input[type=checkbox]', this).hide();
} else {
$('img', this).show();
return $('input[type=checkbox]', this).show();
}
});
};
$('#tableParams').on('click', 'img', function() {
var par;
par = $(this).closest('tr');
if (!par.is(':last-child')) {
par.remove();
}
return fChangeInputVisibility();
});
$('#tableParams').on('keyup', 'input', function(e) {
var cb, code, img, inp, par, tr;
code = e.keyCode || e.which;
if (code !== 9) {
par = $(this).closest('tr');
if (par.is(':last-child')) {
tr = $('<tr>');
img = $('<img>').attr('title', 'Remove?').attr('src', 'red_cross_small.png');
cb = $('<input>').attr('type', 'checkbox').attr('title', 'Password shielded input?');
inp = $('<input>').attr('type', 'text').attr('class', 'textinput');
tr.append($('<td>').append(img));
tr.append($('<td>').append(cb));
tr.append($('<td>').append(inp));
par.parent().append(tr);
return fChangeInputVisibility();
} else if ($(this).val() === '' && !par.is(':only-child')) {
return par.remove();
}
}
});
return fChangeInputVisibility();
};
window.addEventListener('load', fOnLoad, true);

View file

@ -1,130 +0,0 @@
// Generated by CoffeeScript 1.7.1
(function() {
var fOnLoad;
fOnLoad = function() {
var arrKV, arrParams, editor, fChangeInputVisibility, id, param, _i, _len;
document.title = 'Forge Action Invoker';
$('#pagetitle').text("{{{user.username}}}, forge your custom action invoker!");
editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/coffee");
editor.setShowPrintMargin(false);
editor.session.setUseSoftTabs(false);
$('#editor_mode').change(function(el) {
if ($(this).val() === 'CoffeeScript') {
return editor.getSession().setMode("ace/mode/coffee");
} else {
return editor.getSession().setMode("ace/mode/javascript");
}
});
fChangeInputVisibility = function() {
return $('#tableParams tr').each(function(id) {
if ($(this).is(':last-child' || $(this).is(':only-child'))) {
$('img', this).hide();
return $('input[type=checkbox]', this).hide();
} else {
$('img', this).show();
return $('input[type=checkbox]', this).show();
}
});
};
$('#tableParams').on('click', 'img', function() {
var par;
par = $(this).closest('tr');
if (!par.is(':last-child')) {
par.remove();
}
return fChangeInputVisibility();
});
$('#tableParams').on('keyup', 'input', function(e) {
var cb, code, img, inp, par, tr;
code = e.keyCode || e.which;
if (code !== 9) {
par = $(this).closest('tr');
if (par.is(':last-child')) {
tr = $('<tr>');
img = $('<img>').attr('title', 'Remove?').attr('src', 'red_cross_small.png');
cb = $('<input>').attr('type', 'checkbox').attr('title', 'Password shielded input?');
inp = $('<input>').attr('type', 'text').attr('class', 'textinput');
tr.append($('<td>').append(img));
tr.append($('<td>').append(cb));
tr.append($('<td>').append(inp));
par.parent().append(tr);
return fChangeInputVisibility();
} else if ($(this).val() === '' && !par.is(':only-child')) {
return par.remove();
}
}
});
fChangeInputVisibility();
$('#but_submit').click(function() {
var listParams, obj;
if ($('#input_id').val() === '') {
return alert('Please enter an action invoker name!');
} else {
listParams = {};
$('#tableParams tr').each(function() {
var shld, val;
val = $('input.textinput', this).val();
shld = $('input[type=checkbox]', this).is(':checked');
if (val !== "") {
listParams[val] = shld;
}
return true;
});
obj = {
command: 'forge_action_invoker',
payload: {
id: $('#input_id').val(),
lang: $('#editor_mode').val(),
"public": $('#is_public').is(':checked'),
data: editor.getValue(),
params: JSON.stringify(listParams)
}
};
obj.payload = JSON.stringify(obj.payload);
window.scrollTo(0, 0);
return $.post('/usercommand', obj).done(function(data) {
$('#info').text(data.message);
return $('#info').attr('class', 'success');
}).fail(function(err) {
var fDelayed;
if (err.status === 401) {
return window.location.href = 'forge?page=forge_action_invoker';
} else {
fDelayed = function() {
var msg, oErr;
if (err.responseText === '') {
msg = 'No Response from Server!';
} else {
try {
oErr = JSON.parse(err.responseText);
msg = oErr.message;
} catch (_error) {}
}
$('#info').text('Action Invoker not stored! ' + msg);
return $('#info').attr('class', 'error');
};
return setTimeout(fDelayed, 500);
}
});
}
});
arrParams = window.location.search.substring(1).split('&');
id = '';
for (_i = 0, _len = arrParams.length; _i < _len; _i++) {
param = arrParams[_i];
arrKV = param.split('=');
if (arrKV[0] === 'id') {
id = decodeURIComponent(arrKV[1]);
}
}
if (id !== '') {
return console.log(id);
}
};
window.addEventListener('load', fOnLoad, true);
}).call(this);

View file

@ -1,118 +0,0 @@
// Generated by CoffeeScript 1.7.1
(function() {
var fOnLoad;
fOnLoad = function() {
var editor, fChangeInputVisibility;
document.title = 'Forge Event Poller';
$('#pagetitle').text("{{{user.username}}}, forge your custom event poller!");
editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/coffee");
editor.setShowPrintMargin(false);
$('#editor_mode').change(function(el) {
if ($(this).val() === 'CoffeeScript') {
return editor.getSession().setMode("ace/mode/coffee");
} else {
return editor.getSession().setMode("ace/mode/javascript");
}
});
fChangeInputVisibility = function() {
return $('#tableParams tr').each(function(id) {
if ($(this).is(':last-child' || $(this).is(':only-child'))) {
$('img', this).hide();
return $('input[type=checkbox]', this).hide();
} else {
$('img', this).show();
return $('input[type=checkbox]', this).show();
}
});
};
$('#tableParams').on('click', 'img', function() {
var par;
par = $(this).closest('tr');
if (!par.is(':last-child')) {
par.remove();
}
return fChangeInputVisibility();
});
$('#tableParams').on('keyup', 'input', function(e) {
var cb, code, img, inp, par, tr;
code = e.keyCode || e.which;
if (code !== 9) {
par = $(this).closest('tr');
if (par.is(':last-child')) {
tr = $('<tr>');
img = $('<img>').attr('title', 'Remove?').attr('src', 'red_cross_small.png');
cb = $('<input>').attr('type', 'checkbox').attr('title', 'Password shielded input?');
inp = $('<input>').attr('type', 'text').attr('class', 'textinput');
tr.append($('<td>').append(img));
tr.append($('<td>').append(cb));
tr.append($('<td>').append(inp));
tr.append($('<td>'));
par.parent().append(tr);
return fChangeInputVisibility();
} else if ($(this).val() === '' && !par.is(':only-child')) {
return par.remove();
}
}
});
fChangeInputVisibility();
return $('#but_submit').click(function() {
var listParams, obj;
if ($('#input_id').val() === '') {
return alert('Please enter an event poller name!');
} else {
listParams = {};
$('#tableParams tr').each(function() {
var shld, val;
val = $('input.textinput', this).val();
shld = $('input[type=checkbox]', this).is(':checked');
if (val !== "") {
listParams[val] = shld;
}
return true;
});
obj = {
command: 'forge_event_poller',
payload: {
id: $('#input_id').val(),
lang: $('#editor_mode').val(),
"public": $('#is_public').is(':checked'),
data: editor.getValue(),
params: JSON.stringify(listParams)
}
};
obj.payload = JSON.stringify(obj.payload);
window.scrollTo(0, 0);
return $.post('/usercommand', obj).done(function(data) {
$('#info').text(data.message);
return $('#info').attr('class', 'success');
}).fail(function(err) {
var fDelayed;
if (err.status === 401) {
return window.location.href = 'forge?page=forge_event_poller';
} else {
fDelayed = function() {
var msg, oErr;
if (err.responseText === '') {
msg = 'No Response from Server!';
} else {
try {
oErr = JSON.parse(err.responseText);
msg = oErr.message;
} catch (_error) {}
}
$('#info').text('Event Poller not stored! ' + msg);
return $('#info').attr('class', 'error');
};
return setTimeout(fDelayed, 500);
}
});
}
});
};
window.addEventListener('load', fOnLoad, true);
}).call(this);

View file

@ -0,0 +1,215 @@
// Generated by CoffeeScript 1.7.1
(function() {
var arrKV, arrParams, fErrHandler, fOnLoad, moduleName, oParams, param, _i, _len;
arrParams = window.location.search.substring(1).split('&');
oParams = {};
for (_i = 0, _len = arrParams.length; _i < _len; _i++) {
param = arrParams[_i];
arrKV = param.split('=');
oParams[arrKV[0]] = arrKV[1];
}
if (oParams.type === 'event_poller') {
moduleName = 'Event Poller';
} else {
moduleName = 'Action Invoker';
oParams.type = 'action_invoker';
}
if (oParams.id) {
oParams.id = decodeURIComponent(oParams.id);
}
fErrHandler = function(errMsg) {
return function(err) {
var fDelayed;
if (err.status === 401) {
return window.location.href = "forge?page=forge_module?type=" + oParams.type;
} else {
$('#log_col').text("");
fDelayed = function() {
var msg, oErr;
if (err.responseText === '') {
msg = 'No Response from Server!';
} else {
try {
oErr = JSON.parse(err.responseText);
msg = oErr.message;
} catch (_error) {}
}
$('#info').text(errMsg + msg);
return $('#info').attr('class', 'error');
};
return setTimeout(fDelayed, 500);
}
};
};
fOnLoad = function() {
var editor, fAddInputRow, fAddUserParam, fChangeInputVisibility, obj;
document.title = "Forge " + moduleName;
$('#pagetitle').text("{{{user.username}}}, forge your custom " + moduleName + "!");
editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/coffee");
editor.setShowPrintMargin(false);
editor.session.setUseSoftTabs(false);
$('#editor_mode').change(function(el) {
if ($(this).val() === 'CoffeeScript') {
return editor.getSession().setMode("ace/mode/coffee");
} else {
return editor.getSession().setMode("ace/mode/javascript");
}
});
fChangeInputVisibility = function() {
return $('#tableParams tr').each(function(id) {
if ($(this).is(':last-child' || $(this).is(':only-child'))) {
$('img', this).hide();
return $('input[type=checkbox]', this).hide();
} else {
$('img', this).show();
return $('input[type=checkbox]', this).show();
}
});
};
fAddInputRow = function(tag) {
var cb, img, inp, tr;
tr = $('<tr>');
img = $('<img>').attr('title', 'Remove?').attr('src', 'red_cross_small.png');
cb = $('<input>').attr('type', 'checkbox').attr('title', 'Password shielded input?');
inp = $('<input>').attr('type', 'text').attr('class', 'textinput');
tr.append($('<td>').append(img));
tr.append($('<td>').append(cb));
tr.append($('<td>').append(inp));
tag.append(tr);
fChangeInputVisibility();
return tr;
};
$('#tableParams').on('click', 'img', function() {
var par;
par = $(this).closest('tr');
if (!par.is(':last-child')) {
par.remove();
}
return fChangeInputVisibility();
});
$('#tableParams').on('keyup', 'input', function(e) {
var code, par;
code = e.keyCode || e.which;
if (code !== 9) {
par = $(this).closest('tr');
if (par.is(':last-child')) {
return fAddInputRow(par.parent());
} else if ($(this).val() === '' && !par.is(':only-child')) {
return par.remove();
}
}
});
fChangeInputVisibility();
$('#but_submit').click(function() {
var fCheckOverwrite, listParams, obj;
if ($('#input_id').val() === '') {
return alert("Please enter an " + moduleName + " name!");
} else {
listParams = {};
$('#tableParams tr').each(function() {
var shld, val;
val = $('input.textinput', this).val();
shld = $('input[type=checkbox]', this).is(':checked');
if (val !== "") {
listParams[val] = shld;
}
return true;
});
obj = {
command: "forge_" + oParams.type,
payload: JSON.stringify({
id: $('#input_id').val(),
lang: $('#editor_mode').val(),
"public": $('#is_public').is(':checked'),
data: editor.getValue(),
params: JSON.stringify(listParams)
})
};
fCheckOverwrite = function(obj) {
return function(err) {
var payl;
if (err.status === 409) {
if (confirm('Are you sure you want to overwrite the existing module?')) {
payl = JSON.parse(obj.payload);
payl.overwrite = true;
obj.payload = JSON.stringify(payl);
return $.post('/usercommand', obj).done(function(data) {
$('#info').text(data.message);
$('#info').attr('class', 'success');
return alert("You need to update the rules that use this module in order for the changes to be applied to them!");
}).fail(fErrHandler("" + moduleName + " not stored!"));
}
} else {
return fErrHandler("" + moduleName + " not stored!")(err);
}
};
};
window.scrollTo(0, 0);
return $.post('/usercommand', obj).done(function(data) {
$('#info').text(data.message);
return $('#info').attr('class', 'success');
}).fail(fCheckOverwrite(obj));
}
});
fAddUserParam = function(param, shielded) {
var tr;
tr = fAddInputRow($('#tableParams'));
$('input.textinput', tr).val(param);
if (shielded) {
return $('input[type=checkbox]', tr).prop('checked', true);
}
};
if (oParams.id) {
obj = {
command: "get_full_" + oParams.type,
payload: JSON.stringify({
id: oParams.id
})
};
return $.post('/usercommand', obj).done(function(data) {
var oMod, shielded, _ref;
oMod = JSON.parse(data.message);
if (oMod) {
_ref = JSON.parse(oMod.params);
for (param in _ref) {
shielded = _ref[param];
fAddUserParam(param, shielded);
}
$('#input_id').val(oMod.id);
$('#editor_mode').val(oMod.lang);
if (oMod["public"] === 'true') {
$('#is_public').prop('checked', true);
}
editor.setValue(oMod.data);
editor.moveCursorTo(0, 0);
}
return fAddUserParam('', false);
}).fail(fErrHandler("Could not get module " + oParams.id + "!"));
} else {
editor.setValue($("#template_" + oParams.type).text());
editor.moveCursorTo(0, 0);
if (oParams.type === 'event_poller') {
$('#input_id').val('EmailYak');
fAddUserParam('apikey', true);
return fAddUserParam('', false);
} else {
$('#input_id').val('ProBinder');
fAddUserParam('username', false);
fAddUserParam('password', true);
return fAddUserParam('', false);
}
}
};
window.addEventListener('load', fOnLoad, true);
}).call(this);

View file

@ -1,8 +1,22 @@
// Generated by CoffeeScript 1.7.1
(function() {
var fFailedRequest, fOnLoad, fPlaceAndPaintInterval, strPublicKey,
var arrKV, arrParams, fFailedRequest, fOnLoad, fPlaceAndPaintInterval, oParams, param, strPublicKey, _i, _len,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
arrParams = window.location.search.substring(1).split('&');
oParams = {};
for (_i = 0, _len = arrParams.length; _i < _len; _i++) {
param = arrParams[_i];
arrKV = param.split('=');
oParams[arrKV[0]] = arrKV[1];
}
if (oParams.id) {
oParams.id = decodeURIComponent(oParams.id);
}
strPublicKey = '';
fPlaceAndPaintInterval = function() {
@ -34,7 +48,7 @@
});
fOnLoad = function() {
var arrKV, arrParams, editor, fFetchActionFunctionParams, fFetchActionParams, fFetchEventParams, id, obj, param, _i, _len;
var editor, fAddSelectedAction, fFetchActionFunctionParams, fFetchActionParams, fFetchEventParams, obj;
document.title = 'Rule Forge!';
$('#pagetitle').text('{{{user.username}}}, forge your ECA Rule!');
editor = ace.edit("editor_conditions");
@ -48,13 +62,12 @@
arr = name.split(' -> ');
obj = {
command: 'get_event_poller_params',
payload: {
payload: JSON.stringify({
id: arr[0]
}
})
};
obj.payload = JSON.stringify(obj.payload);
return $.post('/usercommand', obj).done(function(data) {
var fAppendParam, oParams, shielded, table, _results;
var fAppendParam, shielded, table, _results;
if (data.message) {
oParams = JSON.parse(data.message);
$('#event_poller_params').html('<br><b>Required Parameters:</b>');
@ -65,7 +78,7 @@
tr = $('<tr>');
tr.append($('<td>').css('width', '20px'));
tr.append($('<td>').attr('class', 'key').text(name));
inp = $('<input>').attr('id', "" + name);
inp = $('<input>');
if (shielded) {
inp.attr('type', 'password');
}
@ -94,13 +107,13 @@
return;
}
fAppendEvents = function(id, events) {
var evt, fAppendEvent, _i, _len, _results;
var evt, fAppendEvent, _j, _len1, _results;
fAppendEvent = function(evt) {
return $('#select_event').append($('<option>').text(id + ' -> ' + evt));
};
_results = [];
for (_i = 0, _len = events.length; _i < _len; _i++) {
evt = events[_i];
for (_j = 0, _len1 = events.length; _j < _len1; _j++) {
evt = events[_j];
_results.push(fAppendEvent(evt));
}
return _results;
@ -144,11 +157,15 @@
return;
}
fAppendActions = function(module, actions) {
var act, _i, _len, _results;
var act, _j, _len1, _results;
_results = [];
for (_i = 0, _len = actions.length; _i < _len; _i++) {
act = actions[_i];
_results.push($('#select_actions').append($('<option>').text(module + ' -> ' + act)));
for (_j = 0, _len1 = actions.length; _j < _len1; _j++) {
act = actions[_j];
if ($("#action_params div:contains(" + module + " -> " + act + ")").length === 0) {
_results.push($('#select_actions').append($('<option>').text(module + ' -> ' + act)));
} else {
_results.push(void 0);
}
}
return _results;
};
@ -162,13 +179,12 @@
fFetchActionParams = function(div, modName) {
obj = {
command: 'get_action_invoker_params',
payload: {
payload: JSON.stringify({
id: modName
}
})
};
obj.payload = JSON.stringify(obj.payload);
return $.post('/usercommand', obj).done(function(data) {
var fAppendActionParam, name, oParams, sh, table, _results;
var fAppendActionParam, name, sh, table, _results;
if (data.message) {
oParams = JSON.parse(data.message);
table = $('<table>');
@ -178,7 +194,7 @@
tr = $('<tr>');
tr.append($('<td>').css('width', '20px'));
tr.append($('<td>').attr('class', 'key').text(name));
inp = $('<input>').attr('id', "" + name);
inp = $('<input>');
if (shielded) {
inp.attr('type', 'password');
} else {
@ -198,22 +214,21 @@
};
fFetchActionFunctionParams = function(tag, arrName) {
obj = {
command: 'get_action_invoker_function_params',
payload: {
command: 'get_action_invoker_function_arguments',
payload: JSON.stringify({
id: arrName[0]
}
})
};
obj.payload = JSON.stringify(obj.payload);
return $.post('/usercommand', obj).done(function(data) {
var functionArgument, oParams, table, td, tr, _i, _len, _ref, _results;
var functionArgument, table, td, tr, _j, _len1, _ref, _results;
if (data.message) {
oParams = JSON.parse(data.message);
if (oParams[arrName[1]]) {
table = $('<table>').appendTo(tag);
_ref = oParams[arrName[1]];
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
functionArgument = _ref[_i];
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
functionArgument = _ref[_j];
tr = $('<tr>').appendTo(table);
td = $('<td>').appendTo(tr);
td.append($('<div>').attr('class', 'funcarg').text(functionArgument));
@ -230,10 +245,9 @@
}
}).fail(fFailedRequest('Error fetching action invoker function params'));
};
$('#select_actions').on('change', function() {
var arrEls, arrName, div, img, opt, subdiv, table, td, tr, _ref;
opt = $('option:selected', this);
arrName = opt.text().split(' -> ');
fAddSelectedAction = function(name) {
var arrEls, arrName, div, img, subdiv, table, td, tr, _ref;
arrName = name.split(' -> ');
arrEls = $("#action_params div.modName").map(function() {
return $(this).text();
}).get();
@ -241,7 +255,7 @@
tr = $('<tr>').appendTo(table);
img = $('<img>').attr('src', 'red_cross_small.png');
tr.append($('<td>').css('width', '20px').append(img));
tr.append($('<td>').attr('class', 'title').text(opt.val()));
tr.append($('<td>').attr('class', 'title').text(name));
td = $('<td>').attr('class', 'funcMappings').appendTo(tr);
fFetchActionFunctionParams(td, arrName);
if (_ref = arrName[0], __indexOf.call(arrEls, _ref) < 0) {
@ -250,7 +264,12 @@
subdiv.append($('<div>')).attr('class', 'modName underlined').text(arrName[0]);
fFetchActionParams(div, arrName[0]);
}
return opt.remove();
return $("#select_actions option:contains(" + name + ")").remove();
};
$('#select_actions').on('change', function() {
var opt;
opt = $('option:selected', this);
return fAddSelectedAction(opt.text());
});
$('#selected_actions').on('click', 'img', function() {
var act, arrName, nMods, opt;
@ -271,12 +290,12 @@
}
});
}
opt = $('<option>').text(arrName[0]);
opt = $('<option>').text(act);
$('#select_actions').append(opt);
return $(this).closest('tr').remove();
});
$('#but_submit').click(function() {
var actParams, acts, ap, arrInp, conds, d, encryptedParams, ep, err, fParseTime, mins, txtInterval;
var actParams, acts, ap, arrInp, conds, d, ep, err, fCheckOverwrite, fParseTime, mins, txtInterval;
window.scrollTo(0, 0);
$('#info').text('');
try {
@ -290,51 +309,67 @@
}
ep = {};
$("#event_poller_params tr").each(function() {
var name, val;
var encryptedParam, key, shielded, val;
key = $(this).children('.key').text();
val = $('input', this).val();
name = $(this).children('.key').text();
if (val === '') {
$('input', this).focus();
throw new Error("Please enter a value for '" + name + "' in the event module!");
throw new Error("Please enter a value for '" + key + "' in the event module!");
}
shielded = $('input', this).attr('type') === 'password';
ep[key] = {
shielded: shielded
};
if ($('input', this).attr('unchanged') === 'true') {
return ep[key].value = val;
} else {
encryptedParam = cryptico.encrypt(val, strPublicKey);
return ep[key].value = encryptedParam.cipher;
}
return ep[name] = val;
});
if ($('#selected_actions tr').length === 0) {
throw new Error('Please select at least one action or create one!');
}
ap = {};
$('> div', $('#action_params')).each(function() {
var encryptedParams, modName, params;
var modName, params;
modName = $('.modName', this).text();
params = {};
$('tr', this).each(function() {
var key, val;
var encryptedParam, key, shielded, val;
key = $('.key', this).text();
val = $('input', this).val();
shielded = $('input', this).attr('type') === 'password';
if (val === '') {
$('input', this).focus();
throw new Error("'" + key + "' missing for '" + modName + "'");
}
return params[key] = val;
params[key] = {
shielded: shielded
};
if ($('input', this).attr('unchanged') === 'true') {
return params[key].value = val;
} else {
encryptedParam = cryptico.encrypt(val, strPublicKey);
return params[key].value = encryptedParam.cipher;
}
});
encryptedParams = cryptico.encrypt(JSON.stringify(params), strPublicKey);
return ap[modName] = encryptedParams.cipher;
return ap[modName] = params;
});
acts = [];
actParams = {};
$('#selected_actions').each(function() {
var actionName;
actionName = $('.title', this).text();
$('#selected_actions td.title').each(function() {
var actionName, par;
actionName = $(this).text();
actParams[actionName] = [];
acts.push(actionName);
return $('.funcMappings tr').each(function() {
var tmp;
tmp = {
argument: $('div.funcarg', this).val(),
par = $(this).parent();
return $('.funcMappings tr', par).each(function() {
return actParams[actionName].push({
argument: $('div.funcarg', this).text(),
value: $('input[type=text]', this).val(),
regexp: $('input[type=checkbox]', this).is(':checked')
};
tmp = cryptico.encrypt(JSON.stringify(tmp), strPublicKey);
return actParams[actionName] = tmp.cipher;
});
});
});
try {
@ -362,61 +397,182 @@
}
};
txtInterval = $('#event_interval').val();
arrInp = txtInterval.split(' ');
if (arrInp.length === 1) {
mins = fParseTime(txtInterval);
if (!txtInterval) {
mins = 1;
} else {
d = parseInt(arrInp[0]) || 0;
mins = d * 24 * 60 + fParseTime(arrInp[1], true);
arrInp = txtInterval.split(' ');
if (arrInp.length === 1) {
mins = fParseTime(txtInterval);
} else {
d = parseInt(arrInp[0]) || 0;
mins = d * 24 * 60 + fParseTime(arrInp[1], true);
}
}
mins = Math.min(mins, 35700);
encryptedParams = cryptico.encrypt(JSON.stringify(ep), strPublicKey);
fCheckOverwrite = function(obj) {
return function(err) {
var payl;
if (err.status === 409) {
if (confirm('Are you sure you want to overwrite the existing rule?')) {
payl = JSON.parse(obj.payload);
payl.overwrite = true;
obj.payload = JSON.stringify(payl);
return $.post('/usercommand', obj).done(function(data) {
$('#info').text(data.message);
return $('#info').attr('class', 'success');
}).fail(fFailedRequest("" + obj.id + " not stored!"));
}
} else {
return fFailedRequest("" + obj.id + " not stored!")(err);
}
};
};
obj = {
command: 'forge_rule',
payload: {
payload: JSON.stringify({
id: $('#input_id').val(),
event: $('#input_event').val(),
event_params: encryptedParams.cipher,
event_params: ep,
event_interval: mins,
conditions: conds,
actions: acts,
action_params: ap,
action_functions: actParams
}
})
};
obj.payload = JSON.stringify(obj.payload);
return $.post('/usercommand', obj).done(function(data) {
$('#info').text(data.message);
return $('#info').attr('class', 'success');
}).fail(function(err) {
var msg;
if (err.responseText === '') {
msg = 'No Response from Server!';
} else {
try {
msg = JSON.parse(err.responseText).message;
} catch (_error) {}
}
return fFailedRequest('Error in upload: ' + msg)(err);
});
}).fail(fCheckOverwrite(obj));
} catch (_error) {
err = _error;
console.log(err);
$('#info').text('Error in upload: ' + err.message);
$('#info').attr('class', 'error');
return alert(err.message);
alert(err.message);
throw err;
}
});
arrParams = window.location.search.substring(1).split('&');
id = '';
for (_i = 0, _len = arrParams.length; _i < _len; _i++) {
param = arrParams[_i];
arrKV = param.split('=');
if (arrKV[0] === 'id') {
id = decodeURIComponent(arrKV[1]);
}
}
if (id !== '') {
return console.log(id);
if (oParams.id) {
obj = {
command: 'get_rule',
payload: JSON.stringify({
id: oParams.id
})
};
return $.post('/usercommand', obj).done(function(data) {
var action, arrMod, arrName, fAddActionModuleArgs, fAddActionModuleParams, mod, oActions, oRule, _j, _len1, _ref, _results;
oRule = JSON.parse(data.message);
if (oRule) {
$('#input_id').val(oRule.id);
$('#select_event').val(oRule.event);
if ($('#select_event').val() !== '') {
fFetchEventParams(oRule.event);
fPlaceAndPaintInterval();
obj = {
command: 'get_event_poller_user_params',
payload: JSON.stringify({
id: oRule.event.split(' -> ')[0]
})
};
$.post('/usercommand', obj).done(function(data) {
var oParam, par;
oParams = JSON.parse(data.message);
for (param in oParams) {
oParam = oParams[param];
par = $("#event_poller_params tr:contains(" + param + ")").parent();
$('input', par).val(oParam.value);
$('input', par).attr('unchanged', 'true');
}
return $('input', par).change(function() {
return $(this).attr('unchanged', 'false');
});
});
}
$('#input_event').val(oRule.event);
$('#event_interval').val(oRule.event_interval);
editor.setValue(JSON.stringify(oRule.conditions));
oActions = {};
_ref = oRule.actions;
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
action = _ref[_j];
fAddSelectedAction(action);
arrName = action.split(' -> ');
if (!oActions[arrName[0]]) {
oActions[arrName[0]] = [];
}
oActions[arrName[0]].push(arrName[1]);
}
fAddActionModuleParams = function(name) {
return function(data) {
var domMod, oParam, par;
oParams = JSON.parse(data.message);
domMod = $("#action_params div.modName:contains(" + name + ")").parent();
for (param in oParams) {
oParam = oParams[param];
par = $("td.key:contains(" + param + ")", domMod).parent();
$('input', par).val(oParam.value);
$('input', par).attr('unchanged', 'true');
}
return $('input', par).change(function() {
return $(this).attr('unchanged', 'false');
});
};
};
fAddActionModuleArgs = function(name) {
return function(data) {
var arrFuncs, key, oFunc, par, tr, _ref1, _results;
_ref1 = data.message;
_results = [];
for (key in _ref1) {
arrFuncs = _ref1[key];
par = $("#selected_actions td.title:contains(" + name + " -> " + key + ")").parent();
_results.push((function() {
var _k, _len2, _ref2, _results1;
_ref2 = JSON.parse(arrFuncs);
_results1 = [];
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
oFunc = _ref2[_k];
tr = $(".funcarg:contains(" + oFunc.argument + ")", par).parent().parent();
$("input[type=text]", tr).val(oFunc.value);
_results1.push($("input[type=checkbox]", tr).prop('checked', oFunc.regexp));
}
return _results1;
})());
}
return _results;
};
};
_results = [];
for (mod in oActions) {
arrMod = oActions[mod];
obj = {
command: 'get_action_invoker_user_params',
payload: JSON.stringify({
id: mod
})
};
$.post('/usercommand', obj).done(fAddActionModuleParams(mod));
obj.command = 'get_action_invoker_user_arguments';
obj.payload = JSON.stringify({
ruleId: oRule.id,
moduleId: mod
});
_results.push($.post('/usercommand', obj).done(fAddActionModuleArgs(mod)));
}
return _results;
}
}).fail(function(err) {
var msg;
if (err.responseText === '') {
msg = 'No Response from Server!';
} else {
try {
msg = JSON.parse(err.responseText).message;
} catch (_error) {}
}
return fFailedRequest('Error in upload: ' + msg)(err);
});
}
};

View file

@ -1,13 +1,33 @@
Action Invoker Name: <input id="input_id" type="text" />
<select id="editor_mode">
<option>CoffeeScript</option>
<option>JavaScript</option>
</select> is public: <input type="checkbox" id="is_public" />
<table id="editor_table">
<tr>
<td id="editor_col" valign="top">
<div id="editor">
<script src="js/ace-src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
<script id="template_event_poller" type="text/template">
#
# EmailYak EVENT POLLER
# ---------------------
#
# Requires user params:
# - apikey: The user's EmailYak API key
#
url = 'https://api.emailyak.com/v1/' + params.apikey + '/json/get/new/email/'
exports.newMail = ( pushEvent ) ->
# needlereq allows the user to make calls to API's
# Refer to https://github.com/tomas/needle for more information
#
# Syntax: needle.request method, url, data, [options], callback
#
needle.request 'get', url, null, null, ( err, resp, body ) ->
if err
log 'Error in EmailYak EM newMail: ' + err.message
else
if resp.statusCode is 200
for mail in body.Emails
pushEvent
subject: mail.Subject
content: mail.TextBody
</script>
<script id="template_action_invoker" type="text/template">
###
ProBinder ACTION INVOKER
------------------------
@ -124,28 +144,4 @@ exports.setRead = ( id ) ->
data:
id: id
callback: standardCallback 'setRead'
</div>
<button id="but_submit">save</button>
</td>
<td id="params_col" valign="top">
This action invoker requires user-specific properties:
<table id="tableParams">
<tr>
<td><img src="red_cross_small.png"></td>
<td><input type="checkbox" title="Password shielded input?" /></td>
<td><input type="text" class="textinput" value="username" /></td>
</tr>
<tr>
<td><img src="red_cross_small.png"></td>
<td><input type="checkbox" title="Password shielded input?" checked="true" /></td>
<td><input type="text" class="textinput" value="password" /></td>
</tr>
<tr>
<td><img src="red_cross_small.png"></td>
<td><input type="checkbox" title="Password shielded input?" /></td>
<td><input type="text" class="textinput" /></td>
</tr>
</table>
</td>
</tr>
</table>
</script>

View file

@ -1,57 +0,0 @@
Event Poller Name: <input id="input_id" type="text" />
<select id="editor_mode">
<option>CoffeeScript</option>
<option>JavaScript</option>
</select> is public: <input type="checkbox" id="is_public" />
<table id="editor_table">
<tr>
<td id="editor_col" valign="top">
<div id="editor">
#
# EmailYak EVENT POLLER
# ---------------------
#
# Requires user params:
# - apikey: The user's EmailYak API key
#
url = 'https://api.emailyak.com/v1/' + params.apikey + '/json/get/new/email/'
exports.newMail = ( pushEvent ) ->
# needlereq allows the user to make calls to API's
# Refer to https://github.com/tomas/needle for more information
#
# Syntax: needle.request method, url, data, [options], callback
#
needle.request 'get', url, null, null, ( err, resp, body ) ->
if err
log 'Error in EmailYak EM newMail: ' + err.message
else
if resp.statusCode is 200
for mail in body.Emails
pushEvent
subject: mail.Subject
content: mail.TextBody
</div>
<button id="but_submit">save</button>
</td>
<td id="params_col" valign="top">
This event poller requires user-specific properties:
<table id="tableParams">
<tr>
<td><img src="red_cross_small.png" title="Remove?"></td>
<td><input type="checkbox" title="Password shielded input?" checked="true" /></td>
<td><input type="text" class="textinput" value="apikey" /></td>
</tr>
<tr>
<td><img src="red_cross_small.png" title="Remove?"></td>
<td><input type="checkbox" title="Password shielded input?" /></td>
<td><input type="text" class="textinput" /></td>
</tr>
</table><!--
<td><input type="checkbox" title="Password shielded input?" /></td>
<td></td> -->
</td>
</tr>
</table>

View file

@ -0,0 +1,17 @@
Module Name: <input id="input_id" type="text" />
<select id="editor_mode">
<option>CoffeeScript</option>
<option>JavaScript</option>
</select> is public: <input type="checkbox" id="is_public" checked/>
<table id="editor_table">
<tr>
<td id="editor_col" valign="top">
<div id="editor"></div>
<button id="but_submit">save</button>
</td>
<td id="params_col" valign="top">
This module requires user-specific properties:
<table id="tableParams"></table>
</td>
</tr>
</table>

View file

@ -15,10 +15,10 @@
};
fCreateLink( 'Forge Event Poller',
fRedirect( 'forge?page=forge_event_poller' )
fRedirect( 'forge?page=forge_module&type=event_poller' )
);
fCreateLink( 'Forge Action Invoker',
fRedirect( 'forge?page=forge_action_invoker' )
fRedirect( 'forge?page=forge_module&type=action_invoker' )
);
fCreateLink( 'Forge Rule',
fRedirect( 'forge?page=forge_rule' )