Initial commit gluon-config-mode
based on freifunk-gluon/packages@9d364a6fbc
This commit is contained in:
		
					parent
					
						
							
								a45db5df08
							
						
					
				
			
			
				commit
				
					
						86348c815b
					
				
			
		
					 14 changed files with 546 additions and 0 deletions
				
			
		|  | @ -0,0 +1,83 @@ | |||
| --[[ | ||||
| Copyright 2013 Nils Schneider <nils@nilsschneider.net> | ||||
| 
 | ||||
| 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$ | ||||
| ]]-- | ||||
| 
 | ||||
| module("luci.controller.gluon-config-mode.index", package.seeall) | ||||
| 
 | ||||
| local site = require 'gluon.site_config' | ||||
| 
 | ||||
| 
 | ||||
| local meshvpn_name = "mesh_vpn" | ||||
| 
 | ||||
| 
 | ||||
| function index() | ||||
|   local uci_state = luci.model.uci.cursor_state() | ||||
| 
 | ||||
|   if uci_state:get_first("gluon-config-mode", "wizard", "running", "0") == "1" then | ||||
|     local root = node() | ||||
|     if not root.target then | ||||
|       root.target = alias("gluon-config-mode") | ||||
|       root.index = true | ||||
|     end | ||||
| 
 | ||||
|     page          = node() | ||||
|     page.lock     = true | ||||
|     page.target   = alias("gluon-config-mode") | ||||
|     page.subindex = true | ||||
|     page.index    = false | ||||
| 
 | ||||
|     page          = node("gluon-config-mode") | ||||
|     page.title    = _("Wizard") | ||||
|     page.target   = alias("gluon-config-mode", "wizard") | ||||
|     page.order    = 5 | ||||
|     page.setuser  = "root" | ||||
|     page.setgroup = "root" | ||||
|     page.index    = true | ||||
| 
 | ||||
|     entry({"gluon-config-mode", "wizard"}, form("gluon-config-mode/wizard")).index = true | ||||
|     entry({"gluon-config-mode", "reboot"}, call("action_reboot")) | ||||
|   end | ||||
| end | ||||
| 
 | ||||
| function action_reboot() | ||||
|   local configmode = require "luci.tools.gluon-config-mode" | ||||
|   local pubkey | ||||
|   local uci = luci.model.uci.cursor() | ||||
|   local meshvpn_enabled = uci:get("fastd", meshvpn_name, "enabled", "0") | ||||
|   local sysconfig = require 'gluon.sysconfig' | ||||
|   if meshvpn_enabled == "1" then | ||||
|     pubkey = configmode.get_fastd_pubkey(meshvpn_name) | ||||
|   end | ||||
| 
 | ||||
|   uci:set("gluon-config-mode", uci:get_first("gluon-config-mode", "wizard"), "configured", "1") | ||||
|   uci:save("gluon-config-mode") | ||||
|   uci:commit("gluon-config-mode") | ||||
| 
 | ||||
|   local hostname = uci:get_first("system", "system", "hostname") | ||||
| 
 | ||||
|   if nixio.fork() ~= 0 then | ||||
|     luci.template.render("gluon-config-mode/reboot", | ||||
|       {luci=luci, pubkey=pubkey, hostname=hostname, site=site, sysconfig=sysconfig}) | ||||
|   else | ||||
|     debug.setfenv(io.stdout, debug.getfenv(io.open '/dev/null')) | ||||
|     io.stdout:close() | ||||
| 
 | ||||
|     -- Sleep a little so the browser can fetch everything required to | ||||
|     -- display the reboot page, then reboot the device. | ||||
|     nixio.nanosleep(2) | ||||
| 
 | ||||
|     -- Run reboot with popen so it gets its own std filehandles. | ||||
|     io.popen("reboot") | ||||
| 
 | ||||
|     -- Prevent any further execution in this child. | ||||
|     os.exit() | ||||
|   end | ||||
| end | ||||
|  | @ -0,0 +1,139 @@ | |||
| local configmode = require "luci.tools.gluon-config-mode" | ||||
| local meshvpn_name = "mesh_vpn" | ||||
| local uci = luci.model.uci.cursor() | ||||
| local f, s, o | ||||
| 
 | ||||
| -- prepare fastd key as early as possible | ||||
| configmode.setup_fastd_secret(meshvpn_name) | ||||
| 
 | ||||
| f = SimpleForm("wizard") | ||||
| f.reset = false | ||||
| f.template = "gluon-config-mode/cbi/wizard" | ||||
| f.submit = "Fertig" | ||||
| 
 | ||||
