summaryrefslogtreecommitdiffstats
path: root/applications/luci-app-wifihistory/root/usr/share/rpcd/ucode/wifihistory.uc
blob: 918ad9818b2e769d7b5a95f3855cb180fb8e82a7 (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
#!/usr/bin/env ucode

'use strict';

import { readfile, writefile } from 'fs';

const HISTORY_FILE = '/var/lib/wifihistory/history.json';

const methods = {
	getHistory: {
		call: function() {
			let content = readfile(HISTORY_FILE);
			if (content == null)
				return { history: {} };

			try {
				return { history: json(content) || {} };
			}
			catch (e) {
				return { history: {} };
			}
		}
	},

	clearHistory: {
		call: function() {
			writefile(HISTORY_FILE, '{}');
			return { result: true };
		}
	}
};

return { 'luci.wifihistory': methods };