vagrant-ie 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e6ea7d5ca11402c041e4651ed95737518b55a7f9
4
+ data.tar.gz: 6cd734ae25444630942b7c8a52f7a378df00d9c0
5
+ SHA512:
6
+ metadata.gz: 59f691ce2397d23876ae07ec60fbec7d1818fd6c4f9824af9970bbde54c7e6fe5104e128a8e64b807491fd3cd0f2c476cf01008458ae1b3f228a89af6dc785dd
7
+ data.tar.gz: 87c715866eec28783b91e56888e4978c9793a1315052c443624122049c947b9a3eecbea7ea6ffdb8c6e9abdfc64f1f3c6c8a3a1098a42dc3b68fad7ddecd5736
@@ -0,0 +1,49 @@
1
+ param ([string]$upstreamHost)
2
+
3
+ Set-StrictMode -Version Latest
4
+
5
+ Import-Module "C:\Users\IEUser\vagrant-ie\HostsModule.psm1" -DisableNameChecking
6
+ Import-Module "C:\Users\IEUser\vagrant-ie\TaskModule.psm1" -DisableNameChecking
7
+
8
+ function Exec {
9
+ [CmdletBinding()]
10
+
11
+ param (
12
+ [Parameter(Position=0, Mandatory=1)]
13
+ [scriptblock]$Command,
14
+ [Parameter(Position=1, Mandatory=0)]
15
+ [string]$ErrorMessage = "Execution of command failed.`n$Command"
16
+ )
17
+
18
+ & $Command
19
+
20
+ if ($LastExitCode -ne 0) {
21
+ throw "Exec: $ErrorMessage"
22
+ }
23
+ }
24
+
25
+ Exec {
26
+ Write-Output "Disabling firewall..."
27
+ NetSh Advfirewall set allprofiles state off
28
+ }
29
+
30
+ Exec {
31
+ Write-Output "Setting network category to PRIVATE..."
32
+ C:\Users\IEUser\vagrant-ie\NLMtool_staticlib.exe -setcategory private | out-null
33
+ }
34
+
35
+ Exec {
36
+ Write-Output "Turning off User Account Control..."
37
+ cmd /C "reg add HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /d 0 /t REG_DWORD /f /reg:64" | out-null
38
+ }
39
+
40
+ Write-Output "Turning off Automatic Updates..."
41
+ C:\Users\IEUser\vagrant-ie\DisableAutomaticUpdates.ps1 | out-null
42
+
43
+ Write-Output "Setting up host entry for host $upstreamHost"
44
+ Add-Host $upstreamHost 'upstream'
45
+
46
+ Write-Output "Setting up the IE task..."
47
+ Upsert-Task 'IE' 'C:\Users\IEUser\vagrant-ie\IE.task.xml'
48
+
49
+ Write-Output "Ok."
@@ -0,0 +1,7 @@
1
+ sc stop wuauserv
2
+
3
+ reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" /v AUOptions /t REG_DWORD /d 1 /f
4
+
5
+ New-Item HKLM:\SOFTWARE\Policies\Microsoft\Windows -Name WindowsUpdate -Force
6
+ New-Item HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate -Name AU -Force
7
+ New-ItemProperty HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU -Name NoAutoUpdate -Value 1 -Force
@@ -0,0 +1,51 @@
1
+ #
2
+ # Powershell script for adding/removing/showing entries to the hosts file.
3
+ #
4
+ # Known limitations:
5
+ # - does not handle entries with comments afterwards ("<ip> <host> # comment")
6
+ #
7
+ # Source: https://gist.github.com/markembling/173887
8
+
9
+ $filename = "$env:windir\System32\drivers\etc\hosts"
10
+
11
+ function Add-Host([string]$ip, [string]$hostname) {
12
+ Remove-Host $filename $hostname
13
+ $ip + "`t`t" + $hostname | Out-File -encoding ASCII -append $filename
14
+ }
15
+
16
+ function Remove-Host([string]$hostname) {
17
+ $c = Get-Content $filename
18
+ $newLines = @()
19
+
20
+ foreach ($line in $c) {
21
+ $bits = [regex]::Split($line, "\t+")
22
+ if ($bits.count -eq 2) {
23
+ if ($bits[1] -ne $hostname) {
24
+ $newLines += $line
25
+ }
26
+ } else {
27
+ $newLines += $line
28
+ }
29
+ }
30
+
31
+ # Write file
32
+ Clear-Content $filename
33
+ foreach ($line in $newLines) {
34
+ $line | Out-File -encoding ASCII -append $filename
35
+ }
36
+ }
37
+
38
+ function Print-Hosts() {
39
+ $c = Get-Content $filename
40
+
41
+ foreach ($line in $c) {
42
+ $bits = [regex]::Split($line, "\t+")
43
+ if ($bits.count -eq 2) {
44
+ Write-Host $bits[0] `t`t $bits[1]
45
+ }
46
+ }
47
+ }
48
+
49
+ Export-ModuleMember -Function 'Add-Host'
50
+ Export-ModuleMember -Function 'Remove-Host'
51
+ Export-ModuleMember -Function 'Print-Hosts'
@@ -0,0 +1,42 @@
1
+ <?xml version="1.0" encoding="UTF-16"?>
2
+ <Task version="1.3" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
3
+ <RegistrationInfo>
4
+ <Date>2017-05-05T12:39:09.3130223</Date>
5
+ <Author>IE11WIN7\IEUser</Author>
6
+ </RegistrationInfo>
7
+ <Triggers />
8
+ <Principals>
9
+ <Principal id="Author">
10
+ <RunLevel>LeastPrivilege</RunLevel>
11
+ <UserId>IE11WIN7\IEUser</UserId>
12
+ <LogonType>InteractiveToken</LogonType>
13
+ </Principal>
14
+ </Principals>
15
+ <Settings>
16
+ <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
17
+ <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
18
+ <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
19
+ <AllowHardTerminate>true</AllowHardTerminate>
20
+ <StartWhenAvailable>false</StartWhenAvailable>
21
+ <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
22
+ <IdleSettings>
23
+ <StopOnIdleEnd>true</StopOnIdleEnd>
24
+ <RestartOnIdle>false</RestartOnIdle>
25
+ </IdleSettings>
26
+ <AllowStartOnDemand>true</AllowStartOnDemand>
27
+ <Enabled>true</Enabled>
28
+ <Hidden>false</Hidden>
29
+ <RunOnlyIfIdle>false</RunOnlyIfIdle>
30
+ <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
31
+ <UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine>
32
+ <WakeToRun>false</WakeToRun>
33
+ <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
34
+ <Priority>7</Priority>
35
+ </Settings>
36
+ <Actions Context="Author">
37
+ <Exec>
38
+ <Command>powershell</Command>
39
+ <Arguments>-File "C:\Users\IEUser\vagrant-ie\.task.ps1"</Arguments>
40
+ </Exec>
41
+ </Actions>
42
+ </Task>
@@ -0,0 +1,5 @@
1
+ Import-Module "C:\Users\IEUser\vagrant-ie\TaskModule.psm1" -DisableNameChecking
2
+
3
+ echo "& `"C:\Program Files\Internet Explorer\iexplore.exe`" $args" > "C:\Users\IEUser\vagrant-ie\.task.ps1"
4
+
5
+ Start-Task "IE"
@@ -0,0 +1,30 @@
1
+ function Upsert-Task([string]$taskName, [string]$template) {
2
+ Remove-Task $taskName
3
+ Add-Task $taskName $template
4
+ }
5
+
6
+ function Add-Task([string]$taskName, [string]$template) {
7
+ schtasks.exe /Create /XML $template /TN $taskName
8
+ }
9
+
10
+ function Remove-Task([string]$taskName) {
11
+ if (Task-Exists $taskName) {
12
+ schtasks.exe /End /TN $taskName | out-null
13
+ schtasks.exe /Delete /F /TN $taskName
14
+ }
15
+ }
16
+
17
+ function Start-Task([string]$taskName) {
18
+ schtasks.exe /Run /TN $taskName
19
+ }
20
+
21
+ function Task-Exists([string]$taskName) {
22
+ schtasks.exe /Query /TN $taskName 2>&1 | out-null
23
+
24
+ return $LastExitCode -eq 0
25
+ }
26
+
27
+ Export-ModuleMember -Function 'Upsert-Task'
28
+ Export-ModuleMember -Function 'Add-Task'
29
+ Export-ModuleMember -Function 'Remove-Task'
30
+ Export-ModuleMember -Function 'Start-Task'
data/lib/vagrant-ie.rb ADDED
@@ -0,0 +1,39 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ ##
5
+ # If you copy this file, dont't delete this comment.
6
+ # This Vagrantfile was created by Daniel Menezes:
7
+ # https://github.com/danielmenezesbr/modernie-winrm
8
+ # E-mail: danielmenezes at gmail dot com
9
+ #
10
+ # Source: https://github.com/danielmenezesbr/modernie-winrm
11
+ ##
12
+
13
+ module VagrantIE
14
+ def self.assets
15
+ File.join(File.expand_path(File.dirname(__FILE__)), '..', 'assets', 'vagrant-ie')
16
+ end
17
+
18
+ class Plugin < Vagrant.plugin(2)
19
+ name "vagrant-ie"
20
+
21
+ config('vagrant-ie', :provisioner) do
22
+ require_relative './vagrant-ie/config'
23
+
24
+ VagrantIE::Config
25
+ end
26
+
27
+ command 'run-ie' do
28
+ require_relative './vagrant-ie/run_ie_command'
29
+
30
+ VagrantIE::RunIECommand
31
+ end
32
+
33
+ provisioner 'vagrant-ie' do
34
+ require_relative './vagrant-ie/provisioner'
35
+
36
+ VagrantIE::Provisioner
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantIE
2
+ class Config < Vagrant.plugin("2", :config)
3
+ attr_accessor :public_ip_addr
4
+ end
5
+ end
@@ -0,0 +1,68 @@
1
+ require 'net/ssh'
2
+
3
+ module VagrantIE
4
+ class PowerShell
5
+ def self.open(&block)
6
+ shell = new
7
+ shell.connect
8
+
9
+ begin
10
+ yield shell
11
+ ensure
12
+ shell.disconnect
13
+ end
14
+ end
15
+
16
+ def connect
17
+ @ssh = Net::SSH.start("localhost", "IEUser", :password => "Passw0rd!", :port => 2222)
18
+ end
19
+
20
+ def invoke_file(file:, args: [])
21
+ ssh_exec! <<-SHELL
22
+ PowerShell
23
+ -InputFormat none
24
+ -Sta
25
+ -NonInteractive
26
+ -File "#{file}"
27
+ #{args.join("\n")}
28
+ SHELL
29
+ end
30
+
31
+ def disconnect
32
+ @ssh.close
33
+ @ssh = nil
34
+ end
35
+
36
+ private
37
+
38
+ def strip(string)
39
+ string.gsub(/\n/, ' ').gsub(/[ ]+/, ' ').strip
40
+ end
41
+
42
+ def ssh_exec!(command)
43
+ exit_code = nil
44
+
45
+ @ssh.open_channel do |channel|
46
+ channel.exec(strip(command)) do |ch, success|
47
+ return false unless success
48
+
49
+ channel.on_data do |ch,data|
50
+ STDOUT.puts data
51
+ end
52
+
53
+ channel.on_extended_data do |ch,type,data|
54
+ STDERR.puts data
55
+ end
56
+
57
+ channel.on_request("exit-status") do |ch,data|
58
+ exit_code = data.read_long
59
+ end
60
+ end
61
+ end
62
+
63
+ @ssh.loop
64
+
65
+ exit_code == 0
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,24 @@
1
+ require 'socket'
2
+ require_relative './power_shell'
3
+
4
+ module VagrantIE
5
+ class Provisioner < Vagrant.plugin(2, :provisioner)
6
+ def configure(_)
7
+ @config.public_ip_addr ||= Socket.ip_address_list
8
+ .reject(&:unix?)
9
+ .reject(&:ipv4_loopback?)
10
+ .reject(&:ipv6_loopback?)
11
+ .first
12
+ .ip_address
13
+ end
14
+
15
+ def provision
16
+ PowerShell.open do |shell|
17
+ shell.invoke_file({
18
+ file: 'C:\Users\IEUser\vagrant-ie\Configure.ps1',
19
+ args: [ @config.public_ip_addr ]
20
+ })
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,66 @@
1
+ require_relative './power_shell'
2
+
3
+ module VagrantIE
4
+ class RunIECommand < Vagrant.plugin(2, :command)
5
+ def execute
6
+ options = {
7
+ 'kiosk' => true
8
+ }
9
+
10
+ opts = OptionParser.new do |o|
11
+ o.banner = "Usage: vagrant run-ie [options] URL"
12
+
13
+ o.on('--embedding') { |v| options['embedding'] = v }
14
+ o.on('--extoff') { |v| options['extoff'] = v }
15
+ o.on('--[no-]frame-merging') { |v| options['frame-merging'] = v }
16
+ o.on('--[no-]session-merging') { |v| options['session-merging'] = v }
17
+ o.on('--no-hang-recovery') { |v| options['hang-recovery'] = v }
18
+ o.on('--private') { |v| options['private'] = v }
19
+ o.on('-k', '--[no-]kiosk') { |v| options['kiosk'] = v }
20
+ end
21
+
22
+ argv = parse_options(opts)
23
+
24
+ return unless argv
25
+
26
+ PowerShell.open do |shell|
27
+ shell.invoke_file({
28
+ file: 'C:\Users\IEUser\vagrant-ie\RunIE.ps1',
29
+ args: map_arguments(options).concat([
30
+ argv[0]
31
+ ])
32
+ })
33
+ end
34
+ end
35
+
36
+ protected
37
+
38
+ def map_arguments(options)
39
+ args = []
40
+
41
+ %w[ embedding extoff private ].each do |literal|
42
+ if options[literal] == true
43
+ args << "-#{literal}"
44
+ end
45
+ end
46
+
47
+ if options['kiosk']
48
+ args << '-k'
49
+ end
50
+
51
+ if options['session-merging'] == true
52
+ args << '-sessionmerging'
53
+ else
54
+ args << '-nosessionmerging'
55
+ end
56
+
57
+ if options['frame-merging'] == true
58
+ args << '-framemerging'
59
+ else
60
+ args << '-noframemerging'
61
+ end
62
+
63
+ args
64
+ end
65
+ end
66
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-ie
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ahmad Amireh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-06 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |
14
+ vagrant-ie is a plugin for vagrant that automates provisioning a Windows 7
15
+ box for IE testing. The plugin works in both headless and GUI provider modes.
16
+ email:
17
+ - ahmad@amireh.net
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - assets/vagrant-ie/Configure.ps1
23
+ - assets/vagrant-ie/DisableAutomaticUpdates.ps1
24
+ - assets/vagrant-ie/HostsModule.psm1
25
+ - assets/vagrant-ie/IE.task.xml
26
+ - assets/vagrant-ie/NLMtool_staticlib.exe
27
+ - assets/vagrant-ie/RunIE.ps1
28
+ - assets/vagrant-ie/TaskModule.psm1
29
+ - lib/vagrant-ie.rb
30
+ - lib/vagrant-ie/config.rb
31
+ - lib/vagrant-ie/power_shell.rb
32
+ - lib/vagrant-ie/provisioner.rb
33
+ - lib/vagrant-ie/run_ie_command.rb
34
+ homepage: https://github.com/amireh/vagrant-ie
35
+ licenses:
36
+ - BSD-3
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 2.4.5.1
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Vagrant plugin for IE automation.
58
+ test_files: []
59
+ has_rdoc: