checkLogin.rb 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env ruby
  2. require 'base64'
  3. require 'json'
  4. require 'mysql2'
  5. require 'json'
  6. require 'pathname'
  7. require Pathname.new(File.dirname(__FILE__)).realpath.to_s + '/Mysql'
  8. session = nil
  9. jsonData = {
  10. "status" => 0,
  11. "msg" => "处理失败"
  12. }
  13. username = ENV["FASTLANE_USER"]
  14. begin
  15. spaceauth_output = `exec fastlane spaceauth`
  16. fastlane_session_regex = %r{Pass the following via the FASTLANE_SESSION environment variable:\n(?<session>.+)\n\n\nExample:\n.+}
  17. if match = spaceauth_output.match(fastlane_session_regex)
  18. session = match[:session].gsub("\e[4m\e[36m", "").gsub("\e[0m\e[0m", "")
  19. end
  20. if !session.nil?
  21. jsonData = {
  22. "status" => 1,
  23. "msg" => "处理成功",
  24. "username" => username,
  25. "session" => Base64.encode64(session)
  26. }
  27. client = Mysql.instance.getClient();
  28. client.query("update prefix_super_cert set fastlane_session = '#{session}' where username = '#{username}'")
  29. Mysql.instance.close()
  30. end
  31. rescue Exception => e
  32. if e.message.include?("=>")
  33. response = JSON.parse e.message.gsub('=>', ':')
  34. jsonData = {
  35. "status" => 0,
  36. "msg" => "处理失败",
  37. "response" => response
  38. }
  39. else
  40. jsonData = {
  41. "status" => 0,
  42. "msg" => e.message
  43. }
  44. end
  45. ensure
  46. puts JSON[jsonData]
  47. end