diff --git a/bin/convert.js b/bin/convert.js index d410f7a4..4302114c 100644 --- a/bin/convert.js +++ b/bin/convert.js @@ -4,6 +4,7 @@ var ueberDB = require("ueberDB"); var mysql = require("mysql"); var async = require("async"); var Changeset = require("../node/utils/Changeset"); +var randomString = require("../node/utils/randomstring"); var AttributePoolFactory = require("../node/utils/AttributePoolFactory"); var settingsFile = process.argv[2]; @@ -450,18 +451,3 @@ function parsePage(array, pageStart, offsets, data, json) start+=unitLength; } } - -/** - * Generates a random String with the given length. Is needed to generate the Author Ids - */ -function randomString(len) -{ - var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - var randomstring = ''; - for (var i = 0; i < len; i++) - { - var rnum = Math.floor(Math.random() * chars.length); - randomstring += chars.substring(rnum, rnum + 1); - } - return randomstring; -} diff --git a/node/db/AuthorManager.js b/node/db/AuthorManager.js index f4f42d11..7c054a56 100644 --- a/node/db/AuthorManager.js +++ b/node/db/AuthorManager.js @@ -22,6 +22,8 @@ var ERR = require("async-stacktrace"); var db = require("./DB").db; var async = require("async"); +var randomString = require("../utils/randomstring"); + /** * Checks if the author exists */ @@ -177,18 +179,3 @@ exports.setAuthorName = function (author, name, callback) { db.setSub("globalAuthor:" + author, ["name"], name, callback); } - -/** - * Generates a random String with the given length. Is needed to generate the Author Ids - */ -function randomString(len) -{ - var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - var randomstring = ''; - for (var i = 0; i < len; i++) - { - var rnum = Math.floor(Math.random() * chars.length); - randomstring += chars.substring(rnum, rnum + 1); - } - return randomstring; -} diff --git a/node/db/GroupManager.js b/node/db/GroupManager.js index 473ea9b7..7e3b7d6d 100644 --- a/node/db/GroupManager.js +++ b/node/db/GroupManager.js @@ -20,6 +20,7 @@ var ERR = require("async-stacktrace"); var customError = require("../utils/customError"); +var randomString = require("../utils/randomstring"); var db = require("./DB").db; var async = require("async"); var padManager = require("./PadManager"); @@ -255,18 +256,3 @@ exports.listPads = function(groupID, callback) } }); } - -/** - * Generates a random String with the given length. Is needed to generate the Author Ids - */ -function randomString(len) -{ - var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - var randomstring = ''; - for (var i = 0; i < len; i++) - { - var rnum = Math.floor(Math.random() * chars.length); - randomstring += chars.substring(rnum, rnum + 1); - } - return randomstring; -} diff --git a/node/db/ReadOnlyManager.js b/node/db/ReadOnlyManager.js index 73b3be9e..1e5079c5 100644 --- a/node/db/ReadOnlyManager.js +++ b/node/db/ReadOnlyManager.js @@ -22,6 +22,8 @@ var ERR = require("async-stacktrace"); var db = require("./DB").db; var async = require("async"); +var randomString = require("../utils/randomstring"); + /** * returns a read only id for a pad * @param {String} padId the id of the pad @@ -70,18 +72,3 @@ exports.getPadId = function(readOnlyId, callback) { db.get("readonly2pad:" + readOnlyId, callback); } - -/** - * Generates a random String with the given length. Is needed to generate the read only ids - */ -function randomString(len) -{ - var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - var randomstring = ''; - for (var i = 0; i < len; i++) - { - var rnum = Math.floor(Math.random() * chars.length); - randomstring += chars.substring(rnum, rnum + 1); - } - return randomstring; -} diff --git a/node/db/SecurityManager.js b/node/db/SecurityManager.js index 52d5afcb..4b86d868 100644 --- a/node/db/SecurityManager.js +++ b/node/db/SecurityManager.js @@ -26,6 +26,8 @@ var padManager = require("./PadManager"); var sessionManager = require("./SessionManager"); var settings = require("../utils/Settings") +var randomString = require("../utils/randomstring"); + /** * This function controlls the access to a pad, it checks if the user can access a pad. * @param padID the pad the user wants to access diff --git a/node/db/SessionManager.js b/node/db/SessionManager.js index a394f544..084d4a69 100644 --- a/node/db/SessionManager.js +++ b/node/db/SessionManager.js @@ -20,6 +20,7 @@ var ERR = require("async-stacktrace"); var customError = require("../utils/customError"); +var randomString = require("../utils/randomstring"); var db = require("./DB").db; var async = require("async"); var groupMangager = require("./GroupManager"); @@ -358,21 +359,6 @@ function listSessionsWithDBKey (dbkey, callback) }); } -/** - * Generates a random String with the given length. Is needed to generate the SessionIDs - */ -function randomString(len) -{ - var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - var randomstring = ''; - for (var i = 0; i < len; i++) - { - var rnum = Math.floor(Math.random() * chars.length); - randomstring += chars.substring(rnum, rnum + 1); - } - return randomstring; -} - //checks if a number is an int function is_int(value) { diff --git a/node/handler/APIHandler.js b/node/handler/APIHandler.js index 0cd9cb58..ca45e1f8 100644 --- a/node/handler/APIHandler.js +++ b/node/handler/APIHandler.js @@ -22,6 +22,7 @@ var ERR = require("async-stacktrace"); var fs = require("fs"); var api = require("../db/API"); var padManager = require("../db/PadManager"); +var randomString = require("../utils/randomstring"); //ensure we have an apikey var apikey = null; @@ -157,18 +158,3 @@ function callAPI(functionName, fields, req, res) //call the api function api[functionName](functionParams[0],functionParams[1],functionParams[2],functionParams[3],functionParams[4]); } - -/** - * Generates a random String with the given length. Is needed to generate the Author Ids - */ -function randomString(len) -{ - var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - var randomstring = ''; - for (var i = 0; i < len; i++) - { - var rnum = Math.floor(Math.random() * chars.length); - randomstring += chars.substring(rnum, rnum + 1); - } - return randomstring; -} diff --git a/node/utils/randomstring.js b/node/utils/randomstring.js new file mode 100644 index 00000000..4c1bba24 --- /dev/null +++ b/node/utils/randomstring.js @@ -0,0 +1,16 @@ +/** + * Generates a random String with the given length. Is needed to generate the Author, Group, readonly, session Ids + */ +var randomString = function randomString(len) +{ + var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + var randomstring = ''; + for (var i = 0; i < len; i++) + { + var rnum = Math.floor(Math.random() * chars.length); + randomstring += chars.substring(rnum, rnum + 1); + } + return randomstring; +}; + +module.exports = randomString;