From b3f3a259e00f6a2e6c3caf2662a5e281438826a4 Mon Sep 17 00:00:00 2001 From: SIA-PatrickL Date: Tue, 15 Oct 2024 08:54:12 +0200 Subject: [PATCH 1/8] working --- App.config | 9 +-- CreateXml.cs | 119 ++++++++++++++++++++++++++++++++ Properties/Settings.Designer.cs | 10 +-- Properties/Settings.settings | 4 +- 4 files changed, 124 insertions(+), 18 deletions(-) create mode 100644 CreateXml.cs diff --git a/App.config b/App.config index 7251b5a..5c15716 100644 --- a/App.config +++ b/App.config @@ -4,9 +4,6 @@
- -
- @@ -16,10 +13,6 @@ 1 - - - - 1 @@ -27,5 +20,5 @@ 1 - + \ No newline at end of file diff --git a/CreateXml.cs b/CreateXml.cs new file mode 100644 index 0000000..cbf6c16 --- /dev/null +++ b/CreateXml.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace XDocument_Sample +{ + class CreateXml + { + string file = "xml.xml"; + + public CreateXml(string xml) { + + XDocument doc = + new XDocument( + new XElement("file", + new XElement("name", new XAttribute("filename", "sample")), + new XElement("date", new XAttribute("modified", DateTime.Now), new XAttribute("hallo", "dsd")), + + // From here the CA Section + new XElement("CA", + new XElement("name", "Sample-CA"), + new XElement("type", "CA"), + new XElement("id", "0"), + new XElement("Private", + new XElement("Bits", "4096"), + new XElement("Pass", "passwortca"), + new XElement("file", "Sample-CA.key.pem") + ), + new XElement("Public", + new XElement("duration", "7300"), + new XElement("pass", "passwortca"), + new XElement("cnf", "openssl-ca.cnf"), + new XElement("subj", + new XElement("C", "DE"), + new XElement("ST", "Bavaria"), + new XElement("L", "Hausen"), + new XElement("OU", "IT"), + new XElement("CN", "Lang-CA"), + new XElement("email", "admin@admin.de") + ) + ) + ), + // From here the Intermediate Section + new XElement("Intermediate", + new XElement("name", "Sample-Intermediate"), + new XElement("type", "Intermediate"), + new XElement("id", "1"), + new XElement("Private", + new XElement("Bits", "4096"), + new XElement("pass", "passwortint") + ), + new XElement("CSR", + new XElement("cnf", "openssl-int.cnf"), + new XElement("pass_priv", "passwortint"), + new XElement("subj", + new XElement("C", "DE"), + new XElement("ST", "Bavaria"), + new XElement("L", "Hausen"), + new XElement("OU", "IT"), + new XElement("CN", "Lang-Intermediate"), + new XElement("email", "admin@admin.de") + ) + ), + new XElement("Sign", + new XElement("cnf-ca", "openssl-ca.cnf"), + new XElement("duration", "3650"), + new XElement("CA", + new XElement("id", "0"), + new XElement("passCa", "passwordca") + ) + ) + ), + // From here server section + new XElement("Server", + new XElement("name", "Sample-Server"), + + new XElement("type", "Server"), + new XElement("id", "1"), + new XElement("Private", + + new XElement("Bits", "4096"), + new XElement("pass", "") + ), + new XElement("CSR", + new XElement("pass_priv", ""), + new XElement("subj", + new XElement("C", "DE"), + new XElement("ST", "Bavaria"), + new XElement("L", "Hausen"), + new XElement("OU", "IT"), + new XElement("CN", "Lang-Server"), + new XElement("email", "admin@admin.de") + ), + new XElement("SAN", + new XElement("DNS.1", "SAN"), + new XElement("IP.1", "192.168.1.1") + ) + ), + new XElement("Sign", + new XElement("cnf", "openssl-int.cnf"), + new XElement("duration", "365"), + new XElement("passInt", "passwordint"), + new XElement("Intermediate", + new XElement("id", "1"), + new XElement("passInt", "passwordint") + ) + ) + ) + ) + ); + + doc.Save(xml); + + } + } +} diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs index 85b04c4..2cb0403 100644 --- a/Properties/Settings.Designer.cs +++ b/Properties/Settings.Designer.cs @@ -41,28 +41,22 @@ public int InterID { } } - [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("1")] public int ServerID { get { return ((int)(this["ServerID"])); } - set { - this["ServerID"] = value; - } } - [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("1")] public int UserID { get { return ((int)(this["UserID"])); } - set { - this["UserID"] = value; - } } } } diff --git a/Properties/Settings.settings b/Properties/Settings.settings index 336f00d..09d28af 100644 --- a/Properties/Settings.settings +++ b/Properties/Settings.settings @@ -8,10 +8,10 @@ 1 - + 1 - + 1 From 1198df6a9e1d6f491c6d54367af45bf501fadab1 Mon Sep 17 00:00:00 2001 From: Sectorchan Date: Wed, 16 Oct 2024 23:37:51 +0200 Subject: [PATCH 2/8] listBox add, sort works --- Form1.Designer.cs | 112 +++++++++++++++++++++------------------- Form1.cs | 74 +++++++++++++++++++------- Form1.resx | 4 +- XDocument_Sample.csproj | 12 +++++ XDocument_Sample.sln | 14 ++--- listen/ca-liste.txt | 0 listen/inter-liste.txt | 0 listen/server-liste.txt | 0 listen/user-liste.txt | 0 9 files changed, 134 insertions(+), 82 deletions(-) create mode 100644 listen/ca-liste.txt create mode 100644 listen/inter-liste.txt create mode 100644 listen/server-liste.txt create mode 100644 listen/user-liste.txt diff --git a/Form1.Designer.cs b/Form1.Designer.cs index 3019d37..d7853d1 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -29,50 +29,53 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { textBox1 = new TextBox(); - button1 = new Button(); - button2 = new Button(); + bt_clist_write = new Button(); + bt_delete = new Button(); button3 = new Button(); button4 = new Button(); button5 = new Button(); textBox2 = new TextBox(); textBox3 = new TextBox(); - listBox1 = new ListBox(); + lb_caliste = new ListBox(); button6 = new Button(); SuspendLayout(); // // textBox1 // - textBox1.Location = new Point(45, 72); + textBox1.Location = new Point(77, 144); + textBox1.Margin = new Padding(5, 6, 5, 6); textBox1.Name = "textBox1"; - textBox1.Size = new Size(100, 23); + textBox1.Size = new Size(169, 35); textBox1.TabIndex = 0; // - // button1 + // bt_clist_write // - button1.Location = new Point(260, 75); - button1.Name = "button1"; - button1.Size = new Size(75, 23); - button1.TabIndex = 1; - button1.Text = "write"; - button1.UseVisualStyleBackColor = true; - button1.Click += button1_Click; + bt_clist_write.Location = new Point(446, 150); + bt_clist_write.Margin = new Padding(5, 6, 5, 6); + bt_clist_write.Name = "bt_clist_write"; + bt_clist_write.Size = new Size(129, 46); + bt_clist_write.TabIndex = 1; + bt_clist_write.Text = "write"; + bt_clist_write.UseVisualStyleBackColor = true; + bt_clist_write.Click += bt_clist_write_Click; // - // button2 + // bt_delete // - button2.Location = new Point(260, 114); - button2.Margin = new Padding(2); - button2.Name = "button2"; - button2.Size = new Size(76, 20); - button2.TabIndex = 2; - button2.Text = "search"; - button2.UseVisualStyleBackColor = true; - button2.Click += button2_Click; + bt_delete.Location = new Point(446, 228); + bt_delete.Margin = new Padding(3, 4, 3, 4); + bt_delete.Name = "bt_delete"; + bt_delete.Size = new Size(130, 40); + bt_delete.TabIndex = 2; + bt_delete.Text = "delete"; + bt_delete.UseVisualStyleBackColor = true; + bt_delete.Click += Bt_delete_Click; // // button3 // - button3.Location = new Point(260, 147); + button3.Location = new Point(446, 294); + button3.Margin = new Padding(5, 6, 5, 6); button3.Name = "button3"; - button3.Size = new Size(75, 23); + button3.Size = new Size(129, 46); button3.TabIndex = 3; button3.Text = "replace"; button3.UseVisualStyleBackColor = true; @@ -80,10 +83,10 @@ private void InitializeComponent() // // button4 // - button4.Location = new Point(474, 72); - button4.Margin = new Padding(2); + button4.Location = new Point(813, 144); + button4.Margin = new Padding(3, 4, 3, 4); button4.Name = "button4"; - button4.Size = new Size(129, 23); + button4.Size = new Size(221, 46); button4.TabIndex = 4; button4.Text = "create xml.xml"; button4.UseVisualStyleBackColor = true; @@ -91,10 +94,10 @@ private void InitializeComponent() // // button5 // - button5.Location = new Point(479, 126); - button5.Margin = new Padding(2); + button5.Location = new Point(821, 252); + button5.Margin = new Padding(3, 4, 3, 4); button5.Name = "button5"; - button5.Size = new Size(153, 24); + button5.Size = new Size(262, 48); button5.TabIndex = 5; button5.Text = "replace entry with textbox"; button5.UseVisualStyleBackColor = true; @@ -102,35 +105,37 @@ private void InitializeComponent() // // textBox2 // - textBox2.Location = new Point(499, 20); - textBox2.Margin = new Padding(2); + textBox2.Location = new Point(855, 40); + textBox2.Margin = new Padding(3, 4, 3, 4); textBox2.Name = "textBox2"; - textBox2.Size = new Size(104, 23); + textBox2.Size = new Size(175, 35); textBox2.TabIndex = 6; // // textBox3 // - textBox3.Location = new Point(658, 126); - textBox3.Margin = new Padding(2); + textBox3.Location = new Point(1128, 252); + textBox3.Margin = new Padding(3, 4, 3, 4); textBox3.Name = "textBox3"; - textBox3.Size = new Size(104, 23); + textBox3.Size = new Size(175, 35); textBox3.TabIndex = 7; textBox3.Text = "grafana"; // - // listBox1 + // lb_caliste // - listBox1.FormattingEnabled = true; - listBox1.ItemHeight = 15; - listBox1.Location = new Point(123, 260); - listBox1.Name = "listBox1"; - listBox1.Size = new Size(120, 94); - listBox1.TabIndex = 8; + lb_caliste.FormattingEnabled = true; + lb_caliste.ItemHeight = 30; + lb_caliste.Location = new Point(211, 520); + lb_caliste.Margin = new Padding(5, 6, 5, 6); + lb_caliste.Name = "lb_caliste"; + lb_caliste.Size = new Size(203, 184); + lb_caliste.TabIndex = 8; // // button6 // - button6.Location = new Point(479, 164); + button6.Location = new Point(821, 328); + button6.Margin = new Padding(5, 6, 5, 6); button6.Name = "button6"; - button6.Size = new Size(75, 23); + button6.Size = new Size(129, 46); button6.TabIndex = 9; button6.Text = "add server to xml"; button6.UseVisualStyleBackColor = true; @@ -138,19 +143,20 @@ private void InitializeComponent() // // Form1 // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(12F, 30F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); + ClientSize = new Size(1371, 900); Controls.Add(button6); - Controls.Add(listBox1); + Controls.Add(lb_caliste); Controls.Add(textBox3); Controls.Add(textBox2); Controls.Add(button5); Controls.Add(button4); Controls.Add(button3); - Controls.Add(button2); - Controls.Add(button1); + Controls.Add(bt_delete); + Controls.Add(bt_clist_write); Controls.Add(textBox1); + Margin = new Padding(5, 6, 5, 6); Name = "Form1"; Text = "Form1"; Load += Form1_Load; @@ -161,14 +167,14 @@ private void InitializeComponent() #endregion private TextBox textBox1; - private Button button1; - private Button button2; + private Button bt_clist_write; + private Button bt_delete; private Button button3; private Button button4; private Button button5; private TextBox textBox2; private TextBox textBox3; - private ListBox listBox1; + private ListBox lb_caliste; private Button button6; } } diff --git a/Form1.cs b/Form1.cs index 1285836..612c98d 100644 --- a/Form1.cs +++ b/Form1.cs @@ -1,7 +1,9 @@ using System.Configuration; using System.IO; +using System.Windows.Forms; using System.Xml.Linq; using System.Xml.XPath; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace XDocument_Sample { @@ -10,42 +12,67 @@ public partial class Form1 : Form readonly string file = "Sample.xml"; readonly string xml = @"xml.xml"; + string caliste = @"listen\ca-liste.txt"; + string interliste = @"listen\inter-liste.txt"; + string serverliste = @"listen\server-liste.txt"; + string userliste = @"listen\user-liste.txt"; int CAident = Properties.Settings.Default.CAID; int Intident = Properties.Settings.Default.InterID; int Servident = Properties.Settings.Default.ServerID; int Usrident = Properties.Settings.Default.UserID; + /// + /// reads the CA-List + /// + /// clears upfront the listBox + public void Cblist_read(bool refreshList) + { + using (StreamReader sr = new StreamReader(caliste)) + { + if (refreshList) + { + lb_caliste.Items.Clear(); + } + while (true) + { + string line = sr.ReadLine(); + if (line == null) + { + break; + } + lb_caliste.Items.Add(line); // Use line. + } + } + lb_caliste.Sorted = true; + } public Form1() { InitializeComponent(); } - private void button1_Click(object sender, EventArgs e) + private void bt_clist_write_Click(object sender, EventArgs e) { - try - { - XDocument doc = - new XDocument( - new XElement("file", - new XElement("name2", "sample12"), - new XElement("CA", "CA_Name"), - - new XElement("name") - - ) - ); + if (!lb_caliste.Items.Cast().Contains(textBox1.Text)) - doc.Save("Sample.xml"); + { + MessageBox.Show("no duplicate"); } - catch (Exception ex) + else { - MessageBox.Show("Fehler bei Debugoutput", ex.Message, MessageBoxButtons.OK); + MessageBox.Show("duplicate"); + return; + }; + StreamWriter sw = new StreamWriter(caliste, true); + sw.WriteLine(textBox1.Text); + sw.Close(); - } - } + Cblist_read(true); + + } private void Form1_Load(object sender, EventArgs e) { + Cblist_read(false); XDocument doc = new XDocument( @@ -323,7 +350,7 @@ private void Replace_Click(object sender, EventArgs e) private void AddServer_Click(object sender, EventArgs e) { - + XDocument doc = XDocument.Load(xml); doc.Root.Element("CA").Add( new XElement("name", "Sample-CA"), @@ -351,7 +378,14 @@ private void AddServer_Click(object sender, EventArgs e) doc.Save(xml); } - + private void Bt_delete_Click(object sender, EventArgs e) + { + using (StreamReader sr = new StreamReader(caliste)) + { + string selectedItem = lb_caliste.SelectedItem.ToString(); + + } + } } } diff --git a/Form1.resx b/Form1.resx index b92c163..4f24d55 100644 --- a/Form1.resx +++ b/Form1.resx @@ -1,7 +1,7 @@