Merge branch 'Toastman-RT' into Toastman-RT-N
[tomato.git] / release / src / router / httpd / dhcp.c
blob0f14b00a45e4cc107b670a1a2b1849511ba8e0a2
1 /*
3 Tomato Firmware
4 Copyright (C) 2006-2009 Jonathan Zarate
6 */
8 #include "tomato.h"
10 #include <sys/sysinfo.h>
11 #include <sys/stat.h>
12 #include <sys/types.h>
15 void asp_dhcpc_time(int argc, char **argv)
17 long exp;
18 struct sysinfo si;
19 long n;
20 int r;
21 char buf[32];
23 if (using_dhcpc()) {
24 exp = 0;
25 r = f_read_string("/var/lib/misc/dhcpc.expires", buf, sizeof(buf));
26 if (r > 0) {
27 n = atol(buf);
28 if (n > 0) {
29 sysinfo(&si);
30 exp = n - si.uptime;
33 web_puts(reltime(buf, exp));
37 void wo_dhcpc(char *url)
39 char *p;
40 char *argv[] = { NULL, NULL };
41 int pid;
43 if ((p = webcgi_get("exec")) != NULL) {
44 if (strcmp(p, "release") == 0)
45 argv[0] = "dhcpc-release";
46 else if (strcmp(p, "renew") == 0)
47 argv[0] = "dhcpc-renew";
48 _eval(argv, NULL, 0, &pid);
50 common_redirect();
54 // -----------------------------------------------------------------------------
57 void wo_dhcpd(char *url)
59 char *p;
61 if ((p = webcgi_get("remove")) != NULL) {
62 f_write_string("/var/tmp/dhcp/delete", p, FW_CREATE|FW_NEWLINE, 0666);
63 killall("dnsmasq", SIGUSR2);
64 f_wait_notexists("/var/tmp/dhcp/delete", 5);
66 web_puts("{}");