summaryrefslogtreecommitdiffstats
path: root/squid-model.lua
blob: 2ab54c8bb5f3625080f09339bb9056f6c5dbf5da (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
-- acf model for squid
-- Copyright(c) 2007 A. Brodmann - Licensed under terms of GPL2
module (..., package.seeall)

get_status = function()

	local retval = "stopped"

	local ptr = io.popen( "/bin/pidof squid" )
	local pid = ptr:read( "*a" )
	ptr:close()
	if pid ~= nil then
		if #pid > 1 then
			retval = "running"
		end
	end
	
	return retval
end

service_control = function( control )

	local retval = ""
	
	local ptr = io.popen( "/etc/init.d/squid " .. control, "r" )
	if ptr ~= nil then
		local retmsg = ptr:read( "*a" )
		ptr:close()
		if retmsg ~= nil then
			retval = retmsg
		else
			retval = "service_control(): Failed to read output from initscript!\n"
		end
	else
		retval = "service_control(): Failed to start/stop/restart service!\n"
	end

	return retval
end

get_adv_config = function()

	local retval = ""
	
	local ptr = io.open( "/etc/squid/squid.conf", "r" )
	if ptr ~= nil then
		local retcfg = ptr:read( "*a" )
		ptr:close()
		if retcfg == nil then
			retval = "\n\n    Error: Failed to read /etc/squid/squid.conf!\n\n"
		else
			retval = retcfg
		end
	end

	return retval
end

get_filter_config = function()

	local retval = ""
	
	
	return retval
end

update_adv_config = function( config )

	local retval = "Successfully updated /etc/squid/squid.conf!"

	local ptr = io.open( "/etc/squid/squid.conf", "wb+" )
	if ptr ~= nil then
		ptr:write( config )
		ptr:close()
	else
		retval = "update_config(): Error, failed to open /etc/squid/squid.conf!\n"
	end

	return retval
end

get_basic_config = function()

	local config = { proxyip = { value="", type="text", label="Proxy IP" },
	                 proxyport = { value="", type="text", label="Proxy Port" },
	                 filterip = { value="", type="text", label="Filter IP" },
	                 filterport = { value="", type="text", label="Filter Port" },
	                 filterregex = { value="", type="text", label="FilterRegex" },
	                 safeports = { value="", type="text", label="Safe_ports" },
	                 sslports = { value="", type="text", label="SSL_ports" },
	                 accesslog = { value="", type="select", label="Access Logs", option={ "yes", "no" } },
	                 diskcache = { value="", type="select", label="Disk Cache Parameters", option={ "yes", "no" } },
	                 authmethod = { value="", type="select", label="Authentication Method", option={ "digest", "ntlm", "none" } }
	               }
	               
	config.proxyip.value = "192.168.83.129"
	config.proxyport.value = 8080
	config.accesslog.value = "yes"
	
	return config
end