/
add_vpnbook.tcl
127 lines (106 loc) · 4.87 KB
/
add_vpnbook.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
namespace eval ::vpnbook {
namespace export *
namespace ensemble create
variable name vpnbook
variable dispname VpnBook
variable host bootstrap
variable port 10443
variable path_config /vpapi/vpnbook/config
variable path_plans /vpapi/vpnbook/plans
# input entries - resettable/modifiable variables
variable newprofilename ""
variable username ""
variable password ""
}
proc ::vpnbook::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 "$dispname username" -anchor e
ttk::entry $pconf.usernameinput -textvariable ::${name}::username
ttk::label $pconf.usernameinfo -foreground grey -text "e.g. vpnbook"
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
hypertext $pconf.link "Get free account from <https://fruho.com/redirect?urlid=vpnbook&cn=$::model::Cn><vpnbook.com>"
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
grid $pconf.link -sticky news -columnspan 3 -padx 10 -pady 10
return $pconf
}
proc ::vpnbook::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 ::vpnbook::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
importline-update $pconf "Importing configuration from $dispname" disabled spin
set result [vpapi-config-direct $newprofilename $host $port $path_config?[this-pcv] $username $password]
if {$result != 200} {
importline-update $pconf [http2importline $result] normal empty
return
}
puts stderr "VPAPI-CONFIG-DIRECT completed"
set result [vpapi-plans-direct $newprofilename $host $port $path_plans?[this-pcv] $username $password]
if {$result != 200} {
importline-update $pconf [http2importline $result] normal empty
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
dict set ::model::Profiles $profileid provider $name
puts stderr "VPAPI-PLANS-DIRECT completed"
importline-update $pconf "" normal empty
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]
}
}
lappend ::model::Supported_providers {020 vpnbook}