Module: KDE
- Defined in:
- lib/wiki_lyrics/utils/kde.rb
Constant Summary collapse
- @@proxy_settings_file =
"#{ENV["HOME"]}/.kde/share/config/kioslaverc"
- @@cfg_type_regexp =
/^ *ProxyType *= *([0-4]+) *$/
- @@excluded_regexp =
/^ *NoProxyFor *= *([^ ]+) *$/
- @@reverse_regexp =
/^ *ReversedException *= *([^ ]+) *$/
- @@protocol_regexp =
/^ *([^: ]+):\/+/
Class Method Summary collapse
-
.get_proxy_settings(protocol = "http") ⇒ Object
returns proxy_url, excluded_urls, reverse.
Class Method Details
.get_proxy_settings(protocol = "http") ⇒ Object
returns proxy_url, excluded_urls, reverse
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/wiki_lyrics/utils/kde.rb', line 31 def KDE.get_proxy_settings( protocol="http" ) protocol = protocol.downcase() raise ArgumentError( "Invalid protocol specified" ) if ! ["http", "https", "ftp"].include?( protocol ) proxy_regexp = /^ *#{protocol}Proxy *= *([^ ]+) *$/ cfg_type = proxy_url = excluded_urls = reverse = "" begin File.open( @@proxy_settings_file ).each() do |row| row.chomp!() md = @@cfg_type_regexp.match( row ) cfg_type = md[1] if md md = proxy_regexp.match( row ) proxy_url = md[1] if md md = @@excluded_regexp.match( row ) excluded_urls = md[1] if md md = @@reverse_regexp.match( row ) reverse = md[1] if md end rescue Exception => e puts "Error reading KDE proxy settings file: " + e.to_s() return nil, [], false end # cfg_type == 0: connect directly to the internet # cfg_type == 1: manual configuration # cfg_type == 2: use proxy configuration url (can't do anything with this one) # cfg_type == 3: detect automatically (can't do anything with this one either) # cfg_type == 4: same as manual configuration but values are read from enviroment variables if cfg_type != "1" && cfg_type != "4" return nil, [], false elsif cfg_type == "4" proxy_url = ENV[proxy].to_s().strip() excluded_urls = ENV[excluded_urls].to_s().strip() end return nil, [], false if proxy_url == "" # verify proxy_url proxy_url = HTTP.normalize_url( proxy_url, "http" ) return nil, [], false if proxy_url == nil # parse excluded_urls list excluded_urls_list = [] excluded_urls.split( "," ).each() do |url| url = HTTP.normalize_url( url, "http" ) excluded_urls_list.insert( -1, url ) if url && !excluded_urls_list.include?( url ) end reverse = reverse.strip().downcase() == "true" return proxy_url, excluded_urls_list, reverse end |