luci-mod-admin-full: Don't show jail bind mounts
[project/luci.git] / modules / luci-mod-admin-full / luasrc / model / cbi / admin_system / fstab.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 require("luci.tools.webadmin")
5
6 local fs   = require "nixio.fs"
7 local util = require "nixio.util"
8 local tp   = require "luci.template.parser"
9
10 local block = io.popen("block info", "r")
11 local ln, dev, devices = nil, nil, {}
12
13 repeat
14         ln = block:read("*l")
15         dev = ln and ln:match("^/dev/(.-):")
16
17         if dev then
18                 local e, s, key, val = { }
19
20                 for key, val in ln:gmatch([[(%w+)="(.-)"]]) do
21                         e[key:lower()] = val
22                         devices[val] = e
23                 end
24
25                 s = tonumber((fs.readfile("/sys/class/block/%s/size" % dev)))
26
27                 e.dev  = "/dev/%s" % dev
28                 e.size = s and math.floor(s / 2048)
29
30                 devices[e.dev] = e
31         end
32 until not ln
33
34 block:close()
35
36
37 m = Map("fstab", translate("Mount Points"))
38
39 local mounts = luci.sys.mounts()
40 local non_system_mounts = {}
41 for rawmount, val in pairs(mounts) do
42     if (string.find(val.mountpoint, "/tmp/.jail") == nil) then
43       repeat 
44           val.umount = false
45           if (val.mountpoint == "/") then
46               break
47           elseif (val.mountpoint == "/overlay") then
48               break
49           elseif (val.mountpoint == "/rom") then
50               break
51           elseif (val.mountpoint == "/tmp") then
52               break
53           elseif (val.mountpoint == "/tmp/shm") then
54               break
55           elseif (val.mountpoint == "/tmp/upgrade") then
56               break
57           elseif (val.mountpoint == "/dev") then
58               break
59           end
60           val.umount = true
61       until true
62       non_system_mounts[rawmount] = val       
63    end   
64 end
65
66 v = m:section(Table, non_system_mounts, translate("Mounted file systems"))
67
68 fs = v:option(DummyValue, "fs", translate("Filesystem"))
69
70 mp = v:option(DummyValue, "mountpoint", translate("Mount Point"))
71
72 avail = v:option(DummyValue, "avail", translate("Available"))
73 function avail.cfgvalue(self, section)
74         return luci.tools.webadmin.byte_format(
75                 ( tonumber(mounts[section].available) or 0 ) * 1024
76         ) .. " / " .. luci.tools.webadmin.byte_format(
77                 ( tonumber(mounts[section].blocks) or 0 ) * 1024
78         )
79 end
80
81 used = v:option(DummyValue, "used", translate("Used"))
82 function used.cfgvalue(self, section)
83         return ( mounts[section].percent or "0%" ) .. " (" ..
84         luci.tools.webadmin.byte_format(
85                 ( tonumber(mounts[section].used) or 0 ) * 1024
86         ) .. ")"
87 end
88
89 unmount = v:option(Button, "unmount", translate("Unmount"))
90 unmount.render = function(self, section, scope)
91         if non_system_mounts[section].umount then
92                 self.title = translate("Unmount")
93                 self.inputstyle = "remove"
94                 Button.render(self, section, scope)
95         end
96 end
97
98 unmount.write = function(self, section)
99         if non_system_mounts[section].umount then
100                 luci.sys.call("/bin/umount '%s'" % luci.util.shellstartsqescape(non_system_mounts[section].mountpoint))
101                 return luci.http.redirect(luci.dispatcher.build_url("admin/system", "fstab"))
102         end
103 end
104
105 mount = m:section(TypedSection, "mount", translate("Mount Points"), translate("Mount Points define at which point a memory device will be attached to the filesystem"))
106 mount.anonymous = true
107 mount.addremove = true
108 mount.template = "cbi/tblsection"
109 mount.extedit  = luci.dispatcher.build_url("admin/system/fstab/mount/%s")
110
111 mount.create = function(...)
112         local sid = TypedSection.create(...)
113         if sid then
114                 luci.http.redirect(mount.extedit % sid)
115                 return
116         end
117 end
118
119
120 mount:option(Flag, "enabled", translate("Enabled")).rmempty = false
121
122 dev = mount:option(DummyValue, "device", translate("Device"))
123 dev.rawhtml = true
124 dev.cfgvalue = function(self, section)
125         local v, e
126
127         v = m.uci:get("fstab", section, "uuid")
128         e = v and devices[v:lower()]
129         if v and e and e.size then
130                 return "UUID: %s (%s, %d MB)" %{ tp.pcdata(v), e.dev, e.size }
131         elseif v and e then
132                 return "UUID: %s (%s)" %{ tp.pcdata(v), e.dev }
133         elseif v then
134                 return "UUID: %s (<em>%s</em>)" %{ tp.pcdata(v), translate("not present") }
135         end
136
137         v = m.uci:get("fstab", section, "label")
138         e = v and devices[v]
139         if v and e and e.size then
140                 return "Label: %s (%s, %d MB)" %{ tp.pcdata(v), e.dev, e.size }
141         elseif v and e then
142                 return "Label: %s (%s)" %{ tp.pcdata(v), e.dev }
143         elseif v then
144                 return "Label: %s (<em>%s</em>)" %{ tp.pcdata(v), translate("not present") }
145         end
146
147         v = Value.cfgvalue(self, section) or "?"
148         e = v and devices[v]
149         if v and e and e.size then
150                 return "%s (%d MB)" %{ tp.pcdata(v), e.size }
151         elseif v and e then
152                 return tp.pcdata(v)
153         elseif v then
154                 return "%s (<em>%s</em>)" %{ tp.pcdata(v), translate("not present") }
155         end
156 end
157
158 mp = mount:option(DummyValue, "target", translate("Mount Point"))
159 mp.cfgvalue = function(self, section)
160         if m.uci:get("fstab", section, "is_rootfs") == "1" then
161                 return "/overlay"
162         else
163                 return Value.cfgvalue(self, section) or "?"
164         end
165 end
166
167 fs = mount:option(DummyValue, "fstype", translate("Filesystem"))
168 fs.cfgvalue = function(self, section)
169         local v, e
170
171         v = m.uci:get("fstab", section, "uuid")
172         v = v and v:lower() or m.uci:get("fstab", section, "label")
173         v = v or m.uci:get("fstab", section, "device")
174
175         e = v and devices[v]
176
177         return e and e.type or m.uci:get("fstab", section, "fstype") or "?"
178 end
179
180 op = mount:option(DummyValue, "options", translate("Options"))
181 op.cfgvalue = function(self, section)
182         return Value.cfgvalue(self, section) or "defaults"
183 end
184
185 rf = mount:option(DummyValue, "is_rootfs", translate("Root"))
186 rf.cfgvalue = function(self, section)
187         local target = m.uci:get("fstab", section, "target")
188         if target == "/" then
189                 return translate("yes")
190         elseif target == "/overlay" then
191                 return translate("overlay")
192         else
193                 return translate("no")
194         end
195 end
196
197 ck = mount:option(DummyValue, "enabled_fsck", translate("Check"))
198 ck.cfgvalue = function(self, section)
199         return Value.cfgvalue(self, section) == "1"
200                 and translate("yes") or translate("no")
201 end
202
203
204 swap = m:section(TypedSection, "swap", "SWAP", translate("If your physical memory is insufficient unused data can be temporarily swapped to a swap-device resulting in a higher amount of usable <abbr title=\"Random Access Memory\">RAM</abbr>. Be aware that swapping data is a very slow process as the swap-device cannot be accessed with the high datarates of the <abbr title=\"Random Access Memory\">RAM</abbr>."))
205 swap.anonymous = true
206 swap.addremove = true
207 swap.template = "cbi/tblsection"
208 swap.extedit  = luci.dispatcher.build_url("admin/system/fstab/swap/%s")
209
210 swap.create = function(...)
211         local sid = TypedSection.create(...)
212         if sid then
213                 luci.http.redirect(swap.extedit % sid)
214                 return
215         end
216 end
217
218
219 swap:option(Flag, "enabled", translate("Enabled")).rmempty = false
220
221 dev = swap:option(DummyValue, "device", translate("Device"))
222 dev.cfgvalue = function(self, section)
223         local v
224
225         v = m.uci:get("fstab", section, "uuid")
226         if v then return "UUID: %s" % v end
227
228         v = m.uci:get("fstab", section, "label")
229         if v then return "Label: %s" % v end
230
231         v = Value.cfgvalue(self, section) or "?"
232         e = v and devices[v]
233         if v and e and e.size then
234                 return "%s (%s MB)" % {v, e.size}
235         else
236                 return v
237         end
238 end
239
240 return m