diff --git a/coffee/components-manager.coffee b/coffee/components-manager.coffee index 8a787c1..ca08d01 100644 --- a/coffee/components-manager.coffee +++ b/coffee/components-manager.coffee @@ -181,6 +181,7 @@ forgeModule = ( user, oPayload, dbMod, callback ) => answ.message = " Module #{ oPayload.id } successfully stored! Found following function(s): #{ funcs }" oPayload.functions = JSON.stringify funcs + oPayload.functionParameters = JSON.stringify cm.funcParams dbMod.storeModule user.username, oPayload if oPayload.public is 'true' dbMod.publish oPayload.id @@ -225,13 +226,27 @@ commandFunctions = getModules user, oPayload, db.actionInvokers, callback get_full_action_invoker: ( user, oPayload, callback ) -> - db.actionInvokers.getModule oPayload.id, ( err, obj ) -> - callback - code: 200 - message: JSON.stringify obj + answ = hasRequiredParams [ 'id' ], oPayload + if answ.code isnt 200 + callback answ + else + db.actionInvokers.getModule oPayload.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_function_params: ( user, oPayload, callback ) -> + answ = hasRequiredParams [ 'id' ], oPayload + if answ.code isnt 200 + callback answ + else + db.actionInvokers.getModuleField oPayload.id, 'functionParameters', ( err, obj ) -> + callback + code: 200 + message: obj forge_action_invoker: ( user, oPayload, callback ) -> forgeModule user, oPayload, db.actionInvokers, callback @@ -281,20 +296,28 @@ commandFunctions = code: 409 message: 'Rule name already existing!' else + console.log 'new ruke' rule = id: oPayload.id event: oPayload.event conditions: oPayload.conditions actions: oPayload.actions strRule = JSON.stringify rule + console.log 'stringified' db.storeRule rule.id, strRule + console.log 'stored' db.linkRule rule.id, user.username + console.log 'linked' db.activateRule rule.id, user.username + console.log 'activated' if oPayload.event_params epModId = rule.event.split( ' -> ' )[0] db.eventPollers.storeUserParams epModId, user.username, oPayload.event_params + console.log 'event params loaded' arrParams = oPayload.action_params + console.log 'arractionparams' db.actionInvokers.storeUserParams id, user.username, JSON.stringify params for id, params of arrParams + console.log 'action aprams stored' db.resetLog user.username, rule.id db.appendLog user.username, rule.id, "INIT", "Rule '#{ rule.id }' initialized" eventEmitter.emit 'rule', @@ -304,6 +327,7 @@ commandFunctions = answ = code: 200 message: "Rule '#{ rule.id }' stored and activated!" + console.log 'done' callback answ delete_rule: ( user, oPayload, callback ) -> diff --git a/coffee/dynamic-modules.coffee b/coffee/dynamic-modules.coffee index 2a52ce4..72f7022 100644 --- a/coffee/dynamic-modules.coffee +++ b/coffee/dynamic-modules.coffee @@ -80,6 +80,15 @@ logFunction = ( uId, rId, mId ) -> ( msg ) -> db.appendLog uId, rId, mId, msg +regexpComments = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg; +getFunctionParamNames = ( fName, func, oFuncs ) -> + fnStr = func.toString().replace regexpComments, '' + result = fnStr.slice( fnStr.indexOf( '(' ) + 1, fnStr.indexOf( ')' ) ).match /([^\s,]+)/g + if not result + result = [] + oFuncs[fName] = result + + ### Try to run a JS module from a string, together with the given parameters. If it is written in CoffeeScript we @@ -142,9 +151,13 @@ exports.compileString = ( src, userId, ruleId, modId, lang, dbMod, cb ) => if not msg msg = 'Try to run the script locally to track the error! Sadly we cannot provide the line number' answ.message = 'Loading Module failed: ' + msg + oFuncParams = {} + for fName, func of sandbox.exports + getFunctionParamNames fName, func, oFuncParams cb answ: answ module: sandbox.exports + funcParams: oFuncParams logger: sandbox.log if dbMod diff --git a/coffee/persistence.coffee b/coffee/persistence.coffee index 357c7d0..ec197dd 100644 --- a/coffee/persistence.coffee +++ b/coffee/persistence.coffee @@ -252,6 +252,10 @@ class IndexedModules @log.info "DB | (IdxedMods) #{ @setname }.getModule( #{ mId } )" @db.hgetall "#{ @setname }:#{ mId }", cb + getModuleField: ( mId, field, cb ) => + @log.info "DB | (IdxedMods) #{ @setname }.getModule( #{ mId } )" + @db.hget "#{ @setname }:#{ mId }", field, cb + #TODO add testing getModuleParams: ( mId, cb ) => @log.info "DB | (IdxedMods) #{ @setname }.getModuleParams( #{ mId } )" diff --git a/config/system.json b/config/system.json index ca43219..c75a3a9 100644 --- a/config/system.json +++ b/config/system.json @@ -6,7 +6,7 @@ "mode": "development", "io-level": "info", "file-level": "info", - "file-path": "server.log" + "file-path": "logs/server.log" }, "keygen-passphrase": "[TODO this has to come from prompt when server is started!]" } \ No newline at end of file diff --git a/examples/action-invokers/emailyak.coffee b/examples/action-invokers/emailyak.coffee index 0961c3d..ed51d03 100644 --- a/examples/action-invokers/emailyak.coffee +++ b/examples/action-invokers/emailyak.coffee @@ -4,9 +4,6 @@ EmailYak ACTION INVOKER # # Requires user params: # - apikey: The user's EmailYak API key -# - sender: The email address belonging to your apikey -# - receipient: The email address for the one that receives the mail -# - subject: The subject of the mail ### url = 'https://api.emailyak.com/v1/' + params.apikey + '/json/send/email/' @@ -29,13 +26,16 @@ standardCallback = ( funcName ) -> ### Send a mail through Emailyak. -@param {Object} args.content the content to be posted in the mail body +@param sender The email address belonging to your apikey +@param receipient The email address for the one that receives the mail +@param subject The subject of the mail +@param content The content of the mail ### -exports.sendMail = ( args ) -> +exports.sendMail = ( sender, receipient, subject, content ) -> data = - FromAddress: params.sender - ToAddress: params.receipient - Subject: params.subject - TextBody: args.content + FromAddress: sender + ToAddress: receipient + Subject: subject + TextBody: content needlereq 'post', url, data, json: true, standardCallback 'sendMail' diff --git a/js/components-manager.js b/js/components-manager.js index 2770d7b..88bfa77 100644 --- a/js/components-manager.js +++ b/js/components-manager.js @@ -249,6 +249,7 @@ Components Manager _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.functionParameters = JSON.stringify(cm.funcParams); dbMod.storeModule(user.username, oPayload); if (oPayload["public"] === 'true') { dbMod.publish(oPayload.id); @@ -303,16 +304,36 @@ Components Manager return getModules(user, oPayload, db.actionInvokers, callback); }, get_full_action_invoker: function(user, oPayload, callback) { - return db.actionInvokers.getModule(oPayload.id, function(err, obj) { - return callback({ - code: 200, - message: JSON.stringify(obj) + var answ; + answ = hasRequiredParams(['id'], oPayload); + if (answ.code !== 200) { + return callback(answ); + } else { + return db.actionInvokers.getModule(oPayload.id, function(err, obj) { + return callback({ + code: 200, + message: JSON.stringify(obj) + }); }); - }); + } }, get_action_invoker_params: function(user, oPayload, callback) { return getModuleParams(user, oPayload, db.actionInvokers, callback); }, + get_action_invoker_function_params: function(user, oPayload, callback) { + var answ; + answ = hasRequiredParams(['id'], oPayload); + if (answ.code !== 200) { + return callback(answ); + } else { + return db.actionInvokers.getModuleField(oPayload.id, 'functionParameters', function(err, obj) { + return callback({ + code: 200, + message: obj + }); + }); + } + }, forge_action_invoker: function(user, oPayload, callback) { return forgeModule(user, oPayload, db.actionInvokers, callback); }, @@ -365,6 +386,7 @@ Components Manager message: 'Rule name already existing!' }; } else { + console.log('new ruke'); rule = { id: oPayload.id, event: oPayload.event, @@ -372,18 +394,25 @@ Components Manager actions: oPayload.actions }; strRule = JSON.stringify(rule); + console.log('stringified'); db.storeRule(rule.id, strRule); + console.log('stored'); db.linkRule(rule.id, user.username); + console.log('linked'); db.activateRule(rule.id, user.username); + console.log('activated'); if (oPayload.event_params) { epModId = rule.event.split(' -> ')[0]; db.eventPollers.storeUserParams(epModId, user.username, oPayload.event_params); } + console.log('event params loaded'); arrParams = oPayload.action_params; + console.log('arractionparams'); for (id in arrParams) { params = arrParams[id]; db.actionInvokers.storeUserParams(id, user.username, JSON.stringify(params)); } + console.log('action aprams stored'); db.resetLog(user.username, rule.id); db.appendLog(user.username, rule.id, "INIT", "Rule '" + rule.id + "' initialized"); eventEmitter.emit('rule', { @@ -395,6 +424,7 @@ Components Manager code: 200, message: "Rule '" + rule.id + "' stored and activated!" }; + console.log('done'); } return callback(answ); }); diff --git a/js/dynamic-modules.js b/js/dynamic-modules.js index 63f1f7e..974430b 100644 --- a/js/dynamic-modules.js +++ b/js/dynamic-modules.js @@ -9,7 +9,7 @@ Dynamic Modules */ (function() { - var cryptico, cryptoJS, cs, db, exports, issueNeedleCall, issueRequest, logFunction, needle, request, vm; + var cryptico, cryptoJS, cs, db, exports, getFunctionParamNames, issueNeedleCall, issueRequest, logFunction, needle, regexpComments, request, vm; db = require('./persistence'); @@ -104,6 +104,18 @@ Dynamic Modules }; }; + regexpComments = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg; + + getFunctionParamNames = function(fName, func, oFuncs) { + var fnStr, result; + fnStr = func.toString().replace(regexpComments, ''); + result = fnStr.slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')')).match(/([^\s,]+)/g); + if (!result) { + result = []; + } + return oFuncs[fName] = result; + }; + /* Try to run a JS module from a string, together with the @@ -134,7 +146,7 @@ Dynamic Modules } } fTryToLoad = function(params) { - var logFunc, msg, oDecrypted, sandbox; + var fName, func, logFunc, msg, oDecrypted, oFuncParams, sandbox, _ref; if (params) { try { oDecrypted = cryptico.decrypt(params, _this.oPrivateRSAkey); @@ -170,9 +182,16 @@ Dynamic Modules } answ.message = 'Loading Module failed: ' + msg; } + oFuncParams = {}; + _ref = sandbox.exports; + for (fName in _ref) { + func = _ref[fName]; + getFunctionParamNames(fName, func, oFuncParams); + } return cb({ answ: answ, module: sandbox.exports, + funcParams: oFuncParams, logger: sandbox.log }); }; diff --git a/js/persistence.js b/js/persistence.js index 4420bf2..60a1974 100644 --- a/js/persistence.js +++ b/js/persistence.js @@ -262,6 +262,7 @@ Persistence this.getModuleIds = __bind(this.getModuleIds, this); this.getAvailableModuleIds = __bind(this.getAvailableModuleIds, this); this.getModuleParams = __bind(this.getModuleParams, this); + this.getModuleField = __bind(this.getModuleField, this); this.getModule = __bind(this.getModule, this); this.unpublish = __bind(this.unpublish, this); this.publish = __bind(this.publish, this); @@ -319,6 +320,11 @@ Persistence return this.db.hgetall("" + this.setname + ":" + mId, cb); }; + IndexedModules.prototype.getModuleField = function(mId, field, cb) { + this.log.info("DB | (IdxedMods) " + this.setname + ".getModule( " + mId + " )"); + return this.db.hget("" + this.setname + ":" + mId, field, cb); + }; + IndexedModules.prototype.getModuleParams = function(mId, cb) { this.log.info("DB | (IdxedMods) " + this.setname + ".getModuleParams( " + mId + " )"); return this.db.hget("" + this.setname + ":" + mId, "params", cb); diff --git a/package.json b/package.json index 6f333fb..f349554 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,6 @@ "dependencies": { "bunyan": "0.22.1", "coffee-script": "1.6.3", - "connect-redis": "1.4.6", "crypto-js": "3.1.2", "express": "3.4.8", "groc": "0.6.1", diff --git a/webpages/handlers/coffee/edit_modules.coffee b/webpages/handlers/coffee/edit_modules.coffee index 2cc3aac..62ede49 100644 --- a/webpages/handlers/coffee/edit_modules.coffee +++ b/webpages/handlers/coffee/edit_modules.coffee @@ -47,11 +47,13 @@ fOnLoad = () -> oMods = JSON.parse data.message for modName of oMods tr = $ '' - img = $( '' ).attr( 'class', 'del' ).attr 'src', 'red_cross_small.png' - imgTwo = $( '' ).attr( 'class', 'log' ).attr 'src', 'logicon.png' inp = $( '
' ).text modName + img = $( '' ).attr( 'class', 'del' ) + .attr( 'title', 'Delete Module' ).attr 'src', 'red_cross_small.png' + tr.append( $( '' ).append img ) + img = $( '' ).attr( 'class', 'log' ) + .attr( 'title', 'Edit Module' ).attr 'src', 'edit.png' tr.append( $( '' ).append img ) - tr.append( $( '' ).append imgTwo ) tr.append( $( '' ).append inp ) $( '#tableModules' ).append tr diff --git a/webpages/handlers/coffee/edit_rules.coffee b/webpages/handlers/coffee/edit_rules.coffee index b8edb95..3abf8f2 100644 --- a/webpages/handlers/coffee/edit_rules.coffee +++ b/webpages/handlers/coffee/edit_rules.coffee @@ -1,3 +1,15 @@ + + + + + + + + # encodeURIComponent(url); -> Rule Name to be passed to forge_rule + + + + fOnLoad = () -> document.title = 'Edit Rules' @@ -29,11 +41,16 @@ fOnLoad = () -> $( '#tableRules tr' ).remove() for ruleName in data.message tr = $ '' - img = $( '' ).attr( 'class', 'del' ).attr 'src', 'red_cross_small.png' - imgTwo = $( '' ).attr( 'class', 'log' ).attr 'src', 'logicon.png' - inp = $( '
' ).text ruleName + img = $( '' ).attr( 'class', 'del' ) + .attr( 'title', 'Delete Rule' ).attr 'src', 'red_cross_small.png' tr.append( $( '' ).append img ) - tr.append( $( '' ).append imgTwo ) + img = $( '' ).attr( 'class', 'edit' ) + .attr( 'title', 'Edit Rule' ).attr 'src', 'edit.png' + tr.append( $( '' ).append img ) + img = $( '' ).attr( 'class', 'log' ) + .attr( 'title', 'Show Rule Log' ).attr 'src', 'logicon.png' + tr.append( $( '' ).append img ) + inp = $( '
' ).text ruleName tr.append( $( '' ).append inp ) $( '#tableRules' ).append tr @@ -52,6 +69,10 @@ fOnLoad = () -> .done fFetchRules .fail fErrHandler 'Could not delete rule! ' + $( '#tableRules' ).on 'click', 'img.edit', () -> + ruleName = $( 'div', $( this ).closest( 'tr' )).text() + window.location.href = 'forge?page=forge_rule&id=' + encodeURIComponent ruleName + $( '#tableRules' ).on 'click', 'img.log', () -> ruleName = $( 'div', $( this ).closest( 'tr' )).text() data = @@ -65,4 +86,38 @@ fOnLoad = () -> $( '#log_col' ).html "

