@@ -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);
}
}
);
@@ -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();
@@ -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();
@@ -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();
@@ -109,7 +109,7 @@ var launchApps = function(config) {

cluster.on('exit', function(worker, code, signal) {
var exitCode = worker.process.exitCode;
clusterLog.info('worker ' + worker.process.pid + ' died ('+exitCode+'). restarting...');
clusterLog.warn('worker ' + worker.process.pid + ' died ('+exitCode+'). restarting...');
cluster.fork();
});

@@ -35,10 +35,10 @@ var urlfmt = require("url").format,
.alias("s", "server")
.alias("P", "port")
.describe("u", "User nickname")
.describe("s", "Server name (default 'localhost')")
.describe("P", "Port (default 80)")
.default("P", 80)
.default("s", "localhost")
.describe("s", "Server name")
.describe("P", "Port")
.default("P", 443)
.default("s", "io.intevation.de")
.argv,
username = argv.u,
server = argv.s,
@@ -28,7 +28,7 @@ var _ = require("underscore"),
postJSON = common.postJSON,
delJSON = common.delJSON,
argv = require("optimist")
.usage("Usage: $0 -u <username> -n <your note>")
.usage("Usage: $0 -u <username> -i <your note>")
.demand(["u", "i"])
.alias("u", "username")
.alias("i", "id")
@@ -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);
});
}
}
);
@@ -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);
}
});
}
}
);
@@ -40,7 +40,7 @@ var fs = require("fs"),
.usage("Usage: $0 -f <email file>")
.demand(["f"])
.alias("f", "file")
.describe("f", "Comma-separated file for email addresses")
.describe("f", "a colon-separated file for email addresses (username:email)")
.argv,
fname = argv.f;

@@ -76,7 +76,7 @@ var main = function() {
var parts;
line.trim();
if (line.length !== 0) {
parts = line.split("\t");
parts = line.split(":");
q.enqueue(setEmail, [parts[0], parts[1], log], group());
}
});
@@ -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");
}
}
);
@@ -42,7 +42,7 @@ var argv = require("optimist")
.describe("n", "Native application")
.describe("s", "Server name")
.describe("P", "Port")
.default("P", 80)
.default("P", 443)
.default("s", "localhost")
.argv;

@@ -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");
}
}
);

}
@@ -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");
}
}
);
@@ -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");
}
}
);
@@ -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();
@@ -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();
@@ -25,14 +25,16 @@ var _ = require("underscore"),
var host,
clientID,
clientSecret,
oa;
oa,
log;

