@@ -105,6 +105,44 @@ Module modPihole
105
105
End Try
106
106
End Function
107
107
108
+ Function SetPiholeBlocking( ByVal strSetBlock As String ) As String
109
+ Dim PiholeSID As String = AuthPiholeAPI()
110
+ Dim strBlockingStatus As String = ""
111
+
112
+ If PiholeSID = "failed" Then
113
+ Return "failed"
114
+ End If
115
+
116
+ Try
117
+ My.Application.Log.WriteEntry( "Requesting Pi-hole statistics" )
118
+ Dim PiholeAPIRequest As System.Net.HttpWebRequest = CType (System.Net.WebRequest.Create( "http://" & My.Settings.Pihole_IPAddress & "/api/dns/blocking?sid=" & PiholeSID), System.Net.HttpWebRequest)
119
+ PiholeAPIRequest.Method = "POST"
120
+ Dim PiholeAPIRequestBody As Byte () = Text.Encoding.UTF8.GetBytes( "{""blocking"":" & strSetBlock & "}" )
121
+ PiholeAPIRequest.ContentType = "application/json"
122
+ PiholeAPIRequest.ContentLength = PiholeAPIRequestBody.Length
123
+ Dim ReqStream As System.IO.Stream = PiholeAPIRequest.GetRequestStream()
124
+ ReqStream.Write(PiholeAPIRequestBody, 0 , PiholeAPIRequestBody.Length)
125
+ Dim PiholeAPIResponse As System.Net.HttpWebResponse = CType (PiholeAPIRequest.GetResponse(), System.Net.HttpWebResponse)
126
+ Dim PiholeAPIResponseStream As New System.IO.StreamReader(PiholeAPIResponse.GetResponseStream(), System.Text.Encoding.UTF8)
127
+ Dim PiholeAPIJSON As String = PiholeAPIResponseStream.ReadToEnd()
128
+ PiholeAPIResponse.Close()
129
+ PiholeAPIResponseStream.Close()
130
+ My.Application.Log.WriteEntry( "Response received: " & PiholeAPIJSON, TraceEventType.Verbose)
131
+ Using JsonResponse = JsonDocument.Parse(PiholeAPIJSON)
132
+ strBlockingStatus = JsonResponse.RootElement.GetProperty( "blocking" ).GetString()
133
+ End Using
134
+
135
+ Return strBlockingStatus
136
+ Catch WebEx As System.Net.WebException
137
+ Using ResStream As System.IO.Stream = WebEx.Response.GetResponseStream()
138
+ Dim Reader As System.IO.StreamReader = New System.IO.StreamReader(ResStream)
139
+ Dim OutputJson As String = Reader.ReadToEnd()
140
+ My.Application.Log.WriteEntry( "Pi-hole Request Error:" & OutputJson, TraceEventType.Error)
141
+ End Using
142
+ Return "failed"
143
+ End Try
144
+ End Function
145
+
108
146
Function Load() As String
109
147
If My.Settings.Pihole_Enable = True Then
110
148
My.Application.Log.WriteEntry( "Loading Pi-hole module" )
0 commit comments