| s = f:section(SimpleSection, nil, nil) | ||||
| 
 | ||||
| o = s:option(Value, "_hostname", "Name dieses Knotens") | ||||
| o.value = uci:get_first("system", "system", "hostname") | ||||
| o.rmempty = false | ||||
| o.datatype = "hostname" | ||||
| 
 | ||||
| o = s:option(Flag, "_autoupdate", "Firmware automatisch aktualisieren") | ||||
| o.default = uci:get_bool("autoupdater", "settings", "enabled") and o.enabled or o.disabled | ||||
| o.rmempty = false | ||||
| 
 | ||||
| s = f:section(SimpleSection, nil, [[Falls du deinen Knoten über das Internet | ||||
| mit Freifunk verbinden möchtest, kannst du hier das Mesh-VPN aktivieren. | ||||
| Solltest du dich dafür entscheiden, hast du die Möglichkeit die dafür | ||||
| genutzte Bandbreite zu beschränken.]]) | ||||
| 
 | ||||
| o = s:option(Flag, "_meshvpn", "Mesh-VPN aktivieren") | ||||
| o.default = uci:get_bool("fastd", meshvpn_name, "enabled") and o.enabled or o.disabled | ||||
| o.rmempty = false | ||||
| 
 | ||||
| o = s:option(Flag, "_limit_enabled", "Mesh-VPN Bandbreite begrenzen") | ||||
| o:depends("_meshvpn", "1") | ||||
| o.default = uci:get_bool("gluon-simple-tc", meshvpn_name, "enabled") and o.enabled or o.disabled | ||||
| o.rmempty = false | ||||
| 
 | ||||
| o = s:option(Value, "_limit_ingress", "Downstream (kbit/s)") | ||||
| o:depends("_limit_enabled", "1") | ||||
| o.value = uci:get("gluon-simple-tc", meshvpn_name, "limit_ingress") | ||||
| o.rmempty = false | ||||
| o.datatype = "integer" | ||||
| 
 | ||||
| o = s:option(Value, "_limit_egress", "Upstream (kbit/s)") | ||||
| o:depends("_limit_enabled", "1") | ||||
| o.value = uci:get("gluon-simple-tc", meshvpn_name, "limit_egress") | ||||
| o.rmempty = false | ||||
| o.datatype = "integer" | ||||
| 
 | ||||
| s = f:section(SimpleSection, nil, [[Um deinen Knoten auf der Karte anzeigen | ||||
| zu können, benötigen wir seine Koordinaten. Hier hast du die Möglichkeit, | ||||
| diese zu hinterlegen.]]) | ||||
| 
 | ||||
| o = s:option(Flag, "_location", "Knoten auf der Karte anzeigen") | ||||
| o.default = uci:get_first("gluon-node-info", "location", "share_location", o.disabled) | ||||
| o.rmempty = false | ||||
| 
 | ||||
| o = s:option(Value, "_latitude", "Breitengrad") | ||||
| o.default = uci:get_first("gluon-node-info", "location", "latitude") | ||||
| o:depends("_location", "1") | ||||
| o.rmempty = false | ||||
| o.datatype = "float" | ||||
| o.description = "z.B. 53.873621" | ||||
| 
 | ||||
| o = s:option(Value, "_longitude", "Längengrad") | ||||
| o.default = uci:get_first("gluon-node-info", "location", "longitude") | ||||
| o:depends("_location", "1") | ||||
| o.rmempty = false | ||||
| o.datatype = "float" | ||||
| o.description = "z.B. 10.689901" | ||||
| 
 | ||||
| s = f:section(SimpleSection, nil, [[Hier kannst du einen | ||||
| <em>öffentlichen</em> Hinweis hinterlegen um anderen Freifunkern zu | ||||
| ermöglichen Kontakt mit dir aufzunehmen. Bitte beachte, dass dieser Hinweis | ||||
| auch öffentlich im Internet, zusammen mit den Koordinaten deines Knotens, | ||||
| einsehbar sein wird.]]) | ||||
| 
 | ||||
| o = s:option(Value, "_contact", "Kontakt") | ||||
| o.default = uci:get_first("gluon-node-info", "owner", "contact", "") | ||||
| o.rmempty = true | ||||
| o.datatype = "string" | ||||
| o.description = "z.B. E-Mail oder Telefonnummer" | ||||
| o.maxlen = 140 | ||||
| 
 | ||||
| function f.handle(self, state, data) | ||||
|   if state == FORM_VALID then | ||||
|     local stat = false | ||||
| 
 | ||||
