mirror of
https://github.com/Hopiu/webapi-eca.git
synced 2026-03-16 22:10:31 +00:00
Started UI improvements for the rules forge
This commit is contained in:
parent
ef0a105a08
commit
d97d634995
34 changed files with 916 additions and 473 deletions
|
|
@ -87,21 +87,21 @@ Processes a user request coming through the request-handler.
|
|||
- `oReq` is the request object that contains:
|
||||
|
||||
- `command` as a string
|
||||
- `payload` an optional stringified JSON object
|
||||
- `body` an optional stringified JSON object
|
||||
The callback function `callback( obj )` will receive an object
|
||||
containing the HTTP response code and a corresponding message.
|
||||
|
||||
@public processRequest ( *user, oReq, callback* )
|
||||
###
|
||||
exports.processRequest = ( user, oReq, callback ) ->
|
||||
if not oReq.payload
|
||||
oReq.payload = '{}'
|
||||
if not oReq.body
|
||||
oReq.body = '{}'
|
||||
try
|
||||
dat = JSON.parse oReq.payload
|
||||
dat = JSON.parse oReq.body
|
||||
catch err
|
||||
return callback
|
||||
code: 404
|
||||
message: 'You had a strange payload in your request!'
|
||||
message: 'You had a strange body in your request!'
|
||||
if commandFunctions[oReq.command]
|
||||
|
||||
# If the command function was registered we invoke it
|
||||
|
|
@ -112,17 +112,17 @@ exports.processRequest = ( user, oReq, callback ) ->
|
|||
message: 'What do you want from me?'
|
||||
|
||||
###
|
||||
Checks whether all required parameters are present in the payload.
|
||||
Checks whether all required parameters are present in the body.
|
||||
|
||||
@private hasRequiredParams ( *arrParams, oPayload* )
|
||||
@private hasRequiredParams ( *arrParams, oBody* )
|
||||
@param {Array} arrParams
|
||||
@param {Object} oPayload
|
||||
@param {Object} oBody
|
||||
###
|
||||
hasRequiredParams = ( arrParams, oPayload ) ->
|
||||
hasRequiredParams = ( arrParams, oBody ) ->
|
||||
answ =
|
||||
code: 400
|
||||
message: "Your request didn't contain all necessary fields! Requires: #{ arrParams.join() }"
|
||||
return answ for param in arrParams when not oPayload[param]
|
||||
return answ for param in arrParams when not oBody[param]
|
||||
answ.code = 200
|
||||
answ.message = 'All required properties found'
|
||||
answ
|
||||
|
|
@ -130,13 +130,13 @@ hasRequiredParams = ( arrParams, oPayload ) ->
|
|||
###
|
||||
Fetches all available modules and return them together with the available functions.
|
||||
|
||||
@private getModules ( *user, oPayload, dbMod, callback* )
|
||||
@private getModules ( *user, oBody, dbMod, callback* )
|
||||
@param {Object} user
|
||||
@param {Object} oPayload
|
||||
@param {Object} oBody
|
||||
@param {Object} dbMod
|
||||
@param {function} callback
|
||||
###
|
||||
getModules = ( user, oPayload, dbMod, callback ) ->
|
||||
getModules = ( user, oBody, dbMod, callback ) ->
|
||||
fProcessIds = ( userName ) ->
|
||||
( err, arrNames ) ->
|
||||
oRes = {}
|
||||
|
|
@ -158,21 +158,21 @@ getModules = ( user, oPayload, dbMod, callback ) ->
|
|||
|
||||
dbMod.getAvailableModuleIds user.username, fProcessIds user.username
|
||||
|
||||
getModuleParams = ( user, oPayload, dbMod, callback ) ->
|
||||
answ = hasRequiredParams [ 'id' ], oPayload
|
||||
getModuleParams = ( user, oBody, dbMod, callback ) ->
|
||||
answ = hasRequiredParams [ 'id' ], oBody
|
||||
if answ.code isnt 200
|
||||
callback answ
|
||||
else
|
||||
dbMod.getModuleField user.username, oPayload.id, "params", ( err, oPayload ) ->
|
||||
answ.message = oPayload
|
||||
dbMod.getModuleField user.username, oBody.id, "params", ( err, oBody ) ->
|
||||
answ.message = oBody
|
||||
callback answ
|
||||
|
||||
getModuleUserParams = ( user, oPayload, dbMod, callback ) ->
|
||||
answ = hasRequiredParams [ 'id' ], oPayload
|
||||
getModuleUserParams = ( user, oBody, dbMod, callback ) ->
|
||||
answ = hasRequiredParams [ 'id' ], oBody
|
||||
if answ.code isnt 200
|
||||
callback answ
|
||||
else
|
||||
dbMod.getUserParams oPayload.id, user.username, ( err, str ) ->
|
||||
dbMod.getUserParams oBody.id, user.username, ( err, str ) ->
|
||||
oParams = JSON.parse str
|
||||
for name, oParam of oParams
|
||||
if not oParam.shielded
|
||||
|
|
@ -180,58 +180,58 @@ getModuleUserParams = ( user, oPayload, dbMod, callback ) ->
|
|||
answ.message = JSON.stringify oParams
|
||||
callback answ
|
||||
|
||||
getModuleUserArguments = ( user, oPayload, dbMod, callback ) ->
|
||||
answ = hasRequiredParams [ 'ruleId' ,'moduleId' ], oPayload
|
||||
getModuleUserArguments = ( user, oBody, dbMod, callback ) ->
|
||||
answ = hasRequiredParams [ 'ruleId' ,'moduleId' ], oBody
|
||||
if answ.code isnt 200
|
||||
callback answ
|
||||
else
|
||||
dbMod.getAllModuleUserArguments user.username, oPayload.ruleId, oPayload.moduleId, ( err, oPayload ) ->
|
||||
answ.message = oPayload
|
||||
dbMod.getAllModuleUserArguments user.username, oBody.ruleId, oBody.moduleId, ( err, oBody ) ->
|
||||
answ.message = oBody
|
||||
callback answ
|
||||
|
||||
forgeModule = ( user, oPayload, modType, dbMod, callback ) =>
|
||||
answ = hasRequiredParams [ 'id', 'params', 'lang', 'data' ], oPayload
|
||||
forgeModule = ( user, oBody, modType, dbMod, callback ) =>
|
||||
answ = hasRequiredParams [ 'id', 'params', 'lang', 'data' ], oBody
|
||||
if answ.code isnt 200
|
||||
callback answ
|
||||
else
|
||||
if oPayload.overwrite
|
||||
storeModule user, oPayload, modType, dbMod, callback
|
||||
if oBody.overwrite
|
||||
storeModule user, oBody, modType, dbMod, callback
|
||||
else
|
||||
dbMod.getModule user.username, oPayload.id, ( err, mod ) =>
|
||||
dbMod.getModule user.username, oBody.id, ( err, mod ) =>
|
||||
if mod
|
||||
answ.code = 409
|
||||
answ.message = 'Module name already existing: ' + oPayload.id
|
||||
answ.message = 'Module name already existing: ' + oBody.id
|
||||
callback answ
|
||||
else
|
||||
storeModule user, oPayload, modType, dbMod, callback
|
||||
storeModule user, oBody, modType, dbMod, callback
|
||||
|
||||
storeModule = ( user, oPayload, modType, dbMod, callback ) =>
|
||||
src = oPayload.data
|
||||
dynmod.compileString src, user.username, id: 'dummyRule' , oPayload.id, oPayload.lang, modType, null, ( cm ) =>
|
||||
storeModule = ( user, oBody, modType, dbMod, callback ) =>
|
||||
src = oBody.data
|
||||
dynmod.compileString src, user.username, id: 'dummyRule' , oBody.id, oBody.lang, modType, 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
|
||||
" Module #{ oBody.id } successfully stored! Found following function(s): #{ funcs }"
|
||||
oBody.functions = JSON.stringify funcs
|
||||
oBody.functionArgs = JSON.stringify cm.funcParams
|
||||
dbMod.storeModule user.username, oBody
|
||||
# if oBody.public is 'true'
|
||||
# dbMod.publish oBody.id
|
||||
callback answ
|
||||
|
||||
storeRule = ( user, oPayload, callback ) =>
|
||||
storeRule = ( user, oBody, callback ) =>
|
||||
# This is how a rule is stored in the database
|
||||
rule =
|
||||
id: oPayload.id
|
||||
event: oPayload.event
|
||||
event_start: oPayload.event_start
|
||||
event_interval: oPayload.event_interval
|
||||
conditions: oPayload.conditions
|
||||
actions: oPayload.actions
|
||||
if oPayload.event_start
|
||||
id: oBody.id
|
||||
event: oBody.event
|
||||
event_start: oBody.event_start
|
||||
event_interval: oBody.event_interval
|
||||
conditions: oBody.conditions
|
||||
actions: oBody.actions
|
||||
if oBody.event_start
|
||||
rule.timestamp = (new Date()).toISOString()
|
||||
strRule = JSON.stringify rule
|
||||
# store the rule
|
||||
|
|
@ -241,20 +241,20 @@ storeRule = ( user, oPayload, callback ) =>
|
|||
# activate the rule
|
||||
db.activateRule rule.id, user.username
|
||||
# if event module parameters were send, store them
|
||||
if oPayload.event_params
|
||||
if oBody.event_params
|
||||
epModId = rule.event.split( ' -> ' )[ 0 ]
|
||||
db.eventPollers.storeUserParams epModId, user.username, JSON.stringify oPayload.event_params
|
||||
oFuncArgs = oPayload.event_functions
|
||||
db.eventPollers.storeUserParams epModId, user.username, JSON.stringify oBody.event_params
|
||||
oFuncArgs = oBody.event_functions
|
||||
# if event function arguments were send, store them
|
||||
for id, args of oFuncArgs
|
||||
arr = id.split ' -> '
|
||||
db.eventPollers.storeUserArguments user.username, rule.id, arr[ 0 ], arr[ 1 ], JSON.stringify args
|
||||
|
||||
# if action module params were send, store them
|
||||
oParams = oPayload.action_params
|
||||
oParams = oBody.action_params
|
||||
for id, params of oParams
|
||||
db.actionInvokers.storeUserParams id, user.username, JSON.stringify params
|
||||
oFuncArgs = oPayload.action_functions
|
||||
oFuncArgs = oBody.action_functions
|
||||
# if action function arguments were send, store them
|
||||
for id, args of oFuncArgs
|
||||
arr = id.split ' -> '
|
||||
|
|
@ -276,126 +276,133 @@ storeRule = ( user, oPayload, callback ) =>
|
|||
code: 200
|
||||
message: "Rule '#{ rule.id }' stored and activated!"
|
||||
|
||||
|
||||
#
|
||||
# COMMAND FUNCTIONS
|
||||
# =================
|
||||
#
|
||||
# Those are the answers to user requests.
|
||||
|
||||
commandFunctions =
|
||||
get_public_key: ( user, oPayload, callback ) ->
|
||||
get_public_key: ( user, oBody, callback ) ->
|
||||
callback
|
||||
code: 200
|
||||
message: encryption.getPublicKey()
|
||||
|
||||
# EVENT POLLERS
|
||||
# -------------
|
||||
get_event_pollers: ( user, oPayload, callback ) ->
|
||||
getModules user, oPayload, db.eventPollers, callback
|
||||
get_event_pollers: ( user, oBody, callback ) ->
|
||||
getModules user, oBody, db.eventPollers, callback
|
||||
|
||||
get_full_event_poller: ( user, oPayload, callback ) ->
|
||||
db.eventPollers.getModule user.username, oPayload.id, ( err, obj ) ->
|
||||
get_full_event_poller: ( user, oBody, callback ) ->
|
||||
db.eventPollers.getModule user.username, oBody.id, ( err, obj ) ->
|
||||
callback
|
||||
code: 200
|
||||
message: JSON.stringify obj
|
||||
|
||||
get_event_poller_params: ( user, oPayload, callback ) ->
|
||||
getModuleParams user, oPayload, db.eventPollers, callback
|
||||
get_event_poller_params: ( user, oBody, callback ) ->
|
||||
getModuleParams user, oBody, db.eventPollers, callback
|
||||
|
||||
get_event_poller_user_params: ( user, oPayload, callback ) ->
|
||||
getModuleUserParams user, oPayload, db.eventPollers, callback
|
||||
get_event_poller_user_params: ( user, oBody, callback ) ->
|
||||
getModuleUserParams user, oBody, db.eventPollers, callback
|
||||
|
||||
get_event_poller_user_arguments: ( user, oPayload, callback ) ->
|
||||
getModuleUserArguments user, oPayload, db.eventPollers, callback
|
||||
get_event_poller_user_arguments: ( user, oBody, callback ) ->
|
||||
getModuleUserArguments user, oBody, db.eventPollers, callback
|
||||
|
||||
get_event_poller_function_arguments: ( user, oPayload, callback ) ->
|
||||
answ = hasRequiredParams [ 'id' ], oPayload
|
||||
get_event_poller_function_arguments: ( user, oBody, callback ) ->
|
||||
answ = hasRequiredParams [ 'id' ], oBody
|
||||
if answ.code isnt 200
|
||||
callback answ
|
||||
else
|
||||
db.eventPollers.getModuleField user.username, oPayload.id, 'functionArgs', ( err, obj ) ->
|
||||
db.eventPollers.getModuleField user.username, oBody.id, 'functionArgs', ( err, obj ) ->
|
||||
callback
|
||||
code: 200
|
||||
message: obj
|
||||
|
||||
forge_event_poller: ( user, oPayload, callback ) ->
|
||||
forgeModule user, oPayload, "eventpoller", db.eventPollers, callback
|
||||
forge_event_poller: ( user, oBody, callback ) ->
|
||||
forgeModule user, oBody, "eventpoller", db.eventPollers, callback
|
||||
|
||||
delete_event_poller: ( user, oPayload, callback ) ->
|
||||
answ = hasRequiredParams [ 'id' ], oPayload
|
||||
delete_event_poller: ( user, oBody, callback ) ->
|
||||
answ = hasRequiredParams [ 'id' ], oBody
|
||||
if answ.code isnt 200
|
||||
callback answ
|
||||
else
|
||||
db.eventPollers.deleteModule user.username, oPayload.id
|
||||
db.eventPollers.deleteModule user.username, oBody.id
|
||||
callback
|
||||
code: 200
|
||||
message: 'OK!'
|
||||
|
||||
# ACTION INVOKERS
|
||||
# ---------------
|
||||
get_action_invokers: ( user, oPayload, callback ) ->
|
||||
getModules user, oPayload, db.actionInvokers, callback
|
||||
get_action_invokers: ( user, oBody, callback ) ->
|
||||
getModules user, oBody, db.actionInvokers, callback
|
||||
|
||||
get_full_action_invoker: ( user, oPayload, callback ) ->
|
||||
answ = hasRequiredParams [ 'id' ], oPayload
|
||||
get_full_action_invoker: ( user, oBody, callback ) ->
|
||||
answ = hasRequiredParams [ 'id' ], oBody
|
||||
if answ.code isnt 200
|
||||
callback answ
|
||||
else
|
||||
db.actionInvokers.getModule user.username, oPayload.id, ( err, obj ) ->
|
||||
db.actionInvokers.getModule user.username, oBody.id, ( err, obj ) ->
|
||||
callback
|
||||
code: 200
|
||||
message: JSON.stringify obj
|
||||
|
||||
get_action_invoker_params: ( user, oPayload, callback ) ->
|
||||
getModuleParams user, oPayload, db.actionInvokers, callback
|
||||
get_action_invoker_params: ( user, oBody, callback ) ->
|
||||
getModuleParams user, oBody, db.actionInvokers, callback
|
||||
|
||||
get_action_invoker_user_params: ( user, oPayload, callback ) ->
|
||||
getModuleUserParams user, oPayload, db.actionInvokers, callback
|
||||
get_action_invoker_user_params: ( user, oBody, callback ) ->
|
||||
getModuleUserParams user, oBody, db.actionInvokers, callback
|
||||
|
||||
get_action_invoker_user_arguments: ( user, oPayload, callback ) ->
|
||||
getModuleUserArguments user, oPayload, db.actionInvokers, callback
|
||||
get_action_invoker_user_arguments: ( user, oBody, callback ) ->
|
||||
getModuleUserArguments user, oBody, db.actionInvokers, callback
|
||||
|
||||
get_action_invoker_function_arguments: ( user, oPayload, callback ) ->
|
||||
answ = hasRequiredParams [ 'id' ], oPayload
|
||||
get_action_invoker_function_arguments: ( user, oBody, callback ) ->
|
||||
answ = hasRequiredParams [ 'id' ], oBody
|
||||
if answ.code isnt 200
|
||||
callback answ
|
||||
else
|
||||
db.actionInvokers.getModuleField user.username, oPayload.id, 'functionArgs', ( err, obj ) ->
|
||||
db.actionInvokers.getModuleField user.username, oBody.id, 'functionArgs', ( err, obj ) ->
|
||||
callback
|
||||
code: 200
|
||||
message: obj
|
||||
|
||||
forge_action_invoker: ( user, oPayload, callback ) ->
|
||||
forgeModule user, oPayload, "actioninvoker", db.actionInvokers, callback
|
||||
forge_action_invoker: ( user, oBody, callback ) ->
|
||||
forgeModule user, oBody, "actioninvoker", db.actionInvokers, callback
|
||||
|
||||
delete_action_invoker: ( user, oPayload, callback ) ->
|
||||
answ = hasRequiredParams [ 'id' ], oPayload
|
||||
delete_action_invoker: ( user, oBody, callback ) ->
|
||||
answ = hasRequiredParams [ 'id' ], oBody
|
||||
if answ.code isnt 200
|
||||
callback answ
|
||||
else
|
||||
db.actionInvokers.deleteModule user.username, oPayload.id
|
||||
db.actionInvokers.deleteModule user.username, oBody.id
|
||||
callback
|
||||
code: 200
|
||||
message: 'OK!'
|
||||
|
||||
# RULES
|
||||
# -----
|
||||
get_rules: ( user, oPayload, callback ) ->
|
||||
get_rules: ( user, oBody, callback ) ->
|
||||
db.getUserLinkedRules user.username, ( err, obj ) ->
|
||||
callback
|
||||
code: 200
|
||||
message: obj
|
||||
|
||||
get_rule: ( user, oPayload, callback ) ->
|
||||
answ = hasRequiredParams [ 'id' ], oPayload
|
||||
get_rule: ( user, oBody, callback ) ->
|
||||
answ = hasRequiredParams [ 'id' ], oBody
|
||||
if answ.code isnt 200
|
||||
callback answ
|
||||
else
|
||||
db.getRule oPayload.id, ( err, obj ) ->
|
||||
db.getRule oBody.id, ( err, obj ) ->
|
||||
callback
|
||||
code: 200
|
||||
message: obj
|
||||
|
||||
get_rule_log: ( user, oPayload, callback ) ->
|
||||
answ = hasRequiredParams [ 'id' ], oPayload
|
||||
get_rule_log: ( user, oBody, callback ) ->
|
||||
answ = hasRequiredParams [ 'id' ], oBody
|
||||
if answ.code isnt 200
|
||||
callback answ
|
||||
else
|
||||
db.getLog user.username, oPayload.id, ( err, obj ) ->
|
||||
db.getLog user.username, oBody.id, ( err, obj ) ->
|
||||
callback
|
||||
code: 200
|
||||
message: obj
|
||||
|
|
@ -406,33 +413,78 @@ commandFunctions =
|
|||
# - event
|
||||
# - conditions
|
||||
# - actions
|
||||
forge_rule: ( user, oPayload, callback ) ->
|
||||
answ = hasRequiredParams [ 'id', 'event', 'conditions', 'actions' ], oPayload
|
||||
forge_rule: ( user, oBody, callback ) ->
|
||||
answ = hasRequiredParams [ 'id', 'event', 'conditions', 'actions' ], oBody
|
||||
if answ.code isnt 200
|
||||
callback answ
|
||||
else
|
||||
if oPayload.overwrite
|
||||
storeRule user, oPayload, callback
|
||||
if oBody.overwrite
|
||||
storeRule user, oBody, callback
|
||||
else
|
||||
db.getRule oPayload.id, ( err, mod ) =>
|
||||
db.getRule oBody.id, ( err, mod ) =>
|
||||
if mod
|
||||
answ.code = 409
|
||||
answ.message = 'Rule name already existing: ' + oPayload.id
|
||||
answ.message = 'Rule name already existing: ' + oBody.id
|
||||
callback answ
|
||||
else
|
||||
storeRule user, oPayload, callback
|
||||
storeRule user, oBody, callback
|
||||
|
||||
delete_rule: ( user, oPayload, callback ) ->
|
||||
answ = hasRequiredParams [ 'id' ], oPayload
|
||||
delete_rule: ( user, oBody, callback ) ->
|
||||
answ = hasRequiredParams [ 'id' ], oBody
|
||||
if answ.code isnt 200
|
||||
callback answ
|
||||
else
|
||||
db.deleteRule oPayload.id
|
||||
db.deleteRule oBody.id
|
||||
eventEmitter.emit 'rule',
|
||||
event: 'del'
|
||||
user: user.username
|
||||
rule: null
|
||||
ruleId: oPayload.id
|
||||
ruleId: oBody.id
|
||||
callback
|
||||
code: 200
|
||||
message: 'OK!'
|
||||
|
||||
|
||||
create_webhook: ( user, oBody, callback ) ->
|
||||
answ = hasRequiredParams [ 'hookname' ], oBody
|
||||
if answ.code isnt 200
|
||||
callback answ
|
||||
else
|
||||
db.getWebhooks ( err, hooks ) =>
|
||||
if hooks.indexOf oBody.hookname > -1
|
||||
answ.code = 409
|
||||
answ.message = 'Webhook already existing: ' + oBody.hookname
|
||||
callback answ
|
||||
else
|
||||
db.storeWebhook user.username, oBody.hookname
|
||||
callback
|
||||
code: 200
|
||||
message: 'OK!'
|
||||
|
||||
delete_webhook: ( user, oBody, callback ) ->
|
||||
answ = hasRequiredParams [ 'hookname' ], oBody
|
||||
if answ.code isnt 200
|
||||
callback answ
|
||||
else
|
||||
db.getWebhooks ( err, hooks ) =>
|
||||
if hooks.indexOf oBody.hookname is -1
|
||||
answ.code = 409
|
||||
answ.message = 'Webhook does not exist: ' + oBody.hookname
|
||||
callback answ
|
||||
else
|
||||
db.deleteWebhook user.username, oBody.hookname
|
||||
callback
|
||||
code: 200
|
||||
message: 'OK!'
|
||||
|
||||
get_webhooks: ( user, oBody, callback ) ->
|
||||
db.getWebhooks user.username, ( err, data ) ->
|
||||
if err
|
||||
callback
|
||||
code: 400
|
||||
message: "We didn't like your request!"
|
||||
else
|
||||
callback
|
||||
code: 200
|
||||
message: JSON.stringify data
|
||||
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ fPushEvent = ( userId, oRule, modType ) ->
|
|||
db.pushEvent
|
||||
event: oRule.event + '_created:' + oRule.timestamp
|
||||
eventid: "#{ userId }_#{ oRule.event }_UTC|#{ timestamp }_#{ rand }"
|
||||
payload: obj
|
||||
body: obj
|
||||
|
||||
else
|
||||
obj.eventid = "#{ userId }_#{ oRule.event }_UTC|#{ timestamp }_#{ rand }"
|
||||
|
|
|
|||
|
|
@ -188,6 +188,7 @@ oOperators =
|
|||
'>': ( x, y ) -> x > y
|
||||
'>=': ( x, y ) -> x >= y
|
||||
'==': ( x, y ) -> x is y
|
||||
'!=': ( x, y ) -> x isnt y
|
||||
'instr': ( x, y ) -> x.indexOf( y ) > -1
|
||||
|
||||
###
|
||||
|
|
@ -252,12 +253,12 @@ processEvent = ( evt ) =>
|
|||
if arrSelectors
|
||||
for sel in arrSelectors
|
||||
selector = sel.substring 2, sel.length - 1
|
||||
data = jsonQuery( evt.payload, selector ).nodes()[ 0 ]
|
||||
data = jsonQuery( evt.body, selector ).nodes()[ 0 ]
|
||||
argument = argument.replace sel, data
|
||||
if oArg.value is sel
|
||||
argument = data # if the user wants to pass an object, we allow him to do so
|
||||
# if oArg.jsselector
|
||||
arrArgs.push argument #jsonQuery( evt.payload, oArg.value ).nodes()[ 0 ]
|
||||
arrArgs.push argument #jsonQuery( evt.body, oArg.value ).nodes()[ 0 ]
|
||||
# else
|
||||
# arrArgs.push oArg.value
|
||||
else
|
||||
|
|
|
|||
|
|
@ -794,6 +794,37 @@ exports.removeUserRole = ( userId, role ) =>
|
|||
replyHandler "srem 'role:#{ role }:users' -> '#{ userId }'"
|
||||
|
||||
|
||||
###
|
||||
Creates and stores a webhook.
|
||||
|
||||
@public createWebhook( *userId, hookname* )
|
||||
@param {String} userId
|
||||
@param {String} hookname
|
||||
###
|
||||
exports.createWebhook = ( userId, hookname ) =>
|
||||
@db.sadd "user:#{ userId }:webhooks", hookname,
|
||||
replyHandler "sadd 'user:#{ userId }:webhooks' -> '#{ hookname }'"
|
||||
|
||||
###
|
||||
Deletes a webhook.
|
||||
|
||||
@public deleteWebhook( *userId, hookname* )
|
||||
@param {String} userId
|
||||
@param {String} hookname
|
||||
###
|
||||
exports.deleteWebhook = ( userId, hookname ) =>
|
||||
@db.srem "user:#{ userId }:webhooks", hookname,
|
||||
replyHandler "srem 'user:#{ userId }:webhooks' -> '#{ hookname }'"
|
||||
|
||||
###
|
||||
Gets all the users webhooks.
|
||||
|
||||
@public getWebhooks( *userId* )
|
||||
@param {String} userId
|
||||
###
|
||||
exports.getWebhooks = ( userId, cb ) =>
|
||||
@db.smembers "user:#{ userId }:webhooks", cb
|
||||
|
||||
###
|
||||
Shuts down the db link.
|
||||
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ this also allows us to send privately stored modules and rules encrypted to the
|
|||
|
||||
|
||||
\subsubsection{User commands}
|
||||
object that has a command as string and an optional payload as a stringified JSON
|
||||
object that has a command as string and an optional body as a stringified JSON
|
||||
|
||||
|
||||
\bibliography{user-manual}
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ pollUntilDone = ( conversionNumber, email, accountid, infoEvent ) ->
|
|||
if oAnsw.statusCode is '4' or oAnsw.statusCode is '5'
|
||||
pushEvent
|
||||
event: infoEvent
|
||||
payload:
|
||||
body:
|
||||
accountid: accountid
|
||||
downloadUrl: oAnsw.downloadUrl
|
||||
else
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ exports.parseTextToJSON = ( eventname, text ) ->
|
|||
try
|
||||
pushEvent
|
||||
event: eventname
|
||||
payload: JSON.parse text
|
||||
body: JSON.parse text
|
||||
log "Text successfully parsed"
|
||||
catch e
|
||||
log "Error during JSON parsing of #{ text }"
|
||||
|
|
@ -17,7 +17,7 @@ exports.parseTextToJSON = ( eventname, text ) ->
|
|||
exports.parseObjectToPrettyText = ( eventname, obj ) ->
|
||||
pushEvent
|
||||
event: eventname
|
||||
payload: JSON.stringify text, undefined, 2
|
||||
body: JSON.stringify text, undefined, 2
|
||||
|
||||
|
||||
lastSend = null
|
||||
|
|
@ -31,7 +31,7 @@ exports.accumulateEvents = ( evtname, evt, sendTime ) ->
|
|||
lastSend = sTime
|
||||
pushEvent
|
||||
event: evtname
|
||||
payload: arrEvents
|
||||
body: arrEvents
|
||||
arrEvents = []
|
||||
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ fPushEvent = () ->
|
|||
log "Pushing changed interval event"
|
||||
pushEvent
|
||||
event: eventname
|
||||
payload: event
|
||||
body: event
|
||||
setTimeout fPushEvent, interval
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -8,17 +8,19 @@ Required module params:
|
|||
###
|
||||
|
||||
io = new importio params.userGuid, params.apikey, "query.import.io"
|
||||
|
||||
isConnected = false
|
||||
tryToConnect = ( numAttempt, cb ) ->
|
||||
io.connect ( connected ) ->
|
||||
if connected
|
||||
cb true
|
||||
else
|
||||
log "Unable to connect, attempting again... ##{ numAttempt++ }"
|
||||
if numAttempt is 5
|
||||
cb false
|
||||
if not isConnected
|
||||
io.connect ( connected ) ->
|
||||
if connected
|
||||
isConnected = true
|
||||
cb true
|
||||
else
|
||||
tryToConnect numAttempt, cb
|
||||
log "Unable to connect, attempting again... ##{ numAttempt++ }"
|
||||
if numAttempt is 5
|
||||
cb false
|
||||
else
|
||||
tryToConnect numAttempt, cb
|
||||
|
||||
arrPages = [
|
||||
"http://www.meteoblue.com/en/switzerland/weather-basel"
|
||||
|
|
@ -87,7 +89,7 @@ exports.currentData = ( idCity ) ->
|
|||
# Helper function to detect and convert temperatures
|
||||
convertTemperature = ( text ) ->
|
||||
arrStr = text.split '°'
|
||||
if arrStr > 1
|
||||
if arrStr.length > 1
|
||||
val = parseFloat arrStr[ 0 ]
|
||||
if arrStr[ 1 ] is 'F'
|
||||
fahrenheit = val
|
||||
|
|
@ -100,7 +102,7 @@ convertTemperature = ( text ) ->
|
|||
|
||||
celsius: celsius
|
||||
fahrenheit: fahrenheit
|
||||
kelvin: celsius - 273.15
|
||||
kelvin: celsius + 273.15
|
||||
|
||||
|
||||
# idCity, the city identifier corresponding to the arrPages array
|
||||
|
|
@ -121,9 +123,12 @@ exports.tempOverThreshold = ( tempUnit, tempThreshold, idCity ) ->
|
|||
connectorGuids: [ "06394265-b4e1-4b48-be82-a9f2acb9040f" ]
|
||||
queryService params, ( data ) ->
|
||||
oTemp = convertTemperature data[ 0 ].current_temp
|
||||
switch tempUnit
|
||||
when "K" then val = oTemp.kelvin
|
||||
when "F" then val = oTemp.fahrenheit
|
||||
else val = oTemp.celsius
|
||||
if val > parseFloat tempThreshold
|
||||
pushEvent oTemp
|
||||
if oTemp
|
||||
switch tempUnit
|
||||
when "K" then val = oTemp.kelvin
|
||||
when "F" then val = oTemp.fahrenheit
|
||||
else val = oTemp.celsius
|
||||
if val > parseFloat tempThreshold
|
||||
pushEvent oTemp
|
||||
else
|
||||
log "Can't grab temperature from #{ data[ 0 ].current_temp }"
|
||||
|
|
@ -5,16 +5,23 @@ ping = require 'net-ping'
|
|||
needle = require 'needle'
|
||||
|
||||
|
||||
# remoteUrl = "localhost:8125"
|
||||
remoteUrl = "http://ec2-54-226-188-9.compute-1.amazonaws.com:8126"
|
||||
fPushEvent = ( evt ) ->
|
||||
needle.post remoteUrl + '/webhooks/uptimestatistics', JSON.stringify( evt ), ( err, resp, body ) ->
|
||||
if err or resp.statusCode isnt 200
|
||||
console.log 'Error in pushing event!'
|
||||
else
|
||||
console.log 'Successfully posted an event'
|
||||
|
||||
try
|
||||
arrHosts = JSON.parse fs.readFileSync 'hostlist.json', 'utf8'
|
||||
# arrHosts = JSON.parse fs.readFileSync 'hostlist.json', 'utf8'
|
||||
histData = JSON.parse fs.readFileSync 'histochart.json', 'utf8'
|
||||
catch err
|
||||
console.error err
|
||||
console.error "Error reading host list file"
|
||||
console.error "Error reading historical data file"
|
||||
process.exit()
|
||||
|
||||
remoteUrl = "http://ec2-54-226-188-9.compute-1.amazonaws.com:8126"
|
||||
# remoteUrl = "localhost:8125"
|
||||
|
||||
# console.log arrHosts
|
||||
# libnmap.nmap 'scan',
|
||||
|
|
@ -26,45 +33,68 @@ remoteUrl = "http://ec2-54-226-188-9.compute-1.amazonaws.com:8126"
|
|||
# report.forEach ( item ) ->
|
||||
# console.log item[ 0 ]
|
||||
|
||||
session = ping.createSession retries: 5
|
||||
session = ping.createSession retries: 2
|
||||
everyMins = 10
|
||||
oHosts = {}
|
||||
oPings = {}
|
||||
i = -1
|
||||
if histData
|
||||
oHosts = histData.hosts
|
||||
oPings = histData.pingtimes
|
||||
pingTime = (new Date()).toISOString()
|
||||
oPings[ pingTime ] = ips: []
|
||||
fPollHosts = () ->
|
||||
semaphore = arrHosts.length
|
||||
pingTime = (new Date()).toISOString()
|
||||
oPings[ pingTime ] = ips: []
|
||||
for host in arrHosts
|
||||
session.pingHost host, ( err, target, sent, rcvd ) ->
|
||||
if not err
|
||||
if not oHosts[ target ]
|
||||
oHosts[ target ] = {}
|
||||
oHosts[ target ][ pingTime ] = (new Date( rcvd - sent )).getTime()
|
||||
oPings[ pingTime ].ips.push target
|
||||
i++
|
||||
console.log "Pinging 131.152.85.#{ i }"
|
||||
session.pingHost "131.152.85.#{ i }", ( err, target, sent, rcvd ) ->
|
||||
if not err
|
||||
if not oHosts[ target ]
|
||||
oHosts[ target ] = {}
|
||||
oHosts[ target ][ pingTime ] = (new Date( rcvd - sent )).getTime()
|
||||
oPings[ pingTime ].ips.push target
|
||||
|
||||
if i is 255
|
||||
i = -1
|
||||
console.log 'All ping requests returned, pushing event into the system and starting again at 0'
|
||||
oPings[ pingTime ].sum = oPings[ pingTime ].ips.length
|
||||
evt =
|
||||
currentlyon: oPings[ pingTime ].ips.length
|
||||
pingtimes: oPings
|
||||
hosts: oHosts
|
||||
fPushEvent evt
|
||||
fs.writeFile 'histochart.json', JSON.stringify( evt, undefined, 2 ), 'utf8'
|
||||
pingTime = (new Date()).toISOString()
|
||||
oPings[ pingTime ] = ips: []
|
||||
|
||||
if --semaphore is 0
|
||||
console.log 'All ping requests returned, pushing event into the system'
|
||||
oPings[ pingTime ].sum = oPings[ pingTime ].ips.length
|
||||
evt =
|
||||
currentlyon: oPings[ pingTime ].ips.length
|
||||
pingtimes: oPings
|
||||
hosts: oHosts
|
||||
fPushEvent evt
|
||||
fs.writeFile 'histochart.json', JSON.stringify( evt, undefined, 2 ), 'utf8'
|
||||
|
||||
console.log "Pinging again in #{ everyMins } minutes"
|
||||
setTimeout fPollHosts, everyMins * 60 * 1000
|
||||
setTimeout fPollHosts, 7000
|
||||
|
||||
|
||||
fPollHosts()
|
||||
|
||||
# Some pings eventually get blocked if you ping 255 IPs within one second...
|
||||
#
|
||||
# fPollHosts = () ->
|
||||
# semaphore = arrHosts.length
|
||||
# pingTime = (new Date()).toISOString()
|
||||
# oPings[ pingTime ] = ips: []
|
||||
# for host in arrHosts
|
||||
# session.pingHost host, ( err, target, sent, rcvd ) ->
|
||||
# if not err
|
||||
# if not oHosts[ target ]
|
||||
# oHosts[ target ] = {}
|
||||
# oHosts[ target ][ pingTime ] = (new Date( rcvd - sent )).getTime()
|
||||
# oPings[ pingTime ].ips.push target
|
||||
|
||||
fPushEvent = ( evt ) ->
|
||||
needle.post remoteUrl + '/webhooks/uptimestatistics', JSON.stringify( evt ), ( err, resp, body ) ->
|
||||
if err or resp.statusCode isnt 200
|
||||
console.log 'Error in pushing event!'
|
||||
else
|
||||
console.log 'Successfully posted an event'
|
||||
# if --semaphore is 0
|
||||
# console.log 'All ping requests returned, pushing event into the system'
|
||||
# oPings[ pingTime ].sum = oPings[ pingTime ].ips.length
|
||||
# evt =
|
||||
# currentlyon: oPings[ pingTime ].ips.length
|
||||
# pingtimes: oPings
|
||||
# hosts: oHosts
|
||||
# fPushEvent evt
|
||||
# fs.writeFile 'histochart.json', JSON.stringify( evt, undefined, 2 ), 'utf8'
|
||||
|
||||
# console.log "Pinging again in #{ everyMins } minutes"
|
||||
# setTimeout fPollHosts, everyMins * 60 * 1000
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ Components Manager
|
|||
- `oReq` is the request object that contains:
|
||||
|
||||
- `command` as a string
|
||||
- `payload` an optional stringified JSON object
|
||||
- `body` an optional stringified JSON object
|
||||
The callback function `callback( obj )` will receive an object
|
||||
containing the HTTP response code and a corresponding message.
|
||||
|
||||
|
|
@ -117,16 +117,16 @@ Components Manager
|
|||
|
||||
exports.processRequest = function(user, oReq, callback) {
|
||||
var dat, err;
|
||||
if (!oReq.payload) {
|
||||
oReq.payload = '{}';
|
||||
if (!oReq.body) {
|
||||
oReq.body = '{}';
|
||||
}
|
||||
try {
|
||||
dat = JSON.parse(oReq.payload);
|
||||
dat = JSON.parse(oReq.body);
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
return callback({
|
||||
code: 404,
|
||||
message: 'You had a strange payload in your request!'
|
||||
message: 'You had a strange body in your request!'
|
||||
});
|
||||
}
|
||||
if (commandFunctions[oReq.command]) {
|
||||
|
|
@ -141,14 +141,14 @@ Components Manager
|
|||
|
||||
|
||||
/*
|
||||
Checks whether all required parameters are present in the payload.
|
||||
Checks whether all required parameters are present in the body.
|
||||
|
||||
@private hasRequiredParams ( *arrParams, oPayload* )
|
||||
@private hasRequiredParams ( *arrParams, oBody* )
|
||||
@param {Array} arrParams
|
||||
@param {Object} oPayload
|
||||
@param {Object} oBody
|
||||
*/
|
||||
|
||||
hasRequiredParams = function(arrParams, oPayload) {
|
||||
hasRequiredParams = function(arrParams, oBody) {
|
||||
var answ, param, _i, _len;
|
||||
answ = {
|
||||
code: 400,
|
||||
|
|
@ -156,7 +156,7 @@ Components Manager
|
|||
};
|
||||
for (_i = 0, _len = arrParams.length; _i < _len; _i++) {
|
||||
param = arrParams[_i];
|
||||
if (!oPayload[param]) {
|
||||
if (!oBody[param]) {
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
|
|
@ -169,14 +169,14 @@ Components Manager
|
|||
/*
|
||||
Fetches all available modules and return them together with the available functions.
|
||||
|
||||
@private getModules ( *user, oPayload, dbMod, callback* )
|
||||
@private getModules ( *user, oBody, dbMod, callback* )
|
||||
@param {Object} user
|
||||
@param {Object} oPayload
|
||||
@param {Object} oBody
|
||||
@param {Object} dbMod
|
||||
@param {function} callback
|
||||
*/
|
||||
|
||||
getModules = function(user, oPayload, dbMod, callback) {
|
||||
getModules = function(user, oBody, dbMod, callback) {
|
||||
var fProcessIds;
|
||||
fProcessIds = function(userName) {
|
||||
return function(err, arrNames) {
|
||||
|
|
@ -216,26 +216,26 @@ Components Manager
|
|||
return dbMod.getAvailableModuleIds(user.username, fProcessIds(user.username));
|
||||
};
|
||||
|
||||
getModuleParams = function(user, oPayload, dbMod, callback) {
|
||||
getModuleParams = function(user, oBody, dbMod, callback) {
|
||||
var answ;
|
||||
answ = hasRequiredParams(['id'], oPayload);
|
||||
answ = hasRequiredParams(['id'], oBody);
|
||||
if (answ.code !== 200) {
|
||||
return callback(answ);
|
||||
} else {
|
||||
return dbMod.getModuleField(user.username, oPayload.id, "params", function(err, oPayload) {
|
||||
answ.message = oPayload;
|
||||
return dbMod.getModuleField(user.username, oBody.id, "params", function(err, oBody) {
|
||||
answ.message = oBody;
|
||||
return callback(answ);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
getModuleUserParams = function(user, oPayload, dbMod, callback) {
|
||||
getModuleUserParams = function(user, oBody, dbMod, callback) {
|
||||
var answ;
|
||||
answ = hasRequiredParams(['id'], oPayload);
|
||||
answ = hasRequiredParams(['id'], oBody);
|
||||
if (answ.code !== 200) {
|
||||
return callback(answ);
|
||||
} else {
|
||||
return dbMod.getUserParams(oPayload.id, user.username, function(err, str) {
|
||||
return dbMod.getUserParams(oBody.id, user.username, function(err, str) {
|
||||
var name, oParam, oParams;
|
||||
oParams = JSON.parse(str);
|
||||
for (name in oParams) {
|
||||
|
|
@ -250,36 +250,36 @@ Components Manager
|
|||
}
|
||||
};
|
||||
|
||||
getModuleUserArguments = function(user, oPayload, dbMod, callback) {
|
||||
getModuleUserArguments = function(user, oBody, dbMod, callback) {
|
||||
var answ;
|
||||
answ = hasRequiredParams(['ruleId', 'moduleId'], oPayload);
|
||||
answ = hasRequiredParams(['ruleId', 'moduleId'], oBody);
|
||||
if (answ.code !== 200) {
|
||||
return callback(answ);
|
||||
} else {
|
||||
return dbMod.getAllModuleUserArguments(user.username, oPayload.ruleId, oPayload.moduleId, function(err, oPayload) {
|
||||
answ.message = oPayload;
|
||||
return dbMod.getAllModuleUserArguments(user.username, oBody.ruleId, oBody.moduleId, function(err, oBody) {
|
||||
answ.message = oBody;
|
||||
return callback(answ);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
forgeModule = (function(_this) {
|
||||
return function(user, oPayload, modType, dbMod, callback) {
|
||||
return function(user, oBody, modType, dbMod, callback) {
|
||||
var answ;
|
||||
answ = hasRequiredParams(['id', 'params', 'lang', 'data'], oPayload);
|
||||
answ = hasRequiredParams(['id', 'params', 'lang', 'data'], oBody);
|
||||
if (answ.code !== 200) {
|
||||
return callback(answ);
|
||||
} else {
|
||||
if (oPayload.overwrite) {
|
||||
return storeModule(user, oPayload, modType, dbMod, callback);
|
||||
if (oBody.overwrite) {
|
||||
return storeModule(user, oBody, modType, dbMod, callback);
|
||||
} else {
|
||||
return dbMod.getModule(user.username, oPayload.id, function(err, mod) {
|
||||
return dbMod.getModule(user.username, oBody.id, function(err, mod) {
|
||||
if (mod) {
|
||||
answ.code = 409;
|
||||
answ.message = 'Module name already existing: ' + oPayload.id;
|
||||
answ.message = 'Module name already existing: ' + oBody.id;
|
||||
return callback(answ);
|
||||
} else {
|
||||
return storeModule(user, oPayload, modType, dbMod, callback);
|
||||
return storeModule(user, oBody, modType, dbMod, callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -288,12 +288,12 @@ Components Manager
|
|||
})(this);
|
||||
|
||||
storeModule = (function(_this) {
|
||||
return function(user, oPayload, modType, dbMod, callback) {
|
||||
return function(user, oBody, modType, dbMod, callback) {
|
||||
var src;
|
||||
src = oPayload.data;
|
||||
src = oBody.data;
|
||||
return dynmod.compileString(src, user.username, {
|
||||
id: 'dummyRule'
|
||||
}, oPayload.id, oPayload.lang, modType, null, function(cm) {
|
||||
}, oBody.id, oBody.lang, modType, null, function(cm) {
|
||||
var answ, funcs, id, name, _ref;
|
||||
answ = cm.answ;
|
||||
if (answ.code === 200) {
|
||||
|
|
@ -304,10 +304,10 @@ Components Manager
|
|||
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);
|
||||
answ.message = " Module " + oBody.id + " successfully stored! Found following function(s): " + funcs;
|
||||
oBody.functions = JSON.stringify(funcs);
|
||||
oBody.functionArgs = JSON.stringify(cm.funcParams);
|
||||
dbMod.storeModule(user.username, oBody);
|
||||
}
|
||||
return callback(answ);
|
||||
});
|
||||
|
|
@ -315,39 +315,39 @@ Components Manager
|
|||
})(this);
|
||||
|
||||
storeRule = (function(_this) {
|
||||
return function(user, oPayload, callback) {
|
||||
return function(user, oBody, callback) {
|
||||
var args, arr, epModId, eventInfo, id, oFuncArgs, oParams, params, rule, strRule;
|
||||
rule = {
|
||||
id: oPayload.id,
|
||||
event: oPayload.event,
|
||||
event_start: oPayload.event_start,
|
||||
event_interval: oPayload.event_interval,
|
||||
conditions: oPayload.conditions,
|
||||
actions: oPayload.actions
|
||||
id: oBody.id,
|
||||
event: oBody.event,
|
||||
event_start: oBody.event_start,
|
||||
event_interval: oBody.event_interval,
|
||||
conditions: oBody.conditions,
|
||||
actions: oBody.actions
|
||||
};
|
||||
if (oPayload.event_start) {
|
||||
if (oBody.event_start) {
|
||||
rule.timestamp = (new Date()).toISOString();
|
||||
}
|
||||
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) {
|
||||
if (oBody.event_params) {
|
||||
epModId = rule.event.split(' -> ')[0];
|
||||
db.eventPollers.storeUserParams(epModId, user.username, JSON.stringify(oPayload.event_params));
|
||||
db.eventPollers.storeUserParams(epModId, user.username, JSON.stringify(oBody.event_params));
|
||||
}
|
||||
oFuncArgs = oPayload.event_functions;
|
||||
oFuncArgs = oBody.event_functions;
|
||||
for (id in oFuncArgs) {
|
||||
args = oFuncArgs[id];
|
||||
arr = id.split(' -> ');
|
||||
db.eventPollers.storeUserArguments(user.username, rule.id, arr[0], arr[1], JSON.stringify(args));
|
||||
}
|
||||
oParams = oPayload.action_params;
|
||||
oParams = oBody.action_params;
|
||||
for (id in oParams) {
|
||||
params = oParams[id];
|
||||
db.actionInvokers.storeUserParams(id, user.username, JSON.stringify(params));
|
||||
}
|
||||
oFuncArgs = oPayload.action_functions;
|
||||
oFuncArgs = oBody.action_functions;
|
||||
for (id in oFuncArgs) {
|
||||
args = oFuncArgs[id];
|
||||
arr = id.split(' -> ');
|
||||
|
|
@ -372,39 +372,39 @@ Components Manager
|
|||
})(this);
|
||||
|
||||
commandFunctions = {
|
||||
get_public_key: function(user, oPayload, callback) {
|
||||
get_public_key: function(user, oBody, callback) {
|
||||
return callback({
|
||||
code: 200,
|
||||
message: encryption.getPublicKey()
|
||||
});
|
||||
},
|
||||
get_event_pollers: function(user, oPayload, callback) {
|
||||
return getModules(user, oPayload, db.eventPollers, callback);
|
||||
get_event_pollers: function(user, oBody, callback) {
|
||||
return getModules(user, oBody, db.eventPollers, callback);
|
||||
},
|
||||
get_full_event_poller: function(user, oPayload, callback) {
|
||||
return db.eventPollers.getModule(user.username, oPayload.id, function(err, obj) {
|
||||
get_full_event_poller: function(user, oBody, callback) {
|
||||
return db.eventPollers.getModule(user.username, oBody.id, function(err, obj) {
|
||||
return callback({
|
||||
code: 200,
|
||||
message: JSON.stringify(obj)
|
||||
});
|
||||
});
|
||||
},
|
||||
get_event_poller_params: function(user, oPayload, callback) {
|
||||
return getModuleParams(user, oPayload, db.eventPollers, callback);
|
||||
get_event_poller_params: function(user, oBody, callback) {
|
||||
return getModuleParams(user, oBody, db.eventPollers, callback);
|
||||
},
|
||||
get_event_poller_user_params: function(user, oPayload, callback) {
|
||||
return getModuleUserParams(user, oPayload, db.eventPollers, callback);
|
||||
get_event_poller_user_params: function(user, oBody, callback) {
|
||||
return getModuleUserParams(user, oBody, db.eventPollers, callback);
|
||||
},
|
||||
get_event_poller_user_arguments: function(user, oPayload, callback) {
|
||||
return getModuleUserArguments(user, oPayload, db.eventPollers, callback);
|
||||
get_event_poller_user_arguments: function(user, oBody, callback) {
|
||||
return getModuleUserArguments(user, oBody, db.eventPollers, callback);
|
||||
},
|
||||
get_event_poller_function_arguments: function(user, oPayload, callback) {
|
||||
get_event_poller_function_arguments: function(user, oBody, callback) {
|
||||
var answ;
|
||||
answ = hasRequiredParams(['id'], oPayload);
|
||||
answ = hasRequiredParams(['id'], oBody);
|
||||
if (answ.code !== 200) {
|
||||
return callback(answ);
|
||||
} else {
|
||||
return db.eventPollers.getModuleField(user.username, oPayload.id, 'functionArgs', function(err, obj) {
|
||||
return db.eventPollers.getModuleField(user.username, oBody.id, 'functionArgs', function(err, obj) {
|
||||
return callback({
|
||||
code: 200,
|
||||
message: obj
|
||||
|
|
@ -412,32 +412,32 @@ Components Manager
|
|||
});
|
||||
}
|
||||
},
|
||||
forge_event_poller: function(user, oPayload, callback) {
|
||||
return forgeModule(user, oPayload, "eventpoller", db.eventPollers, callback);
|
||||
forge_event_poller: function(user, oBody, callback) {
|
||||
return forgeModule(user, oBody, "eventpoller", db.eventPollers, callback);
|
||||
},
|
||||
delete_event_poller: function(user, oPayload, callback) {
|
||||
delete_event_poller: function(user, oBody, callback) {
|
||||
var answ;
|
||||
answ = hasRequiredParams(['id'], oPayload);
|
||||
answ = hasRequiredParams(['id'], oBody);
|
||||
if (answ.code !== 200) {
|
||||
return callback(answ);
|
||||
} else {
|
||||
db.eventPollers.deleteModule(user.username, oPayload.id);
|
||||
db.eventPollers.deleteModule(user.username, oBody.id);
|
||||
return callback({
|
||||
code: 200,
|
||||
message: 'OK!'
|
||||
});
|
||||
}
|
||||
},
|
||||
get_action_invokers: function(user, oPayload, callback) {
|
||||
return getModules(user, oPayload, db.actionInvokers, callback);
|
||||
get_action_invokers: function(user, oBody, callback) {
|
||||
return getModules(user, oBody, db.actionInvokers, callback);
|
||||
},
|
||||
get_full_action_invoker: function(user, oPayload, callback) {
|
||||
get_full_action_invoker: function(user, oBody, callback) {
|
||||
var answ;
|
||||
answ = hasRequiredParams(['id'], oPayload);
|
||||
answ = hasRequiredParams(['id'], oBody);
|
||||
if (answ.code !== 200) {
|
||||
return callback(answ);
|
||||
} else {
|
||||
return db.actionInvokers.getModule(user.username, oPayload.id, function(err, obj) {
|
||||
return db.actionInvokers.getModule(user.username, oBody.id, function(err, obj) {
|
||||
return callback({
|
||||
code: 200,
|
||||
message: JSON.stringify(obj)
|
||||
|
|
@ -445,22 +445,22 @@ Components Manager
|
|||
});
|
||||
}
|
||||
},
|
||||
get_action_invoker_params: function(user, oPayload, callback) {
|
||||
return getModuleParams(user, oPayload, db.actionInvokers, callback);
|
||||
get_action_invoker_params: function(user, oBody, callback) {
|
||||
return getModuleParams(user, oBody, db.actionInvokers, callback);
|
||||
},
|
||||
get_action_invoker_user_params: function(user, oPayload, callback) {
|
||||
return getModuleUserParams(user, oPayload, db.actionInvokers, callback);
|
||||
get_action_invoker_user_params: function(user, oBody, callback) {
|
||||
return getModuleUserParams(user, oBody, db.actionInvokers, callback);
|
||||
},
|
||||
get_action_invoker_user_arguments: function(user, oPayload, callback) {
|
||||
return getModuleUserArguments(user, oPayload, db.actionInvokers, callback);
|
||||
get_action_invoker_user_arguments: function(user, oBody, callback) {
|
||||
return getModuleUserArguments(user, oBody, db.actionInvokers, callback);
|
||||
},
|
||||
get_action_invoker_function_arguments: function(user, oPayload, callback) {
|
||||
get_action_invoker_function_arguments: function(user, oBody, callback) {
|
||||
var answ;
|
||||
answ = hasRequiredParams(['id'], oPayload);
|
||||
answ = hasRequiredParams(['id'], oBody);
|
||||
if (answ.code !== 200) {
|
||||
return callback(answ);
|
||||
} else {
|
||||
return db.actionInvokers.getModuleField(user.username, oPayload.id, 'functionArgs', function(err, obj) {
|
||||
return db.actionInvokers.getModuleField(user.username, oBody.id, 'functionArgs', function(err, obj) {
|
||||
return callback({
|
||||
code: 200,
|
||||
message: obj
|
||||
|
|
@ -468,23 +468,23 @@ Components Manager
|
|||
});
|
||||
}
|
||||
},
|
||||
forge_action_invoker: function(user, oPayload, callback) {
|
||||
return forgeModule(user, oPayload, "actioninvoker", db.actionInvokers, callback);
|
||||
forge_action_invoker: function(user, oBody, callback) {
|
||||
return forgeModule(user, oBody, "actioninvoker", db.actionInvokers, callback);
|
||||
},
|
||||
delete_action_invoker: function(user, oPayload, callback) {
|
||||
delete_action_invoker: function(user, oBody, callback) {
|
||||
var answ;
|
||||
answ = hasRequiredParams(['id'], oPayload);
|
||||
answ = hasRequiredParams(['id'], oBody);
|
||||
if (answ.code !== 200) {
|
||||
return callback(answ);
|
||||
} else {
|
||||
db.actionInvokers.deleteModule(user.username, oPayload.id);
|
||||
db.actionInvokers.deleteModule(user.username, oBody.id);
|
||||
return callback({
|
||||
code: 200,
|
||||
message: 'OK!'
|
||||
});
|
||||
}
|
||||
},
|
||||
get_rules: function(user, oPayload, callback) {
|
||||
get_rules: function(user, oBody, callback) {
|
||||
return db.getUserLinkedRules(user.username, function(err, obj) {
|
||||
return callback({
|
||||
code: 200,
|
||||
|
|
@ -492,13 +492,13 @@ Components Manager
|
|||
});
|
||||
});
|
||||
},
|
||||
get_rule: function(user, oPayload, callback) {
|
||||
get_rule: function(user, oBody, callback) {
|
||||
var answ;
|
||||
answ = hasRequiredParams(['id'], oPayload);
|
||||
answ = hasRequiredParams(['id'], oBody);
|
||||
if (answ.code !== 200) {
|
||||
return callback(answ);
|
||||
} else {
|
||||
return db.getRule(oPayload.id, function(err, obj) {
|
||||
return db.getRule(oBody.id, function(err, obj) {
|
||||
return callback({
|
||||
code: 200,
|
||||
message: obj
|
||||
|
|
@ -506,13 +506,13 @@ Components Manager
|
|||
});
|
||||
}
|
||||
},
|
||||
get_rule_log: function(user, oPayload, callback) {
|
||||
get_rule_log: function(user, oBody, callback) {
|
||||
var answ;
|
||||
answ = hasRequiredParams(['id'], oPayload);
|
||||
answ = hasRequiredParams(['id'], oBody);
|
||||
if (answ.code !== 200) {
|
||||
return callback(answ);
|
||||
} else {
|
||||
return db.getLog(user.username, oPayload.id, function(err, obj) {
|
||||
return db.getLog(user.username, oBody.id, function(err, obj) {
|
||||
return callback({
|
||||
code: 200,
|
||||
message: obj
|
||||
|
|
@ -520,47 +520,108 @@ Components Manager
|
|||
});
|
||||
}
|
||||
},
|
||||
forge_rule: function(user, oPayload, callback) {
|
||||
forge_rule: function(user, oBody, callback) {
|
||||
var answ;
|
||||
answ = hasRequiredParams(['id', 'event', 'conditions', 'actions'], oPayload);
|
||||
answ = hasRequiredParams(['id', 'event', 'conditions', 'actions'], oBody);
|
||||
if (answ.code !== 200) {
|
||||
return callback(answ);
|
||||
} else {
|
||||
if (oPayload.overwrite) {
|
||||
return storeRule(user, oPayload, callback);
|
||||
if (oBody.overwrite) {
|
||||
return storeRule(user, oBody, callback);
|
||||
} else {
|
||||
return db.getRule(oPayload.id, (function(_this) {
|
||||
return db.getRule(oBody.id, (function(_this) {
|
||||
return function(err, mod) {
|
||||
if (mod) {
|
||||
answ.code = 409;
|
||||
answ.message = 'Rule name already existing: ' + oPayload.id;
|
||||
answ.message = 'Rule name already existing: ' + oBody.id;
|
||||
return callback(answ);
|
||||
} else {
|
||||
return storeRule(user, oPayload, callback);
|
||||
return storeRule(user, oBody, callback);
|
||||
}
|
||||
};
|
||||
})(this));
|
||||
}
|
||||
}
|
||||
},
|
||||
delete_rule: function(user, oPayload, callback) {
|
||||
delete_rule: function(user, oBody, callback) {
|
||||
var answ;
|
||||
answ = hasRequiredParams(['id'], oPayload);
|
||||
answ = hasRequiredParams(['id'], oBody);
|
||||
if (answ.code !== 200) {
|
||||
return callback(answ);
|
||||
} else {
|
||||
db.deleteRule(oPayload.id);
|
||||
db.deleteRule(oBody.id);
|
||||
eventEmitter.emit('rule', {
|
||||
event: 'del',
|
||||
user: user.username,
|
||||
rule: null,
|
||||
ruleId: oPayload.id
|
||||
ruleId: oBody.id
|
||||
});
|
||||
return callback({
|
||||
code: 200,
|
||||
message: 'OK!'
|
||||
});
|
||||
}
|
||||
},
|
||||
create_webhook: function(user, oBody, callback) {
|
||||
var answ;
|
||||
answ = hasRequiredParams(['hookname'], oBody);
|
||||
if (answ.code !== 200) {
|
||||
return callback(answ);
|
||||
} else {
|
||||
return db.getWebhooks((function(_this) {
|
||||
return function(err, hooks) {
|
||||
if (hooks.indexOf(oBody.hookname > -1)) {
|
||||
answ.code = 409;
|
||||
answ.message = 'Webhook already existing: ' + oBody.hookname;
|
||||
return callback(answ);
|
||||
} else {
|
||||
db.storeWebhook(user.username, oBody.hookname);
|
||||
return callback({
|
||||
code: 200,
|
||||
message: 'OK!'
|
||||
});
|
||||
}
|
||||
};
|
||||
})(this));
|
||||
}
|
||||
},
|
||||
delete_webhook: function(user, oBody, callback) {
|
||||
var answ;
|
||||
answ = hasRequiredParams(['hookname'], oBody);
|
||||
if (answ.code !== 200) {
|
||||
return callback(answ);
|
||||
} else {
|
||||
return db.getWebhooks((function(_this) {
|
||||
return function(err, hooks) {
|
||||
if (hooks.indexOf(oBody.hookname === -1)) {
|
||||
answ.code = 409;
|
||||
answ.message = 'Webhook does not exist: ' + oBody.hookname;
|
||||
return callback(answ);
|
||||
} else {
|
||||
db.deleteWebhook(user.username, oBody.hookname);
|
||||
return callback({
|
||||
code: 200,
|
||||
message: 'OK!'
|
||||
});
|
||||
}
|
||||
};
|
||||
})(this));
|
||||
}
|
||||
},
|
||||
get_webhooks: function(user, oBody, callback) {
|
||||
return db.getWebhooks(user.username, function(err, data) {
|
||||
if (err) {
|
||||
return callback({
|
||||
code: 400,
|
||||
message: "We didn't like your request!"
|
||||
});
|
||||
} else {
|
||||
return callback({
|
||||
code: 200,
|
||||
message: JSON.stringify(data)
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ Dynamic Modules
|
|||
return db.pushEvent({
|
||||
event: oRule.event + '_created:' + oRule.timestamp,
|
||||
eventid: "" + userId + "_" + oRule.event + "_UTC|" + timestamp + "_" + rand,
|
||||
payload: obj
|
||||
body: obj
|
||||
});
|
||||
} else {
|
||||
obj.eventid = "" + userId + "_" + oRule.event + "_UTC|" + timestamp + "_" + rand;
|
||||
|
|
|
|||
|
|
@ -235,6 +235,9 @@ Engine
|
|||
'==': function(x, y) {
|
||||
return x === y;
|
||||
},
|
||||
'!=': function(x, y) {
|
||||
return x !== y;
|
||||
},
|
||||
'instr': function(x, y) {
|
||||
return x.indexOf(y) > -1;
|
||||
}
|
||||
|
|
@ -318,7 +321,7 @@ Engine
|
|||
for (_j = 0, _len1 = arrSelectors.length; _j < _len1; _j++) {
|
||||
sel = arrSelectors[_j];
|
||||
selector = sel.substring(2, sel.length - 1);
|
||||
data = jsonQuery(evt.payload, selector).nodes()[0];
|
||||
data = jsonQuery(evt.body, selector).nodes()[0];
|
||||
argument = argument.replace(sel, data);
|
||||
if (oArg.value === sel) {
|
||||
argument = data;
|
||||
|
|
|
|||
|
|
@ -1035,6 +1035,50 @@ Persistence
|
|||
})(this);
|
||||
|
||||
|
||||
/*
|
||||
Creates and stores a webhook.
|
||||
|
||||
@public createWebhook( *userId, hookname* )
|
||||
@param {String} userId
|
||||
@param {String} hookname
|
||||
*/
|
||||
|
||||
exports.createWebhook = (function(_this) {
|
||||
return function(userId, hookname) {
|
||||
return _this.db.sadd("user:" + userId + ":webhooks", hookname, replyHandler("sadd 'user:" + userId + ":webhooks' -> '" + hookname + "'"));
|
||||
};
|
||||
})(this);
|
||||
|
||||
|
||||
/*
|
||||
Deletes a webhook.
|
||||
|
||||
@public deleteWebhook( *userId, hookname* )
|
||||
@param {String} userId
|
||||
@param {String} hookname
|
||||
*/
|
||||
|
||||
exports.deleteWebhook = (function(_this) {
|
||||
return function(userId, hookname) {
|
||||
return _this.db.srem("user:" + userId + ":webhooks", hookname, replyHandler("srem 'user:" + userId + ":webhooks' -> '" + hookname + "'"));
|
||||
};
|
||||
})(this);
|
||||
|
||||
|
||||
/*
|
||||
Gets all the users webhooks.
|
||||
|
||||
@public getWebhooks( *userId* )
|
||||
@param {String} userId
|
||||
*/
|
||||
|
||||
exports.getWebhooks = (function(_this) {
|
||||
return function(userId, cb) {
|
||||
return _this.db.smembers("user:" + userId + ":webhooks", cb);
|
||||
};
|
||||
})(this);
|
||||
|
||||
|
||||
/*
|
||||
Shuts down the db link.
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
"aiTwo": {
|
||||
"id":"aiTwo",
|
||||
"lang":"CoffeeScript",
|
||||
"data":"# Send a mail through emailyak\nexports.otherEvent = ( evt ) ->\n\turl = 'https://api.emailyak.com/v1/' + params.apikey + '/json/send/email/'\n\tpayload =\n\t FromAddress : \"testsender@mscliveweb.simpleyak.com\",\n\t ToAddress: \"dominic.bosch@gmail.com\",\n\t Subject: \"TestMAIL\",\n\t TextBody: \"Hello\"\n\t\n\tneedle.post url, payload, ( err, resp, body ) ->\n\t\tif err\n\t\t\tlog err\n\t\tif resp.statusCode isnt 200\n\t\t\tlog 'Request not successful:'\n\t\t\tlog body\n",
|
||||
"data":"# Send a mail through emailyak\nexports.otherEvent = ( evt ) ->\n\turl = 'https://api.emailyak.com/v1/' + params.apikey + '/json/send/email/'\n\tbody =\n\t FromAddress : \"testsender@mscliveweb.simpleyak.com\",\n\t ToAddress: \"dominic.bosch@gmail.com\",\n\t Subject: \"TestMAIL\",\n\t TextBody: \"Hello\"\n\t\n\tneedle.post url, body, ( err, resp, body ) ->\n\t\tif err\n\t\t\tlog err\n\t\tif resp.statusCode isnt 200\n\t\t\tlog 'Request not successful:'\n\t\t\tlog body\n",
|
||||
"public":"false",
|
||||
"params":"[\"apikey\",\"andmore\"]",
|
||||
"functions":"[\"otherEvent\"]",
|
||||
|
|
@ -56,7 +56,7 @@
|
|||
"events": {
|
||||
"eventOne":{
|
||||
"event": "test_1",
|
||||
"payload": {
|
||||
"body": {
|
||||
"property": "test_1",
|
||||
"nestedProperty": {
|
||||
"more": "really nested"
|
||||
|
|
@ -68,7 +68,7 @@
|
|||
},
|
||||
"eventReal":{
|
||||
"event": "epOne -> newMail",
|
||||
"payload": {
|
||||
"body": {
|
||||
"property": "test_1",
|
||||
"nestedProperty": {
|
||||
"more": "really nested"
|
||||
|
|
|
|||
|
|
@ -69,25 +69,25 @@ exports.tearDown = ( cb ) ->
|
|||
setTimeout cb, 100
|
||||
|
||||
exports.requestProcessing =
|
||||
testEmptyPayload: ( test ) =>
|
||||
testEmptyBody: ( test ) =>
|
||||
test.expect 1
|
||||
|
||||
request =
|
||||
command: 'get_event_pollers'
|
||||
|
||||
cm.processRequest oUser, request, ( answ ) =>
|
||||
test.strictEqual 200, answ.code, 'Empty payload did not return 200'
|
||||
test.strictEqual 200, answ.code, 'Empty body did not return 200'
|
||||
test.done()
|
||||
|
||||
testCorruptPayload: ( test ) =>
|
||||
testCorruptBody: ( test ) =>
|
||||
test.expect 1
|
||||
|
||||
request =
|
||||
command: 'get_event_pollers'
|
||||
payload: 'no-json'
|
||||
body: 'no-json'
|
||||
|
||||
cm.processRequest oUser, request, ( answ ) =>
|
||||
test.strictEqual 404, answ.code, 'Corrupt payload did not return 404'
|
||||
test.strictEqual 404, answ.code, 'Corrupt body did not return 404'
|
||||
test.done()
|
||||
|
||||
exports.testListener = ( test ) =>
|
||||
|
|
@ -108,7 +108,7 @@ exports.testListener = ( test ) =>
|
|||
|
||||
request =
|
||||
command: 'forge_rule'
|
||||
payload: strRuleThree
|
||||
body: strRuleThree
|
||||
|
||||
cm.addRuleListener ( evt ) =>
|
||||
strEvt = JSON.stringify evt.rule
|
||||
|
|
@ -162,9 +162,9 @@ exports.moduleHandling =
|
|||
|
||||
request =
|
||||
command: 'get_event_poller_params'
|
||||
payload:
|
||||
body:
|
||||
id: oEpOne.id
|
||||
request.payload = JSON.stringify request.payload
|
||||
request.body = JSON.stringify request.body
|
||||
cm.processRequest oUser, request, ( answ ) =>
|
||||
test.strictEqual 200, answ.code,
|
||||
'Required Module Parameters did not return 200'
|
||||
|
|
@ -181,7 +181,7 @@ exports.moduleHandling =
|
|||
|
||||
request =
|
||||
command: 'forge_action_invoker'
|
||||
payload: JSON.stringify oTmp
|
||||
body: JSON.stringify oTmp
|
||||
|
||||
cm.processRequest oUser, request, ( answ ) =>
|
||||
test.strictEqual 200, answ.code, 'Forging Module did not return 200'
|
||||
|
|
@ -208,7 +208,7 @@ exports.ruleForge =
|
|||
|
||||
request =
|
||||
command: 'forge_rule'
|
||||
payload: JSON.stringify oRuleThree
|
||||
body: JSON.stringify oRuleThree
|
||||
|
||||
cm.processRequest oUser, request, ( answ ) =>
|
||||
test.strictEqual 200, answ.code, "Forging Rule returned #{ answ.code }: #{ answ.message }"
|
||||
|
|
@ -229,7 +229,7 @@ exports.ruleForge =
|
|||
|
||||
request =
|
||||
command: 'delete_rule'
|
||||
payload: JSON.stringify id: oRuleThree.id
|
||||
body: JSON.stringify id: oRuleThree.id
|
||||
|
||||
cm.processRequest oUser, request, ( answ ) =>
|
||||
test.strictEqual 200, answ.code, "Deleting Rule returned #{ answ.code }: #{ answ.message }"
|
||||
|
|
@ -248,7 +248,7 @@ exports.ruleForge =
|
|||
|
||||
request =
|
||||
command: 'forge_rule'
|
||||
payload: JSON.stringify oRuleOne
|
||||
body: JSON.stringify oRuleOne
|
||||
|
||||
cm.processRequest oUser, request, ( answ ) =>
|
||||
test.strictEqual 200, answ.code, "Forging Rule returned #{ answ.code }: #{ answ.message }"
|
||||
|
|
@ -261,14 +261,14 @@ exports.ruleForge =
|
|||
try
|
||||
arrRows = data.split "\n"
|
||||
logged = arrRows[ 1 ].split( '] ' )[1]
|
||||
test.strictEqual logged, "{#{ oAiOne.id }} " + oEventOne.payload.property,
|
||||
test.strictEqual logged, "{#{ oAiOne.id }} " + oEventOne.body.property,
|
||||
'Did not log the right thing'
|
||||
catch e
|
||||
test.ok false, 'Parsing log failed'
|
||||
|
||||
request =
|
||||
command: 'delete_rule'
|
||||
payload: JSON.stringify id: oRuleOne.id
|
||||
body: JSON.stringify id: oRuleOne.id
|
||||
|
||||
cm.processRequest oUser, request, ( answ ) =>
|
||||
test.strictEqual 200, answ.code, "Deleting Rule returned #{ answ.code }: #{ answ.message }"
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ fOnLoad = () ->
|
|||
cmd = 'delete_action_invoker'
|
||||
data =
|
||||
command: cmd
|
||||
payload: JSON.stringify
|
||||
body: JSON.stringify
|
||||
id: modName
|
||||
$.post( '/usercommand', data )
|
||||
.done fFetchModules
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ fOnLoad = () ->
|
|||
$( '#log_col' ).text ""
|
||||
data =
|
||||
command: 'delete_rule'
|
||||
payload: JSON.stringify
|
||||
body: JSON.stringify
|
||||
id: ruleName
|
||||
$.post( '/usercommand', data )
|
||||
.done fFetchRules
|
||||
|
|
@ -64,7 +64,7 @@ fOnLoad = () ->
|
|||
ruleName = $( 'div', $( this ).closest( 'tr' )).text()
|
||||
data =
|
||||
command: 'get_rule_log'
|
||||
payload: JSON.stringify
|
||||
body: JSON.stringify
|
||||
id: ruleName
|
||||
$.post( '/usercommand', data )
|
||||
.done ( data ) ->
|
||||
|
|
|
|||
|
|
@ -1,8 +1,17 @@
|
|||
|
||||
fFindKeyStringPair = ( obj ) ->
|
||||
for key, val of obj
|
||||
if typeof val is 'string' or typeof val is 'number'
|
||||
return key: key, val: val
|
||||
else if typeof val is 'object'
|
||||
oRet = fFindKeyStringPair val
|
||||
if oRet
|
||||
return oRet
|
||||
null
|
||||
|
||||
fOnLoad = () ->
|
||||
document.title = 'Event Forge!'
|
||||
$( '#pagetitle' ).text 'Invoke your custom event!'
|
||||
document.title = 'Push Events!'
|
||||
$( '#pagetitle' ).text 'Push your own custom event directly into the engine!'
|
||||
|
||||
editor = ace.edit "editor"
|
||||
editor.setTheme "ace/theme/monokai"
|
||||
|
|
@ -35,4 +44,25 @@ fOnLoad = () ->
|
|||
$( '#info' ).text 'You have errors in your JSON object! ' + err
|
||||
$( '#info' ).attr 'class', 'error'
|
||||
|
||||
$( '#but_prepare' ). on 'click', () ->
|
||||
|
||||
try
|
||||
obj = JSON.parse editor.getValue() # try to parse, throw an error if JSON not valid
|
||||
if obj.event and typeof obj.event is 'string' and obj.event isnt ''
|
||||
sel = ''
|
||||
if obj.body and typeof obj.body is 'object'
|
||||
oSelector = fFindKeyStringPair obj.body
|
||||
if oSelector
|
||||
sel = "&selkey=#{ oSelector.key }&selval=#{ oSelector.val }"
|
||||
url = 'forge?page=forge_rule&eventname=' + obj.event + sel
|
||||
window.open url, '_blank'
|
||||
else
|
||||
$( '#info' ).text 'Please provide a valid eventname'
|
||||
$( '#info' ).attr 'class', 'error'
|
||||
catch err
|
||||
$( '#info' ).text 'You have errors in your JSON object! ' + err
|
||||
$( '#info' ).attr 'class', 'error'
|
||||
|
||||
|
||||
|
||||
window.addEventListener 'load', fOnLoad, true
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ fErrHandler = ( errMsg ) ->
|
|||
setTimeout fDelayed, 500
|
||||
|
||||
fOnLoad = () ->
|
||||
document.title = "Forge #{ moduleName }"
|
||||
$( '#pagetitle' ).text "{{{user.username}}}, forge your custom #{ moduleName }!"
|
||||
document.title = "Create #{ moduleName }"
|
||||
$( '#pagetitle' ).text "{{{user.username}}}, create your custom #{ moduleName }!"
|
||||
|
||||
# Setup the ACE editor
|
||||
editor = ace.edit "editor"
|
||||
|
|
@ -100,7 +100,7 @@ fOnLoad = () ->
|
|||
true
|
||||
obj =
|
||||
command: "forge_#{ oParams.type }"
|
||||
payload: JSON.stringify
|
||||
body: JSON.stringify
|
||||
id: $( '#input_id' ).val()
|
||||
lang: $( '#editor_mode' ).val()
|
||||
public: $( '#is_public' ).is ':checked'
|
||||
|
|
@ -110,9 +110,9 @@ fOnLoad = () ->
|
|||
( 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
|
||||
bod = JSON.parse obj.body
|
||||
bod.overwrite = true
|
||||
obj.body = JSON.stringify bod
|
||||
$.post( '/usercommand', obj )
|
||||
.done ( data ) ->
|
||||
$( '#info' ).text data.message
|
||||
|
|
@ -140,7 +140,7 @@ fOnLoad = () ->
|
|||
if oParams.id
|
||||
obj =
|
||||
command: "get_full_#{ oParams.type }"
|
||||
payload: JSON.stringify
|
||||
body: JSON.stringify
|
||||
id: oParams.id
|
||||
|
||||
$.post( '/usercommand', obj )
|
||||
|
|
|
|||
|
|
@ -17,27 +17,39 @@ fPlaceAndPaintInterval = () ->
|
|||
<input id="input_interval" type="text" />
|
||||
<b>"days hours:minutes"</b>, default = 10 minutes'
|
||||
|
||||
fDisplayError = ( msg ) ->
|
||||
window.scrollTo 0, 0
|
||||
$( '#info' ).text "Error: #{ msg }"
|
||||
$( '#info' ).attr 'class', 'error'
|
||||
|
||||
fFailedRequest = ( msg ) ->
|
||||
( err ) ->
|
||||
if err.status is 401
|
||||
window.location.href = 'forge?page=forge_rule'
|
||||
else
|
||||
$( '#info' ).text msg
|
||||
$( '#info' ).attr 'class', 'error'
|
||||
fDisplayError msg
|
||||
|
||||
$.post( '/usercommand', command: 'get_public_key' )
|
||||
.done ( data ) ->
|
||||
strPublicKey = data.message
|
||||
.fail ( err ) ->
|
||||
if err.status is 401
|
||||
window.location.href = 'forge?page=forge_rule'
|
||||
else
|
||||
$( '#info' ).text 'Error fetching public key, unable to send user specific parameters securely'
|
||||
$( '#info' ).attr 'class', 'error'
|
||||
fIssueRequest = ( args ) ->
|
||||
$( '#info' ).text ''
|
||||
$.post( '/usercommand', args.body )
|
||||
.done args.done
|
||||
.fail args.fail
|
||||
|
||||
|
||||
fOnLoad = () ->
|
||||
document.title = 'Rule Forge!'
|
||||
$( '#pagetitle' ).text '{{{user.username}}}, forge your ECA Rule!'
|
||||
# Fetch the public key from the engine
|
||||
fIssueRequest
|
||||
body: command: 'get_public_key'
|
||||
done: ( data ) ->
|
||||
strPublicKey = data.message
|
||||
fail: ( err ) ->
|
||||
if err.status is 401
|
||||
window.location.href = 'forge?page=forge_rule'
|
||||
else
|
||||
fDisplayError 'When fetching public key. Unable to send user specific parameters securely!'
|
||||
|
||||
document.title = 'Create Rules!'
|
||||
$( '#pagetitle' ).text '{{{user.username}}}, create your ECA Rule!'
|
||||
|
||||
editor = ace.edit "editor_conditions"
|
||||
editor.setTheme "ace/theme/monokai"
|
||||
|
|
@ -45,23 +57,63 @@ fOnLoad = () ->
|
|||
editor.setShowPrintMargin false
|
||||
# editor.session.setUseSoftTabs false
|
||||
|
||||
|
||||
|
||||
# EVENT
|
||||
$.post( '/usercommand', command: 'get_event_pollers' )
|
||||
.done ( data ) ->
|
||||
try
|
||||
oEps = JSON.parse data.message
|
||||
catch err
|
||||
console.error 'ERROR: non-object received from server: ' + data.message
|
||||
return
|
||||
|
||||
fAppendEvents = ( id, events ) ->
|
||||
fAppendEvent = ( evt ) ->
|
||||
$( '#select_event' ).append $( '<option>' ).text id + ' -> ' + evt
|
||||
fAppendEvent evt for evt in events
|
||||
fAppendEvents id, events for id, events of oEps
|
||||
$( '#input_event' ).val $( '#select_event' ).val()
|
||||
fFetchEventParams $( '#select_event option:selected' ).text()
|
||||
.fail fFailedRequest 'Error fetching event poller'
|
||||
|
||||
# If the user is coming from an event he wants a rule to be setup for him
|
||||
if oParams.eventname
|
||||
$( '#select_event_type' ).val 'Custom Event'
|
||||
inpEvt = $( '<input>' ).attr( 'type', 'text').attr 'id', 'input_eventname'
|
||||
inpEvt.val oParams.eventname
|
||||
$( '#event_parameters' ).append inpEvt
|
||||
|
||||
# Event type is changed, changes the whole event section
|
||||
$( '#select_event_type' ).change () ->
|
||||
$( '#event_parameters *' ).remove()
|
||||
switch $( this ).val()
|
||||
|
||||
# The user wants to act on a custom event
|
||||
when 'Custom Event'
|
||||
inpEvt = $( '<input>' ).attr( 'type', 'text').attr 'id', 'input_eventname'
|
||||
$( '#event_parameters' ).append inpEvt
|
||||
|
||||
# The user wants a webhook as event producer
|
||||
when 'Webhook'
|
||||
fIssueRequest
|
||||
body: command: 'get_webhooks'
|
||||
done: ( data ) ->
|
||||
try
|
||||
arrHooks = JSON.parse data.message
|
||||
if arrHooks.length is 0
|
||||
fDisplayError 'No webhooks found! Choose another Event Type or create a Webhook.'
|
||||
$( '#select_event_type' ).val ''
|
||||
else
|
||||
selHook = $( '<select>' ).attr 'id', 'input_eventname'
|
||||
for hook in arrHooks
|
||||
selHook.append $( '<option>' ).text hook
|
||||
$( '#event_parameters' ).append selHook
|
||||
catch err
|
||||
fDisplayError 'Badly formed webhooks!'
|
||||
fail: fFailedRequest 'Unable to get webhooks!'
|
||||
|
||||
when 'Event Poller'
|
||||
fIssueRequest
|
||||
body: command: 'get_event_pollers'
|
||||
done: ( data ) ->
|
||||
try
|
||||
oEps = JSON.parse data.message
|
||||
fAppendEvents = ( id, events ) ->
|
||||
fAppendEvent = ( evt ) ->
|
||||
$( '#select_event' ).append $( '<option>' ).text id + ' -> ' + evt
|
||||
fAppendEvent evt for evt in events
|
||||
fAppendEvents id, events for id, events of oEps
|
||||
$( '#input_event' ).val $( '#select_event' ).val()
|
||||
fFetchEventParams $( '#select_event option:selected' ).text()
|
||||
catch err
|
||||
console.error 'ERROR: non-object received from server: ' + data.message
|
||||
|
||||
fail: fFailedRequest 'Error fetching event poller'
|
||||
|
||||
$( '#select_event' ).change () ->
|
||||
evtFunc = $( this ).val()
|
||||
|
|
@ -87,20 +139,22 @@ fOnLoad = () ->
|
|||
$( '#event_poller_params *' ).remove()
|
||||
if name
|
||||
arr = name.split ' -> '
|
||||
obj =
|
||||
command: 'get_event_poller_params'
|
||||
payload: JSON.stringify
|
||||
id: arr[ 0 ]
|
||||
$.post( '/usercommand', obj )
|
||||
.done fAddEventParams arr[ 0 ]
|
||||
.fail fFailedRequest 'Error fetching event poller params'
|
||||
fIssueRequest
|
||||
body:
|
||||
command: 'get_event_poller_params'
|
||||
body: JSON.stringify
|
||||
id: arr[ 0 ]
|
||||
done: fAddEventParams arr[ 0 ]
|
||||
fail: fFailedRequest 'Error fetching event poller params'
|
||||
fFetchEventFunctionArgs arr
|
||||
|
||||
fFetchEventFunctionArgs = ( arrName ) ->
|
||||
obj =
|
||||
command: 'get_event_poller_function_arguments'
|
||||
payload: JSON.stringify
|
||||
id: arrName[ 0 ]
|
||||
# FIXME this data gets not populated sometimes!
|
||||
fIssueRequest
|
||||
body:
|
||||
command: 'get_event_poller_function_arguments'
|
||||
body: JSON.stringify
|
||||
id: arrName[ 0 ]
|
||||
$.post( '/usercommand', obj )
|
||||
.done ( data ) ->
|
||||
if data.message
|
||||
|
|
@ -149,7 +203,7 @@ fOnLoad = () ->
|
|||
fFillEventParams = ( moduleId ) ->
|
||||
obj =
|
||||
command: 'get_event_poller_user_params'
|
||||
payload: JSON.stringify
|
||||
body: JSON.stringify
|
||||
id: moduleId
|
||||
$.post( '/usercommand', obj )
|
||||
.done ( data ) ->
|
||||
|
|
@ -163,7 +217,7 @@ fOnLoad = () ->
|
|||
$( this ).attr 'unchanged', 'false'
|
||||
|
||||
obj.command = 'get_event_poller_user_arguments'
|
||||
obj.payload = JSON.stringify
|
||||
obj.body = JSON.stringify
|
||||
ruleId: $( '#input_id' ).val()
|
||||
moduleId: moduleId
|
||||
$.post( '/usercommand', obj )
|
||||
|
|
@ -180,6 +234,16 @@ fOnLoad = () ->
|
|||
# $( "input[type=checkbox]", tr ).prop 'checked', oFunc.jsselector
|
||||
|
||||
# ACTIONS
|
||||
|
||||
|
||||
# <b>Selected Actions:</b>
|
||||
# <table id="selected_actions"></table>
|
||||
# <br><br>
|
||||
# <b>Required Parameters:</b>
|
||||
# <br><br>
|
||||
# <div id="action_params"></div>
|
||||
# <br><br>
|
||||
|
||||
obj =
|
||||
command: 'get_action_invokers'
|
||||
$.post( '/usercommand', obj )
|
||||
|
|
@ -228,7 +292,7 @@ fOnLoad = () ->
|
|||
fFetchActionParams = ( div, modName ) ->
|
||||
obj =
|
||||
command: 'get_action_invoker_params'
|
||||
payload: JSON.stringify
|
||||
body: JSON.stringify
|
||||
id: modName
|
||||
$.post( '/usercommand', obj )
|
||||
.done ( data ) ->
|
||||
|
|
@ -253,7 +317,7 @@ fOnLoad = () ->
|
|||
fFetchActionFunctionArgs = ( tag, arrName ) ->
|
||||
obj =
|
||||
command: 'get_action_invoker_function_arguments'
|
||||
payload: JSON.stringify
|
||||
body: JSON.stringify
|
||||
id: arrName[ 0 ]
|
||||
$.post( '/usercommand', obj )
|
||||
.done ( data ) ->
|
||||
|
|
@ -277,13 +341,13 @@ fOnLoad = () ->
|
|||
fFillActionFunction = ( name ) ->
|
||||
obj =
|
||||
command: 'get_action_invoker_user_params'
|
||||
payload: JSON.stringify
|
||||
body: JSON.stringify
|
||||
id: name
|
||||
$.post( '/usercommand', obj )
|
||||
.done fAddActionUserParams name
|
||||
|
||||
obj.command = 'get_action_invoker_user_arguments'
|
||||
obj.payload = JSON.stringify
|
||||
obj.body = JSON.stringify
|
||||
ruleId: $( '#input_id' ).val()
|
||||
moduleId: name
|
||||
$.post( '/usercommand', obj )
|
||||
|
|
@ -494,9 +558,9 @@ fOnLoad = () ->
|
|||
( err ) ->
|
||||
if err.status is 409
|
||||
if confirm 'Are you sure you want to overwrite the existing rule?'
|
||||
payl = JSON.parse obj.payload
|
||||
payl = JSON.parse obj.body
|
||||
payl.overwrite = true
|
||||
obj.payload = JSON.stringify payl
|
||||
obj.body = JSON.stringify payl
|
||||
$.post( '/usercommand', obj )
|
||||
.done ( data ) ->
|
||||
$( '#info' ).text data.message
|
||||
|
|
@ -511,7 +575,7 @@ fOnLoad = () ->
|
|||
start = start.toISOString()
|
||||
obj =
|
||||
command: 'forge_rule'
|
||||
payload: JSON.stringify
|
||||
body: JSON.stringify
|
||||
id: $( '#input_id' ).val()
|
||||
event: eventId
|
||||
event_params: ep
|
||||
|
|
@ -537,7 +601,7 @@ fOnLoad = () ->
|
|||
if oParams.id
|
||||
obj =
|
||||
command: 'get_rule'
|
||||
payload: JSON.stringify
|
||||
body: JSON.stringify
|
||||
id: oParams.id
|
||||
$.post( '/usercommand', obj )
|
||||
.done ( data ) ->
|
||||
|
|
|
|||
0
webpages/handlers/coffee/forge_webhook.coffee
Normal file
0
webpages/handlers/coffee/forge_webhook.coffee
Normal file
|
|
@ -72,7 +72,7 @@
|
|||
}
|
||||
data = {
|
||||
command: cmd,
|
||||
payload: JSON.stringify({
|
||||
body: JSON.stringify({
|
||||
id: modName
|
||||
})
|
||||
};
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@
|
|||
$('#log_col').text("");
|
||||
data = {
|
||||
command: 'delete_rule',
|
||||
payload: JSON.stringify({
|
||||
body: JSON.stringify({
|
||||
id: ruleName
|
||||
})
|
||||
};
|
||||
|
|
@ -80,7 +80,7 @@
|
|||
ruleName = $('div', $(this).closest('tr')).text();
|
||||
data = {
|
||||
command: 'get_rule_log',
|
||||
payload: JSON.stringify({
|
||||
body: JSON.stringify({
|
||||
id: ruleName
|
||||
})
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,18 +1,37 @@
|
|||
// Generated by CoffeeScript 1.7.1
|
||||
(function() {
|
||||
var fOnLoad;
|
||||
var fFindKeyStringPair, fOnLoad;
|
||||
|
||||
fFindKeyStringPair = function(obj) {
|
||||
var key, oRet, val;
|
||||
for (key in obj) {
|
||||
val = obj[key];
|
||||
if (typeof val === 'string' || typeof val === 'number') {
|
||||
return {
|
||||
key: key,
|
||||
val: val
|
||||
};
|
||||
} else if (typeof val === 'object') {
|
||||
oRet = fFindKeyStringPair(val);
|
||||
if (oRet) {
|
||||
return oRet;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
fOnLoad = function() {
|
||||
var editor;
|
||||
document.title = 'Event Forge!';
|
||||
$('#pagetitle').text('Invoke your custom event!');
|
||||
document.title = 'Push Events!';
|
||||
$('#pagetitle').text('Push your own custom event directly into the engine!');
|
||||
editor = ace.edit("editor");
|
||||
editor.setTheme("ace/theme/monokai");
|
||||
editor.getSession().setMode("ace/mode/json");
|
||||
editor.setShowPrintMargin(false);
|
||||
$('#editor').css('height', '400px');
|
||||
$('#editor').css('width', '600px');
|
||||
return $('#but_submit').click(function() {
|
||||
$('#but_submit').click(function() {
|
||||
var err, val;
|
||||
try {
|
||||
val = editor.getValue();
|
||||
|
|
@ -42,6 +61,30 @@
|
|||
return $('#info').attr('class', 'error');
|
||||
}
|
||||
});
|
||||
return $('#but_prepare').on('click', function() {
|
||||
var err, oSelector, obj, sel, url;
|
||||
try {
|
||||
obj = JSON.parse(editor.getValue());
|
||||
if (obj.event && typeof obj.event === 'string' && obj.event !== '') {
|
||||
sel = '';
|
||||
if (obj.body && typeof obj.body === 'object') {
|
||||
oSelector = fFindKeyStringPair(obj.body);
|
||||
if (oSelector) {
|
||||
sel = "&selkey=" + oSelector.key + "&selval=" + oSelector.val;
|
||||
}
|
||||
}
|
||||
url = 'forge?page=forge_rule&eventname=' + obj.event + sel;
|
||||
return window.open(url, '_blank');
|
||||
} else {
|
||||
$('#info').text('Please provide a valid eventname');
|
||||
return $('#info').attr('class', 'error');
|
||||
}
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
$('#info').text('You have errors in your JSON object! ' + err);
|
||||
return $('#info').attr('class', 'error');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
window.addEventListener('load', fOnLoad, true);
|
||||
|
|
|
|||
|
|
@ -50,8 +50,8 @@
|
|||
|
||||
fOnLoad = function() {
|
||||
var editor, fAddInputRow, fAddUserParam, fChangeInputVisibility, obj;
|
||||
document.title = "Forge " + moduleName;
|
||||
$('#pagetitle').text("{{{user.username}}}, forge your custom " + moduleName + "!");
|
||||
document.title = "Create " + moduleName;
|
||||
$('#pagetitle').text("{{{user.username}}}, create your custom " + moduleName + "!");
|
||||
editor = ace.edit("editor");
|
||||
editor.setTheme("ace/theme/monokai");
|
||||
editor.getSession().setMode("ace/mode/coffee");
|
||||
|
|
@ -126,7 +126,7 @@
|
|||
});
|
||||
obj = {
|
||||
command: "forge_" + oParams.type,
|
||||
payload: JSON.stringify({
|
||||
body: JSON.stringify({
|
||||
id: $('#input_id').val(),
|
||||
lang: $('#editor_mode').val(),
|
||||
"public": $('#is_public').is(':checked'),
|
||||
|
|
@ -136,12 +136,12 @@
|
|||
};
|
||||
fCheckOverwrite = function(obj) {
|
||||
return function(err) {
|
||||
var payl;
|
||||
var bod;
|
||||
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);
|
||||
bod = JSON.parse(obj.body);
|
||||
bod.overwrite = true;
|
||||
obj.body = JSON.stringify(bod);
|
||||
return $.post('/usercommand', obj).done(function(data) {
|
||||
$('#info').text(data.message);
|
||||
$('#info').attr('class', 'success');
|
||||
|
|
@ -171,7 +171,7 @@
|
|||
if (oParams.id) {
|
||||
obj = {
|
||||
command: "get_full_" + oParams.type,
|
||||
payload: JSON.stringify({
|
||||
body: JSON.stringify({
|
||||
id: oParams.id
|
||||
})
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Generated by CoffeeScript 1.7.1
|
||||
(function() {
|
||||
var arrKV, arrParams, fFailedRequest, fOnLoad, fPlaceAndPaintInterval, oParams, param, strPublicKey, _i, _len,
|
||||
var arrKV, arrParams, fDisplayError, fFailedRequest, fIssueRequest, 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('&');
|
||||
|
|
@ -24,68 +24,125 @@
|
|||
return $('#event_interval').html('Interval: <input id="input_interval" type="text" /> <b>"days hours:minutes"</b>, default = 10 minutes');
|
||||
};
|
||||
|
||||
fDisplayError = function(msg) {
|
||||
window.scrollTo(0, 0);
|
||||
$('#info').text("Error: " + msg);
|
||||
return $('#info').attr('class', 'error');
|
||||
};
|
||||
|
||||
fFailedRequest = function(msg) {
|
||||
return function(err) {
|
||||
if (err.status === 401) {
|
||||
return window.location.href = 'forge?page=forge_rule';
|
||||
} else {
|
||||
$('#info').text(msg);
|
||||
return $('#info').attr('class', 'error');
|
||||
return fDisplayError(msg);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
$.post('/usercommand', {
|
||||
command: 'get_public_key'
|
||||
}).done(function(data) {
|
||||
return strPublicKey = data.message;
|
||||
}).fail(function(err) {
|
||||
if (err.status === 401) {
|
||||
return window.location.href = 'forge?page=forge_rule';
|
||||
} else {
|
||||
$('#info').text('Error fetching public key, unable to send user specific parameters securely');
|
||||
return $('#info').attr('class', 'error');
|
||||
}
|
||||
});
|
||||
fIssueRequest = function(args) {
|
||||
$('#info').text('');
|
||||
return $.post('/usercommand', args.body).done(args.done).fail(args.fail);
|
||||
};
|
||||
|
||||
fOnLoad = function() {
|
||||
var editor, fAddActionUserArgs, fAddActionUserParams, fAddEventParams, fAddEventUserArgs, fAddSelectedAction, fFetchActionFunctionArgs, fFetchActionParams, fFetchEventFunctionArgs, fFetchEventParams, fFillActionFunction, fFillEventParams, obj;
|
||||
document.title = 'Rule Forge!';
|
||||
$('#pagetitle').text('{{{user.username}}}, forge your ECA Rule!');
|
||||
var editor, fAddActionUserArgs, fAddActionUserParams, fAddEventParams, fAddEventUserArgs, fAddSelectedAction, fFetchActionFunctionArgs, fFetchActionParams, fFetchEventFunctionArgs, fFetchEventParams, fFillActionFunction, fFillEventParams, inpEvt, obj;
|
||||
fIssueRequest({
|
||||
body: {
|
||||
command: 'get_public_key'
|
||||
},
|
||||
done: function(data) {
|
||||
return strPublicKey = data.message;
|
||||
},
|
||||
fail: function(err) {
|
||||
if (err.status === 401) {
|
||||
return window.location.href = 'forge?page=forge_rule';
|
||||
} else {
|
||||
return fDisplayError('When fetching public key. Unable to send user specific parameters securely!');
|
||||
}
|
||||
}
|
||||
});
|
||||
document.title = 'Create Rules!';
|
||||
$('#pagetitle').text('{{{user.username}}}, create your ECA Rule!');
|
||||
editor = ace.edit("editor_conditions");
|
||||
editor.setTheme("ace/theme/monokai");
|
||||
editor.getSession().setMode("ace/mode/json");
|
||||
editor.setShowPrintMargin(false);
|
||||
$.post('/usercommand', {
|
||||
command: 'get_event_pollers'
|
||||
}).done(function(data) {
|
||||
var err, events, fAppendEvents, id, oEps;
|
||||
try {
|
||||
oEps = JSON.parse(data.message);
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
console.error('ERROR: non-object received from server: ' + data.message);
|
||||
return;
|
||||
if (oParams.eventname) {
|
||||
$('#select_event_type').val('Custom Event');
|
||||
inpEvt = $('<input>').attr('type', 'text').attr('id', 'input_eventname');
|
||||
inpEvt.val(oParams.eventname);
|
||||
$('#event_parameters').append(inpEvt);
|
||||
}
|
||||
$('#select_event_type').change(function() {
|
||||
$('#event_parameters *').remove();
|
||||
switch ($(this).val()) {
|
||||
case 'Custom Event':
|
||||
inpEvt = $('<input>').attr('type', 'text').attr('id', 'input_eventname');
|
||||
return $('#event_parameters').append(inpEvt);
|
||||
case 'Webhook':
|
||||
return fIssueRequest({
|
||||
body: {
|
||||
command: 'get_webhooks'
|
||||
},
|
||||
done: function(data) {
|
||||
var arrHooks, err, hook, selHook, _j, _len1;
|
||||
try {
|
||||
arrHooks = JSON.parse(data.message);
|
||||
if (arrHooks.length === 0) {
|
||||
fDisplayError('No webhooks found! Choose another Event Type or create a Webhook.');
|
||||
return $('#select_event_type').val('');
|
||||
} else {
|
||||
selHook = $('<select>').attr('id', 'input_eventname');
|
||||
for (_j = 0, _len1 = arrHooks.length; _j < _len1; _j++) {
|
||||
hook = arrHooks[_j];
|
||||
selHook.append($('<option>').text(hook));
|
||||
}
|
||||
return $('#event_parameters').append(selHook);
|
||||
}
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
return fDisplayError('Badly formed webhooks!');
|
||||
}
|
||||
},
|
||||
fail: fFailedRequest('Unable to get webhooks!')
|
||||
});
|
||||
case 'Event Poller':
|
||||
return fIssueRequest({
|
||||
body: {
|
||||
command: 'get_event_pollers'
|
||||
},
|
||||
done: function(data) {
|
||||
var err, events, fAppendEvents, id, oEps;
|
||||
try {
|
||||
oEps = JSON.parse(data.message);
|
||||
fAppendEvents = function(id, events) {
|
||||
var evt, fAppendEvent, _j, _len1, _results;
|
||||
fAppendEvent = function(evt) {
|
||||
return $('#select_event').append($('<option>').text(id + ' -> ' + evt));
|
||||
};
|
||||
_results = [];
|
||||
for (_j = 0, _len1 = events.length; _j < _len1; _j++) {
|
||||
evt = events[_j];
|
||||
_results.push(fAppendEvent(evt));
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
for (id in oEps) {
|
||||
events = oEps[id];
|
||||
fAppendEvents(id, events);
|
||||
}
|
||||
$('#input_event').val($('#select_event').val());
|
||||
return fFetchEventParams($('#select_event option:selected').text());
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
return console.error('ERROR: non-object received from server: ' + data.message);
|
||||
}
|
||||
},
|
||||
fail: fFailedRequest('Error fetching event poller')
|
||||
});
|
||||
}
|
||||
fAppendEvents = function(id, events) {
|
||||
var evt, fAppendEvent, _j, _len1, _results;
|
||||
fAppendEvent = function(evt) {
|
||||
return $('#select_event').append($('<option>').text(id + ' -> ' + evt));
|
||||
};
|
||||
_results = [];
|
||||
for (_j = 0, _len1 = events.length; _j < _len1; _j++) {
|
||||
evt = events[_j];
|
||||
_results.push(fAppendEvent(evt));
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
for (id in oEps) {
|
||||
events = oEps[id];
|
||||
fAppendEvents(id, events);
|
||||
}
|
||||
$('#input_event').val($('#select_event').val());
|
||||
return fFetchEventParams($('#select_event option:selected').text());
|
||||
}).fail(fFailedRequest('Error fetching event poller'));
|
||||
});
|
||||
$('#select_event').change(function() {
|
||||
var evtFunc;
|
||||
evtFunc = $(this).val();
|
||||
|
|
@ -110,28 +167,32 @@
|
|||
}
|
||||
});
|
||||
fFetchEventParams = function(name) {
|
||||
var arr, obj;
|
||||
var arr;
|
||||
$('#event_poller_params *').remove();
|
||||
if (name) {
|
||||
arr = name.split(' -> ');
|
||||
obj = {
|
||||
command: 'get_event_poller_params',
|
||||
payload: JSON.stringify({
|
||||
id: arr[0]
|
||||
})
|
||||
};
|
||||
$.post('/usercommand', obj).done(fAddEventParams(arr[0])).fail(fFailedRequest('Error fetching event poller params'));
|
||||
fIssueRequest({
|
||||
body: {
|
||||
command: 'get_event_poller_params',
|
||||
body: JSON.stringify({
|
||||
id: arr[0]
|
||||
})
|
||||
},
|
||||
done: fAddEventParams(arr[0]),
|
||||
fail: fFailedRequest('Error fetching event poller params')
|
||||
});
|
||||
return fFetchEventFunctionArgs(arr);
|
||||
}
|
||||
};
|
||||
fFetchEventFunctionArgs = function(arrName) {
|
||||
var obj;
|
||||
obj = {
|
||||
command: 'get_event_poller_function_arguments',
|
||||
payload: JSON.stringify({
|
||||
id: arrName[0]
|
||||
})
|
||||
};
|
||||
fIssueRequest({
|
||||
body: {
|
||||
command: 'get_event_poller_function_arguments',
|
||||
body: JSON.stringify({
|
||||
id: arrName[0]
|
||||
})
|
||||
}
|
||||
});
|
||||
return $.post('/usercommand', obj).done(function(data) {
|
||||
var functionArgument, table, td, tr, _j, _len1, _ref, _results;
|
||||
if (data.message) {
|
||||
|
|
@ -199,7 +260,7 @@
|
|||
var obj;
|
||||
obj = {
|
||||
command: 'get_event_poller_user_params',
|
||||
payload: JSON.stringify({
|
||||
body: JSON.stringify({
|
||||
id: moduleId
|
||||
})
|
||||
};
|
||||
|
|
@ -221,7 +282,7 @@
|
|||
return _results;
|
||||
});
|
||||
obj.command = 'get_event_poller_user_arguments';
|
||||
obj.payload = JSON.stringify({
|
||||
obj.body = JSON.stringify({
|
||||
ruleId: $('#input_id').val(),
|
||||
moduleId: moduleId
|
||||
});
|
||||
|
|
@ -319,7 +380,7 @@
|
|||
fFetchActionParams = function(div, modName) {
|
||||
obj = {
|
||||
command: 'get_action_invoker_params',
|
||||
payload: JSON.stringify({
|
||||
body: JSON.stringify({
|
||||
id: modName
|
||||
})
|
||||
};
|
||||
|
|
@ -355,7 +416,7 @@
|
|||
fFetchActionFunctionArgs = function(tag, arrName) {
|
||||
obj = {
|
||||
command: 'get_action_invoker_function_arguments',
|
||||
payload: JSON.stringify({
|
||||
body: JSON.stringify({
|
||||
id: arrName[0]
|
||||
})
|
||||
};
|
||||
|
|
@ -385,13 +446,13 @@
|
|||
fFillActionFunction = function(name) {
|
||||
obj = {
|
||||
command: 'get_action_invoker_user_params',
|
||||
payload: JSON.stringify({
|
||||
body: JSON.stringify({
|
||||
id: name
|
||||
})
|
||||
};
|
||||
$.post('/usercommand', obj).done(fAddActionUserParams(name));
|
||||
obj.command = 'get_action_invoker_user_arguments';
|
||||
obj.payload = JSON.stringify({
|
||||
obj.body = JSON.stringify({
|
||||
ruleId: $('#input_id').val(),
|
||||
moduleId: name
|
||||
});
|
||||
|
|
@ -636,9 +697,9 @@
|
|||
var payl;
|
||||
if (err.status === 409) {
|
||||
if (confirm('Are you sure you want to overwrite the existing rule?')) {
|
||||
payl = JSON.parse(obj.payload);
|
||||
payl = JSON.parse(obj.body);
|
||||
payl.overwrite = true;
|
||||
obj.payload = JSON.stringify(payl);
|
||||
obj.body = JSON.stringify(payl);
|
||||
return $.post('/usercommand', obj).done(function(data) {
|
||||
$('#info').text(data.message);
|
||||
return $('#info').attr('class', 'success');
|
||||
|
|
@ -657,7 +718,7 @@
|
|||
}
|
||||
obj = {
|
||||
command: 'forge_rule',
|
||||
payload: JSON.stringify({
|
||||
body: JSON.stringify({
|
||||
id: $('#input_id').val(),
|
||||
event: eventId,
|
||||
event_params: ep,
|
||||
|
|
@ -686,7 +747,7 @@
|
|||
if (oParams.id) {
|
||||
obj = {
|
||||
command: 'get_rule',
|
||||
payload: JSON.stringify({
|
||||
body: JSON.stringify({
|
||||
id: oParams.id
|
||||
})
|
||||
};
|
||||
|
|
|
|||
5
webpages/handlers/js/forge_webhook.js
Normal file
5
webpages/handlers/js/forge_webhook.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
// Generated by CoffeeScript 1.7.1
|
||||
(function() {
|
||||
|
||||
|
||||
}).call(this);
|
||||
|
|
@ -3,11 +3,11 @@
|
|||
<div id="editor">
|
||||
{
|
||||
"event": "mail",
|
||||
"payload": {
|
||||
"body": {
|
||||
"subject": "hello"
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<button id="but_submit">invoke</button>
|
||||
<button id="but_submit">invoke</button><button id="but_prepare">prepare a rule for this event</button>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
Module Name: <input id="input_id" type="text" />
|
||||
<h2>Module Name: <input id="input_id" type="text" /></h2>
|
||||
<select id="editor_mode">
|
||||
<option>CoffeeScript</option>
|
||||
<option>JavaScript</option>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
<b>Rule Name: </b><input id="input_id" type="text" /><br>
|
||||
<h2>Rule Name: <input id="input_id" type="text" /></h2>
|
||||
|
||||
<h2>EVENT</h2>
|
||||
<select id="select_event"><option></option></select><br/>
|
||||
<input id="input_event" type="text" /><br/><br/>
|
||||
<div id="event_start"></div>
|
||||
<div id="event_interval"></div><br/>
|
||||
<div id="event_poller_params"></div>
|
||||
<br>
|
||||
<b>Event Type:</b>
|
||||
<select id="select_event_type">
|
||||
<option></option>
|
||||
<option>Custom Event</option>
|
||||
<option>Webhook</option>
|
||||
<option>Event Poller</option>
|
||||
</select>
|
||||
<div id="event_parameters"></div>
|
||||
|
||||
<h2>CONDITIONS</h2>
|
||||
Refer to <a target="_blank" href="https://github.com/harthur/js-select#selectors">js-select selectors</a> for valid selectors! ( only the first matching element will be returned )
|
||||
<table>
|
||||
|
|
@ -22,15 +26,10 @@ Refer to <a target="_blank" href="https://github.com/harthur/js-select#selectors
|
|||
</div>
|
||||
</td></tr>
|
||||
<tr><td>
|
||||
|
||||
<h2>ACTIONS</h2>
|
||||
<select id="select_actions"><option></option></select>
|
||||
<br><br>
|
||||
<b>Selected Actions:</b>
|
||||
<table id="selected_actions"></table>
|
||||
<br><br>
|
||||
<b>Required Parameters:</b>
|
||||
<br><br>
|
||||
<div id="action_params"></div>
|
||||
<br><br>
|
||||
<div id="action_parameters"></div>
|
||||
<button id="but_submit">save</button>
|
||||
</td></tr></table>
|
||||
|
|
|
|||
5
webpages/handlers/templates/forge_webhook.html
Normal file
5
webpages/handlers/templates/forge_webhook.html
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<input type="text" id="inp_hookname" style="width:300px" />
|
||||
<button type="button" id="but_submit">Create Webhook!</button>
|
||||
<br><br>
|
||||
<h3>This is the Webhook Url you should use:</h3>
|
||||
<div id="display_hookurl" />
|
||||
|
|
@ -14,24 +14,27 @@
|
|||
menubar.append(link);
|
||||
};
|
||||
|
||||
fCreateLink( 'Forge Event Poller',
|
||||
fRedirect( 'forge?page=forge_module&type=event_poller' )
|
||||
);
|
||||
fCreateLink( 'Forge Action Invoker',
|
||||
fRedirect( 'forge?page=forge_module&type=action_invoker' )
|
||||
);
|
||||
fCreateLink( 'Forge Rule',
|
||||
fRedirect( 'forge?page=forge_rule' )
|
||||
);
|
||||
fCreateLink( 'Invoke Event',
|
||||
fCreateLink( 'Push Event',
|
||||
fRedirect( 'forge?page=forge_event' )
|
||||
);
|
||||
fCreateLink( 'Edit Modules',
|
||||
fRedirect( 'forge?page=edit_modules' )
|
||||
fCreateLink( 'Create Rule',
|
||||
fRedirect( 'forge?page=forge_rule' )
|
||||
);
|
||||
fCreateLink( 'Edit Rules',
|
||||
fRedirect( 'forge?page=edit_rules' )
|
||||
);
|
||||
fCreateLink( 'Create EP',
|
||||
fRedirect( 'forge?page=forge_module&type=event_poller' )
|
||||
);
|
||||
fCreateLink( 'Create AI',
|
||||
fRedirect( 'forge?page=forge_module&type=action_invoker' )
|
||||
);
|
||||
fCreateLink( 'Edit EPs & AIs',
|
||||
fRedirect( 'forge?page=edit_modules' )
|
||||
);
|
||||
fCreateLink( 'Webhooks',
|
||||
fRedirect( 'forge?page=forge_webhook' )
|
||||
);
|
||||
// fCreateLink( 'admin', fRedirect( 'admin' ) );
|
||||
|
||||
fCreateLink( 'Logout', function() {
|
||||
|
|
|
|||
|
|
@ -14,14 +14,16 @@
|
|||
$.getJSON('data/histochart.json', function(d) {
|
||||
var data = new google.visualization.DataTable();
|
||||
data.addColumn('datetime', 'Time');
|
||||
data.addColumn('number', '#Online');
|
||||
data.addColumn('number', '# Responding');
|
||||
|
||||
var options_lines = {
|
||||
title: 'Online statistics',
|
||||
title: 'Host Uptime Statistics',
|
||||
curveType:'function',
|
||||
lineWidth: 2,
|
||||
intervals: { 'style':'line' },
|
||||
legend: 'none',
|
||||
vAxis: { title: "Number of Responding Hosts" },
|
||||
hAxis: { title: "Timestamp" }
|
||||
};
|
||||
var dat = d.pingtimes;
|
||||
for(var prop in dat) {
|
||||
|
|
|
|||
|
|
@ -83,6 +83,10 @@ input[type=password]:focus {
|
|||
padding-bottom: 5px;
|
||||
}
|
||||
|
||||
#input_id {
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
#editor_mode {
|
||||
margin-right: 15px;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue