Permalink
Browse files

is-valid-host and dict-set-trim

  • Loading branch information...
hypatia2 committed Nov 2, 2015
1 parent 16aaa27 commit e0ba3e863f56ee7b4c003d7f3c1ba9d490862ec5
Showing with 42 additions and 13 deletions.
  1. +11 −5 fruho/add_from_file.tcl
  2. +1 −0 fruho/bootstrap.lst
  3. +8 −6 fruho/main.tcl
  4. +2 −2 fruho/model.tcl
  5. +20 −0 sklib/skutil.tcl
@@ -78,7 +78,7 @@ proc ::from_file::ImportClicked {tab} {
set slist [extract-servers $tempdir]
puts stderr "slist: $slist"
set plan [dict create name $newprofilename timelimit [dict create start 0 period month nop 1] trafficlimit [dict create used 0 quota 1000000000] slist $slist]
set plan [dict create name $newprofilename timelimit [dict create start 0 period month nop 1000000] trafficlimit [dict create used 0 quota 1000000000] slist $slist]
dict set ::model::Profiles $profileid plans [dict create plainid $plan]
dict set ::model::Profiles $profileid profilename $newprofilename
@@ -186,24 +186,30 @@ proc ::from_file::extract-servers {tempdir} {
set files [find-ovpn-in $tempdir * 1]
set files [concat $files [find-ovpn-in $tempdir */* 1]]
set files [concat $files [find-ovpn-in $tempdir */*/* 1]]
# list of triples {ip proto port}
# list of triples {host proto port}
set endpoints {}
puts stderr "extract-servers files: $files"
foreach f $files {
set ovpn [slurp $f]
puts stderr "slurp ovpn: $ovpn"
set remotes [ovconf raw-get $ovpn remote]
set remotes [concat $remotes [ovconf raw-get $ovpn #remote]]
set remotes [concat $remotes [ovconf raw-get $ovpn "# remote"]]
puts stderr "remotes: $remotes"
set proto [ovconf raw-get $ovpn proto]
foreach r $remotes {
lassign $r ip port
if {[is-valid-ip $ip] && [is-valid-port $port] && [is-valid-proto $proto]} {
set triple [list $ip $proto $port]
lassign $r host port
if {[is-valid-host $host] && [is-valid-port $port] && [is-valid-proto $proto]} {
set triple [list $host $proto $port]
lappend endpoints $triple
}
}
}
set endpoints [lunique $endpoints]
#TODO resolve hostsnames
set slist {}
if {[llength $endpoints] > 0} {
set slist [create-slist $endpoints]
@@ -1,4 +1,5 @@
37.59.65.55:10443
37.59.65.55:443
127.0.0.1:10443
10.0.2.2:10443
94.185.84.100:10443
@@ -756,7 +756,7 @@ proc update-bulk-loc {profileid} {
dict for {planid plan} [dict-pop $::model::Profiles $profileid plans {}] {
set slist [dict-pop $plan slist {}]
set slist [rebuild-slist-with-geoloc $slist $loc]
dict set ::model::Profiles $profileid plans $planid slist $slist
dict-set-trim ::model::Profiles $profileid plans $planid slist $slist
}
} on error {e1 e2} {
puts stderr [log $e1 $e2]
@@ -939,8 +939,8 @@ proc vpapi-plans-direct {profilename host port urlpath username password} {
puts stderr [log Received plans JSON: $data]
set plans [json::json2dict $data]
set profileid [name2id $profilename]
dict set ::model::Profiles $profileid plans $plans
dict set ::model::Profiles $profileid profilename $profilename
dict-set-trim ::model::Profiles $profileid plans $plans
dict-set-trim ::model::Profiles $profileid profilename $profilename
#puts stderr "Profiles: $::model::Profiles"
set httpcode 200
# Never call return from select condition
@@ -3007,7 +3007,7 @@ proc ClickConnect {} {
set ::model::Current_sitem [model selected-sitem $profile $planid]
# additional profile name info in sitem that will be passed as metadata to openvpn config / fruhod
dict set ::model::Current_sitem profile $profile
dict-set-trim ::model::Current_sitem profile $profile
set localconf [::ovconf::parse [ovpndir $profile config.ovpn]]
set ip [dict get $::model::Current_sitem ip]
@@ -3091,12 +3091,14 @@ proc ClickConnect {} {
set modal [ShowModal $w]
if {$modal eq "ok"} {
puts stderr "Userpass entered"
set ::model::Gui_auth_user [string trim $::model::Gui_auth_user]
set ::model::Gui_auth_pass [string trim $::model::Gui_auth_pass]
set localconf [ovconf cset $localconf --custom-auth-user $::model::Gui_auth_user]
set localconf [ovconf cset $localconf --custom-auth-pass $::model::Gui_auth_pass]
# we allow empty credentials in the GUI but don't cache empty ones. Use them once
if {$::model::Gui_auth_user ne "" && $::model::Gui_auth_pass ne ""} {
dict set ::model::Profiles $profile cache_custom_auth_user $::model::Gui_auth_user
dict set ::model::Profiles $profile cache_custom_auth_pass $::model::Gui_auth_pass
dict-set-trim ::model::Profiles $profile cache_custom_auth_user $::model::Gui_auth_user
dict-set-trim ::model::Profiles $profile cache_custom_auth_pass $::model::Gui_auth_pass
}
} else {
set should_connect 0
@@ -131,8 +131,8 @@ if 0 { variable Profiles [dict create fruho {
variable previous_traffic_probes 5
variable Gui_openvpn_connection_timeout 15
variable openvpn_connection_timeout 15
variable Gui_openvpn_connection_timeout 25
variable openvpn_connection_timeout 25
csp::channel ::model::Chan_button_connect
csp::channel ::model::Chan_button_disconnect
@@ -21,6 +21,15 @@ proc parse-ip {s} {
}
}
proc is-valid-host {s} {
if {[is-valid-ip $s]} {
return 1
}
return [regexp {[a-z0-9\-]+\.[a-z0-9\-.]+} $s]
}
proc is-valid-ip {s} {
set parsed [parse-ip $s]
return [expr {$parsed ne ""}]
@@ -631,6 +640,17 @@ proc dict-set-iev {dictVar k v} {
}
# dict set that trims whitespaces from the value
proc dict-set-trim {dictVar args} {
upvar $dictVar d
set v [string trim [lindex $args end]]
set keys [lrange $args 0 end-1]
dict set d {*}$keys $v
return $d
}
#########################
# convert dictionary value dict into string
# hereby insert newlines and spaces to make

0 comments on commit e0ba3e8

Please sign in to comment.