|     uci:set("autoupdater", "settings", "enabled", data._autoupdate) | ||||
|     uci:save("autoupdater") | ||||
|     uci:commit("autoupdater") | ||||
| 
 | ||||
|     -- checks for nil needed due to o:depends(...) | ||||
|     if data._limit_enabled ~= nil then | ||||
|       uci:set("gluon-simple-tc", meshvpn_name, "interface") | ||||
|       uci:set("gluon-simple-tc", meshvpn_name, "enabled", data._limit_enabled) | ||||
|       uci:set("gluon-simple-tc", meshvpn_name, "ifname", "mesh-vpn") | ||||
| 
 | ||||
|       if data._limit_ingress ~= nil then | ||||
|         uci:set("gluon-simple-tc", meshvpn_name, "limit_ingress", data._limit_ingress) | ||||
|       end | ||||
| 
 | ||||
|       if data._limit_egress ~= nil then | ||||
|         uci:set("gluon-simple-tc", meshvpn_name, "limit_egress", data._limit_egress) | ||||
|       end | ||||
| 
 | ||||
|       uci:commit("gluon-simple-tc") | ||||
|     end | ||||
| 
 | ||||
|     uci:set("fastd", meshvpn_name, "enabled", data._meshvpn) | ||||
|     uci:save("fastd") | ||||
|     uci:commit("fastd") | ||||
| 
 | ||||
|     uci:set("system", uci:get_first("system", "system"), "hostname", data._hostname) | ||||
|     uci:save("system") | ||||
|     uci:commit("system") | ||||
| 
 | ||||
|     local sname = uci:get_first("gluon-node-info", "location") | ||||
|     uci:set("gluon-node-info", sname, "share_location", data._location) | ||||
|     if data._location and data._latitude ~= nil and data._longitude ~= nil then | ||||
|       uci:set("gluon-node-info", sname, "latitude", data._latitude) | ||||
|       uci:set("gluon-node-info", sname, "longitude", data._longitude) | ||||
|     end | ||||
|     if data._contact ~= nil then | ||||
|       uci:set("gluon-node-info", uci:get_first("gluon-node-info", "owner"), "contact", data._contact) | ||||
|     else | ||||
|       uci:delete("gluon-node-info", uci:get_first("gluon-node-info", "owner"), "contact") | ||||
|     end | ||||
|     uci:save("gluon-node-info") | ||||
|     uci:commit("gluon-node-info") | ||||
| 
 | ||||
|     luci.http.redirect(luci.dispatcher.build_url("gluon-config-mode", "reboot")) | ||||
|   end | ||||
| 
 | ||||
|   return true | ||||
| end | ||||
| 
 | ||||
| return f | ||||
|  | @ -0,0 +1,29 @@ | |||
| local luci = require "luci" | ||||
| local io = require "io" | ||||
| 
 | ||||
| module "luci.tools.gluon-config-mode" | ||||
| 
 | ||||
| function setup_fastd_secret(name) | ||||
|   local uci = luci.model.uci.cursor() | ||||
|   local secret = uci:get("fastd", name, "secret") | ||||
| 
 | ||||
|   if not secret or not secret:match("%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x") then | ||||
|     local f = io.popen("fastd --generate-key --machine-readable", "r") | ||||
|     local secret = f:read("*a") | ||||
|     f:close() | ||||
| 
 | ||||
|     uci:set("fastd", name, "secret", secret) | ||||
|     uci:save("fastd") | ||||
|     uci:commit("fastd") | ||||
|   end | ||||
| end | ||||
| 
 | ||||
| function get_fastd_pubkey(name) | ||||
|   local f = io.popen("/etc/init.d/fastd show_key " .. name, "r") | ||||
|   local key = f:read("*a") | ||||
|   f:close() | ||||
| 
 | ||||
|   return key | ||||
| end | ||||
| 
 | ||||
| 
 | ||||
|  | @ -0,0 +1,68 @@ | |||
| <%- | ||||
| 	local site = require 'gluon.site_config' | ||||
| 	local sysconfig = require 'gluon.sysconfig' | ||||
| 	local template = require 'luci.template' | ||||
| -%> | ||||
| 
 | ||||
| <h2>Willkommen!</h2> | ||||
| <p> | ||||
| 	<%= template.render_string(site.config_mode.msg_welcome, {hostname=hostname, sysconfig=sysconfig}) %> | ||||
| </p> | ||||
| 
 | ||||
