to be continue

This commit is contained in:
2021-10-23 17:10:17 +03:00
parent 7aca66844e
commit 4cdd960233
8 changed files with 148 additions and 29 deletions

View File

@@ -6,22 +6,10 @@
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<COMReference Include="Microsoft.Office.Interop.Excel">
<WrapperTool>tlbimp</WrapperTool>
<VersionMinor>9</VersionMinor>
<VersionMajor>1</VersionMajor>
<Guid>00020813-0000-0000-c000-000000000046</Guid>
<Lcid>0</Lcid>
<Isolated>false</Isolated>
<EmbedInteropTypes>true</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<ItemGroup>
<Content Include="bins\geckodriver.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Resources\res.json">
@@ -32,6 +20,8 @@
<ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="2.13.1" />
<PackageReference Include="EPPlus" Version="5.7.5" />
<PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
<PackageReference Include="System.Security.Cryptography.Algorithms" Version="4.3.1" />
</ItemGroup>

View File

@@ -19,20 +19,26 @@ namespace Deposits {
public static void RunEncryption(Data dt) {
if (ToEncrypt()) {
Data.CreateNewKeys();
System.IO.File.WriteAllBytes(dt.GetLocation(), Data.EncryptData(dt.GetPlainText()));
System.IO.File.WriteAllBytes(dt.locations, Data.EncryptData(dt.GetPlainText()));
}
}
static void Main(string[] args) {
WebDriver driver = new();
driver.Driver.Url = "https://google.com";
//WebDriver driver = new();
//driver.Driver.Url = "https://google.com";
driver.RunWeb(300, "https://mail.google.com/mail/u/0/#inbox", "https://www.tgspot.co.il/");
//driver.RunWeb(3, "https://mail.google.com/mail/u/0/#inbox", "https://www.tgspot.co.il/");
//foreach (var argu in args) {
// System.Console.WriteLine(argu);
//}
//Data dt = new Data();
//RunEncryption(dt);
//dt = new();
//string resources = System.IO.File.ReadAllText(@"Resources\res.json");
//var location = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(resources);
//System.Console.WriteLine(dt.GetPlainText());
//Data data = new Data(true);
//data.AddToData("{\"phone\":\"0547477082\"}");
//System.Console.WriteLine("yes");
}
}
}

View File

