~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to proxy/mgmt2/html2/configure/f_socks_config.ink

  • Committer: Bazaar Package Importer
  • Author(s): Arno Toell
  • Date: 2011-01-13 11:49:18 UTC
  • Revision ID: james.westby@ubuntu.com-20110113114918-vu422h8dknrgkj15
Tags: upstream-2.1.5-unstable
ImportĀ upstreamĀ versionĀ 2.1.5-unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/////////////////////////////////////////////////////////////////////
 
2
// socks.config form and rule contains following:
 
3
//    Rule Type                 rule_type
 
4
// (INK_SOCKS_BYPASS rule type) 
 
5
//    Dest IP address list       dest_ip
 
6
// (INK_SOCKS_AUTH rule type)
 
7
//    Username                  user
 
8
//    Password                  password
 
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
 
14
//
 
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
 
22
//
 
23
//      http://www.apache.org/licenses/LICENSE-2.0
 
24
//
 
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
/////////////////////////////////////////////////////////////////////
 
31
 
 
32
// 
 
33
// creates a new Rule object; initializes with parameters passed in
 
34
//
 
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;
 
38
 this.user = user;
 
39
 this.password = password;
 
40
 this.socks_servers = socks_servers;
 
41
 this.round_robin = round_robin;
 
42
}
 
43
 
 
44
// 
 
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
 
50
// 
 
51
function createRuleFromForm() {
 
52
  var index = document.form1.rule_type.selectedIndex;
 
53
  var rule_type = document.form1.rule_type.options[index].value;
 
54
 
 
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;
 
59
 
 
60
  index = document.form1.round_robin.selectedIndex;
 
61
  var round_robin = document.form1.round_robin.options[index].value;
 
62
 
 
63
  var rule = new Rule(rule_type, dest_ip, user, password, socks_servers, round_robin);
 
64
 
 
65
  return rule;
 
66
}
 
67
 
 
68
//
 
69
// This function displays the Rule object's information in the format
 
70
// that's used in the select list.
 
71
//
 
72
function textFormat(rule, write)
 
73
{
 
74
  var text = "";
 
75
  var delim = "";
 
76
  var eq = "=";  
 
77
  var space = "";
 
78
  if (write == 1) {
 
79
     space = "  ";
 
80
  } else {  
 
81
     space = "  ";
 
82
  }
 
83
  delim = space + "," + space;
 
84
 
 
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; 
 
91
 
 
92
  return text;
 
93
}
 
94
 
 
95
//
 
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"
 
98
// 
 
99
function hiddenFormat(rule)
 
100
{
 
101
  var delim = "^";
 
102
 
 
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; 
 
104
  return text; 
 
105
}
 
106
 
 
107
// 
 
108
// This function updates the selected Rule object with the values 
 
109
// entered on the form. 
 
110
// 
 
111
function updateRule(index) 
 
112
{
 
113
  var sel = document.form1.rule_type.selectedIndex; 
 
114
  ruleList[index].rule_type =  document.form1.rule_type.options[sel].value;
 
115
 
 
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;
 
120
 
 
121
  sel = document.form1.round_robin.selectedIndex; 
 
122
  ruleList[index].round_robin = document.form1.round_robin.options[sel].value;
 
123
}
 
124
 
 
125
// 
 
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
 
128
//
 
129
function updateForm(index)
 
130
 
131
  if (ruleList.length == 0) 
 
132
        return; 
 
133
        
 
134
  if (index == -1)      
 
135
    index = document.form1.list1.selectedIndex;
 
136
 
 
137
  var i;
 
138
 
 
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;
 
142
  }
 
143
 
 
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;
 
148
 
 
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;
 
152
  }
 
153
}
 
154
 
 
155
// 
 
156
// clears all the fields in the form
 
157
// 
 
158
function clearForm() 
 
159
{
 
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 = "";
 
166
 
 
167
  document.form1.list1.selectedIndex = -1;      
 
168
}
 
169
 
 
170
// 
 
171
// form validation - put detailed alert messages in this function
 
172
//
 
173
function validInput()
 
174
{
 
175
  var rule_index = document.form1.rule_type.selectedIndex;
 
176
  var rr_index = document.form1.round_robin.selectedIndex;
 
177
 
 
178
  if (rule_index < 0 ) {
 
179
        alert("Need to specify a 'Rule Type'");
 
180
        return false;
 
181
  }
 
182
 
 
183
  var type = document.form1.rule_type.options[rule_index].value;
 
184
 
 
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'."); 
 
192
           return false;
 
193
     }
 
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'"); 
 
201
           return false;
 
202
     }
 
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'"); 
 
207
           return false;
 
208
    }
 
209
    if (document.form1.user.value != "" ||
 
210
        document.form1.password.value != "") {
 
211
           alert("Only specify 'Destination IP', 'SOCKS Servers', and/or 'Round Robin'"); 
 
212
           return false;
 
213
     }
 
214
  }
 
215
 
 
216
  return true;          
 
217
}