Browse Source

commit: merge bin path, two step http chain

HOME 4 years ago
parent
commit
713ef16378

+ 1 - 1
DhcpServer/App.config

@@ -11,7 +11,7 @@
   <applicationSettings>
     <DhcpServer.Properties.Settings>
       <setting name="ListenOn" serializeAs="String">
-        <value>192.168.66.55</value>
+        <value>192.168.233.233</value>
       </setting>
     </DhcpServer.Properties.Settings>
   </applicationSettings>

+ 2 - 2
DhcpServer/DhcpServer.csproj

@@ -18,7 +18,7 @@
     <DebugSymbols>true</DebugSymbols>
     <DebugType>full</DebugType>
     <Optimize>false</Optimize>
-    <OutputPath>bin\Debug\</OutputPath>
+    <OutputPath>..\bin\Debug\</OutputPath>
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
@@ -28,7 +28,7 @@
     <PlatformTarget>AnyCPU</PlatformTarget>
     <DebugType>pdbonly</DebugType>
     <Optimize>true</Optimize>
-    <OutputPath>bin\Release\</OutputPath>
+    <OutputPath>..\bin\Release\</OutputPath>
     <DefineConstants>TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>

+ 1 - 1
DhcpServer/Properties/Settings.Designer.cs

@@ -25,7 +25,7 @@ namespace DhcpServer.Properties {
         
         [global::System.Configuration.ApplicationScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute("0.0.0.0")]
+        [global::System.Configuration.DefaultSettingValueAttribute("192.168.233.233")]
         public string ListenOn {
             get {
                 return ((string)(this["ListenOn"]));

+ 1 - 1
DhcpServer/Properties/Settings.settings

@@ -3,7 +3,7 @@
   <Profiles />
   <Settings>
     <Setting Name="ListenOn" Type="System.String" Scope="Application">
-      <Value Profile="(Default)">0.0.0.0</Value>
+      <Value Profile="(Default)">192.168.233.233</Value>
     </Setting>
   </Settings>
 </SettingsFile>

+ 1 - 1
HttpServer/App.config

@@ -11,7 +11,7 @@
     <applicationSettings>
         <HttpServer.Properties.Settings>
             <setting name="ListenPrefix" serializeAs="String">
-                <value>http://*:8444/</value>
+                <value>http://192.168.233.233:8013/</value>
             </setting>
         </HttpServer.Properties.Settings>
     </applicationSettings>

+ 4 - 0
HttpServer/App/IpxeScriptManager.cs

@@ -16,6 +16,10 @@ namespace HttpServer.App
             "#!ipxe\r\n" +
             "echo Error: Boot script is no configured, please edit script file.";
 
+        public static string GetInitScript(string url) =>
+            "#!ipxe\r\n" +
+            "chain " + url + "boot/ipxe/script?mac=${mac:hexhyp}";
+
         public static string GetScript(string mac)
         {
             var path = Path.Combine(ScriptDir, "MAC-" + FilterMac(mac) + ".txt");

+ 22 - 9
HttpServer/HttpProgram.cs

@@ -74,18 +74,31 @@ namespace HttpServer
                     var request = context.Request;
                     Console.WriteLine($"Request from {request.RemoteEndPoint} {request.HttpMethod} {request.RawUrl}");
 
-                    var queryString = HttpUtility.ParseQueryString(request.Url.Query);
-                    var mac = queryString["mac"]?.Replace(":", "-").ToUpper();
-                    var assetTag = queryString["asset"];
+                    var requestPath = request.Url.LocalPath.ToLower();
 
-                    Console.WriteLine($" MAC:{mac}");
-                    Console.WriteLine($" AssetTag:{assetTag}");
+                    if (requestPath == "/boot/ipxe")
+                    {
+                        Console.WriteLine(" Send init script");
+                        var buffer = Encoding.ASCII.GetBytes(IpxeScriptManager.GetInitScript(Properties.Settings.Default.ListenPrefix));
+                        context.Response.OutputStream.Write(buffer, 0, buffer.Length);
+                        context.Response.Close();
+                    }
+                    else if (requestPath == "/boot/ipxe/script")
+                    {
+                        var queryString = HttpUtility.ParseQueryString(request.Url.Query);
+                        var mac = queryString["mac"].ToUpper();
 
-                    var buffer = Encoding.ASCII.GetBytes(IpxeScriptManager.GetScript(mac));
-                    context.Response.OutputStream.Write(buffer, 0, buffer.Length);
-                    context.Response.Close();
+                        Console.WriteLine($" MAC:{mac}, send boot script");
 
-                    Console.WriteLine(" Response closed.");
+                        var buffer = Encoding.ASCII.GetBytes(IpxeScriptManager.GetScript(mac));
+                        context.Response.OutputStream.Write(buffer, 0, buffer.Length);
+                        context.Response.Close();
+                    }
+                    else
+                    {
+                        context.Response.StatusCode = 404;
+                        context.Response.Close();
+                    }
                 }
             }
 

+ 2 - 2
HttpServer/HttpServer.csproj

@@ -18,7 +18,7 @@
     <DebugSymbols>true</DebugSymbols>
     <DebugType>full</DebugType>
     <Optimize>false</Optimize>
-    <OutputPath>bin\Debug\</OutputPath>
+    <OutputPath>..\bin\Debug\</OutputPath>
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
@@ -27,7 +27,7 @@
     <PlatformTarget>AnyCPU</PlatformTarget>
     <DebugType>pdbonly</DebugType>
     <Optimize>true</Optimize>
-    <OutputPath>bin\Release\</OutputPath>
+    <OutputPath>..\bin\Release\</OutputPath>
     <DefineConstants>TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>

+ 1 - 1
HttpServer/Properties/Settings.Designer.cs

@@ -25,7 +25,7 @@ namespace HttpServer.Properties {
         
         [global::System.Configuration.ApplicationScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute("http://0.0.0.0:8444/")]
+        [global::System.Configuration.DefaultSettingValueAttribute("http://192.168.233.233:8013/")]
         public string ListenPrefix {
             get {
                 return ((string)(this["ListenPrefix"]));

+ 1 - 1
HttpServer/Properties/Settings.settings

@@ -3,7 +3,7 @@
   <Profiles />
   <Settings>
     <Setting Name="ListenPrefix" Type="System.String" Scope="Application">
-      <Value Profile="(Default)">http://0.0.0.0:8444/</Value>
+      <Value Profile="(Default)">http://192.168.233.233:8013/</Value>
     </Setting>
   </Settings>
 </SettingsFile>

BootServer.sln → NetBootServer.sln


+ 6 - 4
BootServer.sln.DotSettings

@@ -1,7 +1,9 @@
 <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
-	<s:Boolean x:Key="/Default/UserDictionary/Words/=blksize/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/UserDictionary/Words/=Bootp/@EntryIndexedValue">True</s:Boolean>
 	<s:Boolean x:Key="/Default/UserDictionary/Words/=Dhcp/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/UserDictionary/Words/=ipxe/@EntryIndexedValue">True</s:Boolean>
+	<s:Boolean x:Key="/Default/UserDictionary/Words/=Bootp/@EntryIndexedValue">True</s:Boolean>
+	<s:Boolean x:Key="/Default/UserDictionary/Words/=hexhyp/@EntryIndexedValue">True</s:Boolean>
 	<s:Boolean x:Key="/Default/UserDictionary/Words/=Tftp/@EntryIndexedValue">True</s:Boolean>
-	<s:Boolean x:Key="/Default/UserDictionary/Words/=tsize/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
+	<s:Boolean x:Key="/Default/UserDictionary/Words/=blksize/@EntryIndexedValue">True</s:Boolean>
+	<s:Boolean x:Key="/Default/UserDictionary/Words/=tsize/@EntryIndexedValue">True</s:Boolean>
+	<s:Boolean x:Key="/Default/UserDictionary/Words/=ipxe/@EntryIndexedValue">True</s:Boolean>
+	<s:Boolean x:Key="/Default/UserDictionary/Words/=Iscsi/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

+ 3 - 3
TftpServer/App.config

@@ -13,15 +13,15 @@
             <setting name="ListenOn" serializeAs="String">
                 <value>0.0.0.0</value>
             </setting>
-            <setting name="Root" serializeAs="String">
-                <value>Root</value>
-            </setting>
             <setting name="VerboseMode" serializeAs="String">
                 <value>False</value>
             </setting>
             <setting name="TimeOutSecond" serializeAs="String">
                 <value>30</value>
             </setting>
+            <setting name="Root" serializeAs="String">
+                <value>TftpRoot</value>
+            </setting>
         </TftpServer.Properties.Settings>
     </applicationSettings>
 </configuration>

+ 9 - 9
TftpServer/Properties/Settings.Designer.cs

@@ -34,15 +34,6 @@ namespace TftpServer.Properties {
         
         [global::System.Configuration.ApplicationScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute("Root")]
-        public string Root {
-            get {
-                return ((string)(this["Root"]));
-            }
-        }
-        
-        [global::System.Configuration.ApplicationScopedSettingAttribute()]
-        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
         [global::System.Configuration.DefaultSettingValueAttribute("False")]
         public bool VerboseMode {
             get {
@@ -58,5 +49,14 @@ namespace TftpServer.Properties {
                 return ((int)(this["TimeOutSecond"]));
             }
         }
+        
+        [global::System.Configuration.ApplicationScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("TftpRoot")]
+        public string Root {
+            get {
+                return ((string)(this["Root"]));
+            }
+        }
     }
 }

+ 3 - 3
TftpServer/Properties/Settings.settings

@@ -5,14 +5,14 @@
     <Setting Name="ListenOn" Type="System.String" Scope="Application">
       <Value Profile="(Default)">0.0.0.0</Value>
     </Setting>
-    <Setting Name="Root" Type="System.String" Scope="Application">
-      <Value Profile="(Default)">Root</Value>
-    </Setting>
     <Setting Name="VerboseMode" Type="System.Boolean" Scope="Application">
       <Value Profile="(Default)">False</Value>
     </Setting>
     <Setting Name="TimeOutSecond" Type="System.Int32" Scope="Application">
       <Value Profile="(Default)">30</Value>
     </Setting>
+    <Setting Name="Root" Type="System.String" Scope="Application">
+      <Value Profile="(Default)">TftpRoot</Value>
+    </Setting>
   </Settings>
 </SettingsFile>

BIN
TftpServer/TftpRoot/undionly-http.kpxe


+ 5 - 2
TftpServer/TftpServer.csproj

@@ -18,7 +18,7 @@
     <DebugSymbols>true</DebugSymbols>
     <DebugType>full</DebugType>
     <Optimize>false</Optimize>
-    <OutputPath>bin\Debug\</OutputPath>
+    <OutputPath>..\bin\Debug\</OutputPath>
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
@@ -28,7 +28,7 @@
     <PlatformTarget>AnyCPU</PlatformTarget>
     <DebugType>pdbonly</DebugType>
     <Optimize>true</Optimize>
-    <OutputPath>bin\Release\</OutputPath>
+    <OutputPath>..\bin\Release\</OutputPath>
     <DefineConstants>TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
@@ -61,6 +61,9 @@
   </ItemGroup>
   <ItemGroup>
     <None Include="App.config" />
+    <None Include="TftpRoot\undionly-http.kpxe">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
     <None Include="Properties\Settings.settings">
       <Generator>SettingsSingleFileGenerator</Generator>
       <LastGenOutput>Settings.Designer.cs</LastGenOutput>