@@ -1,16 +1,23 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Security.Cryptography;
using System.Text;
namespace Deposits.SubDep {
class Data {
string plainTextData;
string locations;
public JObject? DataJson { get; }
public string locations { get; }
byte[] encryptedData;
public Data() {
public Data(bool createJson = false) {
string resources = System.IO.File.ReadAllText(@"Resources\res.json");
var location = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(resources);
var location = (JObject)JsonConvert.DeserializeObject(resources);
this.locations = (string)location["data location"];
this.encryptedData = System.IO.File.ReadAllBytes(locations);
this.plainTextData = DecryptData(this.encryptedData);
if (createJson) {
DataJson = DataObject(this.plainTextData);
}
}
public static void CreateNewKeys() {
RSA file = RSA.Create();
@@ -41,6 +48,21 @@ namespace Deposits.SubDep {
//rsaFile.fr
}
public void SetPlainText(string newPlainText) {
this.plainTextData = newPlainText;
}
public void SetPlainText(JObject newPlainText) {
this.plainTextData = newPlainText.ToString();
}
public static byte[] EncryptData(JObject ob) {
RSA rsaFile = RSA.Create();
string prive = System.IO.File.ReadAllText(@"D:\pk");
rsaFile.FromXmlString(prive);
byte[] Data = Encoding.UTF8.GetBytes(ob.ToString());
return rsaFile.Encrypt(Data, RSAEncryptionPadding.Pkcs1);
}
public static string DecryptData(byte[] data) {
RSA rsaFile = RSA.Create();
string prive = System.IO.File.ReadAllText(@"D:\pk");
@@ -48,5 +70,38 @@ namespace Deposits.SubDep {
string Data = System.Text.Encoding.UTF8.GetString(rsaFile.Decrypt(data, RSAEncryptionPadding.Pkcs1));
return Data;
}
public static JObject DataObject(string data) {
return (JObject)JsonConvert.DeserializeObject(data);
}
public static void SaveEncryptedData(byte[] data, string path) {
System.IO.File.WriteAllBytes(path, data);
}
public void AddToData(string data) {
try {
JObject newData = (JObject)JsonConvert.DeserializeObject(data);
if (DataJson != null) {
foreach (var dt in newData) {
DataJson.Add(dt.Key, dt.Value);
}
SaveEncryptedData(EncryptData(DataJson), this.locations);
}
} catch {
}
}
public static void RunEncryption(Data dt) {
if (System.DateTime.Today.Day > 24) {
CreateNewKeys();
System.IO.File.WriteAllBytes(dt.locations, EncryptData(dt.GetPlainText()));
}
}
public void RunEncryption() {
if (System.DateTime.Today.Day > 24) {
CreateNewKeys();
System.IO.File.WriteAllBytes(locations, EncryptData(GetPlainText()));
}
}
}
}

15
Deposits/SubDep/Depen.cs Normal file
View File

@@ -0,0 +1,15 @@
using Newtonsoft.Json;
public class DataDetails {
private static string resources = System.IO.File.ReadAllText(@"Resources\res.json");
private static dynamic location = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(resources);
public static string DataLocation {
get {
return (string)location["data location"];
}
}
public static string ExcelLocation {
get {
return (string)location["deposit xl"];
}
}
}

View File

@@ -4,13 +4,32 @@
//using System.Text;
//using System.Threading.Tasks;
//using System.Runtime.InteropServices;
//using Microsoft.Office.Interop.Excel;
//using OfficeOpenXml.Core;
namespace Deposits.SubDep {
class Excel {
Microsoft.Office.Interop.Excel.Workbooks wb;
private static System.IO.FileInfo file = new System.IO.FileInfo(DataDetails.ExcelLocation);
private OfficeOpenXml.ExcelPackage excelPackage = new OfficeOpenXml.ExcelPackage(file);
public OfficeOpenXml.ExcelWorksheet deposits { get; }
public OfficeOpenXml.ExcelWorksheet creditCard { get; }
public Excel() {
wb.Open(@"D:\Drive\מסמכים\מסמכים לסנכרון\צבירוש.xlsx");
var wb = excelPackage.Workbook;
foreach (var sheet in wb.Worksheets) {
if (sheet.Name.Contains("צבירוש") || sheet.Name.Contains("deposit")) {
this.deposits = sheet;
} else if (sheet.Name.Contains("credit")) {
this.creditCard = sheet;
}
}
if (deposits == null) {
deposits = wb.Worksheets.Add("deposits");
}
if (creditCard == null) {
creditCard = wb.Worksheets.Add("credit card");
}
}
public void UpdateDeposits() {
}
}

View File

@@ -1,7 +1,22 @@
namespace Deposits.SubDep
{
class Fnx
{
using Newtonsoft.Json.Linq;
//using Deposits.SubDep;
namespace Deposits.SubDep {
class Fnx : WebDriver {
string Mail;
string Url;
WebDriver MailApp;
JObject Data;
public Fnx(string url, string mail) {
Url = url;
Mail = mail;
this.Driver.Url = Url;
Deposits.SubDep.Data data = new(true);
Data = (JObject)data.DataJson["humail"];
}
public void DefineMailApp() {
this.MailApp = new();
MailApp.RunWeb()
}
}
}

View File

@@ -0,0 +1,15 @@
namespace Deposits.SubDep {
class UrlActions {
private string _url;
private string?[] fields;
private string?[] data;
private int timeout;
public UrlActions(string url, string?[] fields, string?[] data, int timeout = 0) {
_url = url;
this.fields = fields;
this.data = data;
this.timeout = timeout;
}
}
}

View File

@@ -3,7 +3,9 @@ namespace Deposits.SubDep {
class WebDriver {
FirefoxOptions options = new();
FirefoxProfile profile = new();
string?[] Urls;
public FirefoxDriver Driver;
//JObject UrlAndActions
private void SetProfile() {
this.profile.SetPreference("browser.download.folderList", 2);
this.profile.SetPreference("browser.download.manager.showWhenStarting", false);
@@ -13,11 +15,13 @@ namespace Deposits.SubDep {
this.profile.SetPreference("browser.download.panel.shown", false);
}
private void SetOption() {
SetProfile();
this.options.Profile = this.profile;
this.options.AddArgument("--lang=EN");
}
public WebDriver() {
//System.IO.Path.Join("bins\\geckodriver.exe");
SetOption();
this.Driver = new($"bins", options);
}
public void RunWeb(int timeToWait = 0, params string[] urls) {