Permalink
Browse files

auto installing openvpn dependency

  • Loading branch information...
hypatia2 committed Mar 7, 2016
1 parent 0a8001a commit b394a82ca877ac9fa07071b601bf1ee0980e4d63
Showing with 74 additions and 94 deletions.
  1. +4 −13 build.tcl
  2. BIN fruho/images/32/status/installing.gif
  3. +13 −3 fruho/main.tcl
  4. +2 −1 fruho/model.tcl
  5. +45 −72 fruhod/main.tcl
  6. +7 −0 fruhod/model.tcl
  7. +3 −5 sklib/linuxdeps.tcl
@@ -106,8 +106,8 @@ proc build-deb-rpm {arch} {
proc build-total {} {
foreach arch {x86_64 ix86} {
proc build-total {archs {x86_64 ix86}} {
foreach arch $archs {
build-fruho linux $arch
build-fruhod linux $arch
build-deb-rpm $arch
@@ -243,22 +243,13 @@ proc push-update {os arch tohost} {
set ::FRUHO_VERSION 0.0.13
set ::FRUHO_VERSION 0.0.16
prepare-lib sklib 0.0.0
#build-total
build-total x86_64
#package require i18n
#i18n code2msg ./fruho/main.tcl {es pl} ./fruho/messages.txt
build-fruho linux [this-arch]
build-fruhod linux [this-arch]
build-deb-rpm [this-arch]
#build-fruho linux ix86
#build-fruhod linux ix86
#build-deb-rpm ix86
#push-update linux [this-arch] vbox_123
#release hypatia2
Binary file not shown.
@@ -17,7 +17,6 @@ package require cmdline
package require unix
# unix requires Tclx which litters global namespace. Need to clean up to avoid conflict with csp
rename ::select ""
package require linuxdeps
#http::register https 443 [list tls::socket]
package require http
package require https
@@ -353,7 +352,7 @@ proc main-gui {} {
# don't rely on systray icon
package require tktray
tktray::icon .systray -image [img load 16/logo] -docked 1 -visible 1
.systray balloon "Fruho balloon" 5000
.systray balloon "Fruho installed" 5000
bind .systray <ButtonPress-3> [list pq 99999]
@@ -406,6 +405,10 @@ proc mainstatusline-update {stat} {
set ::model::Mainstatusline [dict create]
set ::model::Mainstatusline_link ""
set ::model::Mainstatusline_last "No connection to fruho daemon. Try to restart fruhod service."
} elseif {$connstatus eq "installing"} {
set ::model::Mainstatusline [dict create]
set ::model::Mainstatusline_link ""
set ::model::Mainstatusline_last "Installing OpenVPN"
} else {
set ::model::Mainstatusline [dict create]
}
@@ -1189,6 +1192,7 @@ proc connect-button-stand {} {
timeout {set state disabled}
cancelled {set state disabled}
failed {set state disabled}
installing {set state disabled}
default {set state disabled}
}
return $state
@@ -1217,6 +1221,7 @@ proc disconnect-button-stand {} {
timeout {set state disabled}
cancelled {set state disabled}
failed {set state disabled}
installing {set state disabled}
default {set state disabled}
}
return $state
@@ -1260,6 +1265,7 @@ proc connect-msg-stand {} {
timeout {set msg [_ "Disconnected"]}
cancelled {set msg [_ "Disconnected"]}
failed {set msg [_ "Disconnected"]}
installing {set msg [_ "Installing"]}
connecting {
if {$city ne "" && $ccode ne ""} {
set msg [_ "Connecting to {0}, {1}" $city $ccode]
@@ -1284,7 +1290,7 @@ proc externalip-stand {} {
}
# for there is a mix of various GUI components updated all together:
# there is a mix of various GUI components updated all together:
# - flag/IP
# - connstatus
# - gauge
@@ -2740,6 +2746,7 @@ proc ffread-loop {} {
ffwrite start
}
{^version (\S+) (.*)$} {
# fruhod reports its version when fruho client connects
set daemon_version [lindex $details 1]
puts stderr [log "DAEMON VERSION: $daemon_version"]
puts stderr [log "FRUHO CLIENT VERSION: [build-version]"]
@@ -3095,6 +3102,9 @@ proc connstatus-loop {} {
proc connstatus-reported {stat} {
if {$stat eq ""} {
set connstatus unknown
} elseif {[dict get $stat ovpn_installing] == 1} {
# when openvpn is being installed (may happen when fruhod starts)
set connstatus installing
} elseif {[dict get $stat ovpn_pid] == 0} {
set connstatus disconnected
# model::mgmt_connstatus may store stale value - it is valid only when ovpn_pid is not zero
@@ -196,7 +196,8 @@ proc ::model::connstatus {args} {
if {[llength $args] == 1} {
set newstatus [lindex $args 0]
# when changing from unknown to not-unknown status clear the mainstatusline last message
if {$::model::Connstatus eq "unknown" && $newstatus ne "unknown"} {
# the same for installing
if { ($::model::Connstatus eq "unknown" && $newstatus ne "unknown") || ($::model::Connstatus eq "installing" && $newstatus ne "installing")} {
set ::model::Mainstatusline_last ""
set ::model::Mainstatusline_link ""
}
@@ -72,6 +72,7 @@ proc main {} {
socket -server daemon-new-connection -myaddr 127.0.0.1 7777
log Listening on 127.0.0.1:7777
cyclic-daemon-model-report
cyclic-linuxdeps-check
} on error {e1 e2} {
log ERROR in main: $e1 $e2
}
@@ -100,6 +101,27 @@ proc cyclic-daemon-model-report {} {
after 400 cyclic-daemon-model-report
}
proc cyclic-linuxdeps-check {} {
# try 7 times every 5 seconds
if {$::model::Linuxdeps_count < 7} {
incr ::model::Linuxdeps_count
log "cyclic-linuxdeps-check # $::model::Linuxdeps_count"
if {![linuxdeps is-openvpn-installed]} {
log "No OpenVPN installed"
set ::model::ovpn_installing 1
if {[catch {linuxdeps openvpn-install} out err]} {
log $err
}
after 5000 cyclic-linuxdeps-check
} else {
set ::model::ovpn_installing 0
log "OpenVPN OK"
}
} else {
set ::model::ovpn_installing 0
}
}
# On new connection to the daemon, close the previous one
@@ -112,6 +134,7 @@ proc daemon-new-connection {sock peerhost peerport} {
set ::model::Ffconn_sock $sock
fconfigure $sock -blocking 0 -buffering line
fileevent $sock readable ffread
# report fruhod version when fruho client connects
daemon-version-report
daemon-model-report
}
@@ -241,20 +264,7 @@ proc ffread {} {
ffwrite ctrl "OpenVPN already running with pid [ovpn-pid]"
return
} else {
model reset-ovpn-state
set config [adjust-config $::model::ovpn_config]
set ovpncmd "openvpn $config"
try {
set stdinout [cmd invoke $ovpncmd OvpnExit OvpnRead OvpnErrRead]
set ::model::Start_pid [pid $stdinout]
set ::model::Start_pid_tstamp [clock milliseconds]
# this call is necessary to update ovpn_pid
ovpn-pid
ffwrite ctrl "OpenVPN with pid [ovpn-pid] started"
} on error {e1 e2} {
ffwrite ctrl "OpenVPN ERROR: $e1"
log $e1 $e2
}
ovpn-start
return
}
}
@@ -487,6 +497,27 @@ proc ovpn-pid {} {
return $::model::ovpn_pid
}
proc ovpn-start {} {
if {$::model::ovpn_installing} {
# postpone openvpn start in hope that openvpn will get installed in the meantime
after 5000 ovpn-start
} else {
model reset-ovpn-state
set config [adjust-config $::model::ovpn_config]
set ovpncmd "openvpn $config"
try {
set stdinout [cmd invoke $ovpncmd OvpnExit OvpnRead OvpnErrRead]
set ::model::Start_pid [pid $stdinout]
set ::model::Start_pid_tstamp [clock milliseconds]
# this call is necessary to update ovpn_pid
ovpn-pid
ffwrite ctrl "OpenVPN with pid [ovpn-pid] started"
} on error {e1 e2} {
ffwrite ctrl "OpenVPN ERROR: $e1"
log $e1 $e2
}
}
}
# TODO
@@ -500,64 +531,6 @@ proc ovpn-is-connected {} {
proc mgmt-is-connected {} {
}
#>>ovpn: Wed Apr 08 09:26:43 2015 TAP-WIN32 device [Local Area Connection 2] opened: \\.\Global\{BDCE36A3-CE0B-4370-900A-03F12CDD67C5}.tap
#>>ovpn: Wed Apr 08 09:26:43 2015 TAP-Windows Driver Version 9.8
#>>ovpn: Wed Apr 08 09:26:43 2015 MANAGEMENT: Client disconnected
#>>ovpn: Wed Apr 08 09:26:43 2015 ERROR: This version of OpenVPN requires a TAP-Windows driver that is at least version 9.9 -- If you recently upgraded your OpenVPN distribution, a reboot is probably required at this point to get Windows to see the new driver.
#Ethernet adapter Local Area Connection 3:
#
# Media State . . . . . . . . . . . : Media disconnected
# Description . . . . . . . . . . . : TAP-Win32 Adapter V9 #2
# Physical Address. . . . . . . . . : 00-FF-3E-A0-C7-D3
#
#Ethernet adapter Local Area Connection 2:
#
# Connection-specific DNS Suffix . :
# Description . . . . . . . . . . . : TAP-Win32 Adapter V9
# Physical Address. . . . . . . . . : 00-FF-BD-CE-36-A3
# Dhcp Enabled. . . . . . . . . . . : Yes
# Autoconfiguration Enabled . . . . : Yes
# IP Address. . . . . . . . . . . . : 10.11.5.22
# Subnet Mask . . . . . . . . . . . : 255.255.255.252
# Default Gateway . . . . . . . . . : 10.11.5.21
# DHCP Server . . . . . . . . . . . : 10.11.5.21
# DNS Servers . . . . . . . . . . . : 10.11.0.1
# Lease Obtained. . . . . . . . . . : 8 kwietnia 2015 09:35:58
# Lease Expires . . . . . . . . . . : 7 kwietnia 2016 09:35:58
# On Windows to check installed drivers:
# driverquery /FO list /v
# sample output:
# ...
#Link Date: 2008-04-13 20:15:55
#Path: C:\WINDOWS\system32\drivers\sysaudio.sys
#Init(bytes): 2˙816,00
#
#Module Name: tap0901
#Display Name: TAP-Win32 Adapter V9
#Description: TAP-Win32 Adapter V9
#Driver Type: Kernel
#Start Mode: Manual
#State: Running
#Status: OK
#Accept Stop: TRUE
#Accept Pause: FALSE
#Paged Pool(bytes): 0,00
#Code(bytes): 20˙480,00
#BSS(bytes): 0,00
#Link Date: 2011-03-24 21:20:11
#Path: C:\WINDOWS\system32\DRIVERS\tap0901.sys
#Init(bytes): 4˙096,00
#
#Module Name: Tcpip
#Display Name: TCP/IP Protocol Driver
#Description: TCP/IP Protocol Driver
#...
# After tun/tap driver update to OpenVPN 2.3.6 the only things that have changed in driver data:
#Code(bytes): 19˙968,00
#Link Date: 2013-08-22 13:40:00
@@ -10,6 +10,10 @@ namespace eval ::model {
# fruhod <--> fruho client socket, also indicates if fruho client connected
variable Ffconn_sock ""
# cyclic-linuxdeps-check counter
variable Linuxdeps_count 0
# OpenVPN config as double-dashed one-line string
variable ovpn_config ""
@@ -64,6 +68,9 @@ namespace eval ::model {
# final openvpn process PID set by algorithm
variable ovpn_pid 0
# flag indicating that openvpn is being installed
variable ovpn_installing 0
}
@@ -68,11 +68,9 @@ proc ::linuxdeps::is-openvpn-installed {} {
# No errors raised, best effort
proc ::linuxdeps::openvpn-install {} {
variable pkgmgr2cmd
if {![is-openvpn-installed]} {
set pkgcmd [linuxdeps find-pkg-mgr-cmd]
if {[llength $pkgcmd] > 0} {
exec {*}$pkgcmd openvpn >&@ stdout
}
set pkgcmd [linuxdeps find-pkg-mgr-cmd]
if {[llength $pkgcmd] > 0} {
exec {*}$pkgcmd openvpn >&@ stdout &
}
}

0 comments on commit b394a82

Please sign in to comment.