Files
TSAnmeldung/TSAnmeldung/cPascom.vb

152 lines
4.7 KiB
VB.net

Imports System.Reflection
Imports System.IO
Imports Chilkat
Public Class cPascom
' Declare Function meh Lib "ChilkatDotNet47.dll" () As Integer
Dim API_USER_AUTHORIZATION = "" '"bW9ieTpnWlhTSVprTnhmaUQxOEU="
Dim Arbeitsplatz As String = ""
Dim TelUrl As String = ""
Sub New()
Dim ds As New DataSet
cSQL.SQL2DS("SELECT Parameter FROM [Doku].[dbo].[TbL_Dienste] where name = 'TelefonanlageURL'", ds)
If ds.Tables(0).Rows.Count > 0 Then
TelUrl = ds.Tables(0).Rows(0).Item(0).ToString
End If
ds.Clear()
cSQL.SQL2DS("SELECT Parameter FROM [Doku].[dbo].[TbL_Dienste] where name = 'PascomAPICred'", ds)
If ds.Tables(0).Rows.Count > 0 Then
API_USER_AUTHORIZATION = ds.Tables(0).Rows(0).Item(0).ToString
End If
End Sub
Public Function Anmelden() As Boolean
If GetTelArbeitsplatz4Host() Then
Try
'Benutzername: moby
'Passwort: XgDsFmMSutaMLA1
'BASIC Auth String: bW9ieTpYZ0RzRm1NU3V0YU1MQTE =
cChilkat_Helper.UnlockCilkat()
' Dim API_STRING = "pbx3.flashnet.at"
Dim API_STRING = TelUrl
Dim rest As New Chilkat.Rest
Dim success As Boolean
Dim bTls As Boolean = True
Dim port As Integer = 443
Dim bAutoReconnect As Boolean = True
success = rest.Connect(API_STRING, port, bTls, bAutoReconnect)
If (success <> True) Then
Debug.WriteLine("ConnectFailReason: " & rest.ConnectFailReason)
Debug.WriteLine(rest.LastErrorText)
Return False
End If
rest.AddHeader("Content-Type", "application/json")
rest.SetAuthBasic("qYAnX6SpQ62SK4ZZfi8IMRIHJ", "10vO6fO2CMVfL1P0hFuqWzvvh")
Dim json As New Chilkat.JsonObject
Dim successJsonLoad As Boolean = json.Load("
{""action"":""relocate"",""username"":""" & Environment.UserName & """}}")
If (successJsonLoad <> True) Then
MsgBox(json.LastErrorText)
Return False
End If
Dim sbRequestBody As New Chilkat.StringBuilder
json.EmitSb(sbRequestBody)
' MsgBox(sbRequestBody.ToString)
Dim sbResponseBody As New Chilkat.StringBuilder
success = rest.FullRequestSb("POST", "/verag/services/location/" & Arbeitsplatz, sbRequestBody, sbResponseBody)
If (success <> True) Then
Debug.WriteLine(rest.LastErrorText)
Return False
End If
Dim respStatusCode As Integer = rest.ResponseStatusCode
If (respStatusCode <> 200) Then
' MsgBox(sbResponseBody.GetAsString())
Return False
End If
Dim jsonResp = New Chilkat.JsonObject()
jsonResp.LoadSb(sbResponseBody)
Dim Logfile As String = "C:\Verag\ErrorLog.txt"
'File.AppendAllText(Logfile, String.Format(rest.ResponseStatusCode & " " & sbRequestBody.ToString))
Using writer As New StreamWriter(Logfile, True)
writer.WriteLine(rest.ResponseStatusCode & " " & Arbeitsplatz & " " & DateTime.Now.ToString & " " & sbRequestBody.ToString)
End Using
Dim gatewayId = jsonResp.StringOf("gatewayId")
Dim Resp_error = jsonResp.StringOf("error")
Dim Resp_errorCode = jsonResp.StringOf("errorCode")
Return True
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
Return True
Else
Return False
End If
End Function
Public Function GetTelArbeitsplatz4Host() As Boolean
Try
Dim lines = IO.File.ReadAllLines("\\verag.ost.dmn\NETLOGON\Telefonarbeitsplaetze.ini")
Dim colCount = lines.First.Split(";"c).Length
For Each line In lines
Dim objFields = From field In line.Split(";"c)
If String.Compare(cRes.LocalUser.Hostname, objFields(0).ToString, True) = 0 Then
Arbeitsplatz = objFields(1).ToString
'_ConString = objFields(2).ToString
Return True
Exit Function
End If
' End Select
Next
Return False
Catch ex As Exception
' MsgBox("Fehler beim Lesen TSAnmeldung.ini: " & vbCrLf & ex.Message)
End Try
End Function
End Class