#{ ruleName } Log:

#{ log }" .fail fErrHandler 'Could not get rule log! ' + # Add parameter list functionality + fChangeInputVisibility = () -> + $( '#tableParams tr' ).each ( id ) -> + if $( this ).is ':last-child' or $( this ).is ':only-child' + $( 'img', this ).hide() + $( 'input[type=checkbox]', this ).hide() + else + $( 'img', this ).show() + $( 'input[type=checkbox]', this ).show() + + $( '#tableParams' ).on 'click', 'img', () -> + par = $( this ).closest 'tr' + if not par.is ':last-child' + par.remove() + fChangeInputVisibility() + + $( '#tableParams' ).on 'keyup', 'input', ( e ) -> + code = e.keyCode or e.which + if code isnt 9 + par = $( this ).closest 'tr' + if par.is ':last-child' + tr = $ '' + img = $( '' ).attr( 'title', 'Remove?').attr 'src', 'red_cross_small.png' + cb = $( '' ).attr( 'type', 'checkbox' ).attr 'title', 'Password shielded input?' + inp = $( '' ).attr( 'type', 'text' ).attr 'class', 'textinput' + tr.append $( '' ).append img + tr.append $( '' ).append cb + tr.append $( '' ).append inp + par.parent().append tr + fChangeInputVisibility() + else if $( this ).val() is '' and not par.is ':only-child' + par.remove() + + fChangeInputVisibility() window.addEventListener 'load', fOnLoad, true diff --git a/webpages/handlers/coffee/forge_action_invoker.coffee b/webpages/handlers/coffee/forge_action_invoker.coffee index a357139..80e9f8b 100644 --- a/webpages/handlers/coffee/forge_action_invoker.coffee +++ b/webpages/handlers/coffee/forge_action_invoker.coffee @@ -17,44 +17,52 @@ fOnLoad = () -> editor.getSession().setMode "ace/mode/javascript" # Add parameter list functionality - fChangeCrosses = () -> - $( '#tableParams img' ).each ( id ) -> - par = $( this ).closest 'tr' - if par.is ':last-child' or par.is ':only-child' - $( this ).hide() + fChangeInputVisibility = () -> + $( '#tableParams tr' ).each ( id ) -> + if $( this ).is ':last-child' or $( this ).is ':only-child' + $( 'img', this ).hide() + $( 'input[type=checkbox]', this ).hide() else - $( this ).show() + $( 'img', this ).show() + $( 'input[type=checkbox]', this ).show() $( '#tableParams' ).on 'click', 'img', () -> par = $( this ).closest 'tr' if not par.is ':last-child' par.remove() - fChangeCrosses() + fChangeInputVisibility() - $( '#tableParams' ).on 'keyup', 'input', () -> - par = $( this ).closest( 'tr' ) - if par.is ':last-child' - tr = $ '' - img = $( '' ).attr 'src', 'red_cross_small.png' - inp = $( '' ).attr 'type', 'text' - tr.append( $( '' ).append img ) - tr.append( $( '' ).append inp ) - par.parent().append tr - fChangeCrosses() - else if $( this ).val() is '' and not par.is ':only-child' - par.remove() - fChangeCrosses() + $( '#tableParams' ).on 'keyup', 'input', ( e ) -> + code = e.keyCode or e.which + if code isnt 9 + par = $( this ).closest( 'tr' ) + if par.is ':last-child' + tr = $ '' + img = $( '' ).attr( 'title', 'Remove?').attr 'src', 'red_cross_small.png' + cb = $( '' ).attr( 'type', 'checkbox' ).attr 'title', 'Password shielded input?' + inp = $( '' ).attr( 'type', 'text' ).attr 'class', 'textinput' + tr.append( $( '' ).append img ) + tr.append( $( '' ).append cb ) + tr.append( $( '' ).append inp ) + par.parent().append tr + fChangeInputVisibility() + else if $( this ).val() is '' and not par.is ':only-child' + par.remove() + + fChangeInputVisibility() # Add submit button logic $( '#but_submit' ).click () -> if $( '#input_id' ).val() is '' alert 'Please enter an action invoker name!' else - listParams = [] - $( '#tableParams input' ).each () -> - val = $( this ).val() + listParams = {} + $( '#tableParams tr' ).each () -> + val = $( 'input.textinput', this ).val() + shld = $( 'input[type=checkbox]', this ).is ':checked' if val isnt "" - listParams.push val + listParams[val] = shld + true obj = command: 'forge_action_invoker' payload: diff --git a/webpages/handlers/coffee/forge_event_poller.coffee b/webpages/handlers/coffee/forge_event_poller.coffee index ecda36c..026f211 100644 --- a/webpages/handlers/coffee/forge_event_poller.coffee +++ b/webpages/handlers/coffee/forge_event_poller.coffee @@ -16,44 +16,53 @@ fOnLoad = () -> editor.getSession().setMode "ace/mode/javascript" # Add parameter list functionality - fChangeCrosses = () -> - $( '#tableParams img' ).each ( id ) -> - par = $( this ).closest 'tr' - if par.is ':last-child' or par.is ':only-child' - $( this ).hide() + fChangeInputVisibility = () -> + $( '#tableParams tr' ).each ( id ) -> + if $( this ).is ':last-child' or $( this ).is ':only-child' + $( 'img', this ).hide() + $( 'input[type=checkbox]', this ).hide() else - $( this ).show() + $( 'img', this ).show() + $( 'input[type=checkbox]', this ).show() $( '#tableParams' ).on 'click', 'img', () -> par = $( this ).closest 'tr' if not par.is ':last-child' par.remove() - fChangeCrosses() + fChangeInputVisibility() - $( '#tableParams' ).on 'keyup', 'input', () -> - par = $( this ).closest( 'tr' ) - if par.is ':last-child' - tr = $ '' - img = $( '' ).attr 'src', 'red_cross_small.png' - inp = $( '' ).attr 'type', 'text' - tr.append( $( '' ).append img ) - tr.append( $( '' ).append inp ) - par.parent().append tr - fChangeCrosses() - else if $( this ).val() is '' and not par.is ':only-child' - par.remove() - fChangeCrosses() + $( '#tableParams' ).on 'keyup', 'input', ( e ) -> + code = e.keyCode or e.which + if code isnt 9 + par = $( this ).closest( 'tr' ) + if par.is ':last-child' + tr = $ '' + img = $( '' ).attr( 'title', 'Remove?').attr 'src', 'red_cross_small.png' + cb = $( '' ).attr( 'type', 'checkbox' ).attr 'title', 'Password shielded input?' + inp = $( '' ).attr( 'type', 'text' ).attr 'class', 'textinput' + tr.append( $( '' ).append img ) + tr.append( $( '' ).append cb ) + tr.append( $( '' ).append inp ) + tr.append $( '' ) + par.parent().append tr + fChangeInputVisibility() + else if $( this ).val() is '' and not par.is ':only-child' + par.remove() + + fChangeInputVisibility() # Add submit button logic $( '#but_submit' ).click () -> if $( '#input_id' ).val() is '' alert 'Please enter an event poller name!' else - listParams = [] - $( '#tableParams input' ).each () -> - val = $( this ).val() + listParams = {} + $( '#tableParams tr' ).each () -> + val = $( 'input.textinput', this ).val() + shld = $( 'input[type=checkbox]', this ).is ':checked' if val isnt "" - listParams.push val + listParams[val] = shld + true obj = command: 'forge_event_poller' payload: diff --git a/webpages/handlers/coffee/forge_rule.coffee b/webpages/handlers/coffee/forge_rule.coffee index f950330..19b3e6b 100644 --- a/webpages/handlers/coffee/forge_rule.coffee +++ b/webpages/handlers/coffee/forge_rule.coffee @@ -1,4 +1,13 @@ strPublicKey = '' + +fFailedRequest = ( msg ) -> + ( err ) -> + if err.status is 401 + window.location.href = 'forge?page=forge_rule' + else + $( '#info' ).text msg + $( '#info' ).attr 'class', 'error' + $.post( '/usercommand', command: 'get_public_key' ) .done ( data ) -> strPublicKey = data.message @@ -6,11 +15,12 @@ $.post( '/usercommand', command: 'get_public_key' ) if err.status is 401 window.location.href = 'forge?page=forge_rule' else - console.log err - $( '#info' ).text 'Error fetching public key, unable to send user-specific parameters securely' + $( '#info' ).text 'Error fetching public key, unable to send user specific parameters securely' $( '#info' ).attr 'class', 'error' fOnLoad = () -> + document.title = 'Rule Forge!' + $( '#pagetitle' ).text '{{{user.username}}}, forge your ECA Rule!' editor = ace.edit "editor_conditions" editor.setTheme "ace/theme/monokai" @@ -18,9 +28,6 @@ fOnLoad = () -> editor.setShowPrintMargin false # editor.session.setUseSoftTabs false - document.title = 'Rule Forge!' - $( '#pagetitle' ).text '{{{user.username}}}, forge your ECA Rule!' - # Fetch Event Poller user-specific parameters fFetchEventParams = ( name ) -> if name @@ -33,39 +40,24 @@ fOnLoad = () -> $.post( '/usercommand', obj ) .done ( data ) -> if data.message - arrParams = JSON.parse data.message + oParams = JSON.parse data.message $( '#event_poller_params table' ).remove() - if arrParams.length > 0 - table = $ '' - $( '#event_poller_params' ).append table - fAppendParam = ( name ) -> - tr = $( '' ) - tr.append $( '
' ).css 'width', '20px' - tr.append $( '' ).attr( 'class', 'key' ).text name - inp = $( '' ).attr( 'type', 'password' ).attr 'id', "#{ name }" - tr.append $( '' ).text( ' :' ).append inp - table.append tr - fAppendParam name for name in arrParams - .fail ( err ) -> - if err.status is 401 - window.location.href = 'forge?page=forge_rule' - else - fDelayed = () -> - console.log err - $( '#info' ).text 'Error fetching event poller params' - $( '#info' ).attr 'class', 'error' - setTimeout fDelayed, 500 - - -#FIXME Add possibility for custom event via text input -#FIXME Add conditions -#FIXME Only send user parameters encrypted! RSA required! Crypto-js doesn't provide it - + table = $ '' + $( '#event_poller_params' ).append table + fAppendParam = ( name, shielded ) -> + tr = $( '' ) + tr.append $( '
' ).css 'width', '20px' + tr.append $( '' ).attr( 'class', 'key' ).text name + inp = $( '' ).attr 'id', "#{ name }" + if shielded + inp.attr( 'type', 'password' ) + tr.append $( '' ).text( ' : ' ).append inp + table.append tr + fAppendParam name, shielded for name, shielded of oParams + .fail fFailedRequest 'Error fetching event poller params' # Init Event Pollers - obj = - command: 'get_event_pollers' - $.post( '/usercommand', obj ) + $.post( '/usercommand', command: 'get_event_pollers' ) .done ( data ) -> try oEps = JSON.parse data.message @@ -79,110 +71,119 @@ fOnLoad = () -> fAppendEvent evt for evt in events fAppendEvents id, events for id, events of oEps fFetchEventParams $( '#select_event option:selected' ).text() - .fail ( err ) -> - if err.status is 401 - window.location.href = 'forge?page=forge_rule' - else - fDelayed = () -> - console.log err - $( '#info' ).text 'Error fetching event poller' - $( '#info' ).attr 'class', 'error' - setTimeout fDelayed, 500 + .fail fFailedRequest 'Error fetching event poller' $( '#select_event' ).change () -> fFetchEventParams $( this ).val() # Init Action Invoker - arrActionInvoker = [] obj = command: 'get_action_invokers' $.post( '/usercommand', obj ) + .done ( data ) -> try oAis = JSON.parse data.message catch err console.error 'ERROR: non-object received from server: ' + data.message return - i = 0 - fAppendActions = ( id, actions ) -> - fAppendAction = ( act ) -> - $( '#select_actions' ).append $( '