1
/////////////////////////////////////////////////////////////////////
2
// socks.config form and rule contains following:
4
// (INK_SOCKS_BYPASS rule type)
5
// Dest IP address list dest_ip
6
// (INK_SOCKS_AUTH rule type)
9
// (INK_SOCKS_MULTIPLE rule type)
10
// SOck Servers List socks_servers
11
// Round Robin round_robin
12
// ** NOTE: the input type names must match those created in
13
// writeSocksConfigForm
15
// Licensed to the Apache Software Foundation (ASF) under one
16
// or more contributor license agreements. See the NOTICE file
17
// distributed with this work for additional information
18
// regarding copyright ownership. The ASF licenses this file
19
// to you under the Apache License, Version 2.0 (the
20
// "License"); you may not use this file except in compliance
21
// with the License. You may obtain a copy of the License at
23
// http://www.apache.org/licenses/LICENSE-2.0
25
// Unless required by applicable law or agreed to in writing, software
26
// distributed under the License is distributed on an "AS IS" BASIS,
27
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28
// See the License for the specific language governing permissions and
29
// limitations under the License.
30
/////////////////////////////////////////////////////////////////////
33
// creates a new Rule object; initializes with parameters passed in
35
function Rule(rule_type, dest_ip, user, password, socks_servers, round_robin) {
36
this.rule_type = rule_type;
37
this.dest_ip = dest_ip;
39
this.password = password;
40
this.socks_servers = socks_servers;
41
this.round_robin = round_robin;
45
// This function creates a new Rule object for ruleList based
46
// on values entered in form.
47
// NOTE: In Netscape, we cannot access the selected value with:
48
// document.form1.rule_type.value. So we have to first get the
49
// selected index to get selected option's value
51
function createRuleFromForm() {
52
var index = document.form1.rule_type.selectedIndex;
53
var rule_type = document.form1.rule_type.options[index].value;
55
var user = document.form1.user.value;
56
var password = document.form1.password.value;
57
var dest_ip = document.form1.dest_ip.value;
58
var socks_servers = document.form1.socks_servers.value;
60
index = document.form1.round_robin.selectedIndex;
61
var round_robin = document.form1.round_robin.options[index].value;
63
var rule = new Rule(rule_type, dest_ip, user, password, socks_servers, round_robin);
69
// This function displays the Rule object's information in the format
70
// that's used in the select list.
72
function textFormat(rule, write)
79
space = " ";
83
delim = space + "," + space;
85
text = "Rule Type" + eq + rule.rule_type;
86
if (rule.user != "") text += delim + "Username" + eq + rule.user;
87
if (rule.password != "") text += delim + "Password" + eq + rule.password;
88
if (rule.dest_ip != "") text += delim + "Destination IP" + eq + rule.dest_ip;
89
if (rule.socks_servers != "") text += delim + "Socks Servers" + eq + rule.socks_servers;
90
if (rule.round_robin != "") text += delim + "Round Robin" + eq + rule.round_robin;
96
// A Rule object also has a hidden format which will be used to help convert
97
// it into an Ele when user hits "Apply"
99
function hiddenFormat(rule)
103
var text = rule.rule_type + delim + rule.dest_ip + delim + rule.user + delim + rule.password + delim + rule.socks_servers + delim + rule.round_robin + delim;
108
// This function updates the selected Rule object with the values
109
// entered on the form.
111
function updateRule(index)
113
var sel = document.form1.rule_type.selectedIndex;
114
ruleList[index].rule_type = document.form1.rule_type.options[sel].value;
116
ruleList[index].user = document.form1.user.value;
117
ruleList[index].password = document.form1.password.value;
118
ruleList[index].dest_ip = document.form1.dest_ip.value;
119
ruleList[index].socks_servers = document.form1.socks_servers.value;
121
sel = document.form1.round_robin.selectedIndex;
122
ruleList[index].round_robin = document.form1.round_robin.options[sel].value;
126
// This function updates the elements on the form displayed to the
127
// user with the values sotred in the ruleList; has an optional index arg
129
function updateForm(index)
131
if (ruleList.length == 0)
135
index = document.form1.list1.selectedIndex;
139
for (i=0; i < document.form1.rule_type.length; i++) {
140
if (document.form1.rule_type.options[i].value == ruleList[index].rule_type)
141
document.form1.rule_type.selectedIndex = i;
144
document.form1.user.value = ruleList[index].user;
145
document.form1.password.value = ruleList[index].password;
146
document.form1.dest_ip.value = ruleList[index].dest_ip;
147
document.form1.socks_servers.value = ruleList[index].socks_servers;
149
for (i=0; i < document.form1.round_robin.length; i++) {
150
if (document.form1.round_robin.options[i].value == ruleList[index].round_robin)
151
document.form1.round_robin.selectedIndex = i;
156
// clears all the fields in the form
160
document.form1.rule_type.value = "no_socks";
161
document.form1.user.value = "";
162
document.form1.password.value = "";
163
document.form1.dest_ip.value = "";
164
document.form1.socks_servers.value = "";
165
document.form1.round_robin.value = "";
167
document.form1.list1.selectedIndex = -1;
171
// form validation - put detailed alert messages in this function
173
function validInput()
175
var rule_index = document.form1.rule_type.selectedIndex;
176
var rr_index = document.form1.round_robin.selectedIndex;
178
if (rule_index < 0 ) {
179
alert("Need to specify a 'Rule Type'");
183
var type = document.form1.rule_type.options[rule_index].value;
185
if (type == "no_socks") {
186
if (document.form1.dest_ip.value == "" ||
187
document.form1.user.value != "" ||
188
document.form1.password.value != "" ||
189
document.form1.socks_servers.value != "" ||
190
document.form1.round_robin.options[rr_index].value != "") {
191
alert("Only specify 'Destination IP'.");
194
} else if (type == "auth") {
195
if (document.form1.user.value == "" ||
196
document.form1.password.value == "" ||
197
document.form1.dest_ip.value != "" ||
198
document.form1.socks_servers.value != "" ||
199
document.form1.round_robin.options[rr_index].value != "") {
200
alert("Only specify 'Username' and 'Password'");
203
} else if (type == "multiple_socks") {
204
if (document.form1.dest_ip.value == "" ||
205
document.form1.socks_servers.value == "") {
206
alert("Need to specify 'Destination IP' and 'SOCKS Servers'");
209
if (document.form1.user.value != "" ||
210
document.form1.password.value != "") {
211
alert("Only specify 'Destination IP', 'SOCKS Servers', and/or 'Round Robin'");