Files
Doku/Dokumentation/Classes/cHost.vb
2019-12-05 08:39:46 +01:00

320 lines
12 KiB
VB.net

Imports System.Reflection
Public Class cHost
Property FQDN As String = ""
Property QINFO As String = ""
Property IPAdresse As String = ""
Property NETNAME As String = ""
Property Seriennummer As String = ""
Property MAC As String = ""
Property Benutzer As String = ""
Property Passwort As String = ""
Property LINK As String = ""
Property INFO As String = ""
Property TYPE As String = ""
Property HOST As Object = Nothing
Property NWSTANDORT As String = ""
Property Modell As String = ""
Property Linked As Object = Nothing
Property LinkedWith As String = ""
Property AddIP As String = ""
Property Standort As String = ""
Property DHCP As String = ""
Property Netzwerk As String = ""
Property Firewall As Boolean = False
Property TeamviewerID As String = ""
Property TeamviewerKennwort As String = ""
Function getparameterlistMaster() As List(Of SQLVariable)
Dim list As New List(Of SQLVariable)
list.Add(New SQLVariable("FQDN", FQDN))
list.Add(New SQLVariable("QINFO", QINFO))
list.Add(New SQLVariable("IPAdresse", IPAdresse))
list.Add(New SQLVariable("NETNAME", NETNAME))
list.Add(New SQLVariable("Seriennummer", Seriennummer))
list.Add(New SQLVariable("MAC", MAC))
list.Add(New SQLVariable("Benutzer", Benutzer))
list.Add(New SQLVariable("Passwort", Passwort))
list.Add(New SQLVariable("Link", LINK))
list.Add(New SQLVariable("INFO", INFO))
list.Add(New SQLVariable("TYPE", TYPE))
list.Add(New SQLVariable("HOST", HOST))
list.Add(New SQLVariable("NWSTANDORT", NWSTANDORT))
list.Add(New SQLVariable("Modell", Modell))
list.Add(New SQLVariable("Linked", Linked))
list.Add(New SQLVariable("LinkedWith", LinkedWith))
list.Add(New SQLVariable("AddIP", AddIP))
list.Add(New SQLVariable("Standort", Standort))
list.Add(New SQLVariable("DHCP", DHCP))
list.Add(New SQLVariable("Netzwerk", Netzwerk))
list.Add(New SQLVariable("Firewall", Firewall))
list.Add(New SQLVariable("TeamviewerID", TeamviewerID))
list.Add(New SQLVariable("TeamviewerKennwort", TeamviewerKennwort))
Return list
End Function
Function getparameterlistSlave() As List(Of SQLVariable)
Dim list As New List(Of SQLVariable)
list.Add(New SQLVariable("FQDN", FQDN))
list.Add(New SQLVariable("QINFO", QINFO))
list.Add(New SQLVariable("IPAdresse", IPAdresse))
'list.Add(New SQLVariable("NETNAME", NETNAME))
list.Add(New SQLVariable("Seriennummer", Seriennummer))
list.Add(New SQLVariable("MAC", MAC))
list.Add(New SQLVariable("Benutzer", Benutzer))
list.Add(New SQLVariable("Passwort", Passwort))
list.Add(New SQLVariable("Link", LINK))
list.Add(New SQLVariable("INFO", INFO))
list.Add(New SQLVariable("TYPE", TYPE))
'list.Add(New SQLVariable("HOST", HOST))
'list.Add(New SQLVariable("NWSTANDORT", NWSTANDORT))
list.Add(New SQLVariable("Modell", Modell))
'list.Add(New SQLVariable("Linked", Linked))
list.Add(New SQLVariable("LinkedWith", LinkedWith))
list.Add(New SQLVariable("AddIP", AddIP))
list.Add(New SQLVariable("Standort", Standort))
list.Add(New SQLVariable("DHCP", DHCP))
'list.Add(New SQLVariable("Netzwerk", Netzwerk))
list.Add(New SQLVariable("Firewall", Firewall))
list.Add(New SQLVariable("TeamviewerID", TeamviewerID))
list.Add(New SQLVariable("TeamviewerKennwort", TeamviewerKennwort))
Return list
End Function
Function clear()
Me.FQDN = ""
Me.QINFO = ""
Me.IPAdresse = ""
Me.NETNAME = ""
Me.Seriennummer = ""
Me.MAC = ""
Me.Benutzer = ""
Me.Passwort = ""
Me.LINK = ""
Me.INFO = ""
Me.TYPE = ""
Me.HOST = Nothing
Me.NWSTANDORT = ""
Me.Modell = ""
Me.Linked = Nothing
Me.LinkedWith = ""
Me.AddIP = ""
Me.Standort = ""
Me.DHCP = ""
Me.Netzwerk = ""
Me.Firewall = False
Me.TeamviewerID = ""
Me.TeamviewerKennwort = ""
End Function
Public Shared Function getHostsEntrys(ByRef ds As DataSet, ByVal HostIP As String)
Dim selector As String = "Select
[fwr_ID]
,[fwr_in]
,[fwr_out]
,[fwr_portsin]
,[fwr_portsout]
,[fwr_dienste]
,[fwr_FQDN]
,[fwr_info]
, case when [fwr_direct] is null then '0'
else [fwr_direct] end as [fwr_direct]
From [Doku].[dbo].[TbL_FirewallRules] where [fwr_hostip] = '" & HostIP & "'
ORDER BY [fwr_in]"
cSQL.SQL2DS(selector, ds)
End Function
Public Function gethost(ip As String)
Dim ds As New DataSet
Dim test As String = ""
cSQL.SQL2DS("select * from TbL_Netzwerkclients where IPAdresse = '" & ip & "'", ds)
For Each c As DataColumn In ds.Tables(0).Columns
Dim propInfo As PropertyInfo = Me.GetType.GetProperty(c.ColumnName)
If propInfo IsNot Nothing Then
If Not IsDBNull(c.Table.Rows(0).Item(c)) Then
propInfo.SetValue(Me, c.Table.Rows(0).Item(c))
End If
End If
Next
' MsgBox("hier")
End Function
Public Function getUpdateCmd(ByRef update As String, ByRef where As String, Optional ByRef slaveupdate As String = "", Optional ByRef slavewhere As String = "", Optional ByVal Linked As Boolean = False, Optional ByVal newhost As cHost = Nothing)
If newhost Is Nothing Then
slavewhere = ""
Dim list As List(Of SQLVariable) = getparameterlistMaster()
Dim slavelist As List(Of SQLVariable) = getparameterlistSlave()
For Each i In list ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''dieser Host
If Not i.SQLText = "IPAdresse" Then
update &= "[" & i.SQLText & "]='" & i.SQLValue & "',"
Else
where &= "IPAdresse = '" & i.SQLValue & "'"
End If
Next
update = update.Substring(0, update.Length - 1) 'wg. ','
For Each i In slavelist ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''alle Hosts, bei denen dieser Host als LinkedWith eingetragen ist
If Not i.SQLText = "IPAdresse" And Not i.SQLText = "LinkedWith" And Not i.SQLText = "NETNAME" And Not i.SQLText = "NWSTANDORT" And Not i.SQLText = "Netzwerk" Then
slaveupdate &= "[" & i.SQLText & "]='" & i.SQLValue & "',"
ElseIf i.SQLText = "IPAdresse" Then
slavewhere &= "(Linked = 'True' AND (LinkedWith = '" & i.SQLValue & "'"
End If
Next
slaveupdate = slaveupdate.Substring(0, slaveupdate.Length - 1)
If Linked = True Then '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
For Each i In slavelist '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Masterhost
If i.SQLText = "LinkedWith" Then
slavewhere &= "OR LinkedWith = '" & i.SQLValue & "') OR IPAdresse = '" & i.SQLValue & "')"
End If
Next
ElseIf Linked = False Then
slavewhere &= "))"
End If
Else
Dim list As List(Of SQLVariable) = newhost.getparameterlistMaster()
For Each i In list ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''dieser Host
If Not i.SQLText = "IPAdresse" Then
update &= "[" & i.SQLText & "]='" & i.SQLValue & "',"
Else
where &= "IPAdresse = '" & i.SQLValue & "'"
End If
Next
update = update.Substring(0, update.Length - 1) 'wg. ','
End If
End Function
Public Function updateHostEntry(ByRef entry As cHost)
Dim update, where, slaveupdate, slavewhere As String
getUpdateCmd(update, where, slaveupdate, slavewhere, Me.Linked)
cSQL.UpdateSQL("TbL_Netzwerkclients", update, where)
cSQL.UpdateSQL("TbL_Netzwerkclients", slaveupdate, slavewhere)
'MsgBox(update & where)
End Function
Function checkIfIPExist(ByVal ip As String)
Dim ds As New DataSet
cSQL.SQL2DS("SELECT * FROM TbL_Netzwerkclients WHERE IPADRESSE = '" & ip & "'", ds)
If ds.Tables(0).Rows.Count > 0 Then
Return True
Else
Return False
End If
End Function
Public Function DeleteHost(Optional ByVal supress As Boolean = False)
If supress = False Then
If MessageBox.Show("Eintrag " & Me.FQDN & " wirklich löschen?", "Hosteintrag löschen", MessageBoxButtons.OKCancel) = DialogResult.OK Then
Dim ds As New DataSet
Dim Slaves As String = ""
cSQL.SQL2DS("SELECT * FROM TbL_Netzwerkclients WHERE LinkedWith ='" & Me.IPAdresse & "'", ds)
If ds.Tables(0).Rows.Count > 0 Then
For Each r As DataRow In ds.Tables(0).Rows
Slaves &= r.Item("IPAdresse").ToString & vbCrLf
Next
If MessageBox.Show("
Achtung! " & vbCrLf & "Der Eintrag " & Me.FQDN & " ist ein MasterEintrag für die IP Adressen " & vbCrLf & Slaves & "
Diese Einträge werden ebenfalls gelöscht. Fortfahren?", "Hosteintrag löschen", MessageBoxButtons.OKCancel) = DialogResult.OK Then
cSQL.DeleteSQL("TbL_Netzwerkclients", "LinkedWith = '" & Me.IPAdresse & "'")
ElseIf DialogResult.Cancel Then
Exit Function
End If
End If
cSQL.DeleteSQL("TbL_Netzwerkclients", "IPAdresse = '" & Me.IPAdresse & "'")
Class1.RefillNW(Me.Netzwerk)
ElseIf DialogResult.Cancel Then
Exit Function
End If
Else
cSQL.DeleteSQL("TbL_Netzwerkclients", "IPAdresse = '" & Me.IPAdresse & "'")
Class1.RefillNW(Me.Netzwerk)
End If
End Function
Public Function MoveHost(newip As String)
If checkIfIPExist(newip) = False Then MsgBox("Die Adresse kann nicht verwendet werden. Bitte überprüfen.") : Return Me : Exit Function
Dim oldip As String = Me.IPAdresse
Dim newhost As New cHost
newhost.gethost(newip)
'Get Slaves of LinkedMaster
Dim ds As New DataSet
cSQL.SQL2DS("SELECT * FROM TbL_Netzwerkclients WHERE LinkedWith = '" & Me.IPAdresse & "'", ds)
'Ziel prüfen und gegebenenfalls anzeigen
If (
newhost.FQDN = "" And
newhost.Modell = "" And
newhost.TYPE = "") Then
Else
If MsgBox("Ziel ist bereits belegt. Anzeigen?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
Me.gethost(newip)
Else
Me.gethost(oldip)
End If
Exit Function
End If
'If Host = LinkedMaster then Update Slaves
If ds.Tables(0).Rows.Count > 0 Then
cSQL.UpdateSQL("TbL_Netzwerkclients", "LinkedWith = '" & newip & "'", "LinkedWith = '" & oldip & "'")
End If
newhost.FQDN = Me.FQDN
newhost.QINFO = Me.QINFO
newhost.Seriennummer = Me.Seriennummer
newhost.MAC = Me.MAC
newhost.Benutzer = Me.Benutzer
newhost.Passwort = Me.Passwort
newhost.LINK = Me.LINK
newhost.INFO = Me.INFO
newhost.TYPE = Me.TYPE
newhost.Modell = Me.Modell
newhost.Linked = Me.Linked
newhost.LinkedWith = Me.LinkedWith
newhost.AddIP = Me.AddIP
newhost.Standort = Me.Standort
newhost.DHCP = Me.DHCP
newhost.Firewall = Me.Firewall
Dim update, where As String
getUpdateCmd(update, where, "", "", newhost.Linked, newhost)
cSQL.UpdateSQL("TbL_Netzwerkclients", update, where)
cFolder.FolderMove(Me.NWSTANDORT & "_" & Me.NETNAME, Me.HOST, newhost.NWSTANDORT & "_" & newhost.NETNAME, newhost.HOST)
Me.DeleteHost(True)
Return newhost
End Function
Public Shared Function getSlaves(ByVal ip As String, ByRef ds As DataSet)
cSQL.SQL2DS("SELECT IPAdresse , (NWSTANDORT + ' ' + NETNAME) as Netzwerk FROM TbL_Netzwerkclients WHERE LinkedWith = '" & ip & "'", ds)
End Function
End Class