This repository has been archived by the owner on Aug 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
112 lines (100 loc) · 3.11 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// test2.js
// from: https://gist.github.com/alessioalex/1360979
//
var request = require('request'), default_headers,
//site_root = 'http://104.236.230.185:8080', //URL to hit
//site_root = 'http://findtrkr.com:8080'
site_root = 'http://localhost:8080';
var argv = require('optimist').argv,
// parser = require('./lib/parser'),
latLon = argv.l || process.env.PINGER_LATLON || null,
uid = argv.u || null,
delay = argv.d || 1,
steps = argv.n || 1,
stat = argv.s || "ok";
if (argv.v) {
require('request-debug')(request);
//request.stopDebugging();
}
default_headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20100101 Firefox/7.0.1',
'Accept': 'text/html,application/json,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'en-us,en;q=0.5',
'Accept-Encoding': 'gzip, deflate',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
// 'Connection': 'keep-alive',
'Cache-Control': 'max-age=0',
'Content-Type': 'application/json'
};
var help = "Usage: pinger [OPTION]\n\
Send ping(s) to TRKR based on [OPTION].\n\
-u=uid\t\tSet user ID\n\
-d=delay\t\tset delay in minutes\n\
-r\t\t\tMove randomly between steps\n\
-v\t\t\t(Verbose) show raw requests and responses to TRKR\n\
-n=steps\t\tRun N steps\n\
-s=status\t\tSet status string\n\
-l=latlon\t\tThe latitude,longitude co-ordinates for the location";
if (argv.help) {
console.log(help);
process.exit(0);
}
if (uid === null) {
console.error('Missing required user id');
console.error(help);
process.exit(1);
}
if (latLon === null) {
console.error('Missing required lat/lon co-ordinates');
console.error(help);
process.exit(1);
}
// break lat lon out to two variables
var comma = latLon.indexOf(",");
var lat = latLon.substr(0,comma);
var lon = latLon.substr(comma+1,latLon.length);
console.log("lat = " + lat + " lon = " + lon);
// now start loop
while (steps > 0){
console.log("step="+steps);
//console.log(options)
// delay for 'delay' minutes
console.log("delaying "+ delay + " minutes");
var t = setTimeout(function(){
// all of this is delayed by delay minutes ----------------------
console.log("Ping from user="+uid+" at "+lat+","+lon+ " with a status of ["+stat+ "] sent at "+new Date());
request({
url: site_root + '/pings',
headers: default_headers,
method: 'POST',
qs: {uid: uid, did: '0'},
//json: true,
//body: JSON.stringify({ user:'my_user', password:'my_pass' })
body: JSON.stringify({source: 'pinger', uid: uid, state: stat, loc: { lat: lat, lon: lon, source: 'pinger' }})
}, function (err, res, body) {
if (err) {
console.log(err);
//process.exit(1);
}
if (!err && res.statusCode == 201) {
//console.log("ping response received => "+body);
console.log("ping response received at ["+new Date()+"] => "+body);
//console.log(body);
} else {
console.error('Unexpected status code from TRKR -> ' +
response.statusCode);
//process.exit(1);
}
});
// if random then modify here
if (argv.r) {
console.log("generating random movement");
lat++;
lon++;
}
}, delay*2000*60);
steps --;
}
console.log("got to end");
//process.exit(0);
//EOF