Skip to content

Commit

Permalink
auto installing openvpn dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
hypatia2 committed Mar 7, 2016
1 parent 0a8001a commit b394a82
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 94 deletions.
17 changes: 4 additions & 13 deletions build.tcl
Expand Up @@ -106,8 +106,8 @@ proc build-deb-rpm {arch} {






proc build-total {} { proc build-total {archs {x86_64 ix86}} {
foreach arch {x86_64 ix86} { foreach arch $archs {
build-fruho linux $arch build-fruho linux $arch
build-fruhod linux $arch build-fruhod linux $arch
build-deb-rpm $arch build-deb-rpm $arch
Expand Down Expand Up @@ -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 prepare-lib sklib 0.0.0
#build-total build-total x86_64
#package require i18n #package require i18n
#i18n code2msg ./fruho/main.tcl {es pl} ./fruho/messages.txt #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 #push-update linux [this-arch] vbox_123

#release hypatia2 #release hypatia2




Expand Down
Binary file added fruho/images/32/status/installing.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 13 additions & 3 deletions fruho/main.tcl
Expand Up @@ -17,7 +17,6 @@ package require cmdline
package require unix package require unix
# unix requires Tclx which litters global namespace. Need to clean up to avoid conflict with csp # unix requires Tclx which litters global namespace. Need to clean up to avoid conflict with csp
rename ::select "" rename ::select ""
package require linuxdeps
#http::register https 443 [list tls::socket] #http::register https 443 [list tls::socket]
package require http package require http
package require https package require https
Expand Down Expand Up @@ -353,7 +352,7 @@ proc main-gui {} {
# don't rely on systray icon # don't rely on systray icon
package require tktray package require tktray
tktray::icon .systray -image [img load 16/logo] -docked 1 -visible 1 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] bind .systray <ButtonPress-3> [list pq 99999]




Expand Down Expand Up @@ -406,6 +405,10 @@ proc mainstatusline-update {stat} {
set ::model::Mainstatusline [dict create] set ::model::Mainstatusline [dict create]
set ::model::Mainstatusline_link "" set ::model::Mainstatusline_link ""
set ::model::Mainstatusline_last "No connection to fruho daemon. Try to restart fruhod service." 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 { } else {
set ::model::Mainstatusline [dict create] set ::model::Mainstatusline [dict create]
} }
Expand Down Expand Up @@ -1189,6 +1192,7 @@ proc connect-button-stand {} {
timeout {set state disabled} timeout {set state disabled}
cancelled {set state disabled} cancelled {set state disabled}
failed {set state disabled} failed {set state disabled}
installing {set state disabled}
default {set state disabled} default {set state disabled}
} }
return $state return $state
Expand Down Expand Up @@ -1217,6 +1221,7 @@ proc disconnect-button-stand {} {
timeout {set state disabled} timeout {set state disabled}
cancelled {set state disabled} cancelled {set state disabled}
failed {set state disabled} failed {set state disabled}
installing {set state disabled}
default {set state disabled} default {set state disabled}
} }
return $state return $state
Expand Down Expand Up @@ -1260,6 +1265,7 @@ proc connect-msg-stand {} {
timeout {set msg [_ "Disconnected"]} timeout {set msg [_ "Disconnected"]}
cancelled {set msg [_ "Disconnected"]} cancelled {set msg [_ "Disconnected"]}
failed {set msg [_ "Disconnected"]} failed {set msg [_ "Disconnected"]}
installing {set msg [_ "Installing"]}
connecting { connecting {
if {$city ne "" && $ccode ne ""} { if {$city ne "" && $ccode ne ""} {
set msg [_ "Connecting to {0}, {1}" $city $ccode] set msg [_ "Connecting to {0}, {1}" $city $ccode]
Expand All @@ -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 # - flag/IP
# - connstatus # - connstatus
# - gauge # - gauge
Expand Down Expand Up @@ -2740,6 +2746,7 @@ proc ffread-loop {} {
ffwrite start ffwrite start
} }
{^version (\S+) (.*)$} { {^version (\S+) (.*)$} {
# fruhod reports its version when fruho client connects
set daemon_version [lindex $details 1] set daemon_version [lindex $details 1]
puts stderr [log "DAEMON VERSION: $daemon_version"] puts stderr [log "DAEMON VERSION: $daemon_version"]
puts stderr [log "FRUHO CLIENT VERSION: [build-version]"] puts stderr [log "FRUHO CLIENT VERSION: [build-version]"]
Expand Down Expand Up @@ -3095,6 +3102,9 @@ proc connstatus-loop {} {
proc connstatus-reported {stat} { proc connstatus-reported {stat} {
if {$stat eq ""} { if {$stat eq ""} {
set connstatus unknown 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} { } elseif {[dict get $stat ovpn_pid] == 0} {
set connstatus disconnected set connstatus disconnected
# model::mgmt_connstatus may store stale value - it is valid only when ovpn_pid is not zero # model::mgmt_connstatus may store stale value - it is valid only when ovpn_pid is not zero
Expand Down
3 changes: 2 additions & 1 deletion fruho/model.tcl
Expand Up @@ -196,7 +196,8 @@ proc ::model::connstatus {args} {
if {[llength $args] == 1} { if {[llength $args] == 1} {
set newstatus [lindex $args 0] set newstatus [lindex $args 0]
# when changing from unknown to not-unknown status clear the mainstatusline last message # 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_last ""
set ::model::Mainstatusline_link "" set ::model::Mainstatusline_link ""
} }
Expand Down
117 changes: 45 additions & 72 deletions fruhod/main.tcl
Expand Up @@ -72,6 +72,7 @@ proc main {} {
socket -server daemon-new-connection -myaddr 127.0.0.1 7777 socket -server daemon-new-connection -myaddr 127.0.0.1 7777
log Listening on 127.0.0.1:7777 log Listening on 127.0.0.1:7777
cyclic-daemon-model-report cyclic-daemon-model-report
cyclic-linuxdeps-check
} on error {e1 e2} { } on error {e1 e2} {
log ERROR in main: $e1 $e2 log ERROR in main: $e1 $e2
} }
Expand Down Expand Up @@ -100,6 +101,27 @@ proc cyclic-daemon-model-report {} {
after 400 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 # On new connection to the daemon, close the previous one
Expand All @@ -112,6 +134,7 @@ proc daemon-new-connection {sock peerhost peerport} {
set ::model::Ffconn_sock $sock set ::model::Ffconn_sock $sock
fconfigure $sock -blocking 0 -buffering line fconfigure $sock -blocking 0 -buffering line
fileevent $sock readable ffread fileevent $sock readable ffread
# report fruhod version when fruho client connects
daemon-version-report daemon-version-report
daemon-model-report daemon-model-report
} }
Expand Down Expand Up @@ -241,20 +264,7 @@ proc ffread {} {
ffwrite ctrl "OpenVPN already running with pid [ovpn-pid]" ffwrite ctrl "OpenVPN already running with pid [ovpn-pid]"
return return
} else { } else {
model reset-ovpn-state ovpn-start
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
}
return return
} }
} }
Expand Down Expand Up @@ -487,6 +497,27 @@ proc ovpn-pid {} {
return $::model::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 # TODO
Expand All @@ -500,64 +531,6 @@ proc ovpn-is-connected {} {
proc mgmt-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: # After tun/tap driver update to OpenVPN 2.3.6 the only things that have changed in driver data:
#Code(bytes): 19˙968,00 #Code(bytes): 19˙968,00
#Link Date: 2013-08-22 13:40:00 #Link Date: 2013-08-22 13:40:00
Expand Down
7 changes: 7 additions & 0 deletions fruhod/model.tcl
Expand Up @@ -10,6 +10,10 @@ namespace eval ::model {


# fruhod <--> fruho client socket, also indicates if fruho client connected # fruhod <--> fruho client socket, also indicates if fruho client connected
variable Ffconn_sock "" variable Ffconn_sock ""

# cyclic-linuxdeps-check counter
variable Linuxdeps_count 0

# OpenVPN config as double-dashed one-line string # OpenVPN config as double-dashed one-line string
variable ovpn_config "" variable ovpn_config ""


Expand Down Expand Up @@ -64,6 +68,9 @@ namespace eval ::model {
# final openvpn process PID set by algorithm # final openvpn process PID set by algorithm
variable ovpn_pid 0 variable ovpn_pid 0


# flag indicating that openvpn is being installed
variable ovpn_installing 0

} }




Expand Down
8 changes: 3 additions & 5 deletions sklib/linuxdeps.tcl
Expand Up @@ -68,11 +68,9 @@ proc ::linuxdeps::is-openvpn-installed {} {
# No errors raised, best effort # No errors raised, best effort
proc ::linuxdeps::openvpn-install {} { proc ::linuxdeps::openvpn-install {} {
variable pkgmgr2cmd variable pkgmgr2cmd
if {![is-openvpn-installed]} { set pkgcmd [linuxdeps find-pkg-mgr-cmd]
set pkgcmd [linuxdeps find-pkg-mgr-cmd] if {[llength $pkgcmd] > 0} {
if {[llength $pkgcmd] > 0} { exec {*}$pkgcmd openvpn >&@ stdout &
exec {*}$pkgcmd openvpn >&@ stdout
}
} }
} }


Expand Down

0 comments on commit b394a82

Please sign in to comment.