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.7 2006/09/18 18:55:30 kattemat 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"
56 extern int netsprintf(char *str, const char* format, ...);
57 #define sprintf netsprintf
61 build_admin_body(char *buf, olsr_u32_t bufsize)
65 while(admin_frame[i] && strcmp(admin_frame[i], "<!-- BASICSETTINGS -->\n"))
67 size += sprintf(&buf[size], admin_frame[i]);
75 size += sprintf(&buf[size], "<tr>\n");
77 size += sprintf(&buf[size], admin_basic_setting_int,
78 "Debug level:", "debug_level", 2, olsr_cnf->debug_level);
79 size += sprintf(&buf[size], admin_basic_setting_float,
80 "Pollrate:", "pollrate", 4, olsr_cnf->pollrate);
81 size += sprintf(&buf[size], admin_basic_setting_string,
82 "TOS:", "tos", 6, "TBD");
84 size += sprintf(&buf[size], "</tr>\n");
85 size += sprintf(&buf[size], "<tr>\n");
87 size += sprintf(&buf[size], admin_basic_setting_int,
88 "TC redundancy:", "tc_redundancy", 1, olsr_cnf->tc_redundancy);
89 size += sprintf(&buf[size], admin_basic_setting_int,
90 "MPR coverage:", "mpr_coverage", 1, olsr_cnf->mpr_coverage);
91 size += sprintf(&buf[size], admin_basic_setting_int,
92 "Willingness:", "willingness", 1, olsr_cnf->willingness);
94 size += sprintf(&buf[size], "</tr>\n");
95 size += sprintf(&buf[size], "<tr>\n");
97 if(olsr_cnf->use_hysteresis)
99 size += sprintf(&buf[size], admin_basic_setting_float,
100 "Hyst scaling:", "hyst_scaling", 4, olsr_cnf->hysteresis_param.scaling);
102 size += sprintf(&buf[size], admin_basic_setting_float,
103 "Lower thr:", "hyst_lower", 4, olsr_cnf->hysteresis_param.thr_low);
104 size += sprintf(&buf[size], admin_basic_setting_float,
105 "Upper thr:", "hyst_upper", 4, olsr_cnf->hysteresis_param.thr_high);
109 size += sprintf(&buf[size], "<td>Hysteresis disabled</td>\n");
112 size += sprintf(&buf[size], "</tr>\n");
113 size += sprintf(&buf[size], "<tr>\n");
115 if(olsr_cnf->lq_level)
117 size += sprintf(&buf[size], admin_basic_setting_int,
118 "LQ level:", "lq_level", 1, olsr_cnf->lq_level);
119 size += sprintf(&buf[size], admin_basic_setting_int,
120 "LQ winsize:", "lq_wsize", 2, olsr_cnf->lq_wsize);
124 size += sprintf(&buf[size], "<td>LQ disabled</td>\n");
128 size += sprintf(&buf[size], "</tr>\n");
129 size += sprintf(&buf[size], "<tr>\n");
131 size += sprintf(&buf[size], "</tr>\n");
135 while(admin_frame[i] && strcmp(admin_frame[i], "<!-- HNAENTRIES -->\n"))
137 size += sprintf(&buf[size], admin_frame[i]);
141 if(!admin_frame[i] || !admin_frame[i+1])
146 if((olsr_cnf->ip_version == AF_INET) && (olsr_cnf->hna4_entries))
148 struct hna4_entry *hna4;
150 for(hna4 = olsr_cnf->hna4_entries; hna4; hna4 = hna4->next)
152 size += sprintf(&buf[size], admin_frame[i],
153 olsr_ip_to_string((union olsr_ip_addr *)&hna4->net),
154 olsr_ip_to_string((union olsr_ip_addr *)&hna4->netmask),
155 olsr_ip_to_string((union olsr_ip_addr *)&hna4->net),
156 olsr_ip_to_string((union olsr_ip_addr *)&hna4->netmask));
159 else if((olsr_cnf->ip_version == AF_INET6) && (olsr_cnf->hna6_entries))
161 struct hna6_entry *hna6;
163 for(hna6 = olsr_cnf->hna6_entries; hna6; hna6 = hna6->next)
165 size += sprintf(&buf[size], admin_frame[i],
166 olsr_ip_to_string((union olsr_ip_addr *)&hna6->net),
167 "TBD"/*hna6->prefix_len*/);
173 while(admin_frame[i])
175 size += sprintf(&buf[size], admin_frame[i]);
183 #ifdef ADMIN_INTERFACE
186 process_param(char *key, char *value)
188 static olsr_u32_t curr_hna_net;
189 static olsr_bool curr_hna_ok = OLSR_FALSE;
191 if(!strcmp(key, "debug_level"))
193 int ival = atoi(value);
194 if((ival < 0) || (ival > 9))
197 olsr_cnf->debug_level = ival;
201 if(!strcmp(key, "tc_redundancy"))
203 int ival = atoi(value);
204 if((ival < 0) || (ival > 3))
207 olsr_cnf->tc_redundancy = ival;
211 if(!strcmp(key, "mpr_coverage"))
213 int ival = atoi(value);
217 olsr_cnf->mpr_coverage = ival;
221 if(!strcmp(key, "willingness"))
223 int ival = atoi(value);
224 if((ival < 0) || (ival > 7))
227 olsr_cnf->willingness = ival;
231 if(!strcmp(key, "lq_level"))
233 int ival = atoi(value);
234 if((ival < 0) || (ival > 2))
237 olsr_cnf->lq_level = ival;
241 if(!strcmp(key, "lq_wsize"))
243 int ival = atoi(value);
244 if((ival < 0) || (ival > 10))
247 olsr_cnf->lq_wsize = ival;
251 if(!strcmp(key, "hyst_scaling"))
254 sscanf(value, "%f", &fval);
255 if((fval < 0.0) || (fval > 1.0))
258 printf("HYST SCALING: %f\n", fval);
259 olsr_cnf->hysteresis_param.scaling = fval;
263 if(!strcmp(key, "hyst_scaling"))
266 sscanf(value, "%f", &fval);
267 if((fval < 0.0) || (fval > 1.0))
270 olsr_cnf->hysteresis_param.scaling = fval;
274 if(!strcmp(key, "hyst_lower"))
277 sscanf(value, "%f", &fval);
278 if((fval < 0.0) || (fval > 1.0))
281 olsr_cnf->hysteresis_param.thr_low = fval;
285 if(!strcmp(key, "hyst_upper"))
288 sscanf(value, "%f", &fval);
289 if((fval < 0.0) || (fval > 1.0))
292 olsr_cnf->hysteresis_param.thr_high = fval;
296 if(!strcmp(key, "pollrate"))
299 sscanf(value, "%f", &fval);
300 if((fval < 0.0) || (fval > 1.0))
303 olsr_cnf->pollrate = fval;
308 if(!strcmp(key, "hna_new_net"))
312 if(inet_aton(value, &in) == 0)
314 fprintf(stderr, "Failed converting new HNA net %s\n", value);
317 curr_hna_ok = OLSR_TRUE;
318 curr_hna_net = in.s_addr;
322 if(!strcmp(key, "hna_new_netmask"))
329 curr_hna_ok = OLSR_FALSE;
331 if(inet_aton(value, &in) == 0)
333 fprintf(stderr, "Failed converting new HNA netmask %s\n", value);
336 add_local_hna4_entry((union olsr_ip_addr *)&curr_hna_net,
337 (union hna_netmask *)&in.s_addr);
342 if(!strncmp(key, "del_hna", 7) && !strcmp(value, "on"))
344 struct in_addr net, mask;
345 char ip_net[16], ip_mask[16];
348 while(key[7 + seperator] != '*')
351 strncpy(ip_net, &key[7], seperator);
352 ip_net[seperator] = 0;
353 strncpy(ip_mask, &key[7 + seperator + 1], 16);
354 olsr_printf(1, "Deleting HNA %s/%s\n", ip_net, ip_mask);
356 if(inet_aton(ip_net, &net) == 0)
358 fprintf(stderr, "Failed converting HNA net %s for deletion\n", ip_net);
362 if(inet_aton(ip_mask, &mask) == 0)
364 fprintf(stderr, "Failed converting HNA netmask %s for deletion\n", ip_mask);
368 remove_local_hna4_entry((union olsr_ip_addr *)&net.s_addr,
369 (union hna_netmask *)&mask.s_addr);
376 { 1, admin_basic_setting_string, "TOS:", "tos", 6, "TBD" },
381 process_set_values(char *data, olsr_u32_t data_size, char *buf, olsr_u32_t bufsize)
384 int i, val_start, key_start;
386 printf("Dynamic Data: %s\n", data);
388 size += sprintf(buf, "<html>\n<head><title>olsr.org httpinfo plugin</title></head>\n<body>\n");
393 for(i = 0; i < data_size; i++)
404 if(!process_param(&data[key_start], &data[val_start]))
406 size += sprintf(&buf[size], "<h2>FAILED PROCESSING!</h2><br>Key: %s Value: %s<br>\n",
407 &data[key_start], &data[val_start]);
411 printf("Key: %s\nValue: %s\n",
412 &data[key_start], &data[val_start]);
417 if(!process_param(&data[key_start], &data[val_start]))
419 size += sprintf(&buf[size], "<b>FAILED PROCESSING!</b><br>Key: %s Value: %s<br>\n",
420 &data[key_start], &data[val_start]);
424 printf("Key: %s\nValue: %s\n",
425 &data[key_start], &data[val_start]);
427 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");
428 size += sprintf(&buf[size], "\n</body>\n</html>\n");