79 lines
2.3 KiB
C#
79 lines
2.3 KiB
C#
using System;
|
|
using ln.types.net;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using System.Net;
|
|
using System.Security.Cryptography.X509Certificates;
|
|
using System.Net.Security;
|
|
using ln.logging;
|
|
|
|
namespace ln.skyscanner.devices
|
|
{
|
|
public class Siklu
|
|
{
|
|
public IPv4 IPAddress { get; }
|
|
public String Username { get; set; }
|
|
public string Password { get; set; }
|
|
|
|
CookieContainer cookieContainer = new CookieContainer();
|
|
WebRequestHandler webRequestHandler;
|
|
HttpClient httpClient;
|
|
|
|
public Siklu(IPv4 ip,string username,string password)
|
|
{
|
|
IPAddress = ip;
|
|
Username = username;
|
|
Password = password;
|
|
|
|
webRequestHandler = new WebRequestHandler();
|
|
webRequestHandler.ServerCertificateValidationCallback = (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => true;
|
|
webRequestHandler.UseCookies = true;
|
|
webRequestHandler.CookieContainer = cookieContainer;
|
|
webRequestHandler.AllowAutoRedirect = true;
|
|
|
|
httpClient = new HttpClient(webRequestHandler);
|
|
|
|
Logging.Log(LogLevel.INFO, "Siklu: {0}", IPAddress);
|
|
}
|
|
|
|
public void Close()
|
|
{
|
|
httpClient.Dispose();
|
|
httpClient = null;
|
|
}
|
|
|
|
public bool Index()
|
|
{
|
|
HttpResponseMessage responseMessage = httpClient.GetAsync(String.Format("https://{0}/",IPAddress.ToString())).Result;
|
|
|
|
foreach (var h in responseMessage.Content.Headers)
|
|
{
|
|
Logging.Log(LogLevel.INFO, "Siklue Header: {0}: [{1}]", h.Key, string.Join(",", h.Value));
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public bool Authenticate()
|
|
{
|
|
MultipartFormDataContent mfdc = new MultipartFormDataContent();
|
|
mfdc.Add(new StringContent(Username), "user");
|
|
mfdc.Add(new StringContent(Password), "password");
|
|
mfdc.Add(new StringContent("/"), "caller_url");
|
|
|
|
try
|
|
{
|
|
HttpResponseMessage responseMessage = httpClient.PostAsync(String.Format("https://{0}/handleform", IPAddress.ToString()), mfdc).Result;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Logging.Log(e);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
}
|
|
}
|