3 * HTTP Info plugin for the olsr.org OLSR daemon
4 * Copyright (c) 2004, Andreas Tønnesen(andreto@olsr.org)
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of olsr.org, olsrd nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
34 * Visit http://www.olsr.org for more information.
36 * If you find this software useful feel free to make a donation
37 * to the project. For more information see the website or contact
38 * the copyright holders.
40 * $Id: admin_interface.c,v 1.6 2005/05/29 12:47:41 br1 Exp $
44 * Dynamic linked library for the olsr.org olsr daemon
48 #include "olsrd_httpinfo.h"
50 #include "admin_html.h"
51 #include "admin_interface.h"
57 build_admin_body(char *buf, olsr_u32_t bufsize)
61 while(admin_frame[i] && strcmp(admin_frame[i], "<!-- BASICSETTINGS -->\n"))
63 size += sprintf(&buf[size], admin_frame[i]);
71 size += sprintf(&buf[size], "<tr>\n");
73 size += sprintf(&buf[size], admin_basic_setting_int,
74 "Debug level:", "debug_level", 2, olsr_cnf->debug_level);
75 size += sprintf(&buf[size], admin_basic_setting_float,
76 "Pollrate:", "pollrate", 4, olsr_cnf->pollrate);
77 size += sprintf(&buf[size], admin_basic_setting_string,
78 "TOS:", "tos", 6, "TBD");
80 size += sprintf(&buf[size], "</tr>\n");
81 size += sprintf(&buf[size], "<tr>\n");
83 size += sprintf(&buf[size], admin_basic_setting_int,
84 "TC redundancy:", "tc_redundancy", 1, olsr_cnf->tc_redundancy);
85 size += sprintf(&buf[size], admin_basic_setting_int,
86 "MPR coverage:", "mpr_coverage", 1, olsr_cnf->mpr_coverage);
87 size += sprintf(&buf[size], admin_basic_setting_int,
88 "Willingness:", "willingness", 1, olsr_cnf->willingness);
90 size += sprintf(&buf[size], "</tr>\n");
91 size += sprintf(&buf[size], "<tr>\n");
93 if(olsr_cnf->use_hysteresis)
95 size += sprintf(&buf[size], admin_basic_setting_float,
96 "Hyst scaling:", "hyst_scaling", 4, olsr_cnf->hysteresis_param.scaling);
98 size += sprintf(&buf[size], admin_basic_setting_float,
99 "Lower thr:", "hyst_lower", 4, olsr_cnf->hysteresis_param.thr_low);
100 size += sprintf(&buf[size], admin_basic_setting_float,
101 "Upper thr:", "hyst_upper", 4, olsr_cnf->hysteresis_param.thr_high);
105 size += sprintf(&buf[size], "<td>Hysteresis disabled</td>\n");
108 size += sprintf(&buf[size], "</tr>\n");
109 size += sprintf(&buf[size], "<tr>\n");
111 if(olsr_cnf->lq_level)
113 size += sprintf(&buf[size], admin_basic_setting_int,
114 "LQ level:", "lq_level", 1, olsr_cnf->lq_level);
115 size += sprintf(&buf[size], admin_basic_setting_int,
116 "LQ winsize:", "lq_wsize", 2, olsr_cnf->lq_wsize);
120 size += sprintf(&buf[size], "<td>LQ disabled</td>\n");
124 size += sprintf(&buf[size], "</tr>\n");
125 size += sprintf(&buf[size], "<tr>\n");
127 size += sprintf(&buf[size], "</tr>\n");
131 while(admin_frame[i] && strcmp(admin_frame[i], "<!-- HNAENTRIES -->\n"))
133 size += sprintf(&buf[size], admin_frame[i]);
137 if(!admin_frame[i] || !admin_frame[i+1])
142 if((olsr_cnf->ip_version == AF_INET) && (olsr_cnf->hna4_entries))
144 struct hna4_entry *hna4;
146 for(hna4 = olsr_cnf->hna4_entries; hna4; hna4 = hna4->next)
148 size += sprintf(&buf[size], admin_frame[i],
149 olsr_ip_to_string((union olsr_ip_addr *)&hna4->net),
150 olsr_ip_to_string((union olsr_ip_addr *)&hna4->netmask),
151 olsr_ip_to_string((union olsr_ip_addr *)&hna4->net),
152 olsr_ip_to_string((union olsr_ip_addr *)&hna4->netmask));
155 else if((olsr_cnf->ip_version == AF_INET6) && (olsr_cnf->hna6_entries))
157 struct hna6_entry *hna6;
159 for(hna6 = olsr_cnf->hna6_entries; hna6; hna6 = hna6->next)
161 size += sprintf(&buf[size], admin_frame[i],
162 olsr_ip_to_string((union olsr_ip_addr *)&hna6->net),
163 "TBD"/*hna6->prefix_len*/);
169 while(admin_frame[i])
171 size += sprintf(&buf[size], admin_frame[i]);
179 #ifdef ADMIN_INTERFACE
182 process_param(char *key, char *value)
184 static olsr_u32_t curr_hna_net;
185 static olsr_bool curr_hna_ok = OLSR_FALSE;
187 if(!strcmp(key, "debug_level"))
189 int ival = atoi(value);
190 if((ival < 0) || (ival > 9))
193 olsr_cnf->debug_level = ival;
197 if(!strcmp(key, "tc_redundancy"))
199 int ival = atoi(value);
200 if((ival < 0) || (ival > 3))
203 olsr_cnf->tc_redundancy = ival;
207 if(!strcmp(key, "mpr_coverage"))
209 int ival = atoi(value);
213 olsr_cnf->mpr_coverage = ival;
217 if(!strcmp(key, "willingness"))
219 int ival = atoi(value);
220 if((ival < 0) || (ival > 7))
223 olsr_cnf->willingness = ival;
227 if(!strcmp(key, "lq_level"))
229 int ival = atoi(value);
230 if((ival < 0) || (ival > 2))
233 olsr_cnf->lq_level = ival;
237 if(!strcmp(key, "lq_wsize"))
239 int ival = atoi(value);
240 if((ival < 0) || (ival > 10))
243 olsr_cnf->lq_wsize = ival;
247 if(!strcmp(key, "hyst_scaling"))
250 sscanf(value, "%f", &fval);
251 if((fval < 0.0) || (fval > 1.0))
254 printf("HYST SCALING: %f\n", fval);
255 olsr_cnf->hysteresis_param.scaling = fval;
259 if(!strcmp(key, "hyst_scaling"))
262 sscanf(value, "%f", &fval);
263 if((fval < 0.0) || (fval > 1.0))
266 olsr_cnf->hysteresis_param.scaling = fval;
270 if(!strcmp(key, "hyst_lower"))
273 sscanf(value, "%f", &fval);
274 if((fval < 0.0) || (fval > 1.0))
277 olsr_cnf->hysteresis_param.thr_low = fval;
281 if(!strcmp(key, "hyst_upper"))
284 sscanf(value, "%f", &fval);
285 if((fval < 0.0) || (fval > 1.0))
288 olsr_cnf->hysteresis_param.thr_high = fval;
292 if(!strcmp(key, "pollrate"))
295 sscanf(value, "%f", &fval);
296 if((fval < 0.0) || (fval > 1.0))
299 olsr_cnf->pollrate = fval;
304 if(!strcmp(key, "hna_new_net"))
308 if(inet_aton(value, &in) == 0)
310 fprintf(stderr, "Failed converting new HNA net %s\n", value);
313 curr_hna_ok = OLSR_TRUE;
314 curr_hna_net = in.s_addr;
318 if(!strcmp(key, "hna_new_netmask"))
325 curr_hna_ok = OLSR_FALSE;
327 if(inet_aton(value, &in) == 0)
329 fprintf(stderr, "Failed converting new HNA netmask %s\n", value);
332 add_local_hna4_entry((union olsr_ip_addr *)&curr_hna_net,
333 (union hna_netmask *)&in.s_addr);
338 if(!strncmp(key, "del_hna", 7) && !strcmp(value, "on"))
340 struct in_addr net, mask;
341 char ip_net[16], ip_mask[16];
344 while(key[7 + seperator] != '*')
347 strncpy(ip_net, &key[7], seperator);
348 ip_net[seperator] = 0;
349 strncpy(ip_mask, &key[7 + seperator + 1], 16);
350 olsr_printf(1, "Deleting HNA %s/%s\n", ip_net, ip_mask);
352 if(inet_aton(ip_net, &net) == 0)
354 fprintf(stderr, "Failed converting HNA net %s for deletion\n", ip_net);
358 if(inet_aton(ip_mask, &mask) == 0)
360 fprintf(stderr, "Failed converting HNA netmask %s for deletion\n", ip_mask);
364 remove_local_hna4_entry((union olsr_ip_addr *)&net.s_addr,
365 (union hna_netmask *)&mask.s_addr);
372 { 1, admin_basic_setting_string, "TOS:", "tos", 6, "TBD" },
377 process_set_values(char *data, olsr_u32_t data_size, char *buf, olsr_u32_t bufsize)
380 int i, val_start, key_start;
382 printf("Dynamic Data: %s\n", data);
384 size += sprintf(buf, "<html>\n<head><title>olsr.org httpinfo plugin</title></head>\n<body>\n");
389 for(i = 0; i < data_size; i++)
400 if(!process_param(&data[key_start], &data[val_start]))
402 size += sprintf(&buf[size], "<h2>FAILED PROCESSING!</h2><br>Key: %s Value: %s<br>\n",
403 &data[key_start], &data[val_start]);
407 printf("Key: %s\nValue: %s\n",
408 &data[key_start], &data[val_start]);
413 if(!process_param(&data[key_start], &data[val_start]))
415 size += sprintf(&buf[size], "<b>FAILED PROCESSING!</b><br>Key: %s Value: %s<br>\n",
416 &data[key_start], &data[val_start]);
420 printf("Key: %s\nValue: %s\n",
421 &data[key_start], &data[val_start]);
423 size += sprintf(&buf[size], "<h2>UPDATE SUCESSFULL!</h2><br>Press BACK and RELOAD in your browser to return to the plugin<br>\n</body>\n</html>\n");
424 size += sprintf(&buf[size], "\n</body>\n</html>\n");