initial commit
This commit is contained in:
commit
df002755ce
2
.gitignore
vendored
Executable file
2
.gitignore
vendored
Executable file
@ -0,0 +1,2 @@
|
||||
packages/
|
||||
*.apk
|
31
APKBUILD
Executable file
31
APKBUILD
Executable file
@ -0,0 +1,31 @@
|
||||
# Contributor: Paolo Asperti <paolo@asperti.com>
|
||||
# Maintainer: Paolo Asperti <paolo@asperti.com>
|
||||
pkgname=acf-openpdu
|
||||
pkgver=0.1
|
||||
pkgrel=1
|
||||
pkgdesc="Linux installation caching system"
|
||||
url="https://github.com/paspo/installinux"
|
||||
arch="noarch"
|
||||
license="GPL2"
|
||||
depends="acf-core"
|
||||
makedepends=""
|
||||
install="acf-openpdu.post-install"
|
||||
subpackages=""
|
||||
source=""
|
||||
|
||||
package() {
|
||||
mkdir -p "$pkgdir"
|
||||
}
|
||||
|
||||
package() {
|
||||
# make DESTDIR=$pkgdir install || return 1
|
||||
install -Dm644 etc/openpdu/openpdu.conf "$pkgdir"/etc/openpdu/openpdu.conf
|
||||
install -Dm755 etc/local.d/openpdu.start "$pkgdir"/etc/local.d/openpdu.start
|
||||
|
||||
install -Dm644 acf-app/openpdu.menu "$pkgdir"/usr/share/acf/app/openpdu/openpdu.menu
|
||||
install -Dm644 acf-app/openpdu.roles "$pkgdir"/usr/share/acf/app/openpdu/openpdu.roles
|
||||
install -Dm644 acf-app/openpdu-controller.lua "$pkgdir"/usr/share/acf/app/openpdu/openpdu-controller.lua
|
||||
install -Dm644 acf-app/openpdu-model.lua "$pkgdir"/usr/share/acf/app/openpdu/openpdu-model.lua
|
||||
install -Dm644 acf-app/openpdu-status-html.lsp "$pkgdir"/usr/share/acf/app/openpdu/openpdu-status-html.lsp
|
||||
|
||||
}
|
19
README
Executable file
19
README
Executable file
@ -0,0 +1,19 @@
|
||||
ACF interface for the OpenPDU project.
|
||||
|
||||
Connect the wires, and install this package.
|
||||
Then go to https://[YOUR_IP], enter user/pass so you can login to ACF.
|
||||
Under "OpenPDU" you can control your outlets.
|
||||
|
||||
DONE:
|
||||
* Basic Outlet Status (almost everything hardcoded :( )
|
||||
* Power control (ON/OFF) for each socket
|
||||
* All the sockets are powered ON on boot
|
||||
* ACF package
|
||||
|
||||
TODO:
|
||||
* configuration file
|
||||
* editing socket parameters
|
||||
* everything else (there's a long list)
|
||||
|
||||
BUGS:
|
||||
* At the moment, the "Edit" button doesn't work
|
19
acf-app/openpdu-controller.lua
Executable file
19
acf-app/openpdu-controller.lua
Executable file
@ -0,0 +1,19 @@
|
||||
-- the openpdu controller
|
||||
|
||||
local mymodule = {}
|
||||
|
||||
mymodule.default_action = "status"
|
||||
|
||||
mymodule.status = function(self)
|
||||
return self.model.status()
|
||||
end
|
||||
|
||||
mymodule.poweron = function(self)
|
||||
return self.handle_form(self, self.model.get_setpower, self.model.setpoweron, self.clientdata, "commitpower", "Action result")
|
||||
end
|
||||
|
||||
mymodule.poweroff = function(self)
|
||||
return self.handle_form(self, self.model.get_setpower, self.model.setpoweroff, self.clientdata, "commitpower", "Action result")
|
||||
end
|
||||
|
||||
return mymodule
|
88
acf-app/openpdu-model.lua
Executable file
88
acf-app/openpdu-model.lua
Executable file
@ -0,0 +1,88 @@
|
||||
local mymodule = {}
|
||||
|
||||
posix = require("posix")
|
||||
fs = require("acf.fs")
|
||||
|
||||
local configpath = "/etc/openpdu/"
|
||||
|
||||
local config = {}
|
||||
for i=1,8 do
|
||||
config[i]={socket=i,status="unknown",description="Socket " .. tostring(i),actions={"on","off"}}
|
||||
end
|
||||
config[1].gpio=1
|
||||
config[2].gpio=2
|
||||
config[3].gpio=3
|
||||
config[4].gpio=7
|
||||
config[5].gpio=8
|
||||
config[6].gpio=9
|
||||
config[7].gpio=11
|
||||
config[8].gpio=12
|
||||
|
||||
mymodule.status = function()
|
||||
mymodule.updatestatus()
|
||||
return cfe({ type="structure", value=config, label="Outlets" })
|
||||
end
|
||||
|
||||
mymodule.updatestatus = function()
|
||||
for i=1,8 do
|
||||
f = "/sys/class/gpio/gpio" .. tostring(config[i].gpio) .. "/value"
|
||||
v = fs.read_file(f)
|
||||
if (tonumber(v) == 0) then
|
||||
s = "On"
|
||||
elseif (tonumber(v) == 1) then
|
||||
s = "Off"
|
||||
else
|
||||
s = "unknown (" .. v .. ")"
|
||||
end
|
||||
config[i].status = s
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
mymodule.setpower = function(socket, power, ret)
|
||||
-- Check to make sure the socket is valid
|
||||
if (socket == nil) then
|
||||
ret.errtxt = "Socket cannot be nil"
|
||||
elseif (not type(socket) == "number") then
|
||||
ret.errtxt = "Socket must be a number"
|
||||
elseif (tonumber(socket) < 0) then
|
||||
ret.errtxt = "Socket must be >0"
|
||||
elseif (tonumber(socket) > 8) then
|
||||
ret.errtxt = "Socket must be <=8"
|
||||
end
|
||||
|
||||
-- If it is, poweron the socket
|
||||
if (ret.errtxt == nil ) then
|
||||
f = "/sys/class/gpio/gpio" .. tostring(config[tonumber(socket)].gpio) .. "/value"
|
||||
if (power == 1) then
|
||||
ret.descr = "Socket " .. tostring(socket) .. " Powered ON"
|
||||
p = "0"
|
||||
else
|
||||
ret.descr = "Socket " .. tostring(socket) .. " Powered OFF"
|
||||
p = "1"
|
||||
end
|
||||
v = fs.write_file(f, p)
|
||||
return ret
|
||||
end
|
||||
|
||||
return ret
|
||||
end
|
||||
|
||||
|
||||
|
||||
mymodule.get_setpower = function(self, clientdata)
|
||||
local socket = cfe({label="Socket", value=clientdata.socket or ""})
|
||||
return cfe({ type="group", label="Set Socket Power state", value={socket=socket} })
|
||||
end
|
||||
|
||||
mymodule.setpoweron = function(self, r)
|
||||
mymodule.setpower(r.value.socket.value, 1, r)
|
||||
return r
|
||||
end
|
||||
|
||||
mymodule.setpoweroff = function(self, r)
|
||||
mymodule.setpower(r.value.socket.value, 0, r)
|
||||
return r
|
||||
end
|
||||
|
||||
return mymodule
|
58
acf-app/openpdu-status-html.lsp
Executable file
58
acf-app/openpdu-status-html.lsp
Executable file
@ -0,0 +1,58 @@
|
||||
<% local view, viewlibrary, page_info, session = ... %>
|
||||
<% htmlviewfunctions = require("htmlviewfunctions") %>
|
||||
<% html = require("acf.html") %>
|
||||
|
||||
<script type="text/javascript">
|
||||
if (typeof jQuery == 'undefined') {
|
||||
document.write('<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery-latest.js"><\/script>');
|
||||
}
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
if (typeof $.tablesorter == 'undefined') {
|
||||
document.write('<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery.tablesorter.js"><\/script>');
|
||||
}
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$("#list").tablesorter({widgets: ['zebra']});
|
||||
});
|
||||
</script>
|
||||
|
||||
<% htmlviewfunctions.displaycommandresults({"edit", "startstop", "poweron", "poweroff"}, session) %>
|
||||
|
||||
<% local header_level = htmlviewfunctions.displaysectionstart(view, page_info) %>
|
||||
<table id="list" class="tablesorter"><thead>
|
||||
<tr>
|
||||
<th>Socket #</th>
|
||||
<th>Status</th>
|
||||
<th>Description</th>
|
||||
<% if viewlibrary.check_permission("edit") or viewlibrary.check_permission("power") then %>
|
||||
<th>Action</th>
|
||||
<% end %>
|
||||
</tr>
|
||||
</thead><tbody>
|
||||
<%
|
||||
local redir = cfe({type="hidden", value=page_info.orig_action})
|
||||
for i,item in ipairs(view.value) do %>
|
||||
<tr>
|
||||
<td><%= html.html_escape(item.socket) %></td>
|
||||
<td><%= html.html_escape(item.status) %></td>
|
||||
<td><%= html.html_escape(item.description) %></td>
|
||||
<% if viewlibrary.check_permission("edit") or viewlibrary.check_permission("power") then %>
|
||||
<td>
|
||||
<% local socket = cfe({type="hidden", value=item.socket}) %>
|
||||
<% if viewlibrary.check_permission("edit") then
|
||||
htmlviewfunctions.displayitem(cfe({type="link", value={socket=socket, redir=redir}, label="", option="Edit", action="edit" }), page_info, -1)
|
||||
end %>
|
||||
<% if viewlibrary.check_permission("poweron") or viewlibrary.check_permission("poweroff") then
|
||||
htmlviewfunctions.displayitem(cfe({type="form", value={socket=socket, redir=redir}, label="", option="Power ON", action="poweron" }), page_info, -1)
|
||||
htmlviewfunctions.displayitem(cfe({type="form", value={socket=socket, redir=redir}, label="", option="Power OFF", action="poweroff" }), page_info, -1)
|
||||
end %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody></table>
|
||||
<% htmlviewfunctions.displaysectionend(header_level) %>
|
2
acf-app/openpdu.menu
Executable file
2
acf-app/openpdu.menu
Executable file
@ -0,0 +1,2 @@
|
||||
#CAT GROUP/DESC TAB ACTION
|
||||
Applications 20OpenPDU Status status
|
4
acf-app/openpdu.roles
Executable file
4
acf-app/openpdu.roles
Executable file
@ -0,0 +1,4 @@
|
||||
USER=openpdu:status
|
||||
EDITOR=openpdu:status
|
||||
EXPERT=openpdu:status
|
||||
ADMIN=openpdu:status,openpdu:edit,openpdu:power,openpdu:poweron,openpdu:poweroff
|
3
acf-openpdu.post-install
Executable file
3
acf-openpdu.post-install
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
exit 0
|
21
etc/local.d/openpdu.start
Executable file
21
etc/local.d/openpdu.start
Executable file
@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
|
||||
OUT1=1
|
||||
OUT2=2
|
||||
OUT3=3
|
||||
OUT4=7
|
||||
OUT5=8
|
||||
OUT6=9
|
||||
OUT7=11
|
||||
OUT8=12
|
||||
|
||||
for n in $(seq 1 8) ; do
|
||||
eval "echo \$OUT$n > /sys/class/gpio/export"
|
||||
eval "echo out > /sys/class/gpio/gpio\$OUT$n/direction"
|
||||
|
||||
# 0=on 1=off :)
|
||||
VAL=0
|
||||
|
||||
eval "echo $VAL > /sys/class/gpio/gpio\$OUT$n/value"
|
||||
sleep 0.2
|
||||
done
|
0
etc/openpdu/openpdu.conf
Executable file
0
etc/openpdu/openpdu.conf
Executable file
Loading…
Reference in New Issue
Block a user