var ActivitySpam = {

init: function(params) {
host = params.host || "https://spamicity.info";
clientID = params.clientID;
clientSecret = params.clientSecret;
log = params.log;
oa = new OAuth(null,
null,
clientID,
@@ -60,7 +62,9 @@ var ActivitySpam = {
callback(null, null, null);
return;
}


log.info({act: act.id, host: host}, "Testing activity");

Step(
function() {
oa.post(host + "/is-this-spam", null, null, json, "application/json", this);
@@ -83,7 +87,14 @@ var ActivitySpam = {
}
this(null, obj.isSpam, obj.probability);
},
callback
function(err, isSpam, probability) {
if (err) {
log.warn({act: act.id, host: host, err: err}, "Error testing activity.");
callback(null, null, 0.5);
} else {
callback(null, isSpam, probability);
}
}
);
}
};
@@ -71,7 +71,11 @@ var makeApp = function(configBase, callback) {
serializers: {
req: Logger.stdSerializers.req,
res: Logger.stdSerializers.res,
err: Logger.stdSerializers.err,
err: function(err) {
var obj = Logger.stdSerializers.err(err);
// only show properties without an initial underscore
return _.pick(obj, _.filter(_.keys(obj), function(key) { return key[0] != "_"; }));
},
principal: function(principal) {
if (principal) {
return {id: principal.id, type: principal.objectType};
@@ -117,12 +121,12 @@ var makeApp = function(configBase, callback) {

log = new Logger(logParams);

log.info("Initializing pump.io");
log.debug("Initializing pump.io");

// Initialize plugins

_.each(config.plugins, function(pluginName) {
log.info({plugin: pluginName}, "Initializing plugin.");
log.debug({plugin: pluginName}, "Initializing plugin.");
plugins[pluginName] = require(pluginName);
if (_.isFunction(plugins[pluginName].initializeLog)) {
plugins[pluginName].initializeLog(log);
@@ -147,7 +151,7 @@ var makeApp = function(configBase, callback) {

_.each(plugins, function(plugin, name) {
if (_.isFunction(plugin.initializeSchema)) {
log.info({plugin: name}, "Initializing schema.");
log.debug({plugin: name}, "Initializing schema.");
plugin.initializeSchema(params.schema);
}
});
@@ -156,7 +160,7 @@ var makeApp = function(configBase, callback) {

// Connect...

log.info("Connecting to databank with driver '"+config.driver+"'");
log.debug("Connecting to databank with driver '"+config.driver+"'");

db.connect({}, function(err) {

@@ -197,20 +201,20 @@ var makeApp = function(configBase, callback) {
}

if (useHTTPS) {
log.info("Setting up HTTPS server.");
log.debug("Setting up HTTPS server.");
app = express.createServer({key: fs.readFileSync(config.key),
cert: fs.readFileSync(config.cert)});

if (useBounce) {
log.info("Setting up micro-HTTP server to bounce to HTTPS.");
log.debug("Setting up micro-HTTP server to bounce to HTTPS.");
bounce = express.createServer(function(req, res, next) {
var host = req.header('Host');
res.redirect('https://'+host+req.url, 301);
});
}

} else {
log.info("Setting up HTTP server.");
log.debug("Setting up HTTP server.");
app = express.createServer();
}

@@ -315,7 +319,7 @@ var makeApp = function(configBase, callback) {
var script;
if (_.isFunction(plugins[pluginName].getScript)) {
script = plugins[pluginName].getScript();
log.info({plugin: pluginName, script: script}, "Adding script");
log.debug({plugin: pluginName, script: script}, "Adding script");
config.scripts.push(script);
}
});
@@ -467,7 +471,7 @@ var makeApp = function(configBase, callback) {
}

if (config.firehose) {
log.info({firehose: config.firehose}, "Setting up firehose");
log.debug({firehose: config.firehose}, "Setting up firehose");
Firehose.setup(config.firehose, log);
}

@@ -476,12 +480,12 @@ var makeApp = function(configBase, callback) {
!config.spamclientsecret) {
throw new Error("Need client ID and secret for spam host");
}
log.info({spamhost: config.spamhost}, "Configuring spam host");
log.debug({spamhost: config.spamhost}, "Configuring spam host");
ActivitySpam.init({
host: config.spamhost,
clientID: config.spamclientid,
clientSecret: config.spamclientsecret,
logger: log
log: log
});
}

@@ -499,10 +503,10 @@ var makeApp = function(configBase, callback) {

if (config.cleanupNonce) {
setTimeout(function() {
log.info("Cleaning up old OAuth nonces");
log.debug("Cleaning up old OAuth nonces");
Nonce.cleanup();
setInterval(function() {
log.info("Cleaning up old OAuth nonces");
log.debug("Cleaning up old OAuth nonces");
Nonce.cleanup();
}, config.cleanupNonce * (config.workers || 1));
}, Math.floor(Math.random() * config.cleanupNonce * (config.workers || 1)));
@@ -532,12 +536,12 @@ var makeApp = function(configBase, callback) {
callback(err);
},
bounceSuccess = function() {
log.info("Finished setting up bounce server.");
log.debug("Finished setting up bounce server.");
removeBounceListeners();
callback(null);
};

log.info("Finished setting up main server.");
log.debug("Finished setting up main server.");

removeListeners();
if (useBounce) {
@@ -558,7 +562,7 @@ var makeApp = function(configBase, callback) {

_.each(plugins, function(plugin, name) {
if (_.isFunction(plugin.initializeApp)) {
log.info({plugin: name}, "Initializing app.");
log.debug({plugin: name}, "Initializing app.");
plugin.initializeApp(app);
}
});
@@ -95,7 +95,7 @@ var clientAuth = function(req, res, next) {
req.client = null;
res.local("client", null); // init to null

log.info("Checking for 2-legged OAuth credentials");
log.debug("Checking for 2-legged OAuth credentials");

// If we're coming in the front door, and we have a path, provide it
if (req.header('Host').toLowerCase() == URLMaker.makeHost() && URLMaker.path) {
@@ -115,18 +115,18 @@ var clientAuth = function(req, res, next) {
}

if (!authenticated) {
log.info("Not authenticated");
log.debug("Not authenticated");
return;
}

log.info("Authentication succeeded");
log.debug("Authentication succeeded");

deetz = areq.getAuthDetails();

log.info(deetz);
log.debug(deetz);

if (!deetz || !deetz.user || !deetz.user.id) {
log.info("Incorrect auth details.");
log.debug("Incorrect auth details.");
return;
}

@@ -182,7 +182,7 @@ var userAuth = function(req, res, next) {
req.client = null;
res.local("client", null); // init to null

log.info("Checking for 3-legged OAuth credentials");
log.debug("Checking for 3-legged OAuth credentials");

// If we're coming in the front door, and we have a path, provide it
if (req.header('Host').toLowerCase() == URLMaker.makeHost() && URLMaker.path) {
@@ -202,18 +202,18 @@ var userAuth = function(req, res, next) {
}

if (!authenticated) {
log.info("Authentication failed");
log.debug("Authentication failed");
return;
}

log.info("Authentication succeeded");
log.debug("Authentication succeeded");

deetz = areq.getAuthDetails();

log.info(deetz, "Authentication details");
log.debug(deetz, "Authentication details");

if (!deetz || !deetz.user || !deetz.user.user || !deetz.user.client) {
log.info("Incorrect auth details.");
log.debug("Incorrect auth details.");
next(new Error("Incorrect auth details"));
return;
}
@@ -234,7 +234,7 @@ var userAuth = function(req, res, next) {
req.client = deetz.user.client;
res.local("client", sanitizedJSON(req.client));

log.info({principalUser: req.principalUser.nickname, principal: req.principal, client: req.client.title},
log.debug({principalUser: req.principalUser.nickname, principal: req.principal, client: req.client.title},
"User authorization complete.");

next();
@@ -301,7 +301,7 @@ var clearPrincipal = function(session, callback) {

var principal = function(req, res, next) {

req.log.info({msg: "Checking for principal", session: req.session});
req.log.debug({msg: "Checking for principal", session: req.session});

Step(
function() {
@@ -310,7 +310,7 @@ var principal = function(req, res, next) {
function(err, principal) {
if (err) throw err;
if (principal) {
req.log.info({msg: "Setting session principal", principal: principal});
req.log.debug({msg: "Setting session principal", principal: principal});
req.principal = principal;
res.local("principal", sanitizedJSON(req.principal));
User.fromPerson(principal.id, this);
@@ -326,7 +326,7 @@ var principal = function(req, res, next) {
} else {
// XXX: null on miss
if (user) {
req.log.info({msg: "Setting session principal user", user: user});
req.log.debug({msg: "Setting session principal user", user: user});
req.principalUser = user;
// Make the profile a "live" object
req.principalUser.profile = req.principal;
@@ -52,7 +52,7 @@ module.exports = {driver: "memory",
smtpfrom: null,
smtptimeout: null,
smtpfrom: null,
compress: false,
compress: true,
clients: [],
sockjs: true,
urlPath: null,
@@ -40,11 +40,11 @@ var Dispatch = {
dsp.setupWorker(worker);
});

if (dsp.log) dsp.log.info("Dispatch setup complete.");
if (dsp.log) dsp.log.debug("Dispatch setup complete.");
},
setupWorker: function(worker) {
var dsp = this;
if (dsp.log) dsp.log.info({id: worker.id}, "Setting up worker.");
if (dsp.log) dsp.log.debug({id: worker.id}, "Setting up worker.");
worker.on('message', function(msg) {
switch (msg.cmd) {
case "follow":
@@ -68,7 +68,7 @@ var Dispatch = {
dsp.followers[url] = [];
}
if (!_.contains(dsp.followers[url], id)) {
if (dsp.log) dsp.log.info({url: url, id: id}, "Adding follower");
if (dsp.log) dsp.log.debug({url: url, id: id}, "Adding follower");
dsp.followers[url].push(id);
}
},
@@ -78,7 +78,7 @@ var Dispatch = {
if (_.has(dsp.followers, url)) {
idx = dsp.followers[url].indexOf(id);
if (idx !== -1) {
if (dsp.log) dsp.log.info({url: url, id: id}, "Removing follower");
if (dsp.log) dsp.log.debug({url: url, id: id}, "Removing follower");
dsp.followers[url].splice(idx, 1);
}
}
@@ -90,12 +90,12 @@ var Dispatch = {
var worker = cluster.workers[id];
// XXX: clear out old subscriptions
if (worker) {
if (dsp.log) dsp.log.info({url: url, activity: activity.id, id: id}, "Dispatching to worker.");
if (dsp.log) dsp.log.debug({url: url, activity: activity.id, id: id}, "Dispatching to worker.");
worker.send({cmd: "update", url: url, activity: activity});
}
});
}
}
};

module.exports = Dispatch;
module.exports = Dispatch;
@@ -48,6 +48,16 @@ var Distributor = function(activity) {
Distributor.log.info(obj, msg);
}
},
ddebug = function(obj, msg) {
if (Distributor.log) {
Distributor.log.debug(obj, msg);
}
},
dwarn = function(obj, msg) {
if (Distributor.log) {
Distributor.log.warn(obj, msg);
}
},
derror = function(err, obj, message) {
if (obj) {
obj.err = err;
@@ -73,7 +83,7 @@ var Distributor = function(activity) {
toGroup(recipient, callback);
break;
default:
dinfo({recipient: recipient}, "Unknown recipient type");
dwarn({recipient: recipient}, "Unknown recipient type");
callback(null);
return;
}
@@ -197,7 +207,7 @@ var Distributor = function(activity) {
err: err},
"Error delivering activity to remote person.");
if (retries === 0 && err.statusCode == 401) { // expired key
dinfo({person: person.id,
ddebug({person: person.id,
activity: activity.id},
"Expired-credentials error; retrying.");
cred.del(function(err) {
@@ -208,7 +218,7 @@ var Distributor = function(activity) {
"Error deleting expired credentials for remote person.");
callback(err);
} else {
dinfo({person: person.id,
ddebug({person: person.id,
activity: activity.id},
"Correctly deleted credentials.");
toRemotePerson(person, retries+1, callback);
@@ -438,9 +448,9 @@ var Distributor = function(activity) {
var endpoint,
cred;

dinfo({person: group.id,
dinfo({group: group.id,
activity: activity.id},
"Delivering activity to remote person.");
"Delivering activity to remote group.");

Step(
function() {
@@ -512,7 +522,7 @@ var Distributor = function(activity) {
// to note an update of this feed with this activity
sendUpdate = function(url) {
if (cluster.isWorker) {
dinfo({url: url, activity: activity.id}, "Dispatching activity to URL");
ddebug({url: url, activity: activity.id}, "Dispatching activity to URL");
cluster.worker.send({cmd: "update",
url: url,
activity: activity});
@@ -572,7 +582,6 @@ var Distributor = function(activity) {
},
cache = {},
notifyByEmail = function(user, activity, callback) {

var options = {defaultEngine: "utml",
root: VIEW_ROOT},
hview = View.compile("activity-notification-html",
@@ -595,16 +604,20 @@ var Distributor = function(activity) {
callback(err, null);
return;
}

if (activity.verb == "post") {
if (activity.object.objectType == "note" || activity.object.objectType == "comment") {
// XXX: Better subject
Mailer.sendEmail({to: user.email,
subject: "pump.io activity notification",
text: text,
attachment: {data: html,
type: "text/html",
alternative: true}},
callback);
}
}

// XXX: Better subject

Mailer.sendEmail({to: user.email,
subject: "Activity notification",
text: text,
attachment: {data: html,
type: "text/html",
alternative: true}},
callback);
},
persevere = function(callback) {
return function(err) {
@@ -684,6 +697,7 @@ var Distributor = function(activity) {
callback(err);
} else {
notifyByEmail(user, activity, callback);

}
}
);
@@ -42,13 +42,13 @@ var Firehose = {
host = hostname;
if (plog) {
log = plog.child({component: "firehose", firehose: hostname});
log.info("Setting up firehose.");
log.debug("Setting up firehose.");
}
},
ping: function(activity, callback) {
var hose = this;

if (log) log.info({activity: activity.id}, "Enqueuing ping.");
if (log) log.debug({activity: activity.id}, "Enqueuing ping.");

// If there's no host, silently skip

@@ -43,7 +43,7 @@ Mailer.setup = function(config, log) {

from = config.smtpfrom || "no-reply@"+hostname;

maillog.info(_.omit(mailopts, "password"), "Connecting to SMTP server");
maillog.debug(_.omit(mailopts, "password"), "Connecting to SMTP server");

smtp = email.server.connect(mailopts);
};
@@ -52,8 +52,8 @@ Mailer.sendEmail = function(props, callback) {

var message = _.extend({"from": from}, props);

maillog.info({to: message.to || null,
subject: message.subject || null}, "Sending email");
maillog.debug({to: message.to || null,
subject: message.subject || null}, "Sending email");

smtp.send(message, function(err, results) {
if (err) {
@@ -75,204 +75,6 @@ var sameUser = function(req, res, next) {
}
};

var maybeAuth = function(req, res, next) {
if (!hasOAuth(req)) {
// No client, no user
next();
} else {
clientAuth(req, res, next);
}
};

var hasOAuth = function(req) {
return (req &&
_.has(req, "headers") &&
_.has(req.headers, "authorization") &&
req.headers.authorization.match(/^OAuth/));
};

// Accept either 2-legged or 3-legged OAuth

var clientAuth = function(req, res, next) {

var log = req.log;

req.client = null;
res.local("client", null); // init to null

if (hasToken(req)) {
userAuth(req, res, next);
return;
}

log.info("Checking for 2-legged OAuth credentials");

req.authenticate(["client"], function(error, authenticated) {

var deetz;

if (error) {
log.error(error);
next(error);
return;
}

if (!authenticated) {
log.info("Not authenticated");
return;
}

log.info("Authentication succeeded");

deetz = req.getAuthDetails();

log.info(deetz);

if (!deetz || !deetz.user || !deetz.user.id) {
log.info("Incorrect auth details.");
return;
}

Client.get(deetz.user.id, function(err, client) {

if (error) {
next(error);
return;
}

req.client = client;
res.local("client", req.client);
next();
});
});
};

var hasToken = function(req) {
return (req &&
(_(req.headers).has("authorization") && req.headers.authorization.match(/oauth_token/)) ||
(req.query && req.query.oauth_token) ||
(req.body && req.headers["content-type"] === "application/x-www-form-urlencoded" && req.body.oauth_token));
};

// Accept only 3-legged OAuth
// XXX: It would be nice to merge these two functions

var userAuth = function(req, res, next) {

var log = req.log;

req.principal = null;
res.local("principal", null); // init to null
req.principalUser = null;
res.local("principalUser", null); // init to null
req.client = null;
res.local("client", null); // init to null

log.info("Checking for 3-legged OAuth credentials");

req.authenticate(["user"], function(error, authenticated) {

var deetz;

if (error) {
log.error(error);
next(error);
return;
}

if (!authenticated) {
log.info("Authentication failed");
return;
}

log.info("Authentication succeeded");

deetz = req.getAuthDetails();

log.info(deetz);

if (!deetz || !deetz.user || !deetz.user.user || !deetz.user.client) {
log.info("Incorrect auth details.");
next();
return;
}

// If email confirmation is required and not yet done, give an error.

if (req.app.config.requireEmail && !deetz.user.user.email) {
next(new HTTPError("Can't use the API until you confirm your email address.", 403));
return;
}

req.principalUser = deetz.user.user;
res.local("principalUser", req.principalUser);

req.principal = req.principalUser.profile;
res.local("principal", req.principal);

req.client = deetz.user.client;
res.local("client", req.client);

next();
});
};

// Accept only 2-legged OAuth with

var remoteUserAuth = function(req, res, next) {

req.client = null;
res.local("client", null); // init to null
req.webfinger = null;
res.local("webfinger", null);
req.host = null;
res.local("host", null);

req.authenticate(["client"], function(error, authenticated) {

var id, client;

if (error) {
next(error);
return;
}

if (!authenticated) {
return;
}

id = req.getAuthDetails().user.id;

Step(
function() {
Client.get(id, this);
},
function(err, results) {
if (err) throw err;
client = results;
if (!client) {
throw new HTTPError("No client", 401);
}
if (!client.webfinger && !client.host) {
throw new HTTPError("OAuth key not associated with a webfinger or host", 401);
}
req.client = client;
res.local("client", req.client);
client.asActivityObject(this);
},
function(err, principal) {
if (err) {
next(err);
} else {
req.principal = principal;
res.local("principal", principal);
next();
}
}
);
});
};

var fileContent = function(req, res, next) {

if (req.headers['content-type'] == 'application/json') {
@@ -376,9 +178,5 @@ var reqGenerator = function(req, res, next) {
exports.reqUser = reqUser;
exports.reqGenerator = reqGenerator;
exports.sameUser = sameUser;
exports.userAuth = userAuth;
exports.clientAuth = clientAuth;
exports.remoteUserAuth = remoteUserAuth;
exports.maybeAuth = maybeAuth;
exports.fileContent = fileContent;
exports.hasOAuth = hasOAuth;

@@ -1503,7 +1503,9 @@ Activity.prototype.checkRecipient = function(person, callback) {
var isInList = function(list, callback) {
Step(
function() {
Collection.isList(list, this);
//console.log("isInLists: "+JSON.stringify(list));
if (list.objectType == 'collection' && list.id.search('.+/api/user/.*/followers') == -1) return true;
else { Collection.isList(list, this);}
},
function(err, isList) {
if (err) throw err;
@@ -1596,7 +1598,7 @@ Activity.prototype.checkRecipient = function(person, callback) {
},
function(err, url) {
if (err) throw err;
if (!url || !recipientWithID(url)) {
if (!url ) { //|| !recipientWithID(url)) {
callback(null, false);
} else {
var Edge = require("./edge").Edge;
@@ -1112,7 +1112,10 @@ ActivityObject.validate = function(props) {
_.each(uriarrayprops, function(uriarrayprop) {
if (_.has(props, uriarrayprop)) {
if (!_.isArray(props[uriarrayprop])) {
throw new TypeError(uriarrayprop + " is not an array");
if(typeof props.upstreamDuplicates[0] == "undefined"){
throw new TypeError(uriarrayprop + " is not an array and has no 0 value");
//console.log("\n"+JSON.stringify(props.upstreamDuplicates[0])+"\n");
}
}

if (_.some(props[uriarrayprop], function(str) { return !_.isString(str); })) {
@@ -326,7 +326,8 @@ Person.match = function(q) {
},
function(err, person) {
if (err) throw err;
if (person.displayName && person.displayName.indexOf(q) != -1) {
// Case-insensitive search
if (person.displayName && person.displayName.toLowerCase().indexOf(q.toLowerCase()) != -1) {
this(null, true);
} else {
this(null, false);
@@ -83,7 +83,7 @@ var Provider = function(logParent, rawClients) {
};

prov.previousRequestToken = function(token, callback) {
if (log) log.info("getting previous request token for " + token);
if (log) log.debug("getting previous request token for " + token);
AccessToken.search({request_token: token}, function(err, ats) {
if (err) {
callback(err, null);
@@ -96,7 +96,7 @@ var Provider = function(logParent, rawClients) {
};

prov.tokenByConsumer = function(consumerKey, callback) {
if (log) log.info("getting token for consumer key " + consumerKey);
if (log) log.debug("getting token for consumer key " + consumerKey);
prov.getClient(consumerKey, function(err, client) {
if (err) {
callback(err, null);
@@ -113,7 +113,7 @@ var Provider = function(logParent, rawClients) {
};

prov.tokenByTokenAndConsumer = function(token, consumerKey, callback) {
if (log) log.info("getting token for consumer key " + consumerKey + " and token " + token);
if (log) log.debug("getting token for consumer key " + consumerKey + " and token " + token);
RequestToken.get(token, function(err, rt) {
if (err) {
callback(err, null);
@@ -126,12 +126,12 @@ var Provider = function(logParent, rawClients) {
};

prov.applicationByConsumerKey = function(consumerKey, callback) {
if (log) log.info("getting application for consumer key " + consumerKey);
if (log) log.debug("getting application for consumer key " + consumerKey);
prov.getClient(consumerKey, callback);
};

prov.fetchAuthorizationInformation = function(username, token, callback) {
if (log) log.info("getting auth information for user "+username+" with token " + token);
if (log) log.debug("getting auth information for user "+username+" with token " + token);
RequestToken.get(token, function(err, rt) {
if (err) {
callback(err, null, null);
@@ -156,12 +156,12 @@ var Provider = function(logParent, rawClients) {
};

prov.validToken = function(accessToken, callback) {
if (log) log.info("checking for valid token " + accessToken);
if (log) log.debug("checking for valid token " + accessToken);
AccessToken.get(accessToken, callback);
};

prov.tokenByTokenAndVerifier = function(token, verifier, callback) {
if (log) log.info("checking for valid request token " + token + " with verifier " + verifier);
if (log) log.debug("checking for valid request token " + token + " with verifier " + verifier);
RequestToken.get(token, function(err, rt) {
if (err) {
callback(err, null);
@@ -177,7 +177,7 @@ var Provider = function(logParent, rawClients) {
var now = Math.floor(Date.now()/1000),
ts;

if (log) log.info("checking for replay with consumer key " + consumerKey + ", token = " + accessToken);
if (log) log.debug("checking for replay with consumer key " + consumerKey + ", token = " + accessToken);

try {
ts = parseInt(timestamp, 10);
@@ -223,7 +223,7 @@ var Provider = function(logParent, rawClients) {
prov.userIdByToken = function(token, callback) {
var user, client, at;

if (log) log.info("checking for user with token = " + token);
if (log) log.debug("checking for user with token = " + token);

Step(
function() {
@@ -252,7 +252,7 @@ var Provider = function(logParent, rawClients) {

prov.authenticateUser = function(username, password, oauthToken, callback) {

if (log) log.info("authenticating user with username " + username + " and token " + oauthToken);
if (log) log.debug("authenticating user with username " + username + " and token " + oauthToken);

User.checkCredentials(username, password, function(err, user) {
if (err) {
@@ -286,7 +286,7 @@ var Provider = function(logParent, rawClients) {

prov.associateTokenToUser = function(username, token, callback) {

if (log) log.info("associating username " + username + " with token " + token);
if (log) log.debug("associating username " + username + " with token " + token);

RequestToken.get(token, function(err, rt) {
if (err) {
@@ -309,7 +309,7 @@ var Provider = function(logParent, rawClients) {

prov.generateRequestToken = function(oauthConsumerKey, oauthCallback, callback) {

if (log) log.info("getting a request token for " + oauthConsumerKey);
if (log) log.debug("getting a request token for " + oauthConsumerKey);

if (oauthCallback !== "oob") {
var parts = url.parse(oauthCallback);
@@ -335,7 +335,7 @@ var Provider = function(logParent, rawClients) {

var rt, at;

if (log) log.info("getting an access token for " + oauthToken);
if (log) log.debug("getting an access token for " + oauthToken);

Step(
function() {
@@ -359,13 +359,13 @@ var Provider = function(logParent, rawClients) {
var props;
if (err) throw err;
if (!ats || ats.length === 0) {
if (log) log.info("creating a new access token for " + oauthToken);
if (log) log.debug("creating a new access token for " + oauthToken);
props = {consumer_key: rt.consumer_key,
request_token: rt.token,
username: rt.username};
AccessToken.create(props, this);
} else {
if (log) log.info("reusing access token " + ats[0].access_token + " for " + oauthToken);
if (log) log.debug("reusing access token " + ats[0].access_token + " for " + oauthToken);
// XXX: keep an array of related request tokens, not just one
ats[0].update({request_token: rt.token}, this);
}
@@ -374,7 +374,7 @@ var Provider = function(logParent, rawClients) {
if (err) throw err;
at = results;
// XXX: delete...?
if (log) log.info("saving access token for " + oauthToken);
if (log) log.debug("saving access token for " + oauthToken);
rt.update({access_token: at.access_token}, this);
},
function(err, rt) {
@@ -389,7 +389,7 @@ var Provider = function(logParent, rawClients) {

prov.cleanRequestTokens = function(consumerKey, callback) {

if (log) log.info("cleaning up request tokens for " + consumerKey);
if (log) log.debug("cleaning up request tokens for " + consumerKey);

Step(
function() {
@@ -83,7 +83,7 @@ var connect = function(app, log) {
var url;
if (err) {
// <sad trombone>
conn.log.error(err);
conn.log.error({err: err}, "Error creating random string");
conn.close();
} else {
url = URLMaker.makeURL("/main/realtime/sockjs/"+str+"/challenge");
@@ -100,7 +100,7 @@ var connect = function(app, log) {
var client,
params = _.object(message.parameters);

conn.log.info(message);
conn.log.debug({riseMessage: message}, "Client rose to challenge");

if (message.action != conn.challengeURL) {
conn.log.error({challenge: conn.challengeURL,
@@ -117,7 +117,7 @@ var connect = function(app, log) {
if (_.has(params, "oauth_token")) {
validateUser(message, function(err, user, client) {
if (err) {
conn.log.error(err,
conn.log.error({err: err},
"Failed user authentication");
conn.close();
} else {
@@ -133,7 +133,7 @@ var connect = function(app, log) {
} else {
validateClient(message, function(err, client) {
if (err) {
conn.log.error(err,
conn.log.error({err: err},
"Failed client authentication");
conn.close();
} else {
@@ -291,7 +291,7 @@ var connect = function(app, log) {
function(err) {
var tosend;
if (err) {
conn.log.error(err);
conn.log.error({err: err}, "Error finishing object");
} else {
tosend = _.pick(msg, "cmd", "url");
tosend.activity = act;
@@ -312,7 +312,7 @@ var connect = function(app, log) {

server.log = slog;

server.log.info("Setting up sockjs server.");
server.log.debug("Setting up sockjs server.");

// snatch the provider

@@ -357,6 +357,9 @@ var connect = function(app, log) {
conn.log.info("Request");
challenge(conn);
break;
default:
conn.log.warn({cmd: data.cmd}, "Unrecognized command; ignoring.");
break;
}
return;
});
@@ -80,7 +80,7 @@ var rawBody = function(req, res, next) {
return;
}

req.log.info("Parsing raw body of request with type " + mimeType);
req.log.debug("Parsing raw body of request with type " + mimeType);

if (_.has(req.headers, "content-length")) {
try {
@@ -135,7 +135,7 @@ var rawBody = function(req, res, next) {
res.end(chunk, encoding);
maybeCleanup(fname, function(err) {
if (err) {
req.log.error(err);
req.log.error({err: err, fname: fname}, "Error cleaning up");
}
});
};
@@ -147,6 +147,7 @@ var activityFeed = function(relmaker, titlemaker, streammaker, finisher) {
},
function(err, activities) {
if (err) throw err;
activities = activities.filter(function(n){return n});
activities.forEach(function(act) {
act.sanitize(principal);
});
@@ -522,21 +523,20 @@ var userStream = activityFeed(
addProxyFinisher
);


var userPublicStream = activityFeed(
function(context) {
var user = context.user;

return "api/user/" + user.nickname + "/feed";
},
return "api/user/" + user.nickname + "/feed/public";
},
function(context) {
var user = context.user;

return "Public activities by " + (user.profile.displayName || user.nickname);
},
function(context, callback) {
var user = context.user;
user.getOutboxPublicStream(callback);
user.getOutboxStream(callback);
},
addProxyFinisher
);
@@ -93,7 +93,7 @@ var Upgrader = new (function() {

if (person._user && _.isObject(person.image) && !_.has(person.image, "width") && _.isString(person.image.url)) {

if (Upgrader.log) Upgrader.log.info({person: person}, "Upgrading person avatar");
if (Upgrader.log) Upgrader.log.debug({person: person}, "Upgrading person avatar");

slug = urlToSlug(person, person.image.url);

@@ -170,7 +170,7 @@ var Upgrader = new (function() {
var fromPerson = ActivityObject.domainOf(person.id),
fromUrl = urlparse(url).hostname;
if (fromPerson != fromUrl) {
if (Upgrader.log) Upgrader.log.info({url: url, person: person.id, fromPerson: fromPerson, fromUrl: fromUrl}, "URL hostname mismatch");
if (Upgrader.log) Upgrader.log.debug({url: url, person: person.id, fromPerson: fromPerson, fromUrl: fromUrl}, "URL hostname mismatch");
return true;
} else {
return false;
@@ -205,7 +205,7 @@ var Upgrader = new (function() {

var discovered;

if (Upgrader.log) Upgrader.log.info({person: person}, "Upgrading remote person feeds");
if (Upgrader.log) Upgrader.log.debug({person: person}, "Upgrading remote person feeds");

Step(
function() {
@@ -216,10 +216,10 @@ var Upgrader = new (function() {
discovered = results;
// These get added accidentally; remove them if they look wrong
_.each(["replies", "likes", "shares"], function(feed) {
if (Upgrader.log) Upgrader.log.info({person: person, feed: feed, personFeed: person[feed]}, "Checking for bad value");
if (Upgrader.log) Upgrader.log.debug({person: person, feed: feed, personFeed: person[feed]}, "Checking for bad value");
if (person[feed] && isMismatchURL(person, person[feed].url)) {
delete person[feed];
if (Upgrader.log) Upgrader.log.info({person: person, feed: feed}, "Deleted bad value");
if (Upgrader.log) Upgrader.log.debug({person: person, feed: feed}, "Deleted bad value");
}
});
person._upgrade_remote_person_feeds = true;
@@ -239,15 +239,15 @@ var Upgrader = new (function() {
callback(null);
});
} else {
if (Upgrader.log) Upgrader.log.info({person: person, stillNeedsUpgrade: needsUpgradeRemotePersonFeeds(person)}, "Finished upgrading remote person");
if (Upgrader.log) Upgrader.log.debug({person: person, stillNeedsUpgrade: needsUpgradeRemotePersonFeeds(person)}, "Finished upgrading remote person");
callback(null);
}
}
);
},
upgradeUserFeeds = function(person, callback) {

if (Upgrader.log) Upgrader.log.info({person: person}, "Upgrading user feeds");
if (Upgrader.log) Upgrader.log.debug({person: person}, "Upgrading user feeds");

if (!_.has(person, "links")) {
person.links = {};
@@ -280,7 +280,7 @@ var Upgrader = new (function() {
function(err) {
var pu;
if (err) throw err;
if (Upgrader.log) Upgrader.log.info({person: person, stillNeedsUpgrade: needsUpgradeUserFeeds(person)}, "Finished upgrading user");
if (Upgrader.log) Upgrader.log.debug({person: person, stillNeedsUpgrade: needsUpgradeUserFeeds(person)}, "Finished upgrading user");
pu = new Activity({actor: person,
verb: "update",
object: person});
@@ -340,7 +340,7 @@ var Upgrader = new (function() {

if (person._user && !person._user_confirmed) {

if (Upgrader.log) Upgrader.log.info({person: person}, "Confirming _user flag");
if (Upgrader.log) Upgrader.log.debug({person: person}, "Confirming _user flag");

Step(
function() {
@@ -350,11 +350,11 @@ var Upgrader = new (function() {
function(err, user) {
if (err) throw err;
if (user) {
if (Upgrader.log) Upgrader.log.info({person: person}, "_user flag confirmed");
if (Upgrader.log) Upgrader.log.debug({person: person}, "_user flag confirmed");
person._user_confirmed = true;
person.save(this);
} else {
if (Upgrader.log) Upgrader.log.info({person: person}, "Bad _user flag; removing");
if (Upgrader.log) Upgrader.log.debug({person: person}, "Bad _user flag; removing");
delete person._user;
person.save(this);
}
@@ -372,7 +372,7 @@ var Upgrader = new (function() {

if (img._slug && _.isObject(img.image) && !_.has(img.image, "width")) {

if (Upgrader.log) Upgrader.log.info({image: img}, "Upgrading image");
if (Upgrader.log) Upgrader.log.debug({image: img}, "Upgrading image");

Step(
function() {
@@ -448,7 +448,7 @@ var Upgrader = new (function() {
return;
}

if (Upgrader.log) Upgrader.log.info({group: group}, "Upgrading group");
if (Upgrader.log) Upgrader.log.debug({group: group}, "Upgrading group");

Step(
function() {
@@ -524,7 +524,7 @@ var Upgrader = new (function() {
return;
}

if (Upgrader.log) Upgrader.log.info({activity: act}, "Upgrading activity");
if (Upgrader.log) Upgrader.log.debug({activity: act}, "Upgrading activity");

// Otherwise, fix them up

@@ -0,0 +1 @@
acct:mgebbe@io.intevation.de
@@ -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");
}
}
);

}
@@ -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');
});

}

BIN -86.5 KB (1.6%) public/images/favicon.ico
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -367,6 +367,7 @@ if (!window.Pump) {

$.fn.wysihtml5.defaultOptions["font-styles"] = false;
$.fn.wysihtml5.defaultOptions["image"] = false;
$.fn.wysihtml5.defaultOptions["html"] = true;
$.fn.wysihtml5.defaultOptions["customTemplates"] = Pump.wysihtml5Tmpl;
};