Permalink
Browse files

http2importline proc for meaningful user messages and fixes

  • Loading branch information...
hypatia2 committed Oct 28, 2015
1 parent 7d4bd21 commit 5b26fcb680fb6809a7073a5b7da251579f4ff4c6
Showing with 33 additions and 38 deletions.
  1. +2 −12 fruho/add_hideipvpn.tcl
  2. +4 −13 fruho/add_mullvad.tcl
  3. +3 −12 fruho/add_securitykiss.tcl
  4. +24 −1 fruho/main.tcl
@@ -97,13 +97,8 @@ proc ::hideipvpn::ImportClicked {tab} {
# in case of hideipvpn using username and password has a different purpose than authentication
# instead of using for basic authentication (any strings will pass) the credentials are included in the returned config.ovpn
set result [vpapi-config-direct $newprofilename $host $port $path_config?[this-pcv] $username $password]
# TODO handle vpapi nuncio errors via http error codes: 401 (credentials error), 402 (premium account required), 503 (service unavailable)
if {$result != 200} {
if {$result == 401} {
set msg "Incorrect username or password"
} else {
set msg $result
}
set msg [http2importline $result]
img place 24/empty $pconf.importline.img
$pconf.importline.button configure -state normal
$pconf.importline.msg configure -text $msg
@@ -114,13 +109,8 @@ proc ::hideipvpn::ImportClicked {tab} {
# in case of hideipvpn using username and password has a different purpose than authentication
# instead of using for basic authentication (any strings will pass) the credentials are included in the returned config.ovpn
set result [vpapi-plans-direct $newprofilename $host $port $path_plans?[this-pcv] $username $password]
# TODO handle vpapi nuncio errors via http error codes: 401 (credentials error), 402 (premium account required), 503 (service unavailable)
if {$result != 200} {
if {$result == 401} {
set msg "Incorrect username/password"
} else {
set msg $result
}
set msg [http2importline $result]
img place 24/empty $pconf.importline.img
$pconf.importline.button configure -state normal
$pconf.importline.msg configure -text $msg
@@ -14,7 +14,7 @@ namespace eval ::mullvad {
# input entries - resettable/modifiable variables
variable newprofilename ""
variable username 1016121332615
variable username 438696513567
variable password ""
}
@@ -64,6 +64,7 @@ proc ::mullvad::add-to-treeview-plist {plist} {
$plist insert {} end -id $name -image [img load 16/logo_$name] -values [list $dispname]
}
# this is csp coroutine
proc ::mullvad::ImportClicked {tab} {
try {
@@ -85,13 +86,8 @@ proc ::mullvad::ImportClicked {tab} {
$pconf.importline.button configure -state disabled
set result [vpapi-config-direct $newprofilename $host $port $path_config?[this-pcv] $username $password]
# TODO handle vpapi nuncio errors via http error codes: 401 (credentials error), 402 (premium account required), 503 (service unavailable)
if {$result != 200} {
if {$result == 401} {
set msg "Incorrect username or password"
} else {
set msg $result
}
set msg [http2importline $result]
img place 24/empty $pconf.importline.img
$pconf.importline.button configure -state normal
$pconf.importline.msg configure -text $msg
@@ -100,13 +96,8 @@ proc ::mullvad::ImportClicked {tab} {
puts stderr "VPAPI-CONFIG-DIRECT completed"
set result [vpapi-plans-direct $newprofilename $host $port $path_plans?[this-pcv] $username $password]
# TODO handle vpapi nuncio errors via http error codes: 401 (credentials error), 402 (premium account required), 503 (service unavailable)
if {$result != 200} {
if {$result == 401} {
set msg "Incorrect username/password"
} else {
set msg $result
}
set msg [http2importline $result]
img place 24/empty $pconf.importline.img
$pconf.importline.button configure -state normal
$pconf.importline.msg configure -text $msg
@@ -90,27 +90,18 @@ proc ::securitykiss::ImportClicked {tab} {
$pconf.importline.button configure -state disabled
set result [vpapi-config-direct $newprofilename $host $port $path_config?[this-pcv] $username $password]
# TODO handle vpapi nuncio errors via http error codes: 401 (credentials error), 402 (premium account required), 503 (service unavailable)
if {$result != 200} {
if {$result == 401} {
set msg "Incorrect username or password"
} else {
set msg $result
}
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]
# TODO handle vpapi nuncio errors via http error codes: 401 (credentials error), 402 (premium account required), 503 (service unavailable)
if {$result != 200} {
if {$result == 401} {
set msg "Incorrect username/password"
} else {
set msg $result
}
set msg [http2importline $result]
img place 24/empty $pconf.importline.img
$pconf.importline.button configure -state normal
$pconf.importline.msg configure -text $msg
@@ -829,6 +829,23 @@ proc curl-dispatch {chout cherr hostport args} {
}
}
# convert http status code into user friendly status message
# this is to handle vpapi nuncio errors
proc http2importline {httpcode} {
if {$httpcode == 401} {
set msg "Incorrect username or password"
} elseif {$httpcode == 402} {
set msg "Account no longer active"
} elseif {$httpcode == 503} {
set msg "Service unavailable"
} elseif {$httpcode == 500} {
set msg "Service error"
} else {
set msg "Service status: $httpcode"
}
return $msg
}
# testing command:
# curl --insecure https://fb028f09a9c7d574@37.59.65.55:10443/vpapi/fruho/config?p=linux-x86_64\&c=fb028f09a9c7d574\&v=0.0.7
@@ -2631,6 +2648,7 @@ proc this-pcv {} {
# go curl-retry $chout $cherr -hostports [lrepeat $n $host:$port] -urlpath $urlpath {*}$args
# tryout - if success, http content response will be sent to this channel or empty string if -gettofile
# tryerr - if all attempts failed, last error (http response code) will be sent to this channel
# This proc is a mess - no clear semantics for retrying on failure (is non-200 http status code a success to be pushed to tryout, or fail to tryerr, or retry?)
proc curl-retry {tryout tryerr args} {
try {
fromargs {-urlpath -indiv_timeout -hostports -hindex -proto -expected_hostname -method -gettofile -postfromfile -basicauth -cadir} \
@@ -2652,6 +2670,7 @@ proc curl-retry {tryout tryerr args} {
set hlen [llength $hostports]
set ncode 0
set ncode_nonempty 0
# host_index is the index to start from when iterating hostports
for {set i $host_index} {$i<$host_index+$hlen} {incr i} {
set hostport [lindex $hostports [expr {$i % $hlen}]]
@@ -2698,6 +2717,9 @@ proc curl-retry {tryout tryerr args} {
set tok [<- $chhttp]
upvar #0 $tok state
set ncode [http::ncode $tok]
if {[string is integer -strict $ncode]} {
set ncode_nonempty $ncode
}
set status [http::status $tok]
if {$status eq "ok" && $ncode == 200} {
set host_index [expr {$i % $hlen}]
@@ -2727,7 +2749,8 @@ proc curl-retry {tryout tryerr args} {
catch {http::cleanup $tok}
}
}
$tryerr <- $ncode
puts stderr [log "curl-retry pushing ncode_nonempty=$ncode_nonempty to tryerr channel"]
$tryerr <- $ncode_nonempty
} on error {e1 e2} {
log "$e1 $e2"
} finally {

0 comments on commit 5b26fcb

Please sign in to comment.