require "lwqzx/version" require 'nokogiri' module Lwqzx def self.auth(login,passwd) lurl = "http://www.lwqzx.sdedu.net/kernel/net_school/active_app/login1.php" user = "login_user_m_=#{login}" psd = "login_password=#{passwd}" res = %x[curl #{lurl} -s -c /tmp/cookies -d #{user} -d #{psd} ] aurl = "http://www.lwqzx.sdedu.net/kernel/net_school/islogin.php" ares = %x[curl -s -b /tmp/cookies #{aurl}] return {} if ares.to_s == "0" infos = %x[curl -s -b /tmp/cookies #{lurl}] content=infos.encode("UTF-8","GB2312") doc = Nokogiri::HTML(content) user = doc.at("span.web1") %x[rm /tmp/cookies] uinfos = user.text.gsub!(/\n+|\r+/, "").strip!.split(" ") uname = uinfos[1].split(":")[1] groups= uinfos[3].split(":")[1].gsub("[","").gsub("]","").split("@").compact.reject(&:empty?) return {login: login, name: uname, groups: groups} end end