Permalink
Browse files

vyprvpn working

  • Loading branch information...
hypatia2 committed Oct 30, 2015
1 parent 5b26fcb commit dfb8ee04683b494e3efeccc15425a5267fc3ec90
Showing with 161 additions and 12 deletions.
  1. +139 −0 fruho/add_vyprvpn.tcl
  2. BIN fruho/images/16/logo_vyprvpn.png
  3. +15 −8 fruho/main.tcl
  4. +6 −4 fruhod/main.tcl
  5. +1 −0 sklib/ovconf.tcl
@@ -0,0 +1,139 @@
namespace eval ::vyprvpn {
namespace export *
namespace ensemble create
variable name vyprvpn
variable dispname VyprVPN
variable host bootstrap
variable port 10443
variable path_config /vpapi/vyprvpn/config
variable path_plans /vpapi/vyprvpn/plans
# input entries - resettable/modifiable variables
variable newprofilename ""
variable username hypatia2@yandex.com
variable password nobel7
}
proc ::vyprvpn::create-import-frame {tab} {
variable name
variable dispname
variable newprofilename
set newprofilename [unique-profilename $dispname]
set pconf $tab.$name
ttk::frame $pconf
ttk::label $pconf.profilelabel -text "Profile name" -anchor e
ttk::entry $pconf.profileinput -textvariable ::${name}::newprofilename
ttk::label $pconf.profileinfo -foreground grey
ttk::label $pconf.usernamelabel -text "Email address" -anchor e
ttk::entry $pconf.usernameinput -textvariable ::${name}::username
ttk::label $pconf.usernameinfo -foreground grey
ttk::label $pconf.passwordlabel -text "$dispname password" -anchor e
ttk::entry $pconf.passwordinput -textvariable ::${name}::password
ttk::label $pconf.passwordinfo -foreground grey
ttk::frame $pconf.importline
ttk::button $pconf.importline.button -text "Import configuration" -command [list go ::${name}::ImportClicked $tab]
# must use non-ttk label for proper animated gif display
label $pconf.importline.img
img place 24/empty $pconf.importline.img
ttk::label $pconf.importline.msg
grid $pconf.importline.button -row 0 -column 0 -padx 10
grid $pconf.importline.img -row 0 -column 1 -padx 10 -pady 10
grid $pconf.importline.msg -row 0 -column 2 -padx 10 -pady 10
grid columnconfigure $pconf 0 -weight 4 -uniform 1
grid columnconfigure $pconf 1 -weight 4 -uniform 1
grid columnconfigure $pconf 2 -weight 4 -uniform 1
grid $pconf.profilelabel -row 1 -column 0 -sticky news -padx 5 -pady 5
grid $pconf.profileinput -row 1 -column 1 -sticky news -padx 5 -pady 5
grid $pconf.profileinfo -row 1 -column 2 -sticky news -pady 5
grid $pconf.usernamelabel -row 5 -column 0 -sticky news -padx 5 -pady 5
grid $pconf.usernameinput -row 5 -column 1 -sticky news -padx 5 -pady 5
grid $pconf.usernameinfo -row 5 -column 2 -sticky news -pady 5
grid $pconf.passwordlabel -row 7 -column 0 -sticky news -padx 5 -pady 5
grid $pconf.passwordinput -row 7 -column 1 -sticky news -padx 5 -pady 5
grid $pconf.passwordinfo -row 7 -column 2 -sticky news -pady 5
grid $pconf.importline -sticky news -columnspan 3
return $pconf
}
proc ::vyprvpn::add-to-treeview-plist {plist} {
variable name
variable dispname
$plist insert {} end -id $name -image [img load 16/logo_$name] -values [list $dispname]
}
# this is csp coroutine
proc ::vyprvpn::ImportClicked {tab} {
try {
variable name
variable dispname
variable host
variable port
variable path_config
variable path_plans
variable username
variable password
variable newprofilename
set profileid [name2id $newprofilename]
set pconf $tab.$name
img place 24/spin $pconf.importline.img
$pconf.importline.msg configure -text "Importing configuration from $dispname"
$pconf.importline.button configure -state disabled
set result [vpapi-config-direct $newprofilename $host $port $path_config?[this-pcv] $username $password]
if {$result != 200} {
set msg [http2importline $result]
img place 24/empty $pconf.importline.img
$pconf.importline.button configure -state normal
$pconf.importline.msg configure -text $msg
return
}
puts stderr "VPAPI-CONFIG-DIRECT completed"
set result [vpapi-plans-direct $newprofilename $host $port $path_plans?[this-pcv] $username $password]
if {$result != 200} {
set msg [http2importline $result]
img place 24/empty $pconf.importline.img
$pconf.importline.button configure -state normal
$pconf.importline.msg configure -text $msg
return
}
# save in the model to be able later refresh the plans via vpapi
dict set ::model::Profiles $profileid vpapi_username $username
dict set ::model::Profiles $profileid vpapi_password $password
dict set ::model::Profiles $profileid vpapi_host $host
dict set ::model::Profiles $profileid vpapi_port $port
dict set ::model::Profiles $profileid vpapi_path_plans $path_plans
puts stderr "VPAPI-PLANS-DIRECT completed"
img place 24/empty $pconf.importline.img
$pconf.importline.msg configure -text ""
$pconf.importline.button configure -state normal
set ::${name}::username ""
set ::${name}::password ""
# when repainting tabset select the newly created tab
set ::model::selected_profile $profileid
tabset-profiles .c.tabsetenvelope
} on error {e1 e2} {
puts stderr [log $e1 $e2]
}
}
dict set model::Supported_providers vyprvpn {
name $::vyprvpn::name
dispname $::vyprvpn::dispname
}
Binary file not shown.
@@ -1097,8 +1097,11 @@ proc connect-button-stand {} {
if {[is-addprovider-tab-selected]} {
return disabled
}
# CSR not completed yet - disable buttons
if {![is-cert-received [current-profile]] || ![is-config-received [current-profile]]} {
if {![is-config-received [current-profile]]} {
return disabled
}
# For Fruho faas, CSR not completed yet - disable buttons
if {[current-profile] eq "fruho" && ![is-cert-received [current-profile]]} {
return disabled
}
set slist [current-slist [model now] [current-profile]]
@@ -1125,8 +1128,11 @@ proc disconnect-button-stand {} {
# In case of Disconnect button on addprovider tab apply the full connstatus logic
if {![is-addprovider-tab-selected]} {
# These checks make sense only when real profile selected
# CSR not completed yet - disable buttons
if {![is-cert-received [current-profile]] || ![is-config-received [current-profile]]} {
if {![is-config-received [current-profile]]} {
return disabled
}
# For Fruho faas, CSR not completed yet - disable buttons
if {[current-profile] eq "fruho" && ![is-cert-received [current-profile]]} {
return disabled
}
}
@@ -2529,6 +2535,7 @@ proc ServerListClicked {} {
if {![img exists $flag]} {
set flag 24/flag/EMPTY
}
#puts stderr "TREE INSERT $id $country $city $ip"
$wt insert {} end -id $id -image [img load $flag] -values [list $country $city $ip]
}
$wt selection set $ssid
@@ -3008,17 +3015,17 @@ proc ClickConnect {} {
set ::model::Current_protoport [select-protoport-ovs $::model::Current_sitem]
lassign $::model::Current_protoport proto port
#TODO handle inline certs and keys
# include local certs/keys if files present
set cert [ovconf get $localconf --cert]
if {$cert eq ""} {
if {$cert eq "" && [file exists [ovpndir $profile client.crt]]} {
set localconf [ovconf cset $localconf --cert [ovpndir $profile client.crt]]
}
set key [ovconf get $localconf --key]
if {$key eq ""} {
if {$key eq "" && [file exists [ovpndir $profile client.key]]} {
set localconf [ovconf cset $localconf --key [ovpndir $profile client.key]]
}
set ca [ovconf get $localconf --ca]
if {$ca eq ""} {
if {$ca eq "" && [file exists [ovpndir $profile ca.crt]]} {
set localconf [ovconf cset $localconf --ca [ovpndir $profile ca.crt]]
}
@@ -190,10 +190,12 @@ proc adjust-config {conf} {
proc load-config {conf} {
# every attempt to load config should reset the previous one
set ::model::ovpn_config ""
# sanitize config input
if {![regexp {^[\d\w\s_:/\-.\{\}"]*$} $conf]} {
log "CONF:\n$conf"
return "Config contains illegal characters"
# sanitize config input - DON'T. It may contain custom-auth-user and custom-auth-pass
if 0 {
if {![regexp {^[\d\w\s@_:/\-.\{\}"]*$} $conf]} {
log "CONF:\n$conf"
return "Config contains illegal characters"
}
}
set patherror [::ovconf::check-paths-exist $conf]
if {$patherror ne ""} {
@@ -167,6 +167,7 @@ proc ::ovconf::inline-section-coords {config tag} {
set tag [string tolower $tag]
set istart [string first "<$tag>" $config]
set iend [string first "</$tag>" $config]
#puts stderr "inline-section-coords for tag $tag: istart=$istart, iend=$iend"
if {$istart != -1 && $iend != -1 && $iend - $istart > 200} {
return [list $istart $iend]
}

0 comments on commit dfb8ee0

Please sign in to comment.