| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| // -*- mode: javascript -*- | ||
|
|
||
| // registeruser.js | ||
| // | ||
| // Register a new user with the activity pump | ||
| // | ||
| // Copyright 2011-2012, E14N https://e14n.com/ | ||
| // 2013, Intevation GmbH Mathias Gebbe | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| var _ = require("underscore"), | ||
| url = require("url"), | ||
| Step = require("step"), | ||
| readline = require('readline'), | ||
| common = require("../lib/pumpclient"), | ||
| clientCred = common.clientCred, | ||
| setUserCred = common.setUserCred, | ||
| postJSON = common.postJSON, | ||
| argv = require("optimist") | ||
| .usage("Usage: $0 -u <nickname>") | ||
| .demand(["u"]) | ||
| .alias("u", "username") | ||
| .alias("p", "password") | ||
| .alias("s", "server") | ||
| .alias("P", "port") | ||
| .alias("a", "adminpw") | ||
| .alias("e", "email") | ||
| .alias("v", "verbose") | ||
| .describe("u", "Username to register") | ||
| .describe("p", "Password for user") | ||
| .describe("s", "Server name") | ||
| .describe("P", "Port") | ||
| .describe("e", "User email address") | ||
| .describe("a", "Admin Password") | ||
| .describe("v", "Verbose") | ||
| .default("P", 443) | ||
| .default("s", "io.intevation.de") | ||
| .argv; | ||
|
|
||
| var user = {"nickname": argv.u}; | ||
|
|
||
| var server = argv.s; | ||
| var port = argv.P; | ||
| var verbose = argv.v | ||
|
|
||
| var rl = readline.createInterface({ | ||
| input: process.stdin, | ||
| output: process.stdout | ||
| }); | ||
|
|
||
|
|
||
| Step( | ||
| function(){ | ||
| var callback=this; | ||
| if(argv.a === undefined) { | ||
| rl.question("Enter the admin password: ", function(adminpw) { | ||
| adminpw.trim(); | ||
| user.adminpw=adminpw; | ||
| callback(); | ||
| }); | ||
| }else{ | ||
| user.adminpw = argv.a; | ||
| callback(); | ||
| } | ||
| }, | ||
| function(){ | ||
| var callback=this; | ||
| if(argv.e === undefined) { | ||
| rl.question("Enter email address for user "+user.nickname+": ", function(email) { | ||
| email.trim(); | ||
| user.email = email; | ||
| callback(); | ||
| }); | ||
| }else{ | ||
| user.email = argv.e; | ||
| callback(); | ||
| } | ||
|
|
||
| }, | ||
| function(){ | ||
| var callback=this; | ||
| if(argv.p === undefined) { | ||
| rl.question("Enter password for user "+user.nickname+": ", function(password) { | ||
| password.trim(); | ||
| user.password = password; | ||
| callback(); | ||
| }); | ||
| }else{ | ||
| user.password = argv.p; | ||
| callback(); | ||
| } | ||
|
|
||
| }, | ||
| function() { | ||
| clientCred(server, this); | ||
| }, | ||
| function(err, cred) { | ||
| if (err) throw err; | ||
| var endpoint = url.format({ | ||
| protocol: ((port == 443) ? "https" : "http"), | ||
| host: ((port == 80) ? server : server + ":" + port), | ||
| pathname: "/api/users" | ||
| }); | ||
| postJSON(endpoint, cred, user, this); | ||
| }, | ||
| function(err, body, result) { | ||
| if (err) { | ||
| console.error(err); | ||
| process.exit(0); | ||
| } else { | ||
| setUserCred(body.nickname, server, {token: body.token, token_secret: body.secret}, this); | ||
| if(verbose) console.log(body); | ||
| else console.log("OK"); | ||
| process.exit(0); | ||
| } | ||
| } | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| // -*- mode: javascript -*- | ||
|
|
||
| // Copyright 2013, Mathias Gebbe | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| var fs = require("fs"), | ||
| path = require("path") | ||
| urlparse = require("url").parse, | ||
| Step = require("step"), | ||
| _ = require("underscore"), | ||
| Logger = require("bunyan"), | ||
| Queue = require("jankyqueue"), | ||
| databank = require("databank"), | ||
| Databank = databank.Databank, | ||
| DatabankObject = databank.DatabankObject, | ||
| Distributor = require("../lib/distributor").Distributor, | ||
| schema = require("../lib/schema").schema, | ||
| Activity = require("../lib/model/activity").Activity, | ||
| Stream = require("../lib/model/stream").Stream, | ||
| ActivityObject = require("../lib/model/activityobject").ActivityObject, | ||
| URLMaker = require("../lib/urlmaker").URLMaker, | ||
| User = require("../lib/model/user").User, | ||
| argv = require("optimist") | ||
| .usage("Usage: $0 -t type") | ||
| .alias("t", "type") | ||
| .demand(["t"]) | ||
| .describe("t", "type") | ||
| .argv, | ||
| type = argv.t; | ||
|
|
||
| var QUEUE_MAX = 1; | ||
|
|
||
| var main = function() { | ||
| var config = getConfig(argv.c), | ||
| q = new Queue(QUEUE_MAX), | ||
| log = setupLogger(config); | ||
|
|
||
| log.info("Initializing pump.io"); | ||
|
|
||
| URLMaker.hostname = config.hostname; | ||
| URLMaker.port = (config.urlPort) ? config.urlPort : config.port; | ||
|
|
||
| Step( | ||
| function() { | ||
| log.info("Connecting to databank"); | ||
| connectDatabank(config, this); | ||
| }, | ||
| function(err, db) { | ||
|
|
||
| db.scan(type, scanfind, function(result) { | ||
| console.log("fin!"); | ||
| process.exit(0); | ||
| }); | ||
|
|
||
| } | ||
| ); | ||
| }; | ||
|
|
||
| var scanfind = function(find) { | ||
| console.log(find) | ||
| } | ||
|
|
||
| // Gets the configuration vars for this server from config files | ||
|
|
||
| var getConfig = function(filename) { | ||
| var files, | ||
| config = {}, | ||
| i, | ||
| raw, | ||
| parsed; | ||
|
|
||
| if (filename) { | ||
| files = [filename]; | ||
| } else { | ||
| files = ['/etc/pump.io.json', | ||
| path.join(process.env.HOME, ".pump.io.json")]; | ||
| } | ||
|
|
||
| // This is all sync | ||
| for (i = 0; i < files.length; i++) { | ||
| if (fs.existsSync(files[i])) { | ||
| raw = fs.readFileSync(files[i]); | ||
| try { | ||
| parsed = JSON.parse(raw); | ||
| _.extend(config, parsed); | ||
| } catch (err) { | ||
| console.log(err); | ||
| process.exit(1); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return config; | ||
| }; | ||
|
|
||
| var connectDatabank = function(config, callback) { | ||
|
|
||
| var params, | ||
| db; | ||
|
|
||
| if (_(config).has("params")) { | ||
| params = config.params; | ||
| } else { | ||
| params = {}; | ||
| } | ||
|
|
||
| if (_(params).has("schema")) { | ||
| _.extend(params.schema, schema); | ||
| } else { | ||
| params.schema = schema; | ||
| } | ||
|
|
||
| db = Databank.get(config.driver, params); | ||
|
|
||
| // Connect... | ||
|
|
||
| db.connect({}, function(err) { | ||
| if (err) { | ||
| callback(err, null); | ||
| return; | ||
| } | ||
|
|
||
| DatabankObject.bank = db; | ||
| callback(null, db); | ||
| }); | ||
| }; | ||
|
|
||
| var setupLogger = function(config) { | ||
| var log, | ||
| logParams = { | ||
| name: "pump.io", | ||
| component: "testing-databank" | ||
| }; | ||
|
|
||
| if (config.logfile) { | ||
| logParams.streams = [{path: config.logfile}]; | ||
| } else if (config.nologger) { | ||
| logParams.streams = [{path: "/dev/null"}]; | ||
| } else { | ||
| logParams.streams = [{stream: process.stderr}]; | ||
| } | ||
|
|
||
| log = new Logger(logParams); | ||
|
|
||
| return log; | ||
| }; | ||
|
|
||
| main(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| // -*- mode: javascript -*- | ||
|
|
||
| // Copyright 2013, Mathias Gebbe | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| var fs = require("fs"), | ||
| path = require("path") | ||
| urlparse = require("url").parse, | ||
| Step = require("step"), | ||
| _ = require("underscore"), | ||
| Logger = require("bunyan"), | ||
| Queue = require("jankyqueue"), | ||
| databank = require("databank"), | ||
| Databank = databank.Databank, | ||
| DatabankObject = databank.DatabankObject, | ||
| Distributor = require("../lib/distributor").Distributor, | ||
| schema = require("../lib/schema").schema, | ||
| Activity = require("../lib/model/activity").Activity, | ||
| Stream = require("../lib/model/stream").Stream, | ||
| ActivityObject = require("../lib/model/activityobject").ActivityObject, | ||
| URLMaker = require("../lib/urlmaker").URLMaker, | ||
| User = require("../lib/model/user").User, | ||
| argv = require("optimist") | ||
| .usage("Usage: $0 -u username -i nodeid") | ||
| .demand(["u","t"]) | ||
| .alias("u", "user") | ||
| .alias("t", "type") | ||
| .describe("t", "type (note,share,etc..)") | ||
| .describe("u", "username@server.tld") | ||
| .argv, | ||
| user = argv.u; | ||
| type = argv.t; | ||
|
|
||
| var QUEUE_MAX = 1; | ||
|
|
||
| var main = function() { | ||
| var config = getConfig(argv.c), | ||
| q = new Queue(QUEUE_MAX), | ||
| log = setupLogger(config); | ||
|
|
||
| log.info("Initializing pump.io"); | ||
|
|
||
| URLMaker.hostname = config.hostname; | ||
| URLMaker.port = (config.urlPort) ? config.urlPort : config.port; | ||
|
|
||
| Step( | ||
| function() { | ||
| log.info("Connecting to databank"); | ||
| connectDatabank(config, this); | ||
| }, | ||
| function(err, db) { | ||
|
|
||
| db.search(type, {"author.id":"acct:"+user} ,scanfind, function(result) { | ||
| console.log("fin!"); | ||
| process.exit(0); | ||
|
|
||
| }); | ||
| }, | ||
| function(err) { | ||
| if (err) { | ||
| log.error(err); | ||
| process.exit(1); | ||
| } else { | ||
| log.info("Done."); | ||
| process.exit(0); | ||
| } | ||
| } | ||
| ); | ||
| }; | ||
|
|
||
| var scanfind = function(find) { | ||
| console.log(find) | ||
| } | ||
|
|
||
| // Gets the configuration vars for this server from config files | ||
|
|
||
| var getConfig = function(filename) { | ||
| var files, | ||
| config = {}, | ||
| i, | ||
| raw, | ||
| parsed; | ||
|
|
||
| if (filename) { | ||
| files = [filename]; | ||
| } else { | ||
| files = ['/etc/pump.io.json', | ||
| path.join(process.env.HOME, ".pump.io.json")]; | ||
| } | ||
|
|
||
| // This is all sync | ||
| for (i = 0; i < files.length; i++) { | ||
| if (fs.existsSync(files[i])) { | ||
| raw = fs.readFileSync(files[i]); | ||
| try { | ||
| parsed = JSON.parse(raw); | ||
| _.extend(config, parsed); | ||
| } catch (err) { | ||
| console.log(err); | ||
| process.exit(1); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return config; | ||
| }; | ||
|
|
||
| var connectDatabank = function(config, callback) { | ||
|
|
||
| var params, | ||
| db; | ||
|
|
||
| if (_(config).has("params")) { | ||
| params = config.params; | ||
| } else { | ||
| params = {}; | ||
| } | ||
|
|
||
| if (_(params).has("schema")) { | ||
| _.extend(params.schema, schema); | ||
| } else { | ||
| params.schema = schema; | ||
| } | ||
|
|
||
| db = Databank.get(config.driver, params); | ||
|
|
||
| // Connect... | ||
|
|
||
| db.connect({}, function(err) { | ||
| if (err) { | ||
| callback(err, null); | ||
| return; | ||
| } | ||
|
|
||
| DatabankObject.bank = db; | ||
| callback(null, db); | ||
| }); | ||
| }; | ||
|
|
||
| var setupLogger = function(config) { | ||
| var log, | ||
| logParams = { | ||
| name: "pump.io", | ||
| component: "testing-databank" | ||
| }; | ||
|
|
||
| if (config.logfile) { | ||
| logParams.streams = [{path: config.logfile}]; | ||
| } else if (config.nologger) { | ||
| logParams.streams = [{path: "/dev/null"}]; | ||
| } else { | ||
| logParams.streams = [{stream: process.stderr}]; | ||
| } | ||
|
|
||
| log = new Logger(logParams); | ||
|
|
||
| return log; | ||
| }; | ||
|
|
||
| main(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,190 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| // -*- mode: javascript -*- | ||
|
|
||
| // import an activitystreams JSON collection | ||
| // | ||
| // Copyright 2013, Mathias Gebbe | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| var fs = require("fs"), | ||
| path = require("path"), | ||
| urlparse = require("url").parse, | ||
| Step = require("step"), | ||
| _ = require("underscore"), | ||
| Logger = require("bunyan"), | ||
| Queue = require("jankyqueue"), | ||
| databank = require("databank"), | ||
| Databank = databank.Databank, | ||
| DatabankObject = databank.DatabankObject, | ||
| randomString = require("../lib/randomstring").randomString, | ||
| Distributor = require("../lib/distributor").Distributor, | ||
| schema = require("../lib/schema").schema, | ||
| Activity = require("../lib/model/activity").Activity, | ||
| Stream = require("../lib/model/stream").Stream, | ||
| ActivityObject = require("../lib/model/activityobject").ActivityObject, | ||
| URLMaker = require("../lib/urlmaker").URLMaker, | ||
| User = require("../lib/model/user").User, | ||
| argv = require("optimist") | ||
| .usage("Usage: $0 -u username -p passwordHash") | ||
| .demand(["p","u"]) | ||
| .alias("u", "username") | ||
| .alias("p", "password") | ||
| .describe("u", "username") | ||
| .describe("p", "the bcrypt passwort hash") | ||
| .argv, | ||
| passwordHash = argv.p; | ||
| username = argv.u | ||
|
|
||
| var QUEUE_MAX = 1; | ||
|
|
||
| // Connect to databank and start importing activities | ||
|
|
||
| var main = function() { | ||
| var config = getConfig(argv.c), | ||
| q = new Queue(QUEUE_MAX), | ||
| log = setupLogger(config); | ||
|
|
||
| log.info("Initializing pump.io"); | ||
|
|
||
| URLMaker.hostname = config.hostname; | ||
| URLMaker.port = (config.urlPort) ? config.urlPort : config.port; | ||
|
|
||
| Step( | ||
| function() { | ||
| log.info("Connecting to databank"); | ||
| connectDatabank(config, this); | ||
| }, | ||
| function(err, db) { | ||
| if (err) throw err; | ||
| console.log("connected..."); | ||
| //setPassword = function(nickname, passwordHash, log, callback) | ||
| setPassword(username,passwordHash,log,this); | ||
| }, | ||
| function(err) { | ||
| if (err) { | ||
| log.error(err); | ||
| process.exit(1); | ||
| } else { | ||
| log.info("Done."); | ||
| process.exit(0); | ||
| } | ||
| } | ||
| ); | ||
| }; | ||
|
|
||
| // Gets the configuration vars for this server from config files | ||
|
|
||
| var getConfig = function(filename) { | ||
| var files, | ||
| config = {}, | ||
| i, | ||
| raw, | ||
| parsed; | ||
|
|
||
| if (filename) { | ||
| files = [filename]; | ||
| } else { | ||
| files = ['/etc/pump.io.json', | ||
| path.join(process.env.HOME, ".pump.io.json")]; | ||
| } | ||
|
|
||
| // This is all sync | ||
| for (i = 0; i < files.length; i++) { | ||
| if (fs.existsSync(files[i])) { | ||
| raw = fs.readFileSync(files[i]); | ||
| try { | ||
| parsed = JSON.parse(raw); | ||
| _.extend(config, parsed); | ||
| } catch (err) { | ||
| console.log(err); | ||
| process.exit(1); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return config; | ||
| }; | ||
|
|
||
| var connectDatabank = function(config, callback) { | ||
|
|
||
| var params, | ||
| db; | ||
|
|
||
| if (_(config).has("params")) { | ||
| params = config.params; | ||
| } else { | ||
| params = {}; | ||
| } | ||
|
|
||
| if (_(params).has("schema")) { | ||
| _.extend(params.schema, schema); | ||
| } else { | ||
| params.schema = schema; | ||
| } | ||
|
|
||
| db = Databank.get(config.driver, params); | ||
|
|
||
| // Connect... | ||
|
|
||
| db.connect({}, function(err) { | ||
| if (err) { | ||
| callback(err, null); | ||
| return; | ||
| } | ||
|
|
||
| DatabankObject.bank = db; | ||
| callback(null, db); | ||
| }); | ||
| }; | ||
|
|
||
| var setupLogger = function(config) { | ||
| var log, | ||
| logParams = { | ||
| name: "pump.io", | ||
| component: "admin-set-password" | ||
| }; | ||
|
|
||
| if (config.logfile) { | ||
| logParams.streams = [{path: config.logfile}]; | ||
| } else if (config.nologger) { | ||
| logParams.streams = [{path: "/dev/null"}]; | ||
| } else { | ||
| logParams.streams = [{stream: process.stderr}]; | ||
| } | ||
|
|
||
| log = new Logger(logParams); | ||
|
|
||
| return log; | ||
| }; | ||
|
|
||
| var setPassword = function(nickname, passwordHash, log, callback) { | ||
|
|
||
| log.info({nickname: nickname}, "Setting password"); | ||
|
|
||
| Step( | ||
| function() { | ||
| User.get(nickname, this); | ||
| }, | ||
| function(err, user) { | ||
| if (err) throw err; | ||
| if (!user) throw new Error("no user"); | ||
| user._passwordHash = passwordHash; | ||
| user.save(this); | ||
| }, | ||
| callback | ||
| ); | ||
| }; | ||
|
|
||
| main(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| // -*- mode: javascript -*- | ||
|
|
||
| // Copyright 2013, Mathias Gebbe | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| var bcrypt = require("bcrypt"), | ||
| Step = require("step"), | ||
| argv = require("optimist") | ||
| .usage("Usage: $0 -p <password>") | ||
| .demand(["p"]) | ||
| .alias("p", "password") | ||
| .alias("c", "check") | ||
| .describe("p", "Password for user") | ||
| .describe("c", "Compare Password") | ||
| .describe("h", "Compare Hash") | ||
| .argv; | ||
|
|
||
| password = argv.p; | ||
| cpassword = argv.c; | ||
| chash = argv.h; | ||
|
|
||
|
|
||
| Step( | ||
| function() { | ||
| bcrypt.genSalt(10, this); | ||
| }, | ||
| function(err, salt) { | ||
| if (err) throw err; | ||
| bcrypt.hash(password, salt, this); | ||
| }, | ||
| function(err, hash) { | ||
| if (err) { | ||
| callback(err, null); | ||
| } else { | ||
| console.log ("Passwort Hash Generator: " + hash); | ||
| if ( chash === undefined ) chash = hash; | ||
| this(err,hash); | ||
| } | ||
| }, | ||
| function(err, hash) { | ||
| if (err){ | ||
| callback(err, null); | ||
| } else { | ||
| bcrypt.compare(cpassword, chash, function(err, res) { | ||
| console.log(res); | ||
| }); | ||
| } | ||
| } | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| // -*- mode: javascript -*- | ||
|
|
||
| // postnote.js | ||
| // | ||
| // Post an image with optional description | ||
| // | ||
| // Copyright 2011-2013, E14N https://e14n.com/ | ||
| // 2014, Intevation GmbH | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| var path = require("path"), | ||
| _ = require("underscore"), | ||
| Step = require("step"), | ||
| url = require("url"), | ||
| common = require("../lib/pumpclient"), | ||
| userCred = common.userCred, | ||
| getJSON = common.getJSON, | ||
| argv = require("optimist") | ||
| .usage("Usage: $0 -u <username>") | ||
| .demand(["u"]) | ||
| .alias("u", "username") | ||
| .alias("s", "server") | ||
| .alias("n", "nodeurl") | ||
| .alias("P", "port") | ||
| .describe("u", "User nickname") | ||
| .describe("s", "Server name (default 'io.intevation.de')") | ||
| .describe("P", "Port (default 443)") | ||
| .default("P", 443) | ||
| .default("s", "io.intevation.de") | ||
| .argv, | ||
| username = argv.u, | ||
| server = argv.s, | ||
| description = argv.d, | ||
| port = argv.P, | ||
| note = argv.n, | ||
| cred; | ||
|
|
||
| Step( | ||
| function() { | ||
| userCred(username, server, this); | ||
| }, | ||
| function(err, results) { | ||
| var endpoint; | ||
| if (err) throw err; | ||
| cred = results; | ||
| endpoint = url.format({ | ||
| protocol: ((port == 443) ? "https" : "http"), | ||
| host: ((port == 80 || port == 443) ? server : server + ":" + port), | ||
| pathname: "/api/user/"+username+"/feed" | ||
| }); | ||
| getJSON(endpoint, cred, this); | ||
| }, | ||
| function(err, body, resp) { | ||
| if (err) { | ||
| console.error(err); | ||
| } else { | ||
| var posts = _.filter(body.items, function(items){ return items.verb == 'share'; }); | ||
| _.each(posts, function(item) { | ||
| if ( note === undefined ) { | ||
| console.log("Note: "+item.object.id+" Activity: "+item.id); | ||
| } else { | ||
| if (item.object.id.indexOf(note) != -1) console.log("Note: "+item.object.id+" Activity: "+item.id); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| // -*- mode: javascript -*- | ||
|
|
||
| // postnote.js | ||
| // | ||
| // Post a note with the given text | ||
| // | ||
| // Copyright 2011-2012, E14N https://e14n.com/ | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| var _ = require("underscore"), | ||
| Step = require("step"), | ||
| url = require("url"), | ||
| common = require("../lib/pumpclient"), | ||
| userCred = common.userCred, | ||
| postJSON = common.postJSON, | ||
| argv = require("optimist") | ||
| .usage("Usage: $0 -u <username> -n <your note>") | ||
| .demand(["u", "n"]) | ||
| .alias("u", "username") | ||
| .alias("n", "note") | ||
| .alias("s", "server") | ||
| .alias("P", "port") | ||
| .describe("u", "User nickname") | ||
| .describe("n", "Text of note to post (HTML OK)") | ||
| .describe("s", "Server name") | ||
| .describe("P", "Port") | ||
| .default("P", 443) | ||
| .default("s", "io.intevation.de") | ||
| .argv, | ||
| username = argv.u, | ||
| server = argv.s, | ||
| note = argv.n, | ||
| port = argv.P; | ||
|
|
||
| Step( | ||
| function() { | ||
| userCred(username, server, this); | ||
| }, | ||
| function(err, cred) { | ||
| if (err) throw err; | ||
| var activity = { | ||
| "verb": "post", | ||
| cc: [{id: "http://activityschema.org/collection/public", | ||
| objectType: "collection"}], | ||
| to: [{id: "https://"+server+"/api/user/"+username+"/followers", | ||
| objectType: "collection"}], | ||
| "object": { | ||
| "objectType": "note", | ||
| "content": note | ||
| } | ||
| }; | ||
| var endpoint = url.format({ | ||
| protocol: ((port == 443) ? "https" : "http"), | ||
| host: ((port == 80) ? server : server + ":" + port), | ||
| pathname: "/api/user/"+username+"/feed" | ||
| }); | ||
| postJSON(endpoint, cred, activity, this); | ||
| }, | ||
| function(err, body, resp) { | ||
| if (err) { | ||
| console.error(err); | ||
| } else { | ||
| console.log("OK"); | ||
| } | ||
| } | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| // -*- mode: javascript -*- | ||
|
|
||
| // Copyright 2013, Mathias Gebbe Intevation GmbH | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| var request = require('request'), | ||
| readline = require('readline'), | ||
| Step = require("step"), | ||
| optimist = require("optimist") | ||
| .usage("Usage: $0 -s serverUrl -u username") | ||
| .alias("s", "serverUrl") | ||
| .alias("u", "username") | ||
| .alias("h", "help") | ||
| .describe("s", "The Server URL") | ||
| .describe("u", "The username") | ||
| .describe("h","Print this help text") | ||
| .default("s", "https://io.intevation.de/main/recover"); | ||
|
|
||
| var argv = optimist.argv; | ||
|
|
||
| var username = argv.u, | ||
| serverurl = argv.s; | ||
|
|
||
| var start,end,verifier; | ||
|
|
||
| var rl = readline.createInterface({ | ||
| input: process.stdin, | ||
| output: process.stdout | ||
| }); | ||
|
|
||
| Step( | ||
| function(){ | ||
| var callback=this; | ||
| if (argv.h) { | ||
| optimist.showHelp(); | ||
| process.exit(0); | ||
| } | ||
| if(username === undefined) { | ||
| rl.question("Enter the username: ", function(gusername) { | ||
| gusername.trim(); | ||
| username=gusername; | ||
| callback(); | ||
| }); | ||
| }else{ | ||
| callback(); | ||
| } | ||
| }, | ||
| function() { | ||
| sendRecover(username) | ||
| } | ||
| ); | ||
|
|
||
|
|
||
| function sendRecover(username){ | ||
|
|
||
| request.post( | ||
| serverurl, | ||
| { form: { nickname: username } }, | ||
| function (error, response, body) { | ||
| if (!error && response.statusCode == 200) { | ||
| console.log("Done!"); | ||
| process.exit("0"); | ||
| }else{ | ||
| console.log("Error! Maybe wrong credentials."); | ||
| process.exit("1"); | ||
| } | ||
| } | ||
| ); | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| // -*- mode: javascript -*- | ||
|
|
||
| // postnote.js | ||
| // | ||
| // Post a note with the given text | ||
| // | ||
| // Copyright 2011-2012, E14N https://e14n.com/ | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| var _ = require("underscore"), | ||
| Step = require("step"), | ||
| url = require("url"), | ||
| common = require("../lib/pumpclient"), | ||
| userCred = common.userCred, | ||
| postJSON = common.postJSON, | ||
| argv = require("optimist") | ||
| .usage("Usage: $0 -u <username> -n <url to note>") | ||
| .demand(["u", "n"]) | ||
| .alias("u", "username") | ||
| .alias("n", "noteurl") | ||
| .alias("s", "server") | ||
| .alias("P", "port") | ||
| .describe("u", "Username") | ||
| .describe("n", "API-URL to note for example https://io.intevation.de/api/note/31kVTfBdQnKScY54db1EbA/ ") | ||
| //.describe("n", "URL to note for example 31kVTfBdQnKScY54db1EbA from https://io.intevation.de/api/note/31kVTfBdQnKScY54db1EbA/ ") | ||
| .describe("s", "Server name (default 'io.intevation.de')") | ||
| .describe("P", "Port (default 443)") | ||
| .default("P", 443) | ||
| .default("s", "io.intevation.de") | ||
| .argv, | ||
| username = argv.u, | ||
| server = argv.s, | ||
| note = argv.n, | ||
| port = argv.P; | ||
|
|
||
| Step( | ||
| function() { | ||
| userCred(username, server, this); | ||
| }, | ||
| function(err, cred) { | ||
| if (err) throw err; | ||
| var activity = { | ||
| "verb": "share", | ||
| cc: [{id: "http://activityschema.org/collection/public", | ||
| objectType: "collection"}], | ||
| to: [{id: "https://"+server+"/api/user/"+username+"/followers", | ||
| objectType: "collection"}], | ||
| "object": { | ||
| "id" : note, | ||
| //"id" : "https://"+server+"/api/note/"+note, | ||
| "objectType": "note" | ||
| } | ||
| }; | ||
| var endpoint = url.format({ | ||
| protocol: ((port == 443) ? "https" : "http"), | ||
| host: ((port == 80) ? server : server + ":" + port), | ||
| pathname: "/api/user/"+username+"/feed" | ||
| }); | ||
| postJSON(endpoint, cred, activity, this); | ||
| }, | ||
| function(err, body, resp) { | ||
| if (err) { | ||
| console.error(err); | ||
| } else { | ||
| console.log("OK"); | ||
| } | ||
| } | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| // -*- mode: javascript -*- | ||
|
|
||
| // stopfollowing.js | ||
| // | ||
| // stop following another user | ||
| // | ||
| // Copyright 2011-2012, E14N https://e14n.com/ | ||
| // 2013, Intevation GmbH http://intevation.org | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| var _ = require("underscore"), | ||
| Step = require("step"), | ||
| url = require("url"), | ||
| common = require("../lib/pumpclient"), | ||
| userCred = common.userCred, | ||
| postJSON = common.postJSON, | ||
| argv = require("optimist") | ||
| .usage("Usage: $0 -u <username> -n <note>") | ||
| .demand(["u", "n"]) | ||
| .alias("u", "username") | ||
| .alias("n", "note") | ||
| .alias("s", "server") | ||
| .alias("P", "port") | ||
| .describe("u", "User nickname") | ||
| .describe("n", "api-link to unshare note (https://server/api/note/LGuQo1P0TZWheCJg2_mQ5A)") | ||
| .describe("s", "Server name (default 'io.intevation.de')") | ||
| .describe("P", "Port (default 443)") | ||
| .default("P", 443) | ||
| .default("s", "io.intevation.de") | ||
| .argv, | ||
| username = argv.u, | ||
| server = argv.s, | ||
| port = argv.P, | ||
| noteurl = argv.n; | ||
|
|
||
| Step( | ||
| function() { | ||
| userCred(username, server, this); | ||
| }, | ||
| function(err, cred) { | ||
| if (err) throw err; | ||
| var activity = { | ||
| "verb": "unshare", | ||
| "object": { | ||
| "objectType": "note", | ||
| id: noteurl | ||
| } | ||
| }; | ||
| var endpoint = url.format({ | ||
| protocol: ((port == 443) ? "https" : "http"), | ||
| host: ((port == 80) ? server : server + ":" + port), | ||
| pathname: "/api/user/"+username+"/feed" | ||
| }); | ||
| postJSON(endpoint, cred, activity, this); | ||
| }, | ||
| function(err, body, resp) { | ||
| if (err) { | ||
| console.error(err); | ||
| } else { | ||
| console.log("OK"); | ||
| } | ||
| } | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| // -*- mode: javascript -*- | ||
|
|
||
| // Copyright 2013, Mathias Gebbe | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| var fs = require("fs"), | ||
| path = require("path") | ||
| urlparse = require("url").parse, | ||
| Step = require("step"), | ||
| _ = require("underscore"), | ||
| Logger = require("bunyan"), | ||
| Queue = require("jankyqueue"), | ||
| databank = require("databank"), | ||
| Databank = databank.Databank, | ||
| DatabankObject = databank.DatabankObject, | ||
| Distributor = require("../lib/distributor").Distributor, | ||
| schema = require("../lib/schema").schema, | ||
| Activity = require("../lib/model/activity").Activity, | ||
| Stream = require("../lib/model/stream").Stream, | ||
| ActivityObject = require("../lib/model/activityobject").ActivityObject, | ||
| URLMaker = require("../lib/urlmaker").URLMaker, | ||
| User = require("../lib/model/user").User, | ||
| argv = require("optimist") | ||
| .usage("Usage: $0 -u username -i nodeid") | ||
| .alias("u", "user") | ||
| .describe("u", "username") | ||
| .describe("i", "nodeid for example: IjcLdOmtQDKNU0c5SgVUxg") | ||
| .argv, | ||
| user = argv.u; | ||
| nodeid = argv.i; | ||
|
|
||
| var QUEUE_MAX = 1; | ||
|
|
||
| var main = function() { | ||
| var config = getConfig(argv.c), | ||
| q = new Queue(QUEUE_MAX), | ||
| log = setupLogger(config); | ||
|
|
||
| log.info("Initializing pump.io"); | ||
|
|
||
| URLMaker.hostname = config.hostname; | ||
| URLMaker.port = (config.urlPort) ? config.urlPort : config.port; | ||
|
|
||
| Step( | ||
| function() { | ||
| log.info("Connecting to databank"); | ||
| connectDatabank(config, this); | ||
| }, | ||
| function(err, db) { | ||
|
|
||
| db.scan('note', scanfind, function(result) { | ||
| console.log("fin!"); | ||
| }); | ||
|
|
||
| return; | ||
| // ENDE | ||
| }, | ||
| function(err) { | ||
| if (err) { | ||
| log.error(err); | ||
| process.exit(1); | ||
| } else { | ||
| log.info("Done."); | ||
| process.exit(0); | ||
| } | ||
| } | ||
| ); | ||
| }; | ||
|
|
||
| var scanfind = function(find) { | ||
| console.log(find) | ||
| } | ||
|
|
||
| // Gets the configuration vars for this server from config files | ||
|
|
||
| var getConfig = function(filename) { | ||
| var files, | ||
| config = {}, | ||
| i, | ||
| raw, | ||
| parsed; | ||
|
|
||
| if (filename) { | ||
| files = [filename]; | ||
| } else { | ||
| files = ['/etc/pump.io.json', | ||
| path.join(process.env.HOME, ".pump.io.json")]; | ||
| } | ||
|
|
||
| // This is all sync | ||
| for (i = 0; i < files.length; i++) { | ||
| if (fs.existsSync(files[i])) { | ||
| raw = fs.readFileSync(files[i]); | ||
| try { | ||
| parsed = JSON.parse(raw); | ||
| _.extend(config, parsed); | ||
| } catch (err) { | ||
| console.log(err); | ||
| process.exit(1); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return config; | ||
| }; | ||
|
|
||
| var connectDatabank = function(config, callback) { | ||
|
|
||
| var params, | ||
| db; | ||
|
|
||
| if (_(config).has("params")) { | ||
| params = config.params; | ||
| } else { | ||
| params = {}; | ||
| } | ||
|
|
||
| if (_(params).has("schema")) { | ||
| _.extend(params.schema, schema); | ||
| } else { | ||
| params.schema = schema; | ||
| } | ||
|
|
||
| db = Databank.get(config.driver, params); | ||
|
|
||
| // Connect... | ||
|
|
||
| db.connect({}, function(err) { | ||
| if (err) { | ||
| callback(err, null); | ||
| return; | ||
| } | ||
|
|
||
| DatabankObject.bank = db; | ||
| callback(null, db); | ||
| }); | ||
| }; | ||
|
|
||
| var setupLogger = function(config) { | ||
| var log, | ||
| logParams = { | ||
| name: "pump.io", | ||
| component: "testing-databank" | ||
| }; | ||
|
|
||
| if (config.logfile) { | ||
| logParams.streams = [{path: config.logfile}]; | ||
| } else if (config.nologger) { | ||
| logParams.streams = [{path: "/dev/null"}]; | ||
| } else { | ||
| logParams.streams = [{stream: process.stderr}]; | ||
| } | ||
|
|
||
| log = new Logger(logParams); | ||
|
|
||
| return log; | ||
| }; | ||
|
|
||
| main(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| // -*- mode: javascript -*- | ||
|
|
||
| // Copyright 2013, Mathias Gebbe | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| var fs = require("fs"), | ||
| path = require("path") | ||
| urlparse = require("url").parse, | ||
| Step = require("step"), | ||
| _ = require("underscore"), | ||
| Logger = require("bunyan"), | ||
| Queue = require("jankyqueue"), | ||
| databank = require("databank"), | ||
| Databank = databank.Databank, | ||
| DatabankObject = databank.DatabankObject, | ||
| Distributor = require("../lib/distributor").Distributor, | ||
| schema = require("../lib/schema").schema, | ||
| Activity = require("../lib/model/activity").Activity, | ||
| Stream = require("../lib/model/stream").Stream, | ||
| ActivityObject = require("../lib/model/activityobject").ActivityObject, | ||
| URLMaker = require("../lib/urlmaker").URLMaker, | ||
| User = require("../lib/model/user").User, | ||
| argv = require("optimist") | ||
| .usage("Usage: $0 -u username -i nodeid") | ||
| .demand(["u","t"]) | ||
| .alias("u", "user") | ||
| .alias("t", "type") | ||
| .describe("t", "type (note,share,etc..)") | ||
| .describe("u", "username@server.tld") | ||
| .argv, | ||
| user = argv.u; | ||
| type = argv.t; | ||
|
|
||
| var QUEUE_MAX = 1; | ||
|
|
||
| var main = function() { | ||
| var config = getConfig(argv.c), | ||
| q = new Queue(QUEUE_MAX), | ||
| log = setupLogger(config); | ||
|
|
||
| log.info("Initializing pump.io"); | ||
|
|
||
| URLMaker.hostname = config.hostname; | ||
| URLMaker.port = (config.urlPort) ? config.urlPort : config.port; | ||
|
|
||
| Step( | ||
| function() { | ||
| log.info("Connecting to databank"); | ||
| connectDatabank(config, this); | ||
| }, | ||
| function(err, db) { | ||
|
|
||
| db.search(type, {"author.id":"acct:"+user} ,scanfind, function(result) { | ||
| console.log("fin!"); | ||
| process.exit(0); | ||
|
|
||
| }); | ||
| }, | ||
| function(err) { | ||
| if (err) { | ||
| log.error(err); | ||
| process.exit(1); | ||
| } else { | ||
| log.info("Done."); | ||
| process.exit(0); | ||
| } | ||
| } | ||
| ); | ||
| }; | ||
|
|
||
| var scanfind = function(find) { | ||
| console.log(find.id) | ||
| //console.log(find); | ||
| } | ||
|
|
||
| // Gets the configuration vars for this server from config files | ||
|
|
||
| var getConfig = function(filename) { | ||
| var files, | ||
| config = {}, | ||
| i, | ||
| raw, | ||
| parsed; | ||
|
|
||
| if (filename) { | ||
| files = [filename]; | ||
| } else { | ||
| files = ['/etc/pump.io.json', | ||
| path.join(process.env.HOME, ".pump.io.json")]; | ||
| } | ||
|
|
||
| // This is all sync | ||
| for (i = 0; i < files.length; i++) { | ||
| if (fs.existsSync(files[i])) { | ||
| raw = fs.readFileSync(files[i]); | ||
| try { | ||
| parsed = JSON.parse(raw); | ||
| _.extend(config, parsed); | ||
| } catch (err) { | ||
| console.log(err); | ||
| process.exit(1); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return config; | ||
| }; | ||
|
|
||
| var connectDatabank = function(config, callback) { | ||
|
|
||
| var params, | ||
| db; | ||
|
|
||
| if (_(config).has("params")) { | ||
| params = config.params; | ||
| } else { | ||
| params = {}; | ||
| } | ||
|
|
||
| if (_(params).has("schema")) { | ||
| _.extend(params.schema, schema); | ||
| } else { | ||
| params.schema = schema; | ||
| } | ||
|
|
||
| db = Databank.get(config.driver, params); | ||
|
|
||
| // Connect... | ||
|
|
||
| db.connect({}, function(err) { | ||
| if (err) { | ||
| callback(err, null); | ||
| return; | ||
| } | ||
|
|
||
| DatabankObject.bank = db; | ||
| callback(null, db); | ||
| }); | ||
| }; | ||
|
|
||
| var setupLogger = function(config) { | ||
| var log, | ||
| logParams = { | ||
| name: "pump.io", | ||
| component: "testing-databank" | ||
| }; | ||
|
|
||
| if (config.logfile) { | ||
| logParams.streams = [{path: config.logfile}]; | ||
| } else if (config.nologger) { | ||
| logParams.streams = [{path: "/dev/null"}]; | ||
| } else { | ||
| logParams.streams = [{stream: process.stderr}]; | ||
| } | ||
|
|
||
| log = new Logger(logParams); | ||
|
|
||
| return log; | ||
| }; | ||
|
|
||
| main(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| acct:mgebbe@io.intevation.de |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| // -*- mode: javascript -*- | ||
|
|
||
| // Copyright 2013, Mathias Gebbe Intevation GmbH | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| //'oauth_token' : 'WlumbeW1LFNipktUGKCSJg', | ||
| //'username' : 'USERNAME', | ||
| //'password': 'PASSWORD' | ||
|
|
||
| var request = require('request'), | ||
| readline = require('readline'), | ||
| Step = require("step"), | ||
| optimist = require("optimist") | ||
| .usage("Usage: $0 -s serverUrl -u username -p passwort -o oauthtoken") | ||
| .alias("s", "serverUrl") | ||
| .alias("u", "username") | ||
| .alias("p", "password") | ||
| .alias("o", "oauthtoken") | ||
| .alias("h", "help") | ||
| .describe("s", "The Server URL - use https: https://server/oauth/authorize") | ||
| .describe("u", "The username") | ||
| .describe("p", "The password") | ||
| .describe("o", "The shown OAuth Token") | ||
| .describe("h","Print this help text") | ||
| .default("s", "https://io.intevation.de/oauth/authorize"); | ||
|
|
||
| var argv = optimist.argv; | ||
|
|
||
| var oauthtoken = argv.o, | ||
| username = argv.u, | ||
| password = argv.p, | ||
| serverurl = argv.s; | ||
|
|
||
| var start,end,verifier; | ||
|
|
||
| var rl = readline.createInterface({ | ||
| input: process.stdin, | ||
| output: process.stdout | ||
| }); | ||
|
|
||
| Step( | ||
| function(){ | ||
| var callback=this; | ||
| if (argv.h) { | ||
| optimist.showHelp(); | ||
| process.exit(0); | ||
| } | ||
| if(username === undefined) { | ||
| rl.question("Enter the username: ", function(gusername) { | ||
| gusername.trim(); | ||
| username=gusername; | ||
| callback(); | ||
| }); | ||
| }else{ | ||
| callback(); | ||
| } | ||
| }, | ||
| function(){ | ||
| var callback=this; | ||
| if(password === undefined) { | ||
| rl.question("Enter password for user "+username+": ", function(gpassword) { | ||
| gpassword.trim(); | ||
| password = gpassword; | ||
| callback(); | ||
| }); | ||
| }else{ | ||
| callback(); | ||
| } | ||
|
|
||
| }, | ||
| function(){ | ||
| var callback=this; | ||
| if(oauthtoken === undefined) { | ||
| rl.question("Enter oauth token: ", function(goauth) { | ||
| goauth.trim(); | ||
| oauthtoken = goauth; | ||
| callback(); | ||
| }); | ||
| }else{ | ||
| callback(); | ||
| } | ||
|
|
||
| }, | ||
| function() { | ||
| getVerifier(username,password,oauthtoken) | ||
| } | ||
| ); | ||
|
|
||
|
|
||
| function getVerifier(username,password,oauthtoken){ | ||
|
|
||
| request.post( | ||
| serverurl, | ||
| { form: { oauth_token: oauthtoken, username: username, password: password } }, | ||
| function (error, response, body) { | ||
| if (!error && response.statusCode == 200) { | ||
| // in body is the hole anwser | ||
| start = body.indexOf("name=\"verifier\""); | ||
| end = body.indexOf("\"/>",start); | ||
| verifier = body.substring(start+23,end); | ||
|
|
||
| if ( verifier.search(/!DOCTYPE.+/) != -1){ | ||
| start = body.indexOf("<td id=\"verifier\">"); | ||
| end = body.indexOf("<\/td>",start); | ||
| verifier = body.substring(start+18,end); | ||
| console.log("The verifier is: " + verifier); | ||
| process.exit("0"); | ||
| }else{ | ||
| console.log("The verifier is: " + verifier); | ||
| process.exit("0"); | ||
| } | ||
| }else{ | ||
| console.log("Error! Maybe wrong credentials."); | ||
| process.exit("1"); | ||
| } | ||
| } | ||
| ); | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| // -*- mode: javascript -*- | ||
|
|
||
| // Copyright 2013, Intevation GmbH, Mathias Gebbe | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| var fs = require("fs"), | ||
| path = require("path"), | ||
| _ = require("underscore"), | ||
| Step = require("step"), | ||
| url = require("url"), | ||
| common = require("../lib/pumpclient"), | ||
| userCred = common.userCred, | ||
| getJSON = common.getJSON, | ||
| postJSON = common.postJSON, | ||
| argv = require("optimist") | ||
| .usage("Usage: $0 -u <username>") | ||
| .demand(["u"]) | ||
| .alias("u", "username") | ||
| .alias("s", "server") | ||
| .alias("n", "news") | ||
| .alias("f", "file") | ||
| .alias("v", "verbose") | ||
| .alias("P", "port") | ||
| .describe("u", "User nickname") | ||
| .describe("s", "Server name (default 'io.intevation.de')") | ||
| .describe("P", "Port (default 443)") | ||
| .describe("n", "File with already shared news") | ||
| .describe("f", "File with allowed Users") | ||
| .describe("v", "Verbose") | ||
| .default("P", 443) | ||
| .default("s", "io.intevation.de") | ||
| .default("n", "./db.shares") | ||
| .default("f", "./db.users") | ||
| .argv, | ||
| username = argv.u, | ||
| server = argv.s, | ||
| description = argv.d, | ||
| port = argv.P, | ||
| userfile = argv.f, | ||
| verbose = argv.v, | ||
| newsfile = argv.n, | ||
| cred; | ||
|
|
||
| if(verbose) console.log("starting newsbot"); | ||
| newsbot_run(); | ||
|
|
||
|
|
||
| function newsbot_run () { | ||
| Step( | ||
| function() { | ||
| userCred(username, server, this); | ||
| }, | ||
| function(err, results) { | ||
| var endpoint; | ||
| if (err) throw err; | ||
| cred = results; | ||
| endpoint = url.format({ | ||
| protocol: ((port == 443) ? "https" : "http"), | ||
| host: ((port == 80 || port == 443) ? server : server + ":" + port), | ||
| pathname: "/api/user/"+username+"/inbox" | ||
| }); | ||
| getJSON(endpoint, cred, this); | ||
| }, | ||
| function(err, body, resp) { | ||
| if (err) { | ||
| console.error(err); | ||
| } else { | ||
| // get the messages from users | ||
|
|
||
| var posts = _.filter(body.items, function(items){ return items.verb == 'post'; }); | ||
| _.each(posts, function(item) { | ||
| // only posts from user (no follow, no share etc) | ||
| // here can we start to publish news | ||
| printNewsbot(item.actor.id,item.object.content,item.object.id); | ||
| }); | ||
|
|
||
| var shares = _.filter(body.items, function(items){ return items.verb == 'share'; }); | ||
| _.each(shares, function(item) { | ||
| // only share from user | ||
| // here can we start to publish news | ||
| printNewsbot(item.actor.id,item.object.content,item.object.id); | ||
| }); | ||
|
|
||
|
|
||
| } | ||
| } | ||
| ); | ||
|
|
||
| } | ||
|
|
||
| function printNewsbot(id,content,link) { | ||
|
|
||
| var ret,userdb; | ||
|
|
||
| if ( id === undefined || content === undefined || link === undefined) return | ||
|
|
||
| if(!fs.existsSync(userfile)) { console.log("ERROR: File "+userfile+" not found"); return } | ||
|
|
||
| userdb = fs.readFileSync(userfile,'utf8'); | ||
| userdb.trim(); | ||
|
|
||
| if (userdb.indexOf(id+"\n") != -1) ret=true; | ||
| else return; | ||
|
|
||
| // here are only valid posts | ||
|
|
||
| //console.log(id); | ||
| //console.log(content); | ||
| //console.log(link); | ||
| //console.log(ret); | ||
| //console.log("---------------------------------"); | ||
| ProofandShare(link); | ||
|
|
||
| } | ||
|
|
||
|
|
||
| function ProofandShare(link) { | ||
|
|
||
| var newsdb; | ||
|
|
||
| if(!fs.existsSync(newsfile)) { console.log("ERROR: File "+newsfile+" not found"); return } | ||
|
|
||
| newsdb = fs.readFileSync(newsfile,'utf8'); | ||
| newsdb.trim(); | ||
|
|
||
| if (newsdb.indexOf(link+"\n") != -1) { | ||
| if (verbose) console.log("already shared"); | ||
| } | ||
| else { | ||
| console.log("i would share: "+link); | ||
| sharePost(link); | ||
| markShare(link); | ||
| } | ||
| } | ||
|
|
||
| function sharePost(link) { | ||
|
|
||
| Step( | ||
| function() { | ||
| userCred(username, server, this); | ||
| }, | ||
| function(err, cred) { | ||
| if (err) throw err; | ||
| var activity = { | ||
| "verb": "share", | ||
| cc: [{id: "http://activityschema.org/collection/public", | ||
| objectType: "collection"}], | ||
| to: [{id: "https://"+server+"/api/user/"+username+"/followers", | ||
| objectType: "collection"}], | ||
| "object": { | ||
| "id" : link, | ||
| "objectType": "note" | ||
| } | ||
| }; | ||
| var endpoint = url.format({ | ||
| protocol: ((port == 443) ? "https" : "http"), | ||
| host: ((port == 80) ? server : server + ":" + port), | ||
| pathname: "/api/user/"+username+"/feed" | ||
| }); | ||
| postJSON(endpoint, cred, activity, this); | ||
| }, | ||
| function(err, body, resp) { | ||
| if (err) { | ||
| console.error(err); | ||
| } else { | ||
| console.log("OK"); | ||
| } | ||
| } | ||
| ); | ||
|
|
||
|
|
||
| } | ||
|
|
||
| function markShare(link) { | ||
| fs.appendFile(newsfile, link+"\n", 'utf8', function (err) { | ||
| if (err) throw err; | ||
| if (verbose) console.log('The '+link+' was marked as read'); | ||
| }); | ||
|
|
||
| } | ||
|
|