Class: CommentMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/models/common_method.rb

Class Method Summary collapse

Class Method Details

.ar_month(month) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/models/common_method.rb', line 141

def self.ar_month(month)
  {
    "يناير"=> "January",
    "فبراير"=>  "February",
    "مارس"=>  "March",
    "أبريل"=> "April",
    "مايو"=>  "May",
    "يونيو"=> "June",
    "يوليو"=> "July",
    "أغسطس"=> "August",
    "سبتمبر"=>  "September",
    "أكتوبر"=>  "October",
    "نوفمبر"=>  "November",
    "ديسمبر"=>  "December"
  }[month]
end

.ar_month2(month) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/models/common_method.rb', line 158

def self.ar_month2(month)
  {
    "جانفي"=> "January",
    "فيفري"=> "February",
    "مارس"=>  "March",
    "أفريل"=> "April",
    "ماي"=> "May",
    "جوان"=>  "June",
    "جويلية"=>  "July",
    "أوت"=> "August",
    "سبتمبر"=>  "September",
    "أكتوبر"=>  "October",
    "نوفمبر"=>  "November",
    "ديسمبر"=>  "December"
  }[month]
end

.chk_jschl(params) ⇒ Object

页面503 需要验证时 获取cookie



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
# File 'lib/models/common_method.rb', line 4

def self.chk_jschl(params)
  cxt = V8::Context.new
  url = params[:url]
  sub_site_url = params[:sub_site_url]
  header = params[:header]

  conn = Faraday.new(:url => url)
  res = conn.get do |req|
    req.url url
    req.headers = header
  end
  cookie = res.headers["set-cookie"].split(";")[0]
  doc = Hpricot(res.body)
  k_pre = doc.to_s.match(/k = \'(.*?)\';/)[1] rescue nil
  k_int= doc.to_s.match(/;k\+=(.*?);/)[1] rescue nil
  k_int = cxt.eval(k_int).to_s
  p = doc.search("##{k_pre+k_int}").inner_html rescue nil
  line1 = doc.to_s.match(/var s,t,o,p.*?,f(.+?);/).to_s
  line2 = doc.to_s.match(/;(.+?); '; 121'/)[1].to_s.gsub("t.length", sub_site_url.size.to_s).gsub("a.value = ", "") rescue ""
  # line2 = doc.to_s.match(/;(.+?); '; 121'/)[1].to_s
  line3 = line2.gsub(/function\(p\)\{var .*?return \+\(p\)}\(\)/,"+(#{p})")
  line4 = line3.gsub(/function\(p\).*?\)\);/,"'#{sub_site_url}'.charCodeAt(1)));")
  jschl_answer = cxt.eval(line1+line4).to_s

  r = doc.search("input[@name=r]")[0][:value]
  jschl_vc = doc.search("input[@name=jschl_vc]")[0][:value]
  pass = doc.search("input[@name=pass]")[0][:value]

  # form_params = doc.search("form#challenge-form input").map{|x| [x["name"],x["value"]]}.to_h
  # form_params["jschl_answer"] = jschl_answer if jschl_answer.present?
  # query = URI.encode_www_form(form_params)

  query = URI.encode_www_form([['r', r], ['jschl_vc', jschl_vc], ['pass', pass], ['jschl_answer', jschl_answer],['cf_ch_verify','plat']])


  link = doc.search("form#challenge-form")[0]["action"]
  sleep 4
  res1 =  conn.post do |req|
    req.url link
    req.headers = header
    req.headers["cookie"]= cookie
    req.body = query
  end
  res1.headers["set-cookie"]

  if res1.headers["set-cookie"].nil?
    return nil
  else
    cf_clearance = res1.headers["set-cookie"].split(";")[0].split("=")[1]
    cookie += "; cf_clearance=#{cf_clearance}"
    return cookie
  end
end

.es_month(month) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/models/common_method.rb', line 90

def self.es_month(month)
  {
    "enero"=> "January",
    "febrero"=> "February",
    "marzo"=> "March",
    "abril"=> "April",
    "mayo"=>  "May",
    "junio"=> "June",
    "julio"=> "July",
    "agosto"=>  "August",
    "septiembre"=>  "September",
    "octubre"=> "October",
    "noviembre"=> "November",
    "diciembre"=> "December"
  }[month]
