diff --git a/IPPoolService.cs b/IPPoolService.cs index 932affc..90b6b1e 100644 --- a/IPPoolService.cs +++ b/IPPoolService.cs @@ -8,14 +8,16 @@ using System.Collections.Generic; using System.Linq; using ln.json; using ln.types.odb.ng.storage.session; +using ln.types.net; namespace ln.provider { public class IPPoolService : ApplicationServiceBase { CoreService CoreService { get; set; } - ProviderApplication Application => (ProviderApplication)base.CurrentApplicationInterface; + ProviderApplication Application => base.CurrentApplication as ProviderApplication; - RPC rpc; + + RPC rpc; SessionStorageContainer mapperSession; Mapper mapper; @@ -31,7 +33,7 @@ namespace ln.provider rpc = new RPC(this); } - public override void ServiceMain(IApplicationInterface applicationInterface) + public override void ServiceMain(Application applicationInterface) { CoreService = Dependency(); @@ -110,21 +112,30 @@ namespace ln.provider IPAllocation allocation = pool; while (!allocation.CIDR.Equals(cidr)) { - foreach (IPv6 splitCIDR in allocation.CIDR.Split(1)) + IPAllocation split = null; + + foreach (IPv6 splitCIDR in allocation.CIDR.Split(1)) { if (splitCIDR.Contains(cidr)) { - IPAllocation split = GetAllocation(splitCIDR); + split = GetAllocation(splitCIDR); if (split == null) { split = new IPAllocation(splitCIDR,allocation.CIDR); mapper.Save(split); - allocation = split; break; } - } + else if (Equals(String.Empty,split.AllocatedTo)) + { + break; + } + throw new ArgumentOutOfRangeException(String.Format("No subnet available below {0}",allocation.CIDR.ToCIDR())); + } } + allocation = split; } + allocation.AllocatedTo = usage; + mapper.Save(allocation); return allocation; } else @@ -140,7 +151,6 @@ namespace ln.provider return allocation; } - return null; } diff --git a/Program.cs b/Program.cs index 50e4dad..21834da 100644 --- a/Program.cs +++ b/Program.cs @@ -3,6 +3,11 @@ using ln.types.odb.ng; using ln.provider.data.phone; using ln.provider.data; using ln.logging; +using ln.provider.netwatch.entities; +using ln.manage; +using System.Threading; +using ln.types.threads; +using ln.types.net; namespace ln.provider { @@ -10,8 +15,34 @@ namespace ln.provider { public static void Main(string[] args) { - ProviderApplication providerApplication = new ProviderApplication(); - providerApplication.Start(args); + //new ProviderApplication().Start(args); + + ManagedRoot managedRoot = new ManagedRoot(); + ManagedConsole managedConsole = new ManagedConsole(managedRoot); + + ManagedNativeContainer layer2segments = new ManagedNativeContainer(managedRoot); + ManagedNativeContainer networkDevices = new ManagedNativeContainer(managedRoot); + + IManagedObject nd0 = networkDevices.CreateManagedObject(); + nd0.Enabled = true; + IManagedObject nd1 = networkDevices.CreateManagedObject(); + nd1.SetValue("IPAddresses", new IPv6[] { IPv6.Parse("10.118.254.1"), IPv6.Parse("10.118.2.1") }); + nd1.Enabled = true; + IManagedObject nd2 = networkDevices.CreateManagedObject(); + nd2.Enabled = true; + + Thread.Sleep(5000); + nd1.Enabled = false; + Thread.Sleep(5000); + + Console.WriteLine(managedConsole.Export()); + + Thread.Sleep(5000); + + nd0.Enabled = false; + nd1.Enabled = false; + nd2.Enabled = false; + } } } diff --git a/ProviderApplication.cs b/ProviderApplication.cs index 1b3d2b6..b3c5ef1 100644 --- a/ProviderApplication.cs +++ b/ProviderApplication.cs @@ -3,13 +3,8 @@ using ln.application; using ln.application.service; using System.Threading; using ln.http.resources; -using System.IO; -using ln.types.rpc; using ln.types.odb.ng; using ln.types.odb.ng.storage; -using System.Security.Cryptography; -using System.Linq; -using ln.types; using ln.types.odb.ng.storage.session; using ln.types.odb.ng.storage.fs; namespace ln.provider @@ -17,53 +12,30 @@ namespace ln.provider public class ProviderApplication : Application { public String ServerString { get; private set; } - public String WWWPath { get; private set; } = "www"; - - public ResourceApplication WWWApplication { get; private set; } - public RPCContainer RPCContainer { get; private set; } public ProviderApplication() { ServerString = "ln.provider(0.1)"; - RPCContainer = new RPCContainer(); - if (Directory.Exists("../../www")) - WWWPath = "../../www"; - - ServiceDefinition coreRPCService = ServiceDefinition.From(true); - ServiceContainer.Add(coreRPCService); + DirectoryResource www = new DirectoryResource(new string[] { "../../www", "www" }); + www.DefaultResource = www.GetResource("index.html"); + www.FallBackResource = www.DefaultResource; + RootResource = www; + + ServiceContainer.Add(ServiceDefinition.From(true)); ServiceContainer.Add(ServiceDefinition.From(true)); } public override void PrepareStart() { - DirectoryResource www = new DirectoryResource(new string[] { "../../www", "www" }); - www.DefaultResource = www.GetResource("index.html"); - - ApplicationWebSocket applicationWebSocket = new ApplicationWebSocket(null, "socket", RPCContainer); - www.InjectResource(applicationWebSocket); - - WWWApplication = new ResourceApplication(); - WWWApplication.RootResource = www; } - public override AuthenticatedUser AuthenticateUser(string username, object prove) - { - CoreService coreService = ServiceContainer[typeof(CoreService)].ServiceBase as CoreService; - - String[] tokens = prove.ToString().Split(':'); - int token = int.Parse(tokens[0]); - - AuthenticatedUser authenticatedUser = coreService.Authenticate(username, token, tokens[1]); - - return authenticatedUser; - } } public class CoreService : ApplicationServiceBase { - public ProviderApplication Application => (ProviderApplication)base.CurrentApplicationInterface; + public ProviderApplication Application => (ProviderApplication)base.CurrentApplication; public IStorageContainer CoreStorageContainer { get; private set; } public SessionStorageContainer CoreStorageSession { get; private set; } @@ -74,7 +46,7 @@ namespace ln.provider { } - public override void ServiceMain(IApplicationInterface applicationInterface) + public override void ServiceMain(Application application) { CoreStorageContainer = new FSStorageContainer("/var/cache/ln.provider"); CoreStorageContainer.Open(); @@ -82,12 +54,6 @@ namespace ln.provider CoreStorageSession = new SessionStorageContainer(CoreStorageContainer); CoreStorageMapper = new Mapper(CoreStorageSession); - CoreStorageMapper.EnsureIndex("ID"); - CoreStorageMapper.EnsureIndex("Name"); - - - - Application.HttpServer.DefaultApplication = Application.WWWApplication; Application.RPCContainer.Add("core",new RPC(Application)); Ready(); @@ -107,32 +73,6 @@ namespace ln.provider CoreStorageContainer = null; } - public AuthenticatedUser Authenticate(string username,int token,string secretHash) - { - AuthenticatedUser authenticatedUser = CoreStorageMapper.Load(Query.Equals("Name", username)).FirstOrDefault(); - - if (authenticatedUser != null) - { - if (token <= authenticatedUser.Token) - return null; - - authenticatedUser.Token = token; - - CoreStorageMapper.Save(authenticatedUser); - - byte[] secretHashBytes = Extensions.BytesFromHexString(secretHash); - - SHA256 sha256 = SHA256.Create(); - sha256.TransformBlock(token.GetBytes(), 0, 4, null, 0); - sha256.TransformFinalBlock(authenticatedUser.SecretHash, 0, authenticatedUser.SecretHash.Length); - - if (sha256.Hash.AreEqual(secretHashBytes)) - return authenticatedUser; - - return null; - } - return null; - } class RPC { @@ -153,25 +93,6 @@ namespace ln.provider ThreadPool.QueueUserWorkItem((state) => providerApplication.Stop()); } - public bool Authenticate(string username,string secretHash) - { - return false; - } - - public Guid GetApplicationContext(string contextID) - { - Guid id; - if (string.Empty.Equals(contextID)) - id = Guid.Empty; - else - id = Guid.Parse(contextID); - - ApplicationContext applicationContext = providerApplication.GetApplicationContext(id); - ApplicationContext.SetCurrentContext(applicationContext); - - return applicationContext.ContextID; - } - } diff --git a/ln.provider b/ln.provider new file mode 100644 index 0000000..dfd2c1f --- /dev/null +++ b/ln.provider @@ -0,0 +1,10 @@ +{ + "folders": [ + { + "path": "www" + }, + { + "path": "/home/haraldwolff/src/mono/ln.application/www" + } + ] +} \ No newline at end of file diff --git a/ln.provider.csproj b/ln.provider.csproj index 041962e..4b7354b 100644 --- a/ln.provider.csproj +++ b/ln.provider.csproj @@ -70,6 +70,14 @@ {D9342117-3249-4D8B-87C9-51A50676B158} ln.json + + {A5BB8163-FA35-44D6-BAB8-B7A921D83462} + ln.provider.netwatch + + + {D4E4FD39-6C21-4FCC-8DE0-6494FBE82CEA} + ln.manage + diff --git a/ln.provider.sln b/ln.provider.sln index eda3275..c21095c 100644 --- a/ln.provider.sln +++ b/ln.provider.sln @@ -21,6 +21,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ln.application", "..\ln.app EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ln.templates", "..\ln.templates\ln.templates.csproj", "{AD0267BB-F08C-4BE1-A88D-010D49041761}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ln.provider.netwatch", "..\ln.provider.netwatch\ln.provider.netwatch.csproj", "{A5BB8163-FA35-44D6-BAB8-B7A921D83462}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ln.manage", "..\ln.manage\ln.manage.csproj", "{D4E4FD39-6C21-4FCC-8DE0-6494FBE82CEA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x86 = Debug|x86 @@ -67,5 +71,13 @@ Global {AD0267BB-F08C-4BE1-A88D-010D49041761}.Debug|x86.Build.0 = Debug|Any CPU {AD0267BB-F08C-4BE1-A88D-010D49041761}.Release|x86.ActiveCfg = Release|Any CPU {AD0267BB-F08C-4BE1-A88D-010D49041761}.Release|x86.Build.0 = Release|Any CPU + {A5BB8163-FA35-44D6-BAB8-B7A921D83462}.Debug|x86.ActiveCfg = Debug|Any CPU + {A5BB8163-FA35-44D6-BAB8-B7A921D83462}.Debug|x86.Build.0 = Debug|Any CPU + {A5BB8163-FA35-44D6-BAB8-B7A921D83462}.Release|x86.ActiveCfg = Release|Any CPU + {A5BB8163-FA35-44D6-BAB8-B7A921D83462}.Release|x86.Build.0 = Release|Any CPU + {D4E4FD39-6C21-4FCC-8DE0-6494FBE82CEA}.Debug|x86.ActiveCfg = Debug|Any CPU + {D4E4FD39-6C21-4FCC-8DE0-6494FBE82CEA}.Debug|x86.Build.0 = Debug|Any CPU + {D4E4FD39-6C21-4FCC-8DE0-6494FBE82CEA}.Release|x86.ActiveCfg = Release|Any CPU + {D4E4FD39-6C21-4FCC-8DE0-6494FBE82CEA}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/www/index.html b/www/index.html index 22ea9ee..da19b01 100644 --- a/www/index.html +++ b/www/index.html @@ -4,66 +4,44 @@ ln.provider Web Interface + - - - - - - - - - + + + + + + + +
- + + - + -
+
-
+ - +
diff --git a/www/ln.provider.js b/www/ln.provider.js index 29e3382..2b89fc7 100644 --- a/www/ln.provider.js +++ b/www/ln.provider.js @@ -11,12 +11,6 @@ this.lagDetector = null; this.IPAllocations = []; - - LN().option("wsError",(e)=>self.wsError(e)); - LN().option("wsClose",(e)=>self.wsClose(e)); - LN().option("wsUpdate",(e)=>self.wsUpdate(e)); - - LN().connect(); } initialize(){ diff --git a/www/ln.provider.pool.js b/www/ln.provider.pool.js index b077514..17fed99 100644 --- a/www/ln.provider.pool.js +++ b/www/ln.provider.pool.js @@ -1,45 +1,33 @@ -LNProvider.initializers.push( - new Promise((resolve,reject)=>{ - LN() - .load("/ln.provider.pool.html") - .then((template)=>{ - LNProvider.routes.push( - { - path: "/ippool", - label: "IP Pool", - component: { - props: { - LNP: Object, - }, - template: template, - data: function(){ - return { - allocationWidth: 64, - targetCIDR: "", - independentAllocation: false, - allocationType: 0, - allocationUsage: "", - }; - }, - computed: { - IPAllocations: ()=>LNP.IPAllocations, - subnetWidth: { - get: function(){ - return 128 - this.allocationWidth; - }, - set: function(v){ - this.allocationWidth = 128 - v; - }, - }, - }, - beforeRouteEnter: function(to,from,next){ - LNP.loadIPAllocations(); - next(); - }, +LNVue.$_.addModule({ + routes: { + '/ippool': { + url: '/ln.provider.pool.html', + data: function(){ + return { + allocationWidth: 64, + targetCIDR: "", + independentAllocation: false, + allocationType: 0, + allocationUsage: "", + }; + }, + computed: { + IPAllocations: ()=>LNP.IPAllocations, + subnetWidth: { + get: function(){ + return 128 - this.allocationWidth; }, - } - ); - resolve(); - }); - }) -); + set: function(v){ + this.allocationWidth = 128 - v; + }, + }, + }, + }, + }, + navigation: { + ippool: { + label: "IP Pool", + path: '/ippool', + } + }, +});