WIP
parent
9a4f448a47
commit
32e4ace694
|
@ -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<CoreService>();
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
35
Program.cs
35
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<Layer2Segment> layer2segments = new ManagedNativeContainer<Layer2Segment>(managedRoot);
|
||||
ManagedNativeContainer<NetworkDevice> networkDevices = new ManagedNativeContainer<NetworkDevice>(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;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<CoreService>(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<CoreService>(true));
|
||||
ServiceContainer.Add(ServiceDefinition.From<IPPoolService>(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<AuthenticatedUser>("ID");
|
||||
CoreStorageMapper.EnsureIndex<AuthenticatedUser>("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<AuthenticatedUser>(Query.Equals<AuthenticatedUser>("Name", username)).FirstOrDefault();
|
||||
|
||||
if (authenticatedUser != null)
|
||||
{
|
||||
if (token <= authenticatedUser.Token)
|
||||
return null;
|
||||
|
||||
authenticatedUser.Token = token;
|
||||
|
||||
CoreStorageMapper.Save<AuthenticatedUser>(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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "www"
|
||||
},
|
||||
{
|
||||
"path": "/home/haraldwolff/src/mono/ln.application/www"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -70,6 +70,14 @@
|
|||
<Project>{D9342117-3249-4D8B-87C9-51A50676B158}</Project>
|
||||
<Name>ln.json</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\ln.provider.netwatch\ln.provider.netwatch.csproj">
|
||||
<Project>{A5BB8163-FA35-44D6-BAB8-B7A921D83462}</Project>
|
||||
<Name>ln.provider.netwatch</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\ln.manage\ln.manage.csproj">
|
||||
<Project>{D4E4FD39-6C21-4FCC-8DE0-6494FBE82CEA}</Project>
|
||||
<Name>ln.manage</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="www\" />
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -4,66 +4,44 @@
|
|||
<meta charset="utf-8" />
|
||||
<title>ln.provider Web Interface</title>
|
||||
|
||||
<link href="/css/ln.vue.css"/>
|
||||
<link href="/style.css" rel="stylesheet" />
|
||||
<link href="/page.layout.css" rel="stylesheet" />
|
||||
<link href="/tables.layout.css" rel="stylesheet" />
|
||||
|
||||
<script type="text/javascript" src="/vue.js"></script>
|
||||
<script type="text/javascript" src="/vue-router.js"></script>
|
||||
<script type="text/javascript" src="/ln.tools.js"></script>
|
||||
<script type="text/javascript" src="/ln.application.js"></script>
|
||||
|
||||
<script type="text/javascript" src="ln.provider.components.js"></script>
|
||||
<script type="text/javascript" src="ln.provider.js"></script>
|
||||
<script type="text/javascript" src="ln.provider.pool.js"></script>
|
||||
|
||||
<script type="text/javascript" src="/js/vue.js"></script>
|
||||
<script type="text/javascript" src="/js/vue-router.js"></script>
|
||||
<script type="text/javascript" src="/js/ln.vue.js"></script>
|
||||
<script type="text/javascript" src="/js/ln.vue.components.js"></script>
|
||||
|
||||
<script type="text/javascript" src="/ln.provider.components.js"></script>
|
||||
<script type="text/javascript" src="/ln.provider.js"></script>
|
||||
<script type="text/javascript" src="/ln.provider.pool.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="body">
|
||||
<div id="header">
|
||||
<section id="header">
|
||||
<div class="logo">
|
||||
<div style="background-color: #2a7fff; color: white;">ln.</div><div style="background-color: white;">provider</div>
|
||||
</div>
|
||||
</div>
|
||||
<ln-identity></ln-identity>
|
||||
</section>
|
||||
|
||||
<div id="navbar">
|
||||
<router-link
|
||||
v-for="route in LNProvider.routes"
|
||||
v-if="route.label"
|
||||
v-bind:to="route.path"
|
||||
>{{ route.label }}</router-link>
|
||||
</div>
|
||||
<ln-navbar></ln-navbar>
|
||||
|
||||
<div id="page">
|
||||
<section id="page">
|
||||
<router-view
|
||||
v-bind="{ LNP: LNP }"
|
||||
></router-view>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div id="footer" class="flex row">
|
||||
<div id="ServerString" class="silver">{{ LNP.serverString }}</div>
|
||||
<div class="grow"></div>
|
||||
<div id="ServerTime" class="" style="margin-right: 12px;">{{ LNP.serverTime }}</div>
|
||||
</div>
|
||||
<section id="footer" class="flex row">
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var LNP = new LNProvider();
|
||||
|
||||
LNP
|
||||
.initialize()
|
||||
.then(function(){
|
||||
const router = new VueRouter({
|
||||
routes: LNProvider.routes,
|
||||
});
|
||||
new Vue({
|
||||
el: "#body",
|
||||
data: {
|
||||
LNP,
|
||||
},
|
||||
router,
|
||||
}).$mount("#body");
|
||||
});
|
||||
var LNP = new LNVue();
|
||||
LNP.Start();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -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(){
|
||||
|
|
|
@ -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',
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue