<%# LuCI - Lua Configuration Interface Copyright 2008 Steven Barth Copyright 2008 Jo-Philipp Wich Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 $Id$ -%> <%- local function enable_channel(name) return (os.execute("smart channel --enable '"..name.."' >/dev/null 2>&1") == 0) end local function disable_channel(name) return (os.execute("smart channel --disable '"..name.."' >/dev/null 2>&1") == 0) end local function remove_channel(name) return (os.execute("smart channel --remove '"..name.."' --yes >/dev/null 2>&1") == 0) end local function add_channel(name, type, baseurl, disabled) return (os.execute("smart channel --add '"..name.."' type="..type.." baseurl='"..baseurl.."' disabled="..disabled.." --yes >/dev/null 2>&1") == 0) end if action and channel then local ret = false if action == "enable" then ret = enable_channel(channel) elseif action == "disable" then ret = disable_channel(channel) elseif action == "remove" then ret = remove_channel(channel) elseif action == "add" then ret = add_channel(channel, chntype, baseurl, "no") elseif action == "adddisabled" then ret = add_channel(channel, chntype, baseurl, "yes") end luci.http.prepare_content("text/plain") if ret then luci.http.write("finish") else luci.http.write("failed") end else local types = { ['rpm-sys'] = "RPM Installed Packages", ['rpm-md'] = "RPM MetaData" } local function channel_type_editable(type) return not string.match(type, ".*Installed Packages") end local channels = {} os.execute("echo start >> /tmp/smart.log"); local index = 0 local cmd = io.popen("env -i smart channel --show -y") local name = "" local type = "" local url = "" local disabled = false if cmd then while true do local l = cmd:read("*l") if not l then break end local tmp = l:match("%[([^%]]+)%]") if tmp then name = tmp elseif name and name != "" then tmp = l:match("type = (.+)") if tmp then type = tmp else tmp = l:match("baseurl = (.+)") if tmp then url = tmp else tmp = l:match("disabled = (.+)") if tmp and tmp == "yes" then disabled = true else index = index + 1 channels[index] = { index = tostring(index), name = name, type = types[type], url = url, disabled = disabled } type = "" url = "" name = "" disabled = false end end end end data = true end cmd:close() end channels[99] = { type = types['rpm-md']} -%> <%+header%>

<%:Software%>

<% for _, p in ipairs(channels) do %> <% end %>
  <%:Name%> <%:Type%> <%:Base%> <%:URL%> <%:Status%> <%:Action%>
<%=p.name%> <%=p.type%> <%=p.url%> <% if channel_type_editable(p.type) then %> <% if p.disabled then %> <% else %> <% end %> <% else %> <% end %> <% if channel_type_editable(p.type) then %> <% else %> <% end %>
<%:Enabled%>
<%+footer%> <%- end -%>