OSDN Git Service

change function _ajax_alert_on -> show_alert_msg
[karesansui/karesansui.git] / karesansui / templates / default / hostby1firewall / hostby1firewall.part
1 <%doc>Copyright (C) 2009-2010 HDE, Inc.</%doc>
2 <%inherit file="../include/common.part" />
3 <script type="text/javascript">
4 <!--
5 // lib
6 function firewall_read_event(){
7     $("#init_firewall").one("click", function(){ 
8         ajax_put("${ctx.homepath}/host/${host_id}/firewall/status.part",
9             {"status" : FIREWALL_READ},
10             function(data, status){},
11             true,
12             "${ctx.homepath}${ctx.path}"
13         );
14     });
15 }
16
17 function firewall_start_event(){
18     $("#start_firewall").one("click", function(){ 
19         ajax_put("${ctx.homepath}/host/${host_id}/firewall/status.part",
20             {"status" : FIREWALL_STAR},
21             function(data, status){},
22             true,
23             "${ctx.homepath}${ctx.path}"
24         );
25     });
26 }
27
28 function firewall_stop_event(){
29     $("#stop_firewall").one("click", function(){ 
30         ajax_put("${ctx.homepath}/host/${host_id}/firewall/status.part",
31             {"status" : FIREWALL_STOP},
32             function(data, status){},
33             true,
34             "${ctx.homepath}${ctx.path}"
35         );
36     });
37 }
38
39 function firewall_restart_event(){
40     $("#esc_firewall").one("click", function(){ 
41         ajax_put("${ctx.homepath}/host/${host_id}/firewall/status.part",
42             {"status" : FIREWALL_RESTART},
43             function(data, status){},
44             true,
45             "${ctx.homepath}${ctx.path}"
46         );
47     });
48 }
49
50 function get_target_id(){
51     var target_id = null;
52     $("#firewall_tab td").each(function(){
53         if($(this).hasClass("firewall_active") == true){
54             target_id = $(this).attr("id");
55         }
56     });
57     return target_id;
58 }
59
60 function bind_add_event(){
61     $("#add_firewall").one("click.once", function() {
62         grayout_view("GET",
63             "${ctx.homepath}${ctx.path}?mode=input",
64             "${_('Add Rule')}",
65             "${ctx.homepath}${ctx.path}");
66     });
67 }
68
69 function bind_edit_event(){
70     $("#edit_firewall").one("click.once", function(){
71         var target_id = get_target_id();
72         var val = target_id.split("_");
73
74         var edit_url = null;
75         if(val[0] == "policy"){
76             edit_url = "${ctx.homepath}/host/${host_id}/firewall/policy.part?mode=input";
77         } else if(val[0] == "rule"){
78             target_id = selected_row("rule_row");
79             edit_url = "${ctx.homepath}/host/${host_id}/firewall/rule/" + target_id + ".part?mode=input";
80         } else {
81             show_alert_msg("${_('Please select a target.')}", "ERROR");
82         }
83
84         grayout_view("GET",
85             edit_url,
86             "${_('Firewall Settings')}",
87             "${ctx.homepath}/host/${host_id}/firewall.part");
88     });
89 }
90 function bind_delete_event(){
91     $("#delete_firewall").click(function(){
92         var target_id = get_target_id();
93         var val = target_id.split("_");
94         var delete_url = null;
95         if(val[0] == "rule"){
96             target_id = selected_row("rule_row");
97             delete_url = "${ctx.homepath}/host/${host_id}/firewall/rule/" + target_id + ".part";
98             var param = null;
99             delete_dialog("#firewall_dialog", delete_url, param, "${ctx.homepath}${ctx.path}", "#delete_firewall");
100         } else {
101             show_alert_msg("${_('Please select a target.')}", "ERROR");
102         }
103     });
104 }
105
106 // binding event it only once on each rule page.
107 function bind_rule_row_event(){
108     $("tr[id^='rule_row']").one("click.once", function(){
109         unbind_event();
110         bind_add_event();
111         tool_reset("#edit_firewall");
112         bind_edit_event();
113         tool_reset("#delete_firewall");
114         bind_delete_event();
115         $("tr[id^='rule_row']").unbind("click.once");
116     });
117 }
118
119 function unbind_event(){
120     $("#add_firewall").unbind("click.once");
121     $("#edit_firewall").unbind("click.once");
122     $("#delete_firewall").unbind("click");
123 }
124
125 $(document).ready(function(){
126     // init 
127     tool_invalid("#delete_firewall");
128     tool_invalid("#edit_firewall");
129     tool_invalid("#add_firewall");
130
131     $("#action>a").hover(
132         function(){tool_over(this);},
133         function(){tool_over(this);}
134     ).mousedown(function(){
135         var id = $(this).attr("id");
136         tool_active(this);
137     });
138
139     // event
140     $("#firewall_tab td").each(function(){
141         $(this).click(function(){
142             var target = $(this).attr("id");
143             var target_val = target.split("_");
144             
145             unbind_event();
146             switch(target_val[0]){
147                 case "policy":
148                     ajax_get("#firewall_value", 
149                         "${ctx.homepath}/host/${host_id}/firewall/policy.part",
150                         null);
151                     tool_reset("#edit_firewall");
152                     bind_edit_event();
153                     tool_invalid("#add_firewall");
154                     tool_invalid("#delete_firewall");
155                     break;
156                 case "rule":
157                     ajax_get("#firewall_value", 
158                         "${ctx.homepath}/host/${host_id}/firewall/rule.part",
159                         null,
160                         false);
161                     tool_invalid("#edit_firewall");
162                     tool_invalid("#delete_firewall");
163                     tool_reset("#add_firewall");
164                     bind_add_event();
165                     bind_rule_row_event();
166                     $('#tablesorter_pager img[name="pager_button"]').click(function(){
167                         bind_rule_row_event();
168                     });
169                     break;
170                 default:
171                     show_alert_msg("${_('Received an unexpected value.')}", "ERROR");
172             }
173             // icon active
174             $("#firewall_tab td").each(function(){
175                 if($(this).attr("id") != target){
176                     $(this).removeClass("firewall_active");
177                 } else {
178                     $(this).addClass("firewall_active");
179                 }
180             });
181         });
182     });
183     // fire wall control
184     firewall_read_event();
185     firewall_start_event();
186     firewall_stop_event();
187     firewall_restart_event();
188
189     renew_main_event("#tool_renew", "${ctx.homepath}${ctx.path}");
190 });
191 -->
192 </script>
193
194                     <div id="firewall_dialog"></div>
195                     <div id="action">
196                         <div class="left"></div>
197 % if have_config is True:
198
199 % if iptables.is_running is not True:
200                         <a href="#" name="start_firewall" id="start_firewall" class="tool-link">
201                             <div class="tool-mid">
202                                 <div class="tool-left"></div>
203                                 <div class="tool-img">
204                                     <img src="${ctx.homepath}/static/images/tool-start.png" alt="" />
205                                 </div>
206                                 <div class="tool-right">
207                                     <div class="tool-text" >${_('Start')}</div>
208                                 </div>
209                             </div>
210                         </a>
211 % else:
212                         <a href="#" name="stop_firewall" id="stop_firewall" class="tool-link">
213                             <div class="tool-mid">
214                                 <div class="tool-left"></div>
215                                 <div class="tool-img">
216                                     <img src="${ctx.homepath}/static/images/tool-stop.png" alt="" />
217                                 </div>
218                                 <div class="tool-right">
219                                     <div class="tool-text" >${_('Stop')}</div>
220                                 </div>
221                             </div>
222                         </a>
223                         <a href="#" name="esc_firewall" id="esc_firewall" class="tool-link">
224                             <div class="tool-mid">
225                                 <div class="tool-left"></div>
226                                 <div class="tool-img">
227                                     <img src="${ctx.homepath}/static/images/tool-restart.png" alt="" />
228                                 </div>
229                                 <div class="tool-right">
230                                     <div class="tool-text" >${_('Restart')}</div>
231                                 </div>
232                             </div>
233                         </a>
234 % endif
235                         <a href="#" name="add_firewall" id="add_firewall" class="tool-link">
236                             <div class="tool-mid">
237                                 <div class="tool-left"></div>
238                                 <div class="tool-img">
239                                     <img src="${ctx.homepath}/static/images/tool-add.png" alt="" />
240                                 </div>
241                                 <div class="tool-right">
242                                     <div class="tool-text" >${_('Add')}</div>
243                                 </div>
244                             </div>
245                         </a>
246
247                         <a href="#" name="edit_firewall" id="edit_firewall" class="tool-link">
248                             <div class="tool-mid">
249                                 <div class="tool-left"></div>
250                                 <div class="tool-img">
251                                     <img src="${ctx.homepath}/static/images/tool-edit.png" alt="" />
252                                 </div>
253                                 <div class="tool-right">
254                                     <div class="tool-text" >${_('Edit')}</div>
255                                 </div>
256                             </div>
257                         </a>
258                         <a href="#" name="delete_firewall" id="delete_firewall" class="tool-link">
259                             <div class="tool-mid">
260                                 <div class="tool-left"></div>
261                                 <div class="tool-img">
262                                     <img src="${ctx.homepath}/static/images/tool-trash.png" alt="" />
263                                 </div>
264                                 <div class="tool-right">
265                                     <div class="tool-text" >${_('Delete')}</div>
266                                 </div>
267                             </div>
268                         </a>
269 % else:
270                         <a href="#" name="init_firewall" id="init_firewall" class="tool-link">
271                             <div class="tool-mid">
272                                 <div class="tool-left"></div>
273                                 <div class="tool-img">
274                                     <img src="${ctx.homepath}/static/images/tool-refresh.png" alt="" />
275                                 </div>
276                                 <div class="tool-right">
277                                     <div class="tool-text" >${_('Initialize')}</div>
278                                 </div>
279                             </div>
280                         </a>
281 % endif
282                         <div class="right">
283                             <a href="#" class="tool-link" >
284                                 <div class="tool-mid">
285                                     <img src="${ctx.homepath}/static/images/reload.gif" alt="renew" id="tool_renew"/>
286                                 </div>
287                             </a>
288                         </div>
289                     </div>
290                     <br style="clear: both;"/>
291                     <div class="space"></div>
292                     <br style="clear: both;"/>
293                     <div class="alert"></div>
294                     <div id="view">
295                         <div id="result_message"></div>
296 <table width="100%" cellspacing="1" border="0" style="background-color:#bcbcbc;">
297     <tr>
298         <td style="background-color:#E4E4DD; padding:0px; text-align:left;" bgcolor="#FFFFFF" width="10%" valign="top">
299             <table id="firewall_tab" width="100%" cellspacing="0" border="0" style="background-color:#e4e4dd;">
300                 <tr>
301                     <td id="policy_" style="font-size:10px;" align="center">
302                         <img src="${ctx.homepath}/static/images/firewall-policy.png" alt=""><br />
303                         <span class="status">-&nbsp;Policy&nbsp;-</span>
304                     </td>
305                 </tr>
306                 <tr>
307                     <td id="rule_" style="font-size:10px;" align="center">
308                         <img src="${ctx.homepath}/static/images/firewall-rule.png" alt=""><br />
309                         <span class="status">-&nbsp;Rule&nbsp;-</span>
310                     </td>
311                 </tr>
312             </table>
313         </td>
314         <td bgcolor="#FFFFFF" valign="top" id="firewall_value" width="90%" style="padding:10px;">
315         ${_('Firewall Settings')}
316         </td>
317     </tr>
318 </table>
319                         </div>
320                     </div>
321                     <br style="clear: both;"/>