-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheckrep-line-assembler-not-finished.rb
83 lines (72 loc) · 2.45 KB
/
checkrep-line-assembler-not-finished.rb
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
#!/usr/bin/env ruby
require "json"
require "net/http"
require "uri"
puts "./script pad " if not ARGV
padurl = ARGV[0]
uri = URI(padurl)
padname = padurl.split("/").last
TOKEN="t.1"#token=t.1
CLIENTREADY=JSON(
{
"component"=>"pad",
"type"=>"CLIENT_READY",
"padId"=>padname,
"sessionID"=>"null",
"password"=>"null",
"token"=>TOKEN,
"protocolVersion"=>2
}
)
#connect and get a cookie
res = Net::HTTP.get_response(uri)
COOKIE = res['Set-Cookie'].split(';').select{|p|p.match(/^express_sid/)}.first
#connect to the xhr interface
xhr = URI("#{uri.scheme}://#{uri.hostname}:#{uri.port}/socket.io/1")
req = Net::HTTP::Get.new(xhr.request_uri)
req['Cookie'] = COOKIE
res = Net::HTTP.start(xhr.hostname,xhr.port) {|http|
http.request(req)
}
XHREND = URI("#{xhr}/xhr-polling/#{res.body.split(":").first}")
req = Net::HTTP::Get.new(XHREND.request_uri)
req['Cookie'] = "#{COOKIE}; token=#{TOKEN}"
res = Net::HTTP.start(XHREND.hostname,XHREND.port) {|http|
http.request(req)
}
#tell ep we are ready
http = Net::HTTP.new(XHREND.host,XHREND.port)
req = Net::HTTP::Post.new(XHREND.request_uri)
req['Cookie'] = "#{COOKIE}; token=#{TOKEN}"
req.body = "4:::#{CLIENTREADY}"
res=http.request(req)
#get our author name
#and the initial text which we need to build our CLEARPAD changeset
req = Net::HTTP::Get.new(XHREND.request_uri)
req['Cookie'] = "#{COOKIE}; token=#{TOKEN}"
res = Net::HTTP.start(XHREND.hostname,XHREND.port) {|http|
http.request(req)
}
AUTHOR = res.body.match(/userId":"([^"]+)/)[1]
initialtext = JSON.parse(res.body.split(':::')[1].match(/(.*}})(.[0-9]+.4$)?/)[1])['data']['collab_client_vars']['initialAttributedText']['text']
puts initialtext
puts initialtext.size
#delete all chars from pad
size=initialtext.size.to_s(36)
size2=(initialtext.size+1).to_s(36)
drop=(initialtext.size-1).to_s(36)
lines=initialtext.scan("\n").size-1 #last char is always \n
CLEARPADCS = "Z:6c<1|3=g=1o-1$"
puts CLEARPADCS
CLEARPAD="4:::{\"type\":\"COLLABROOM\",\"component\":\"pad\",\"data\":{\"type\":\"USER_CHANGES\",\"baseRev\":2000,\"changeset\":\"#{CLEARPADCS}\",\"apool\":{\"numToAttrib\":{},\"nextNum\":0}}}"
http = Net::HTTP.new(XHREND.host,XHREND.port)
req = Net::HTTP::Post.new(XHREND.request_uri)
req['Cookie'] = "#{COOKIE}; token=#{TOKEN}"
req.body = CLEARPAD
res=http.request(req)
req = Net::HTTP::Get.new(XHREND.request_uri)
req['Cookie'] = "#{COOKIE}; token=#{TOKEN}"
res = Net::HTTP.start(XHREND.hostname,XHREND.port) {|http|
http.request(req)
}
puts res.body