end

.es_simple_month(month) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/models/common_method.rb', line 124

def self.es_simple_month(month)
  {
    "ene"=> "January",
    "feb"=> "February",
    "mar"=> "March",
    "abr"=> "April",
    "may"=> "May",
    "jun"=> "June",
    "jul"=> "July",
    "ago"=> "August",
    "sep"=> "September",
    "oct"=> "October",
    "nov"=> "November",
    "dic"=> "December"
  }[month]
end

.french_month(month) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/models/common_method.rb', line 72

def self.french_month(month)
  {
    "janvier" => "January",
    "février" => "February",
    "mars" => "March",
    "avril" => "April",
    "mai" => "May",
    "juin" => "June",
    "juillet" => "July",
    "août" => "August",
    "aout" => "August",
    "septembre" => "September",
    "octobre" => "October",
    "novembre" => "November",
    "décembre" => "December",
  }[month]
end

.get_email(encode_email) ⇒ Object



59
60
61
62
63
64
# File 'lib/models/common_method.rb', line 59

def self.get_email(encode_email)
  cxt = V8::Context.new
  js_str = "function r(e, t) {\n\tvar r = e.substr(t, 2);\n\treturn parseInt(r, 16)\n}\n\nfunction n(n, c) {\n\t\tfor (var o = \"\", a = r(n, c), i = c + 2; i < n.length; i += 2) {\n\t\t\tvar l = r(n, i) ^ a;\n\t\t\to += String.fromCharCode(l)\n\t\t}\n\t\ttry {\n\t\t\to = decodeURIComponent(escape(o))\n\t\t} catch (u) {\n\t\t\te(u)\n\t\t}\n\t\treturn o\n}\n\n\nn(\"#{encode_email}\",28)"
  email = cxt.eval(js_str) rescue nil
  return email
end

.get_token(ts) ⇒ Object



66
67
68
69
70
# File 'lib/models/common_method.rb', line 66

def self.get_token(ts)
  secret = "henttlxnn"
  key = "getsetredis"
  Digest::MD5.hexdigest("#{key}#{secret}#{ts}")
end

.id_month(month) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/models/common_method.rb', line 180

def self.id_month(month)
  {
    "Januari" => "January",
    "Februari" => "February",
    "Maret" => "March",
    "April" => "April",
    "Mei" => "May",
    "Juni" => "June",
    "Juli" => "July",
    "Agustus" => "August",
    "September" => "September",
    "Oktober" => "October",
    "November" => "November",
    "Desember" => "December",
  }[month]
end

.it_month(month) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/models/common_method.rb', line 107

def self.it_month(month)
  {
    "gennaio"=> "January",
    "febbraio"=>  "February",
    "marzo"=> "March",
    "aprile"=>  "April",
    "maggio"=>  "May",
    "giugno"=>  "June",
    "luglio"=>  "July",
    "agosto"=>  "August",
    "settembre"=> "September",
    "ottobre"=> "October",
    "novembre"=>  "November",
    "dicembre"=>  "December"
  }[month]
end

.ru_month(month) ⇒ Object



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/models/common_method.rb', line 202

def self.ru_month(month)
  months = {
    'января'=> 'January',
    'февраля'=> 'February',
    'марта'=> 'March',
    'апреля'=> 'April',
    'мая'=> 'May',
    'июня'=> 'June',
    'июля'=> 'July',
    'августа'=> 'August',
    'сентября'=> 'September',
    'октября'=> 'October',
    'ноября'=> 'November',
    'декабря'=> 'December'
  }[month]
end

.th_month(month) ⇒ Object



176
177
178
# File 'lib/models/common_method.rb', line 176

def self.th_month(month)
  {"มกราคม"=>"01", "กุมภาพันธ์"=>"02", "มีนาคม"=>"03", "เมษายน"=>"04", "พฤษภาคม"=>"05", "มิถุนายน"=>"06", "กรกฎาคม"=>"7", "สิงหาคม"=>"08", "กันยายน"=>"09", "ตุลาคม"=>"10", "พฤศจิกายน"=>"11", "ธันวาคม"=>"12"}[month]
end

.th_year(year) ⇒ Object



197
198
199
200
# File 'lib/models/common_method.rb', line 197

def self.th_year(year)
  year = year.to_i - 543
  return year
end