@@ -91,75 +91,6 @@ def create_user(sid, email, password)
9191 return user, sid
9292end
9393
94- def generate_captcha (key )
95- second = Random ::Secure .rand(12 )
96- second_angle = second * 30
97- second = second * 5
98-
99- minute = Random ::Secure .rand(12 )
100- minute_angle = minute * 30
101- minute = minute * 5
102-
103- hour = Random ::Secure .rand(12 )
104- hour_angle = hour * 30 + minute_angle.to_f / 12
105- if hour == 0
106- hour = 12
107- end
108-
109- clock_svg = <<-END_SVG
110- <svg viewBox="0 0 100 100" width="200px" height="200px">
111- <circle cx="50" cy="50" r="45" fill="#eee" stroke="black" stroke-width="2"></circle>
112-
113- <text x="69" y="20.091" text-anchor="middle" fill="black" font-family="Arial" font-size="10px"> 1</text>
114- <text x="82.909" y="34" text-anchor="middle" fill="black" font-family="Arial" font-size="10px"> 2</text>
115- <text x="88" y="53" text-anchor="middle" fill="black" font-family="Arial" font-size="10px"> 3</text>
116- <text x="82.909" y="72" text-anchor="middle" fill="black" font-family="Arial" font-size="10px"> 4</text>
117- <text x="69" y="85.909" text-anchor="middle" fill="black" font-family="Arial" font-size="10px"> 5</text>
118- <text x="50" y="91" text-anchor="middle" fill="black" font-family="Arial" font-size="10px"> 6</text>
119- <text x="31" y="85.909" text-anchor="middle" fill="black" font-family="Arial" font-size="10px"> 7</text>
120- <text x="17.091" y="72" text-anchor="middle" fill="black" font-family="Arial" font-size="10px"> 8</text>
121- <text x="12" y="53" text-anchor="middle" fill="black" font-family="Arial" font-size="10px"> 9</text>
122- <text x="17.091" y="34" text-anchor="middle" fill="black" font-family="Arial" font-size="10px">10</text>
123- <text x="31" y="20.091" text-anchor="middle" fill="black" font-family="Arial" font-size="10px">11</text>
124- <text x="50" y="15" text-anchor="middle" fill="black" font-family="Arial" font-size="10px">12</text>
125-
126- <circle cx="50" cy="50" r="3" fill="black"></circle>
127- <line id="second" transform="rotate(#{ second_angle } , 50, 50)" x1="50" y1="50" x2="50" y2="12" fill="black" stroke="black" stroke-width="1"></line>
128- <line id="minute" transform="rotate(#{ minute_angle } , 50, 50)" x1="50" y1="50" x2="50" y2="16" fill="black" stroke="black" stroke-width="2"></line>
129- <line id="hour" transform="rotate(#{ hour_angle } , 50, 50)" x1="50" y1="50" x2="50" y2="24" fill="black" stroke="black" stroke-width="2"></line>
130- </svg>
131- END_SVG
132-
133- image = " data:image/png;base64,"
134- image += Process .run(%( rsvg-convert -w 400 -h 400 -b none -f png) , shell: true ,
135- input: IO ::Memory .new(clock_svg), output: Process ::Redirect ::Pipe
136- ) do |proc |
137- Base64 .strict_encode(proc.output.gets_to_end)
138- end
139-
140- answer = " #{ hour } :#{ minute.to_s.rjust(2 , '0' ) } :#{ second.to_s.rjust(2 , '0' ) } "
141- answer = OpenSSL ::HMAC .hexdigest(:sha256 , key, answer)
142-
143- return {
144- question: image,
145- tokens: {generate_response(answer, {" :login" }, key, use_nonce: true )},
146- }
147- end
148-
149- def generate_text_captcha (key )
150- response = make_client(TEXTCAPTCHA_URL , & .get(" /github.com/iv.org/invidious.json" ).body)
151- response = JSON .parse(response)
152-
153- tokens = response[" a" ].as_a.map do |answer |
154- generate_response(answer.as_s, {" :login" }, key, use_nonce: true )
155- end
156-
157- return {
158- question: response[" q" ].as_s,
159- tokens: tokens,
160- }
161- end
162-
16394def subscribe_ajax (channel_id, action, env_headers)
16495 headers = HTTP ::Headers .new
16596 headers[" Cookie" ] = env_headers[" Cookie" ]
0 commit comments