Hash :
ab362bb4
Author :
Thomas de Grivel
Date :
2022-01-30T12:15:41
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
#!/usr/bin/env ruby
require 'capybara'
require 'io/console'
require 'optparse'
Options = Struct.new(:cmd, :user)
def usage()
puts """Usage :
$ kmxgit (-h | --help)
Display this help message and exit.
$ kmxgit [OPTIONS] (-m | --mirror)
Mirror website
Available options :
-u USER | --user=USER Login as USER.
"""
end
def main(argv)
@options = Options.new(nil, nil)
OptionParser.new do |opts|
opts.on("-h", "--help") do
@options.cmd = :help
end
opts.on("-m", "--mirror") do
@options.cmd = :mirror
end
opts.on("-uUSER", "--user=USER") do |user|
@options.user = user
end
end.parse!
case @options.cmd
when :help
usage()
return 0
when :mirror
@session = Capybara::Session.new(:selenium)
if @options.user
login()
end
return mirror()
else
usage()
return 1
end
end
def login()
@session.visit("https://git.kmx.io/_log_in")
while @session.has_selector?('form #user_password')
password = IO::console.getpass("Password: ")
@session.fill_in 'Login', with: @options.user
@session.fill_in 'Password', with: password
@session.click_button 'Submit'
end
while @session.has_selector?('form #user_totp')
totp = IO::console.getpass("TOTP: ")
@session.fill_in 'TOTP', with: totp
@session.click_button 'Submit'
end
if @session.current_path == "/_log_in"
raise "Failed to login"
end
end
def mirror
1
end
main ARGV