Method: Rex::Compat.open_webrtc_browser

Defined in:
lib/rex/compat.rb

.open_webrtc_browser(url = 'http://google.com/') ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/rex/compat.rb', line 151

def self.open_webrtc_browser(url='http://google.com/')
  found_browser = false

  case RUBY_PLATFORM
  when /mswin2|mingw|cygwin/
      paths = [
        "Google\\Chrome\\Application\\chrome.exe",
        "Mozilla Firefox\\firefox.exe",
        "Opera\\launcher.exe"
      ]

      prog_files = ENV['ProgramFiles']
      paths = paths.map { |p| "#{prog_files}\\#{p}" }

      # Old chrome path
      app_data = ENV['APPDATA']
      paths << "#{app_data}\\Google\\Chrome\\Application\\chrome.exe"

      paths.each do |path|
        if File.exists?(path)
          args = (path =~ /chrome\.exe/) ? "--allow-file-access-from-files" : ""
          system("#{path} #{args} #{url}")
          found_browser = true
          break
        end
      end

  when /darwin/
    ['Google Chrome.app', 'Firefox.app'].each do |browser|
      browser_path = "/Applications/#{browser}"
      if File.directory?(browser_path)
        args = (browser_path =~ /Chrome/) ? "--args --allow-file-access-from-files" : ""

        system("open #{url} -a \"#{browser_path}\" #{args} &")
        found_browser = true
        break
      end
    end
  else
    if defined? ENV['PATH']
      ['firefox', 'google-chrome', 'chrome', 'chromium', 'firefox', 'opera'].each do |browser|
        ENV['PATH'].split(':').each do |path|
          browser_path = "#{path}/#{browser}"
          if File.exists?(browser_path)
            args = (browser_path =~ /Chrome/) ? "--allow-file-access-from-files" : ""
            system("#{browser_path} #{args} #{url} &")
            found_browser = true
            break
          end
        end
      end
    end
  end

  found_browser
end