Class: Pincerna::Vpn
Overview
Connects or disconnects from system’s VPNs.
Constant Summary
- MATCHER =
The expression to match.
/^(?<all>.*)$/i
- ICON =
The icon to show for each feedback item.
Pincerna::Base::ROOT + "/images/vpn.png"
Constants inherited from Base
Base::CACHE_ROOT, Base::FULL_NAME, Base::RELEVANT_MATCHES, Base::ROOT, Base::TYPES, Base::WORKFLOW_ROOT
Instance Attribute Summary
Attributes inherited from Base
#format, #format_content_type, #output
Instance Method Summary (collapse)
-
- (Array) perform_filtering(query)
Connects to or disconnects from system VPN.
-
- (Array) process_results(results)
Processes items to obtain feedback items.
-
- (Boolean) vpn_connected?(name)
Checks if a VPN is connected.
Methods inherited from Base
#add_feedback_item, execute!, #filter, #format_float, #initialize, #output_feedback, #round_float
Constructor Details
This class inherits a constructor from Pincerna::Base
Instance Method Details
- (Array) perform_filtering(query)
Connects to or disconnects from system VPN.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pincerna/vpn.rb', line 20 def perform_filtering(query) rv = [] interface_filter ||= query.empty? ? /.+/ : /#{query}/i execute_command("/usr/sbin/networksetup", "-listnetworkserviceorder").split(/\n\n/).each do |i| # Scan every interface token = StringScanner.new(i) if token.scan_until(/^\(\d+\)/) then name = token.scan_until(/\n/).strip # Get VPN name next if !interface_filter.match(name) # Get the type token.scan_until(/Hardware Port:\s/) # If type matches rv << {name: name, connected: vpn_connected?(name)} if is_vpn_service?(token.scan_until(/,/)) end end rv end |
- (Array) process_results(results)
Processes items to obtain feedback items.
47 48 49 50 51 52 53 54 55 |
# File 'lib/pincerna/vpn.rb', line 47 def process_results(results) results.map do |result| title = "#{result[:connected] ? "Disconnect from" : "Connect to"} #{result[:name]}" subtitle = "Action this item to #{result[:connected] ? "disconnect from" : "connect to"} the VPN service." arg = "#{result[:connected] ? "disconnect" : "connect"} service \"#{result[:name]}\"" {title: title, arg: arg, subtitle: subtitle, icon: ICON} end end |
- (Boolean) vpn_connected?(name)
Checks if a VPN is connected.
61 62 63 |
# File 'lib/pincerna/vpn.rb', line 61 def vpn_connected?(name) execute_command("/usr/sbin/networksetup", "-showpppoestatus", "\"#{name}\"").strip == "connected" end |