summaryrefslogtreecommitdiff
path: root/release/src/router/httpd/dhcp.c
blob: aef5bcd341260f3b16e33fa68734586635d640bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*

	Tomato Firmware
	Copyright (C) 2006-2009 Jonathan Zarate

*/

#include "tomato.h"

#include <sys/sysinfo.h>
#include <sys/stat.h>
#include <sys/types.h>


void asp_dhcpc_time(int argc, char **argv)
{
	long exp;
	struct sysinfo si;
	long n;
	int r;
	char buf[32];

	if (using_dhcpc()) {
		exp = 0;
		r = f_read_string("/var/lib/misc/dhcpc.expires", buf, sizeof(buf));
		if (r > 0) {
			n = atol(buf);
			if (n > 0) {
				sysinfo(&si);
				exp = n - si.uptime;
			}
		}
		web_puts(reltime(buf, exp));
	}
}

void wo_dhcpc(char *url)
{
	char *p;

	if ((p = webcgi_get("exec")) != NULL) {
		if (strcmp(p, "release") == 0) eval("dhcpc-release");
			else if (strcmp(p, "renew") == 0) eval("dhcpc-renew");
	}
	common_redirect();
}


// -----------------------------------------------------------------------------


void wo_dhcpd(char *url)
{
	char *p;

	if ((p = webcgi_get("remove")) != NULL) {
		f_write_string("/var/tmp/dhcp/delete", p, FW_CREATE|FW_NEWLINE, 0666);
		killall("dnsmasq", SIGUSR2);
		f_wait_notexists("/var/tmp/dhcp/delete", 5);
	}
	web_puts("{}");
}