mamman-sync: more wip
This commit is contained in:
		
							parent
							
								
									751589417b
								
							
						
					
					
						commit
						4dcf3e0212
					
				@ -2,8 +2,8 @@ msgid ""
 | 
			
		||||
msgstr ""
 | 
			
		||||
"Project-Id-Version: \n"
 | 
			
		||||
"POT-Creation-Date: \n"
 | 
			
		||||
"PO-Revision-Date: 2021-12-15 06:29+0100\n"
 | 
			
		||||
"Last-Translator: Cyrus Fox <cyrus@lambdacore.de>\n"
 | 
			
		||||
"PO-Revision-Date: 2021-12-15 07:33+0100\n"
 | 
			
		||||
"Last-Translator: Maciej Krüger <maciej@xeredo.it>\n"
 | 
			
		||||
"Language-Team: German\n"
 | 
			
		||||
"Language: de\n"
 | 
			
		||||
"MIME-Version: 1.0\n"
 | 
			
		||||
@ -16,10 +16,14 @@ msgid "Enable ManMan sync"
 | 
			
		||||
msgstr "ManMan synchronisierung aktivieren"
 | 
			
		||||
 | 
			
		||||
msgid "ManMan location ID"
 | 
			
		||||
msgstr "ManMan Knoten ID"
 | 
			
		||||
msgstr "ManMan Standort-ID"
 | 
			
		||||
 | 
			
		||||
msgid ""
 | 
			
		||||
"Sync data from ManMan by entering ManMan location id here.\n"
 | 
			
		||||
"This will automatically keep name, location and ips in sync with the values "
 | 
			
		||||
"specified in ManMan."
 | 
			
		||||
msgstr ""
 | 
			
		||||
"Synchronisiere die Konfiguration aus ManMan, indem du hier die ManMan "
 | 
			
		||||
"Standort-ID eingibst.\n"
 | 
			
		||||
"Dadurch werden Name, Standort und IP-Addressen automatisch mit den in "
 | 
			
		||||
"ManMan angegebenen Werten synchronisiert."
 | 
			
		||||
 | 
			
		||||
@ -13,5 +13,5 @@ end
 | 
			
		||||
if not msg then return end
 | 
			
		||||
 | 
			
		||||
renderer.render_string(msg, {
 | 
			
		||||
	node_id = uci:get("gluon", "manman_sync", "node_id")
 | 
			
		||||
	location_id = uci:get("gluon", "manman_sync", "location_id")
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
@ -1,20 +1,62 @@
 | 
			
		||||
#!/usr/bin/lua
 | 
			
		||||
 | 
			
		||||
local uci = require('simple-uci').cursor()
 | 
			
		||||
local ip = require "luci.ip" -- luci-lib-ip
 | 
			
		||||
 | 
			
		||||
local manman = 'https://manman.graz.funkfeuer.at'
 | 
			
		||||
 | 
			
		||||
-- NOTE: these will have mesh_ appended for static-ip
 | 
			
		||||
local mappings = {
 | 
			
		||||
  wifi = 'radio0',
 | 
			
		||||
  tunnel = 'vpn'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
if uci:get_bool('gluon', 'manman_sync', 'enabled') then
 | 
			
		||||
  if not uci:get('gluon', 'manman_sync', 'node_id') then
 | 
			
		||||
    print('E: manman node_id missing')
 | 
			
		||||
  if not uci:get('gluon', 'manman_sync', 'location_id') then
 | 
			
		||||
    print('E: manman location_id missing')
 | 
			
		||||
    return 2
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  -- check manman location, abort if not reachable
 | 
			
		||||
 | 
			
		||||
  location = getLocation()
 | 
			
		||||
  print('Syncing with location ' .. location['name'])
 | 
			
		||||
 | 
			
		||||
  local device
 | 
			
		||||
 | 
			
		||||
  if #location['devices'] > 1 then
 | 
			
		||||
    print('E: multiple devices, not impl yet')
 | 
			
		||||
    -- TODO: iterate devices, check if any with matching hostname, then use that
 | 
			
		||||
    return 2
 | 
			
		||||
  else
 | 
			
		||||
    device = location['devices'][0]
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  if device == nil then
 | 
			
		||||
    print('E: unable to find matching device')
 | 
			
		||||
    return 2
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  print('Syncing with device ' .. device['name'])
 | 
			
		||||
 | 
			
		||||
  -- TODO: compare device
 | 
			
		||||
 | 
			
		||||
  -- try to fetch data
 | 
			
		||||
  -- check if anything changed since last time
 | 
			
		||||
  -- if yes, apply changes and do gluon-reload
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  for index, net in ipairs(device['networks']) do
 | 
			
		||||
    net_name = net['name']
 | 
			
		||||
    net_mapped = 'mesh_' .. (mappings[net_name] or net_name)
 | 
			
		||||
 | 
			
		||||
    cidr = ip.new(net['ip'], net['netmask']):string()
 | 
			
		||||
 | 
			
		||||
    print('Syncing ' .. net_name .. ' as ' .. net_mapped .. ' to ' .. cidr)
 | 
			
		||||
    uci:set('gluon-static-ip', net_mapped, 'ip4', cidr)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  -- TODO: exec gluon-reload
 | 
			
		||||
else
 | 
			
		||||
  print('manman-sync not enabled, skipping')
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user