| 1 | #include <stdio.h> |
|---|
| 2 | #include <stdlib.h> |
|---|
| 3 | #include <string.h> |
|---|
| 4 | #include <sys/types.h> |
|---|
| 5 | #include <netinet/in.h> |
|---|
| 6 | #include <arpa/inet.h> |
|---|
| 7 | #include <net/route.h> |
|---|
| 8 | |
|---|
| 9 | #include <broadcom.h> |
|---|
| 10 | |
|---|
| 11 | void |
|---|
| 12 | ej_exec_milkfish_service (webs_t wp, int argc, char_t ** argv) |
|---|
| 13 | { |
|---|
| 14 | |
|---|
| 15 | FILE *fp; |
|---|
| 16 | char line[254]; |
|---|
| 17 | char *request; |
|---|
| 18 | |
|---|
| 19 | #ifdef FASTWEB |
|---|
| 20 | ejArgs (argc, argv, "%s", &request); |
|---|
| 21 | #else |
|---|
| 22 | if (ejArgs (argc, argv, "%s", &request) < 1) |
|---|
| 23 | { |
|---|
| 24 | websError (wp, 400, "Insufficient args\n"); |
|---|
| 25 | } |
|---|
| 26 | #endif |
|---|
| 27 | |
|---|
| 28 | if ((fp = popen (request, "r"))) |
|---|
| 29 | { |
|---|
| 30 | while (fgets (line, sizeof (line), fp) != NULL) |
|---|
| 31 | { |
|---|
| 32 | websWrite (wp, line); |
|---|
| 33 | websWrite (wp, "<br>"); |
|---|
| 34 | } |
|---|
| 35 | pclose (fp); |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | return; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | void |
|---|
| 42 | ej_exec_milkfish_phonebook (webs_t wp, int argc, char_t ** argv) |
|---|
| 43 | { |
|---|
| 44 | |
|---|
| 45 | FILE *fp; |
|---|
| 46 | char line[254]; |
|---|
| 47 | char *request; |
|---|
| 48 | |
|---|
| 49 | #ifdef FASTWEB |
|---|
| 50 | ejArgs (argc, argv, "%s", &request); |
|---|
| 51 | #else |
|---|
| 52 | if (ejArgs (argc, argv, "%s", &request) < 1) |
|---|
| 53 | { |
|---|
| 54 | websError (wp, 400, "Insufficient args\n"); |
|---|
| 55 | } |
|---|
| 56 | #endif |
|---|
| 57 | |
|---|
| 58 | if ((fp = popen (request, "r"))) |
|---|
| 59 | { |
|---|
| 60 | while (fgets (line, sizeof (line), fp) != NULL) |
|---|
| 61 | { |
|---|
| 62 | websWrite (wp, line); |
|---|
| 63 | } |
|---|
| 64 | pclose (fp); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | return; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | void |
|---|
| 72 | validate_subscribers (webs_t wp, char *value, struct variable *v) |
|---|
| 73 | { |
|---|
| 74 | |
|---|
| 75 | int i, error = 0; |
|---|
| 76 | char *buf, *cur; |
|---|
| 77 | int count, sof; |
|---|
| 78 | struct variable subscriber_variables[] = { |
|---|
| 79 | {argv:ARGV ("30")}, |
|---|
| 80 | {argv:ARGV ("30")}, |
|---|
| 81 | {NULL}, |
|---|
| 82 | }, *which; |
|---|
| 83 | buf = nvram_safe_get ("milkfish_ddsubscribersnum"); |
|---|
| 84 | if (buf == NULL || strlen (buf) == 0) |
|---|
| 85 | return; |
|---|
| 86 | count = atoi (buf); |
|---|
| 87 | sof = (count * 128) + 1; |
|---|
| 88 | buf = (char *) malloc (sof); |
|---|
| 89 | cur = buf; |
|---|
| 90 | buf[0] = 0; |
|---|
| 91 | |
|---|
| 92 | for (i = 0; i < count; i++) |
|---|
| 93 | { |
|---|
| 94 | |
|---|
| 95 | char subscriber_user[] = "userXXX"; |
|---|
| 96 | char subscriber_pass[] = "passXXX"; |
|---|
| 97 | char *user = "", new_user[200] = "", *pass = "", new_pass[200] = |
|---|
| 98 | ""; |
|---|
| 99 | |
|---|
| 100 | snprintf (subscriber_user, sizeof (subscriber_user), "user%d", i); |
|---|
| 101 | snprintf (subscriber_pass, sizeof (subscriber_pass), "pass%d", i); |
|---|
| 102 | |
|---|
| 103 | user = websGetVar (wp, subscriber_user, ""); |
|---|
| 104 | pass = websGetVar (wp, subscriber_pass, ""); |
|---|
| 105 | |
|---|
| 106 | which = &subscriber_variables[0]; |
|---|
| 107 | if (strcmp (user, "")) |
|---|
| 108 | { |
|---|
| 109 | if (!valid_name (wp, user, &which[0])) |
|---|
| 110 | { |
|---|
| 111 | error_value = 1; |
|---|
| 112 | continue; |
|---|
| 113 | } |
|---|
| 114 | else |
|---|
| 115 | { |
|---|
| 116 | httpd_filter_name (user, new_user, sizeof (new_user), SET); |
|---|
| 117 | } |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | if (strcmp (pass, "")) |
|---|
| 121 | { |
|---|
| 122 | if (!valid_name (wp, pass, &which[1])) |
|---|
| 123 | { |
|---|
| 124 | error_value = 1; |
|---|
| 125 | continue; |
|---|
| 126 | } |
|---|
| 127 | else |
|---|
| 128 | { |
|---|
| 129 | httpd_filter_name (pass, new_pass, sizeof (new_pass), SET); |
|---|
| 130 | } |
|---|
| 131 | } |
|---|
| 132 | cur += snprintf (cur, buf + sof - cur, "%s%s:%s", |
|---|
| 133 | cur == buf ? "" : " ", new_user, new_pass); |
|---|
| 134 | |
|---|
| 135 | } |
|---|
| 136 | if (!error) |
|---|
| 137 | nvram_set (v->name, buf); |
|---|
| 138 | free (buf); |
|---|
| 139 | |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | void |
|---|
| 144 | show_subscriber_table (webs_t wp, char *type, int which) |
|---|
| 145 | { |
|---|
| 146 | |
|---|
| 147 | static char word[256]; |
|---|
| 148 | char *next, *wordlist; |
|---|
| 149 | char *user, *pass; |
|---|
| 150 | static char new_user[200], new_pass[200]; |
|---|
| 151 | int temp; |
|---|
| 152 | wordlist = nvram_safe_get ("milkfish_ddsubscribers"); |
|---|
| 153 | temp = which; |
|---|
| 154 | |
|---|
| 155 | foreach (word, wordlist, next) |
|---|
| 156 | { |
|---|
| 157 | if (which-- == 0) |
|---|
| 158 | { |
|---|
| 159 | pass = word; |
|---|
| 160 | user = strsep (&pass, ":"); |
|---|
| 161 | if (!user || !pass) |
|---|
| 162 | continue; |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | if (!strcmp (type, "user")) |
|---|
| 166 | { |
|---|
| 167 | httpd_filter_name (user, new_user, sizeof (new_user), GET); |
|---|
| 168 | websWrite (wp, "%s", new_user); |
|---|
| 169 | } |
|---|
| 170 | else if (!strcmp (type, "pass")) |
|---|
| 171 | { |
|---|
| 172 | httpd_filter_name (pass, new_pass, sizeof (new_pass), GET); |
|---|
| 173 | websWrite (wp, "%s", new_pass); |
|---|
| 174 | } |
|---|
| 175 | return; |
|---|
| 176 | } |
|---|
| 177 | } |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | void |
|---|
| 184 | ej_show_subscribers (webs_t wp, int argc, char_t ** argv) |
|---|
| 185 | { |
|---|
| 186 | int i; |
|---|
| 187 | char *count; |
|---|
| 188 | int c; |
|---|
| 189 | |
|---|
| 190 | count = nvram_safe_get ("milkfish_ddsubscribersnum"); |
|---|
| 191 | if (count == NULL || strlen (count) == 0 || (c=atoi(count))<=0) |
|---|
| 192 | { |
|---|
| 193 | websWrite (wp, "<tr>\n"); |
|---|
| 194 | websWrite (wp, |
|---|
| 195 | "<td colspan=\"4\" align=\"center\" valign=\"middle\">- <script type=\"text/javascript\">Capture(share.none)</script> -</td>\n"); |
|---|
| 196 | websWrite (wp, "</tr>\n"); |
|---|
| 197 | } |
|---|
| 198 | for (i = 0; i < c; i++) |
|---|
| 199 | { |
|---|
| 200 | websWrite (wp, "<tr><td>\n"); |
|---|
| 201 | websWrite (wp, "<input maxlength=\"30\" size=\"30\" name=\"user%d\" onblur=\"valid_name(this,'Name')\" value=\"",i); |
|---|
| 202 | show_subscriber_table (wp, "user", i); |
|---|
| 203 | websWrite (wp, "\" /></td>\n"); |
|---|
| 204 | websWrite (wp, "<td>\n"); |
|---|
| 205 | websWrite (wp, "<input maxlength=\"30\" size=\"30\" name=\"pass%d\" onblur=\"valid_name(this,'Name')\" value=\"",i); |
|---|
| 206 | show_subscriber_table (wp, "pass", i); |
|---|
| 207 | websWrite (wp, "\" /></td>\n"); |
|---|
| 208 | websWrite (wp, "</tr>\n"); |
|---|
| 209 | } |
|---|
| 210 | return; |
|---|
| 211 | } |
|---|
| 212 | |
|---|
| 213 | void |
|---|
| 214 | validate_aliases (webs_t wp, char *value, struct variable *v) |
|---|
| 215 | { |
|---|
| 216 | |
|---|
| 217 | int i, error = 0; |
|---|
| 218 | char *buf, *cur; |
|---|
| 219 | int count, sof; |
|---|
| 220 | struct variable alias_variables[] = { |
|---|
| 221 | {argv:ARGV ("30")}, |
|---|
| 222 | {argv:ARGV ("30")}, |
|---|
| 223 | {NULL}, |
|---|
| 224 | }, *which; |
|---|
| 225 | buf = nvram_safe_get ("milkfish_ddaliasesnum"); |
|---|
| 226 | if (buf == NULL || strlen (buf) == 0) |
|---|
| 227 | return; |
|---|
| 228 | count = atoi (buf); |
|---|
| 229 | sof = (count * 128) + 1; |
|---|
| 230 | buf = (char *) malloc (sof); |
|---|
| 231 | cur = buf; |
|---|
| 232 | buf[0] = 0; |
|---|
| 233 | |
|---|
| 234 | for (i = 0; i < count; i++) |
|---|
| 235 | { |
|---|
| 236 | |
|---|
| 237 | char alias_user[] = "userXXX"; |
|---|
| 238 | char alias_pass[] = "passXXX"; |
|---|
| 239 | char *user = "", new_user[200] = "", *pass = "", new_pass[200] = |
|---|
| 240 | ""; |
|---|
| 241 | |
|---|
| 242 | snprintf (alias_user, sizeof (alias_user), "user%d", i); |
|---|
| 243 | snprintf (alias_pass, sizeof (alias_pass), "pass%d", i); |
|---|
| 244 | |
|---|
| 245 | user = websGetVar (wp, alias_user, ""); |
|---|
| 246 | pass = websGetVar (wp, alias_pass, ""); |
|---|
| 247 | |
|---|
| 248 | which = &alias_variables[0]; |
|---|
| 249 | if (strcmp (user, "")) |
|---|
| 250 | { |
|---|
| 251 | if (!valid_name (wp, user, &which[0])) |
|---|
| 252 | { |
|---|
| 253 | error_value = 1; |
|---|
| 254 | continue; |
|---|
| 255 | } |
|---|
| 256 | else |
|---|
| 257 | { |
|---|
| 258 | httpd_filter_name (user, new_user, sizeof (new_user), SET); |
|---|
| 259 | } |
|---|
| 260 | } |
|---|
| 261 | |
|---|
| 262 | if (strcmp (pass, "")) |
|---|
| 263 | { |
|---|
| 264 | if (!valid_name (wp, pass, &which[1])) |
|---|
| 265 | { |
|---|
| 266 | error_value = 1; |
|---|
| 267 | continue; |
|---|
| 268 | } |
|---|
| 269 | else |
|---|
| 270 | { |
|---|
| 271 | httpd_filter_name (pass, new_pass, sizeof (new_pass), SET); |
|---|
| 272 | } |
|---|
| 273 | } |
|---|
| 274 | cur += snprintf (cur, buf + sof - cur, "%s%s:%s", |
|---|
| 275 | cur == buf ? "" : " ", new_user, new_pass); |
|---|
| 276 | |
|---|
| 277 | } |
|---|
| 278 | if (!error) |
|---|
| 279 | nvram_set (v->name, buf); |
|---|
| 280 | free (buf); |
|---|
| 281 | |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | void |
|---|
| 286 | show_aliases_table (webs_t wp, char *type, int which) |
|---|
| 287 | { |
|---|
| 288 | |
|---|
| 289 | static char word[256]; |
|---|
| 290 | char *next, *wordlist; |
|---|
| 291 | char *user, *pass; |
|---|
| 292 | static char new_user[200], new_pass[200]; |
|---|
| 293 | int temp; |
|---|
| 294 | wordlist = nvram_safe_get ("milkfish_ddaliases"); |
|---|
| 295 | temp = which; |
|---|
| 296 | |
|---|
| 297 | foreach (word, wordlist, next) |
|---|
| 298 | { |
|---|
| 299 | if (which-- == 0) |
|---|
| 300 | { |
|---|
| 301 | pass = word; |
|---|
| 302 | user = strsep (&pass, ":"); |
|---|
| 303 | if (!user || !pass) |
|---|
| 304 | continue; |
|---|
| 305 | |
|---|
| 306 | |
|---|
| 307 | if (!strcmp (type, "user")) |
|---|
| 308 | { |
|---|
| 309 | httpd_filter_name (user, new_user, sizeof (new_user), GET); |
|---|
| 310 | websWrite (wp, "%s", new_user); |
|---|
| 311 | } |
|---|
| 312 | else if (!strcmp (type, "pass")) |
|---|
| 313 | { |
|---|
| 314 | httpd_filter_name (pass, new_pass, sizeof (new_pass), GET); |
|---|
| 315 | websWrite (wp, "%s", new_pass); |
|---|
| 316 | } |
|---|
| 317 | return; |
|---|
| 318 | } |
|---|
| 319 | } |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | |
|---|
| 323 | void |
|---|
| 324 | ej_show_aliases (webs_t wp, int argc, char_t ** argv) |
|---|
| 325 | { |
|---|
| 326 | int i; |
|---|
| 327 | char *count; |
|---|
| 328 | int c; |
|---|
| 329 | count = nvram_safe_get ("milkfish_ddaliasesnum"); |
|---|
| 330 | if (count == NULL || strlen (count) == 0 || (c=atoi(count))<=0) |
|---|
| 331 | { |
|---|
| 332 | websWrite (wp, "<tr>\n"); |
|---|
| 333 | websWrite (wp, |
|---|
| 334 | "<td colspan=\"4\" align=\"center\" valign=\"middle\">- <script type=\"text/javascript\">Capture(share.none)</script> -</td>\n"); |
|---|
| 335 | websWrite (wp, "</tr>\n"); |
|---|
| 336 | } |
|---|
| 337 | for (i = 0; i < c; i++) |
|---|
| 338 | { |
|---|
| 339 | websWrite (wp, "<tr><td>\n"); |
|---|
| 340 | websWrite (wp, "<input maxlength=\"30\" size=\"30\" name=\"user%d\" onblur=\"valid_name(this,'Name')\" value=\"",i); |
|---|
| 341 | show_aliases_table (wp, "user", i); |
|---|
| 342 | websWrite (wp, "\" /></td>\n"); |
|---|
| 343 | websWrite (wp, "<td>\n"); |
|---|
| 344 | websWrite (wp, "<input maxlength=\"30\" size=\"30\" name=\"pass%d\" onblur=\"valid_name(this,'Name')\" value=\"",i); |
|---|
| 345 | show_aliases_table (wp, "pass", i); |
|---|
| 346 | websWrite (wp, "\" /></td>\n"); |
|---|
| 347 | websWrite (wp, "</tr>\n"); |
|---|
| 348 | } |
|---|
| 349 | return; |
|---|
| 350 | } |
|---|
| 351 | |
|---|
| 352 | void |
|---|
| 353 | milkfish_sip_message (webs_t wp) |
|---|
| 354 | { |
|---|
| 355 | char *message = websGetVar (wp, "sip_message", NULL); |
|---|
| 356 | char *dest = websGetVar (wp, "sip_message_dest", NULL); |
|---|
| 357 | int i; |
|---|
| 358 | FILE *fp=fopen("/tmp/sipmessage","wb"); |
|---|
| 359 | if (fp==NULL) |
|---|
| 360 | return; |
|---|
| 361 | char *host_key = message; |
|---|
| 362 | i = 0; |
|---|
| 363 | do |
|---|
| 364 | { |
|---|
| 365 | if (host_key[i] != 0x0D) |
|---|
| 366 | fprintf (fp, "%c", host_key[i]); |
|---|
| 367 | } |
|---|
| 368 | while (host_key[++i]); |
|---|
| 369 | putc(0xa,fp); |
|---|
| 370 | fclose(fp); |
|---|
| 371 | eval("milkfish_services","simple",dest); |
|---|
| 372 | return; |
|---|
| 373 | } |
|---|
| 374 | |
|---|
| 375 | void |
|---|
| 376 | show_registrations_table (webs_t wp, char *type, int which) |
|---|
| 377 | { |
|---|
| 378 | |
|---|
| 379 | static char word[256]; |
|---|
| 380 | char *next, *wordlist; |
|---|
| 381 | char *user, *contact, *agent; |
|---|
| 382 | static char new_user[200], new_contact[200], new_agent[200]; |
|---|
| 383 | int temp; |
|---|
| 384 | wordlist = nvram_safe_get ("milkfish_ddactive"); |
|---|
| 385 | temp = which; |
|---|
| 386 | |
|---|
| 387 | foreach (word, wordlist, next) |
|---|
| 388 | { |
|---|
| 389 | if (which-- == 0) |
|---|
| 390 | { |
|---|
| 391 | contact = word; |
|---|
| 392 | user = strsep (&contact, ":"); |
|---|
| 393 | if (!user || !contact) |
|---|
| 394 | continue; |
|---|
| 395 | |
|---|
| 396 | agent = contact; |
|---|
| 397 | contact = strsep (&agent, ":"); |
|---|
| 398 | if (!contact || !agent) |
|---|
| 399 | continue; |
|---|
| 400 | |
|---|
| 401 | |
|---|
| 402 | if (!strcmp (type, "user")) |
|---|
| 403 | { |
|---|
| 404 | httpd_filter_name (user, new_user, sizeof (new_user), GET); |
|---|
| 405 | websWrite (wp, "%s", new_user); |
|---|
| 406 | } |
|---|
| 407 | else if (!strcmp (type, "contact")) |
|---|
| 408 | { |
|---|
| 409 | httpd_filter_name (contact, new_contact, sizeof (new_contact), GET); |
|---|
| 410 | websWrite (wp, "%s", new_contact); |
|---|
| 411 | } |
|---|
| 412 | else if (!strcmp (type, "agent")) |
|---|
| 413 | { |
|---|
| 414 | httpd_filter_name (agent, new_agent, sizeof (new_agent), GET); |
|---|
| 415 | websWrite (wp, "%s", new_agent); |
|---|
| 416 | } |
|---|
| 417 | |
|---|
| 418 | return; |
|---|
| 419 | } |
|---|
| 420 | } |
|---|
| 421 | } |
|---|
| 422 | |
|---|
| 423 | |
|---|
| 424 | void |
|---|
| 425 | ej_show_registrations (webs_t wp, int argc, char_t ** argv) |
|---|
| 426 | { |
|---|
| 427 | int i; |
|---|
| 428 | char *count; |
|---|
| 429 | int c; |
|---|
| 430 | count = nvram_safe_get ("milkfish_ddactivenum"); |
|---|
| 431 | if (count == NULL || strlen (count) == 0 || (c=atoi(count))<=0) |
|---|
| 432 | { |
|---|
| 433 | websWrite (wp, "<tr>\n"); |
|---|
| 434 | websWrite (wp, |
|---|
| 435 | "<td colspan=\"4\" align=\"center\" valign=\"middle\">- <script type=\"text/javascript\">Capture(share.none)</script> -</td>\n"); |
|---|
| 436 | websWrite (wp, "</tr>\n"); |
|---|
| 437 | } |
|---|
| 438 | for (i = 0; i < c; i++) |
|---|
| 439 | { |
|---|
| 440 | websWrite (wp, "<tr><td>\n"); |
|---|
| 441 | websWrite (wp, "<input maxlength=\"20\" size=\"20\" name=\"user%d\" onblur=\"valid_name(this,'Name')\" value=\"",i); |
|---|
| 442 | show_registrations_table (wp, "user", i); |
|---|
| 443 | websWrite (wp, "\" readonly=\"readonly\" /></td>\n"); |
|---|
| 444 | websWrite (wp, "<td>\n"); |
|---|
| 445 | websWrite (wp, "<input maxlength=\"50\" size=\"50\" name=\"contact%d\" onblur=\"valid_name(this,'Name')\" value=\"",i); |
|---|
| 446 | show_registrations_table (wp, "contact", i); |
|---|
| 447 | websWrite (wp, "\" readonly=\"readonly\" /></td>\n"); |
|---|
| 448 | websWrite (wp, "<td>\n"); |
|---|
| 449 | websWrite (wp, "<input maxlength=\"50\" size=\"50\" name=\"agent%d\" onblur=\"valid_name(this,'Name')\" value=\"",i); |
|---|
| 450 | show_registrations_table (wp, "agent", i); |
|---|
| 451 | websWrite (wp, "\" readonly=\"readonly\" /></td>\n"); |
|---|
| 452 | websWrite (wp, "</tr>\n"); |
|---|
| 453 | } |
|---|
| 454 | return; |
|---|
| 455 | } |
|---|
| 456 | |
|---|
| 457 | |
|---|