-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tinder-HTTP.rb
145 lines (119 loc) · 3.95 KB
/
Tinder-HTTP.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
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
#!/usr/bin/ruby
require 'rubygems'
require 'builder'
require 'sinatra'
require 'cgi'
require 'json'
require 'tinderChannelBase.rb'
require 'drb'
if !$tinderChannel
DRb.start_service
$tinderServer, $tinderBot = getServer
$tinderChannel = addChannel("www", 'TinderChannel')
$tinderChannel.tinderBot = $tinderBot
end
class String
def each
self.split($/).each { |e| yield e }
end
end
def get_html(param)
args = param.gsub('://','##%').gsub('\/','##@').split('/')
cmd = args.shift
cmd = 'help' if cmd == '' or cmd == nil
case cmd
when /get|rss/
args = args.join('/')
when /php/
args = CGI.unescape(args.join(";\n"))
when /ruby|tcl|textile/
args = CGI.unescape(args.join("\n"))
else
args = CGI.unescape(args.join(" "))
end
args.gsub!('##@',"/")
args.gsub!('##@',"://")
return $tinderChannel.runCommand(cmd, args, 'www', 'host', ['channel','global','private','system','www'])
end
get '/text/*' do
get_html(params['splat'].first).gsub('<BR[/]*>',"\n").gsub(/<[^>]*>/,'')
end
get '/soap' do
outStr = get_html('')
outputArr = {}
outputArr['command'] = ''
if outStr[0,7] == 'http://' and !outStr.match(/ /)
outStr.gsub!(/<[^>]*>/,'')
outputArr['body'] = outStr.chomp
outputArr['url'] = outStr.chomp
else
outputArr['url'] = ''
outStr.gsub!(/(http:\/\/[\w\/\?&\.\=\_\#\@\!-]+)/i, '<a href="\1">\1</a>').chomp if !outStr.match(/<[^>]*>/)
outputArr['body'] = outStr.gsub(/<BR[\/]?>/m,"\n").chomp
$outStr = ''
xml = ::Builder::XmlMarkup.new( :target => $outStr, :indent => 0 )
xml.tinderResponseResponse('xmlns'=>'http://www.viper-7.com/tinder/soap') do
xml.command( outputArr['command'], 'xsi:type'=>'xsd:string' )
xml.url( outputArr['url'], 'xsi:type'=>'xsd:string' )
xml.body( outputArr['body'], 'xsi:type'=>'xsd:string' )
end
'<?xml version="1.0" encoding="utf-8"?>' + "\n" +
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' + "\n" +
'<soap:Body>' + $outStr + '</soap:Body>' + "\n" +
'</soap:Envelope>'
end
end
get '/xml/*' do
outStr = get_html(params['splat'].first)
outputArr = {}
outputArr['command'] = params['splat'].first
if outStr[0,7] == 'http://' and !outStr.match(/ /)
outStr.gsub!(/<[^>]*>/,'')
outputArr['body'] = outStr.chomp
outputArr['url'] = outStr.chomp
else
outputArr['url'] = ''
outStr.gsub!(/(http:\/\/[\w\/\?&\.\=\_\#\@\!-]+)/i, '<a href="\1">\1</a>').chomp if !outStr.match(/<[^>]*>/)
outputArr['body'] = outStr.gsub(/<BR[\/]?>/m,"\n").chomp
$outStr = ''
xml = ::Builder::XmlMarkup.new( :target => $outStr, :indent => 0 )
xml.instruct! :xml, :version => "1.1", :encoding => "utf-8"
xml.tinderResponse do
outputArr.each do | name, choice |
xml.response( choice, 'type'=>name )
end
end
$outStr
end
end
get '/json/*' do
outStr = get_html(params['splat'].first)
outputArr = {}
outputArr['command'] = params['splat'].first
if outStr[0,7] == 'http://' and !outStr.match(/ /)
outStr.gsub!(/<[^>]*>/,'')
outputArr['body'] = outStr.chomp
outputArr['url'] = outStr.chomp
else
outputArr['url'] = ''
outStr.gsub!(/(http:\/\/[\w\/\?&\.\=\_\#\@\!-]+)/i, '<a href="\1">\1</a>') if !outStr.match(/<[^>]*>/)
outputArr['body'] = outStr.gsub(/<BR[\/]?>/m,"\n").chomp
outputArr.to_json
end
end
get '/*' do
outStr = get_html(params['splat'].first)
if outStr[0,7] == 'http://' and !outStr.match(/ /)
outStr.gsub!(/<[^>]*>/,'')
redirect outStr.chomp
else
outStr.gsub!(/(http:\/\/[\w\/\?&\.\=\_\#\@\!-]+)/i, '<a href="\1">\1</a>') if !outStr.match(/<[^>]*>/)
if outStr.match(/<html/)
outStr
else
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>' + "\n" +
'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">' + "\n<head><title>" + params['splat'].first + '</title></head>' + "\n" +
'<body>' + "\n" + outStr + "\n</body></html>"
end
end
end