-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch master from https://github.com/styluslabs/stylusboard.
- Loading branch information
Showing
3 changed files
with
116 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
# Stylusboard # | ||
|
||
Shared whiteboard server for [Stylus Labs Write](http://www.styluslabs.com) - enables multiple users to collaborate in real time on a handwritten document. | ||
In Write, enable advanced preferences, then in the Advanced -> Whiteboard server field enter the host name or IP address of the machine running `stylusboard`. | ||
In Write, enable advanced preferences, then in the Advanced -> Whiteboard server field enter the host name or IP address of the machine running this server. | ||
|
||
Last tested with an ancient version of node.js (0.10.36) | ||
Run `node.js whiteboard.js`. Last tested with an ancient version of node.js (0.10.36) | ||
|
||
Linux executable packaged with jx: http://www.styluslabs.com/write/stylusboard (Download and run this to get started quickly). | ||
|
||
By default, runs in anonymous mode, accepting all connections. To require login, specify a sqlite database file with the --db argument or db option in config file. dbUtil.js can be used to create and add users to the database - run `node dbUtil.js help` for options. | ||
|
||
Contact support at styluslabs.com with any issues or to request changes to the client-side code in Write. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
var wbDB = require('./whiteboardDB'); | ||
var fs = require('fs'); | ||
var pargs = require('minimist')(process.argv); | ||
|
||
if(pargs["db"] && !fs.existsSync(pargs["db"])) | ||
console.log("Database file " + pargs["db"] + " will be created."); | ||
|
||
var db = wbDB.openDB(pargs["db"], function(err) { | ||
if(err) { | ||
console.log("Error opening database " + pargs["db"] + ": ", err); | ||
process.exit(-102); | ||
} | ||
}); | ||
|
||
// copied from stylusweb app | ||
|
||
var addNewAccount = function(newData, callback) | ||
{ | ||
// check for conflict | ||
db.get("SELECT username, email FROM users WHERE username = ? OR email = ?", newData.user, newData.email, | ||
function(err, row) { | ||
if(row) { | ||
callback(row.username == newData.user ? 'username-taken' : 'email-taken'); | ||
} | ||
else { | ||
// no conflict | ||
var pwhash = wbDB.saltAndHash(newData.pass); | ||
db.run("INSERT INTO users(username, password, email, displayname) VALUES(?, ?, ?, ?)", | ||
newData.user, pwhash, newData.email, newData.displayname, callback); | ||
} | ||
}); | ||
} | ||
|
||
var updatePasswordByUser = function(username, newPass, callback) | ||
{ | ||
var pwhash = wbDB.saltAndHash(newPass); | ||
db.run("UPDATE users SET password = ? WHERE username = ?", pwhash, username, callback); | ||
} | ||
|
||
var deleteAccountByUser = function(username, callback) | ||
{ | ||
db.run("DELETE FROM users WHERE username = ?", username, callback); | ||
} | ||
|
||
|
||
// commands | ||
args = pargs._.slice(2); | ||
var cmd = args[0]; | ||
|
||
if(cmd == "adduser") { | ||
var userData = {'user': args[1], 'pass': args[2], 'email': args[3], 'displayname': args[4]}; | ||
addNewAccount(userData, function(e){ | ||
if(e) | ||
console.log("Error adding user: ", e); | ||
else | ||
console.log("User added."); | ||
}); | ||
} | ||
else if(cmd == "updatepw") { | ||
var user = args[1]; | ||
var pass = args[2]; | ||
updatePasswordByUser(user, pass, function(e){ | ||
if(e) | ||
console.log("Error updating password: ", e); | ||
else if(!this.changes) | ||
console.log("User not found."); | ||
else | ||
console.log("Password updated."); | ||
}); | ||
} | ||
else if(cmd == "rmuser") { | ||
var user = args[1]; | ||
deleteAccountByUser(user, function(e){ | ||
if(e) | ||
console.log("Error removing user: ", e); | ||
else | ||
console.log("User deleted."); | ||
}); | ||
} | ||
else if(cmd == "list") { | ||
db.all("SELECT username FROM users", function(err, rows) { | ||
rows.forEach(function(row){ console.log(row.username); }); | ||
}); | ||
} | ||
else { | ||
console.log("Stylus Labs whiteboard database utility"); | ||
console.log("Available commands:"); | ||
//console.log(" node dbTool.js --db <path to database file> createdb"); | ||
console.log(" adduser <username> <password> [[<email> <displayname>]] - add new user"); | ||
console.log(" updatepw <username> <newpassword> - change password for user"); | ||
console.log(" rmuser <username> - delete user"); | ||
console.log(" list - list all users"); | ||
console.log("Arguments:"); | ||
console.log(" --db <path to database file> (required)"); | ||
console.log("Example"); | ||
console.log("node dbUtil.js --db db1.sqlite adduser user1 passwd1"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters