// /** // * File: HotspotManager.cs // * Author: haraldwolff // * // * This file and it's content is copyrighted by the Author and / or copyright holder. // * Any use wihtout proper permission is illegal and may lead to legal actions. // * // * // **/ using System; using ln.types.odb; using ln.types.odb.mapped; using ln.types.btree; using ln.types.net; using System.Collections.Generic; using System.IO; using skyspot.radius; using System.Linq; using skyspot.session; namespace skyspot.hotspot { public class HotspotManager { public string BasePath { get; private set; } = "/var/cache/ln.skyspot"; public RadiusSecretsStore SecretsStore { get; private set; } ODB odb; public ODBCollection hotspotNetworks { get; private set; } public ODBCollection radiusSecretsCollection; MappingBTree hotspotRuntimes = new MappingBTree((hr) => hr.HotspotNetwork); public SessionManager SessionManager { get; private set; } public HotspotManager() { odb = new ODB(BasePath); hotspotNetworks = odb.GetCollection(); radiusSecretsCollection = odb.GetCollection(); SecretsStore = radiusSecretsCollection.FirstOrDefault(); if (SecretsStore == null) SecretsStore = new RadiusSecretsStore(); SessionManager = new SessionManager(this); } public void SaveSecretsStore() => radiusSecretsCollection.Upsert(SecretsStore); public void AddHotspotNetwork(HotspotNetwork hotspotNetwork) { if (!hotspotRuntimes.ContainsKey(hotspotNetwork)) hotspotRuntimes.Add(new HotspotNetworkRuntime(hotspotNetwork)); } public void RemoveHotspotNetwork(HotspotNetwork hotspotNetwork) { if (hotspotRuntimes.ContainsKey(hotspotNetwork)) { hotspotRuntimes.RemoveKey(hotspotNetwork); } } public HotspotNetworkRuntime GetHotspotNetworkRuntime(HotspotNetwork hotspotNetwork) { return hotspotRuntimes[hotspotNetwork]; } public HotspotNetworkRuntime GetHotspotNetworkRuntime(string networkName) { foreach (HotspotNetworkRuntime hotspotNetworkRuntime in hotspotRuntimes) { if (hotspotNetworkRuntime.HotspotNetwork.Name.Equals(networkName)) return hotspotNetworkRuntime; } throw new KeyNotFoundException(); } public HotspotNetwork GetHotspotNetwork(String name) { foreach (HotspotNetworkRuntime hotspotNetworkRuntime in hotspotRuntimes) { if (hotspotNetworkRuntime.HotspotNetwork.Name.Equals(name)) return hotspotNetworkRuntime.HotspotNetwork; } throw new KeyNotFoundException(); } } }