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
/
index.js.orig
147 lines (122 loc) · 3.17 KB
/
index.js.orig
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env node
//var request2 = require('request').debug = true;
var request = require('request');
require('request-debug')(request);
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";
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\
-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);
}
//var apiEndPoint =
/***
if (stat) {
apiEndPoint += '&status=' + stat;
}
***/
// 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);
var headers = {
'User-Agent': 'Super Agent/0.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'
};
function callback(error, response, body) {
console.log("in callback");
if (error) {
console.log(error);
//process.exit(1);
//throw error;
}
if (response.statusCode != 201) {
console.error('Unexpected status code from TRKR -> ' +
response.statusCode);
//process.exit(1);
}
//var info = JSON.parse(body);
console.log(response.statusCode, body);
/***
try {
var data = JSON.parse(body2);
console.log(parser.currently(data, degrees, argv));
//process.exit(0);
} catch (e) {
console.log(e);
console.error('unabled to parse TRKR data');
process.exit(1);
}
****/
};
// Configure the request
var options = {
//url: 'http://104.236.230.185:8080/pings', //URL to hit
//uri: 'http://104.236.230.185:8080/pings', //URL to hit
uri: 'http://localhost:8080/pings', //URL to hit
//url: 'http://findtrkr.com:8080/pings',
method: 'POST',
headers: headers,
qs: {'uid': uid, 'did': '0'},
timeout: 1000,
//json: true,
body: JSON.stringify({
source: 'pinger',
uid: uid,
oid: '01',
tid: '01',
loc: {
lat: lat,
lon: lon,
source: 'pinger'
}
})
};
// now start loop
while (steps > 0){
console.log("step="+steps);
console.log(options);
request(options, callback);
// if random then modify here
if (argv.r) {
console.log("generating random movement");
}
// delay for delay minutes
if (steps > 1){
// delay minutes
console.log("delaying "+ delay + " minutes");
}
steps --;
}
console.log("got to end");
process.exit(0);
// EOF