| <% if not self.embedded then %> | ||||
| <form method="post" enctype="multipart/form-data" action="<%=REQUEST_URI%>"> | ||||
| 	<div> | ||||
| 		<script type="text/javascript" src="<%=resource%>/cbi.js"></script> | ||||
| 		<input type="hidden" name="cbi.submit" value="1" /> | ||||
| 	</div> | ||||
| <% end %> | ||||
| 	<div class="cbi-map" id="cbi-<%=self.config%>"> | ||||
| 		<% if self.title and #self.title > 0 then %><h2><a id="content" name="content"><%=self.title%></a></h2><% end %> | ||||
| 		<% if self.description and #self.description > 0 then %><div class="cbi-map-descr"><%=self.description%></div><% end %> | ||||
| 		<% self:render_children() %> | ||||
| 		<br /> | ||||
| 	</div> | ||||
| <%- if self.message then %> | ||||
| 	<div><%=self.message%></div> | ||||
| <%- end %> | ||||
| <%- if self.errmessage then %> | ||||
| 	<div class="error"><%=self.errmessage%></div> | ||||
| <%- end %> | ||||
| <% if not self.embedded then %> | ||||
| 	<div class="cbi-page-actions"> | ||||
| <%- | ||||
| 	if type(self.hidden) == "table" then | ||||
| 		for k, v in pairs(self.hidden) do | ||||
| -%> | ||||
| 	<input type="hidden" id="<%=k%>" name="<%=k%>" value="<%=pcdata(v)%>" /> | ||||
| <%- | ||||
| 		end | ||||
| 	end | ||||
| %> | ||||
| <% if redirect then %> | ||||
| 	<div style="float:left"> | ||||
| 		<input class="cbi-button cbi-button-link" type="button" value="<%:Back to Overview%>" onclick="location.href='<%=pcdata(redirect)%>'" /> | ||||
| 	</div> | ||||
| <% end %> | ||||
| <%- if self.flow and self.flow.skip then %> | ||||
| 	<input class="cbi-button cbi-button-skip" type="submit" name="cbi.skip" value="<%:Skip%>" /> | ||||
| <% end %> | ||||
| <%- if self.submit ~= false then %> | ||||
| 	<input class="cbi-button cbi-button-save" type="submit" value=" | ||||
| 		<%- if not self.submit then -%><%-:Submit-%><%-else-%><%=self.submit%><%end-%> | ||||
| 	" /> | ||||
| <% end %> | ||||
| <%- if self.reset ~= false then %> | ||||
| 	<input class="cbi-button cbi-button-reset" type="reset" value=" | ||||
| 		<%- if not self.reset then -%><%-:Reset-%><%-else-%><%=self.reset%><%end-%> | ||||
| 	" /> | ||||
| <% end %> | ||||
| <%- if self.cancel ~= false and self.on_cancel then %> | ||||
| 	<input class="cbi-button cbi-button-reset" type="submit" name="cbi.cancel" value=" | ||||
| 		<%- if not self.cancel then -%><%-:Cancel-%><%-else-%><%=self.cancel%><%end-%> | ||||
| 	" /> | ||||
| <% end %> | ||||
| 		<script type="text/javascript">cbi_d_update();</script> | ||||
| 	</div> | ||||
| </form> | ||||
| <% end %> | ||||
|  | @ -0,0 +1,31 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||||
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<%=luci.i18n.context.lang%>" lang="<%=luci.i18n.context.lang%>"> | ||||
|   <head> | ||||
|     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||||
|     <title><%=hostname%> - <% if title then %><%=title%><% else %><%:Rebooting...%><% end %></title> | ||||
|     <link rel="stylesheet" type="text/css" media="screen" href="<%=media%>/cascade.css" /> | ||||
|   </head> | ||||
|   <body> | ||||
|     <div id="maincontainer"> | ||||
|       <div id="maincontent"> | ||||
|         <h2>Geschafft! Dein Freifunkknoten ist nun fertig eingerichtet.</h2> | ||||
|         <% if pubkey then %> | ||||
|         <fieldset class="cbi-section"> | ||||
|           <p> | ||||
|             <%= luci.template.render_string(site.config_mode.msg_pubkey) %> | ||||
|           </p> | ||||
|           <div class="the-key"> | ||||
|             # <%= hostname %> | ||||
|             <br/> | ||||
|             <%= pubkey %> | ||||
|           </div> | ||||
|         </fieldset> | ||||
|         <% end %> | ||||
|         <fieldset class="cbi-section"> | ||||
|           <%= luci.template.render_string(site.config_mode.msg_reboot) %> | ||||
|         </fieldset> | ||||
|       </div> | ||||
|     </div> | ||||
|   </body> | ||||
| </html> | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 ohrensessel
				ohrensessel