Skip to content

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferda Mravenec committed Dec 3, 2021
1 parent 54a48e4 commit d144398
Show file tree
Hide file tree
Showing 7 changed files with 322 additions and 0 deletions.
6 changes: 6 additions & 0 deletions App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
52 changes: 52 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Zradelna
{
class Program
{
static void Main(string[] args)
{
//Create new instance of client
WebApiClient wa = new WebApiClient();

//Open homepage first to get sessin ID and cookie
wa.OpenHomepage();

//Login as "FFFFFFFF"
wa.Login(CardToId("FFFFFFFF"));

//Get current account balance
wa.GetAccountBalance();
}

/// <summary>
/// HEX (Little-endian) string to UInt32 as string
/// </summary>
/// <param name="hexString"></param>
/// <returns></returns>
static string CardToId(string hexString)
{
StringBuilder sb = new StringBuilder();

uint num = uint.Parse(hexString, System.Globalization.NumberStyles.AllowHexSpecifier);

byte[] floatVals = BitConverter.GetBytes(num);
byte[] newArray = new byte[4];
int position = 3;

foreach (byte b in floatVals)
{
newArray[position] = b;
position--;
}

return BitConverter.ToUInt32(newArray, 0).ToString();
}
}


}
36 changes: 36 additions & 0 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Zradelna")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HP Inc.")]
[assembly: AssemblyProduct("Zradelna")]
[assembly: AssemblyCopyright("Copyright © HP Inc. 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("9d0dfb31-ab4a-4a14-8b90-260300cdf667")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
136 changes: 136 additions & 0 deletions WebApiClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;
using System.Data;
using System.Web;
using Newtonsoft.Json;
using System.Text.RegularExpressions;

namespace Zradelna
{
public class WebApiClient
{
string cookie = string.Empty;

private string login_id;
private string boarder;
private string workstation;
private string acc_id;

private double accountBalance;

public string Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9";
public string UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36 OPR/81.0.4196.60";

public string Login_id { get => login_id; set => login_id = value; }
public string Boarder { get => boarder; set => boarder = value; }
public string Workstation { get => workstation; set => workstation = value; }
public string Acc_id { get => acc_id; set => acc_id = value; }
public double AccountBalance { get => accountBalance; }

/// <summary>
/// Open homepage to set session ID and get in the cookie
/// </summary>
public void OpenHomepage()
{
var request = (HttpWebRequest)WebRequest.Create("http://172.15.27.236:8080/isis/objednavkytouch/index");

request.Accept = Accept;
request.Method = "GET";
request.ContentType = "text/html; charset=utf-8";
request.UserAgent = UserAgent;

var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

cookie = response.Headers[HttpResponseHeader.SetCookie]; //Get cookie
}

/// <summary>
/// Call login function using cookie
/// </summary>
/// <param name="cardreader">Card ID - personal indetifier</param>
/// <returns></returns>
public void Login(string cardreader)
{
var request = (HttpWebRequest)WebRequest.Create("http://172.15.27.236:8080/isis/objednavkytouch/loginon");

var postData = "{\"cardreader\": \"" + cardreader + "\"}";
var data = Encoding.ASCII.GetBytes(postData);

request.Accept = Accept;
request.Method = "POST";
request.ContentLength = data.Length;
request.ContentType = "application/json";
request.UserAgent = UserAgent;
request.Referer = "http://172.15.27.236:8080/isis/objednavkytouch/index";

request.Headers[HttpRequestHeader.Cookie] = cookie; //Set cookie

using (var stream = request.GetRequestStream())
stream.Write(data, 0, data.Length);

var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

GetLoginInfo( responseString);
}

/// <summary>
/// Get login info from response string while logged in
/// </summary>
/// <param name="response"></param>
public void GetLoginInfo(string response)
{
//Get login info
string json = new Regex("a_data=(.*)").Match(response).Groups[1].Value; //Extract desired JSON data
DataTable dtLoginInfo = (DataTable)Newtonsoft.Json.JsonConvert.DeserializeObject("[" + json + "]", (typeof(DataTable))); //Convert to DataTable

login_id = dtLoginInfo.Rows[0]["login_id"].ToString();
boarder = dtLoginInfo.Rows[0]["boarder"].ToString();
workstation = dtLoginInfo.Rows[0]["workstation"].ToString();
acc_id = dtLoginInfo.Rows[0]["acc_id"].ToString();
}

/// <summary>
/// Get current account balance for active login
/// </summary>
public void GetAccountBalance()
{
var request = (HttpWebRequest)WebRequest.Create("http://172.15.27.236:8080/isis/objednavky/AccountList");

var postData = "{\"login_id\": \"" + login_id + "\",";
postData += "\"boarder\": \"" + boarder + "\",";
postData += "\"accounts\": \"" + "" + "\",";
postData += "\"workstation\": \"" + workstation + "\",";
postData += "\"acc_id\": \"" + acc_id + "\",";
postData += "\"dest_id\": \"" + acc_id + "\"}";
var data = Encoding.ASCII.GetBytes(postData);

request.Accept = Accept;
request.Method = "POST";
request.ContentLength = data.Length;
request.ContentType = "application/json";
request.UserAgent = UserAgent;
request.Referer = "http://172.15.27.236:8080/isis/objednavkytouch/index";

request.Headers[HttpRequestHeader.Cookie] = cookie; //Set cookie

using (var stream = request.GetRequestStream())
stream.Write(data, 0, data.Length);

var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

string stringBalance = new Regex("<b>(.*) Kč</b>").Match(responseString).Groups[1].Value; //Extract desired data

Double.TryParse(stringBalance, out accountBalance);
}


}
}
62 changes: 62 additions & 0 deletions Zradelna.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9D0DFB31-AB4A-4A14-8B90-260300CDF667}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Zradelna</RootNamespace>
<AssemblyName>Zradelna</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="HtmlAgilityPack, Version=1.11.39.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
<HintPath>packages\HtmlAgilityPack.1.11.39\lib\Net45\HtmlAgilityPack.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WebApiClient.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
25 changes: 25 additions & 0 deletions Zradelna.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29728.190
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Zradelna", "Zradelna.csproj", "{9D0DFB31-AB4A-4A14-8B90-260300CDF667}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9D0DFB31-AB4A-4A14-8B90-260300CDF667}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D0DFB31-AB4A-4A14-8B90-260300CDF667}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D0DFB31-AB4A-4A14-8B90-260300CDF667}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D0DFB31-AB4A-4A14-8B90-260300CDF667}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {32E404A9-25D5-43C3-8020-D181EA891837}
EndGlobalSection
EndGlobal
5 changes: 5 additions & 0 deletions packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="HtmlAgilityPack" version="1.11.39" targetFramework="net472" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net472" />
</packages>

0 comments on commit d144398

Please sign in to comment.