-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwowi_upload.rb
141 lines (111 loc) · 3.44 KB
/
wowi_upload.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
#! /c/ruby/bin/ruby
require 'net/http'
require 'uri'
require 'digest/md5'
require 'xmlsimple'
require 'rubygems'
require 'mime/types'
#~ require 'cgi'
#########################
## Multipart ##
#########################
BOUNDARY = 'tek-likes-bear-dick-314'
HEADER = {"Content-type" => "multipart/form-data, boundary=#{BOUNDARY} "}
def prepare_query(params)
query = ""
params.each do |k,v|
if v.respond_to?(:read)
query << %Q|\r\n--#{BOUNDARY}\r\nContent-Disposition: form-data; name="#{k}"; filename="#{v.path}"\r\nContent-Transfer-Encoding: binary\r\nContent-Type: #{MIME::Types.type_for(v.path)}\r\n\r\n#{v.read}\r\n|
else
query << %Q|--#{BOUNDARY}\r\nContent-Disposition: form-data; name="#{k}"\r\n\r\n#{v}\r\n|
end
end
query << "--#{BOUNDARY}--"
return query, HEADER
end
######################
credentials = File.read("c:\\Users\\Tekkub\\.wowicreds.txt")
username, password = $1, $2 if credentials =~ /\A(.+)\n(.+)\Z/
unless username && password
puts "Could not find username and password"
exit 1
end
addon_name, new_version, zip_file, changelog_file, description_file, wrath_compat = $*
unless addon_name && new_version && zip_file && changelog_file && description_file
puts "Usage: addon_name, new_version, zip_file, changelog_file, description_file"
exit 1
end
changelog = File.read(changelog_file)
description = File.read(description_file)
def urlencode(str)
str.gsub(/[^a-zA-Z0-9_\.\-]/n) {|s| sprintf('%%%02x', s[0]) }
end
url = URI.parse("http://www.wowinterface.com/forums/login.php")
Net::HTTP.start("www.wowinterface.com") do |http|
puts "Logging in as #{username}"
params = {
"vb_login_username" => username,
"vb_login_password" => password,
"cb_cookieuser_navbar" => "1",
"forceredirect" => "1",
"do" => "login"
}
req = Net::HTTP::Post.new("/forums/login.php")
req.body = params.map {|k,v| "#{urlencode(k.to_s)}=#{urlencode(v.to_s)}" }.join('&')
req.content_type = 'application/x-www-form-urlencoded'
res = http.request req
if res.body =~ /You have used up your failed login quota/
puts res.body
puts "Your account has been locked out for 15 minutes due to an invalid password"
exit 1
elsif res.body =~ /You have entered an invalid username or password/
puts "Invalid username or password"
exit 1
elsif res.body =~ /Thank you for logging in/
puts "Login successful"
session = $1 if res.body =~ /s=([a-z0-9]+)"/
else
puts res.body
puts "Unknown login error"
exit 1
end
unless session
puts "Cannot create edit session"
exit 1
end
password = Digest::MD5.hexdigest(password)
res = http.get("/downloads/editfile_xml.php?do=listfiles&l=#{username}&p=#{password}")
xml_in = XmlSimple.xml_in(res.body)
addon_id = xml_in["id"][xml_in["title"].index(addon_name)]
unless addon_id
puts "Error finding WoWI addon ID"
exit 1
end
file = File.open(zip_file, "rb")
params = {
"op" => "editfile",
"type" => "0",
"mode" => "0",
"wgp" => "1",
"allowpa" => "1",
"fileaction" => "replace",
"sbutton" => "Update",
"ftitle" => addon_name,
"id" => addon_id,
"s" => session,
"version" => new_version,
"message" => description,
"changelog" => changelog,
"replacementfile" => file,
"wgp" => (wrath_compat == "--wrath" ? "1" : "0"),
}
query, headers = prepare_query(params)
file.close
res = http.post("/downloads/editfile.php", query, headers)
if res.body =~ /The file has been updated/
puts "Upload successful"
else
puts res.body
puts "Error uploading file"
end
end