summaryrefslogtreecommitdiffstats
path: root/squid-model.lua
blob: f1fee4302f7bddff134f0e59468898b780a5bed0 (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
-- 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_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

update_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