Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.package
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Guillaume Hervier
slapos.package
Commits
296bbc27
Commit
296bbc27
authored
Apr 16, 2013
by
Jondy Zhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use ip script to add/remove Openvpn tap driver in the Cygwin.
parent
5f4fa13d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
361 additions
and
179 deletions
+361
-179
windows/scripts/ip
windows/scripts/ip
+361
-179
No files found.
windows/scripts/ip
View file @
296bbc27
...
...
@@ -291,13 +291,20 @@ function prefix_to_netmask()
echo
$result
}
#
# Parameter:
# ifname: interface name or guid name
#
# If ifname is guid name, return the corresponding connection name,
# otherwise return the original ifname.
#
function
format_interface_name
()
{
if
[[
"
$1
"
==
""
]]
;
then
return
1
fi
local
guid
=
$1
local
guid
=
"
$1
"
if
!
[[
"
${
guid
:0:1
}
"
==
"{"
]]
;
then
echo
$1
else
...
...
@@ -306,6 +313,157 @@ function format_interface_name()
fi
}
#
# Parameter:
# ifname: connection name
#
# Add a TAP-WINDOWS driver of Openvpn, then rename the connection name
# as ifname.
#
function
install_tap_driver
()
{
local
FILENAME
=
"/etc/openvpn/driver/OemWin2k.inf"
local
DEVFILE
=
$(
cygpath
-w
$FILENAME
)
local
DEVCON
=
$(
which devcon.exe
)
local
HWID
=
tap0901
local
CHECKSCRIPT
=
$(
cygpath
-m
/etc/openvpn/check_driver_signing_dialog.vbs
)
local
CSCRIPT
=
$(
which cscript
)
local
GETSCRIPT
=
$(
cygpath
-m
/etc/openvpn/get_last_connection.vbs
)
if
[[
!
-f
$FILENAME
]]
;
then
echo
"Error: no TAP-WINDOWS driver inf file found"
return
1
fi
if
[[
!
-x
$DEVCON
]]
;
then
echo
"Error: no devcon.exe found"
return
1
fi
if
[[
!
-x
$CSCRIPT
]]
;
then
echo
"Error: no cscript.exe found"
return
1
fi
if
!
[[
-f
$CHECKSCRIPT
]]
;
then
cat
<<
EOF
>
$CHECKSCRIPT
Set oShell = CreateObject("WScript.Shell")
Do
If oShell.AppActivate("Hardware Installation") Then
WScript.Sleep 1000
oShell.SendKeys "%C"
WScript.Sleep 2000
End If
WScript.Sleep 1000
Loop While True
EOF
fi
# install driver
$CSCRIPT
$CHECKSCRIPT
>
/dev/null &
local
sid
=
$!
$DEVCON
install
$DEVFILE
$HWID
kill
$sid
# rename the connection name
if
[[
!
"
$1
"
==
""
]]
;
then
if
[[
!
-f
$GETSCRIPT
]]
;
then
cat
<<
EOF
>
$GETSCRIPT
strComputer = "."
strPrefix = "Local Area Connection"
Set objWMIService = GetObject("winmgmts:
\\\\
" & strComputer & "
\r
oot
\C
IMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT NetConnectionID FROM Win32_NetworkAdapter WHERE " & _
"NetConnectionID Like '" & strPrefix & "%'", _
"WQL", 48)
strLastConnectionName = ""
i = -1
k = Len(strPrefix)
For Each objItem In colItems
s = Right(objItem.NetConnectionID, Len(objItem.NetConnectionID) - k)
If s = "" Then
j = 0
Else
j = Int(s)
End If
If j > i Then
strLastConnectionName = objItem.NetConnectionID
i = j
End If
Next
WScript.StdOut.Write(strLastConnectionName)
WScript.Quit(0)
EOF
fi
local
OLDNAME
=
$(
$CSCRIPT
//Nologo
$GETSCRIPT
)
if
((
$?
==
0
))
;
then
netsh interface
set
interface
name
=
"
$OLDNAME
"
newname
=
"
$1
"
fi
fi
}
#
# Parameter:
# ifname: connection name
#
# Remove a TAP-WINDOWS driver of Openvpn which connection name equals
# ifname.
#
function
uninstall_tap_driver
()
{
local
DEVCON
=
$(
which devcon.exe
)
local
CSCRIPT
=
$(
which cscript.exe
)
local
GETSCRIPT
=
$(
cygpath
-m
/etc/openvpn/get_pnpid_connection.vbs
)
if
[[
"
$1
"
==
""
]]
;
then
echo
"Error: missing connection name"
return
1
fi
local
IFNAME
=
$1
if
[[
!
-x
$DEVCON
]]
;
then
echo
"Error: no devcon.exe found"
return
1
fi
if
[[
!
-x
$CSCRIPT
]]
;
then
echo
"Error: no cscript.exe found"
return
1
fi
if
[[
!
-f
$GETSCRIPT
]]
;
then
cat
<<
EOF
>
$GETSCRIPT
If WScript.Arguments.Count < 1 Then
WScript.Echo "Error: missing paramter connection name"
WScript.Quit(1)
End If
strComputer = "."
strDriverName = "TAP-Windows Adapter V9"
strConnectionName = WScript.Arguments(0)
Set objWMIService = GetObject("winmgmts:
\\\\
" & strComputer & "
\r
oot
\C
IMV2")
Set colItems = objWMIService.ExecQuery(_
"SELECT PNPDeviceID FROM Win32_NetworkAdapter WHERE Name='" _
& strDriverName & "' AND NetConnectionID='" & strConnectionName & "'", _
"WQL", 48)
strDeviceID = ""
For Each objItem In colItems
strDeviceID = objItem.PNPDeviceID
Next
WScript.StdOut.Write(strDeviceId)
WScript.Quit(0)
EOF
fi
local
PNPDEVICEID
=
$(
$CSCRIPT
//Nologo
"
$GETSCRIPT
"
"
$IFNAME
"
)
if
((
$?
==
0
))
;
then
$DEVCON
remove
=
Net
"@
$PNPDEVICEID
"
return
$?
fi
}
orig_cmd
=
"
$0
$*
"
opt_family
=
opt_statistics
=
0
...
...
@@ -338,12 +496,8 @@ while [[ "$1" != "" ]] && [[ "$object" == "" ]] ; do
-s
|
-stats
|
-statistics
)
let
opt_statistics+
=
1
;;
tuntap
)
echo
$orig_cmd
exit
0
;;
link
|
addr
|
addrlabel
|
route
|
rule
|
neigh
|
tunnel
|
\
maddr
|
mroute
|
monitor
)
maddr
|
mroute
|
monitor
|
tuntap
)
object
=
$1
;;
*
)
echo
Warning: unsupport options
"
$1
"
...
...
@@ -402,7 +556,7 @@ elif [[ $object == "addr" ]] ; then
while
[[
"
$1
"
!=
""
]]
;
do
case
$1
in
dev
)
dev
=
\"
$(
format_interface_name
$2
)
\"
dev
=
$(
format_interface_name
"
$2
"
)
shift
;;
*
)
echo
Warning: unsupport parameter
"
$1
"
...
...
@@ -411,7 +565,7 @@ elif [[ $object == "addr" ]] ; then
shift
done
ipcmd
=
"
$ipcmd
$dev
$address
"
ipcmd
=
"
$ipcmd
\"
$dev
\"
$address
"
elif
[[
$object
==
"addrlabel"
]]
;
then
...
...
@@ -520,7 +674,7 @@ elif [[ $object == "route" ]] ; then
while
[[
"
$1
"
!=
""
]]
;
do
case
$1
in
dev
)
interface
=
\"
$(
format_interface_name
$2
)
\"
interface
=
$(
format_interface_name
"
$2
"
)
shift
;;
proto
)
...
...
@@ -565,8 +719,37 @@ elif [[ $object == "route" ]] ; then
fi
fi
ipcmd
=
"
$ipcmd
$prefix
$interface
$nexthop
"
ipcmd
=
"
$ipcmd
$prefix
\"
$interface
\"
$nexthop
"
elif
[[
$object
==
"tuntap"
]]
;
then
while
[[
"
$1
"
!=
""
]]
;
do
case
$1
in
dev
)
dev
=
$(
format_interface_name
"
$2
"
)
shift
;;
mode
)
mode
=
$2
shift
;;
*
)
echo
Warning: unsupport parameter
"
$1
"
esac
shift
done
if
[[
"
$command
"
==
"add"
]]
;
then
install_tap_driver
"
$dev
"
exit
$?
elif
[[
"
$command
"
==
"del"
]]
;
then
uninstall_tap_driver
"
$dev
"
exit
$?
else
echo
$orig_cmd
echo
"Error: unsupported command
\"
$command
\"
for tuntap"
exit
1
fi
# elif [[ $object == "rule" ]] ; then
# echo "Error: unsupported ip object \"$object\" in the Cygwin"
# exit 1
...
...
@@ -593,4 +776,3 @@ fi
echo
"Mapped to:
$ipcmd
"
$ipcmd
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment