Repository navigation
Expand file tree
/
Copy pathhexfile.js
More file actions
202 lines (150 loc) · 5.52 KB
/
Copy pathhexfile.js
File metadata and controls
202 lines (150 loc) · 5.52 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// script.js
var pcApp = angular.module('pcApp', ['ngFileUpload']);
var getUID = function(size) {
// create a randon string of length N
// default = 6 ~ 1Billion unique combinations
size = size || 6;
// AAH, the uid is case insensitive, owing to oddnesses of DNS
// so we have to work with a lower entropy random number
// var keyStr = 'ABCDEFGHIJKLMNOP' +
// 'QRSTUVWXYZabcdef' +
// 'ghijklmnopqrstuv' +
// // 'wxyz0123456789+-';
// 'wxyz0123456789';
var keyStr = 'abcdefghijklmnopqrstuvwxyz' +
'0123456789';
// for sanity, first char can't be '+,-'
// so this is really base32 encoding
// generate N randon characters
var rs = "";
for(var i=0; i < size ; i++){
// randon #, length 64,ish
// var r = Math.floor((Math.random() * 62));
var r = Math.floor((Math.random() * keyStr.length));
rs = rs + keyStr.charAt(r);
// rs+=c;
// var c = keyStr.charAt(r);
// console.log ( 'loop', i , r , c , rs);
}
return rs ;
};
//
// controller for form submission
//
pcApp.controller('formController', ['$scope', 'Upload', '$timeout','$interval',
function ($scope, Upload, $timeout, $interval) {
// create a blank object to hold our form information
// $scope will allow this to pass between controller and view
$scope.formFields = {
delay : "100"
};
$scope.fileButtonMessage = "Click here to load a file";
$scope.fileSize = 0;
$scope.logresult = '';
var dummyImg = new Image();
$scope.showFileName = function(myFile) {
// generate a new UID
$scope.uid = getUID();
if ( myFile ) {
$scope.fileButtonMessage = myFile.name ;
$scope.fileSize = myFile.size / 1000000 ; // MB'ish
console.log('file selected, size :',$scope.fileSize , myFile);
}
};
$scope.uploadPic = function() {
// save the Filetype in the UID or somewhere for the url
// on the CGI side
// get a pointer to the file object
// (instead of passing it in the function)
var myFile = $scope.formFields.file;
// myFile is an object describing the datafile,
// it DOES NOT have the data. That's still in the field
console.log('file:',myFile);
console.log('fields:',$scope.formFields);
// we're still using the ng-file uploader to handle the UI bits
// but the internal filereader() to get the raw data
// read in the file then process it line by line
var reader = new FileReader();
reader.onload = function(e) {
$scope.processFile(reader.result,$scope.uid);
};
reader.readAsBinaryString(myFile);
};
$scope.logMessage = function(s) {
// just a wrapper to scope.$apply to force the dispatcher
// to fire when we need it
$scope.$apply(function(){
$scope.logresult += s + "\n";
});
};
$scope.processFile = function( data , uid ) {
// ?filename=hello.txt&uid=s5tbk4&showdata=on
// break the data into fixed sized chunks
// convert each chunk into hex
$scope.logresult = '';
console.log( 'processFile : delay : ', $scope.formFields.delay);
var blocks = data.match( /[\s\S]{1,31}/g );
var path = '/icos/favico.png';
// var domain = '.cdn.ignoremydata.com';
var domain = '.ignoremydata.com';
var startName = 'start.' + uid + domain;
var stopName = 'stop.' + uid + domain;
// we want a delay between each DNS query, and the 'timeout' functions,
// are non-blocking. So the safest thing is to generate all the queries,
// stack them into an array, then interval them
// var startImg = 'http://start.' + uid + '.ignoremydata.com/favico.png';
// var stopImg = 'http://stop.' + uid + '.ignoremydata.com/favico.png';
var queries = [ startName ];
// $timeout(function(){
// console.log ('after timeout');
// },3000);
//
// console.log ('post timeout');
for( var block in blocks ) {
var idx = block;
idx ++ ; // 1 based cointing for the URL
var q = Hexdump.dump( blocks[block] ) +
'.'+ idx +'.'+ uid + domain ;
queries.push( q );
}
queries.push( stopName );
console.log ( 'slices' , queries.length );
// now load the dns queries, at a fixed interval
qidx = 0 ;
$interval(function(){
// now use that string to generate a fake image url
// var iurl = "http://"+s+"/favico.jpg";
// var startImg = 'http://' + startName + path ;
// var stopImg = 'http://' + stopName + path ;
var q = queries[qidx];
var iurl = 'http://' + q + path ;
// and force a query
dummyImg.src = iurl;
// $interval calls $digest, so no need to call 'logMessage()'
// $scope.logMessage(q);
console.log ('query',q);
$scope.logresult += q + "\n";
qidx++;
},$scope.formFields.delay,queries.length);
};
}]);
//
// Poor person's simplified hex dump routines
//
var Hexdump = {
to_hex: function( number ) {
var r = number.toString(16);
if( r.length < 2 ) {
return "0" + r;
} else {
return r;
}
},
dump: function( s ) {
var dumped = "";
for( var i = 0; i < s.length; i++ ) {
dumped += Hexdump.to_hex( s.charCodeAt( i ) ) ;
}
return dumped;
}
};