Projektdateien hinzufügen.
This commit is contained in:
parent
75d3dae8e0
commit
821cc02b81
25
PrüfungCMSOhneVersion.sln
Normal file
25
PrüfungCMSOhneVersion.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.10.35122.118
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrüfungCMSOhneVersion", "PrüfungCMSOhneVersion\PrüfungCMSOhneVersion.csproj", "{F99A1659-EA94-46E5-A615-7082AA9563CC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{F99A1659-EA94-46E5-A615-7082AA9563CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F99A1659-EA94-46E5-A615-7082AA9563CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F99A1659-EA94-46E5-A615-7082AA9563CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F99A1659-EA94-46E5-A615-7082AA9563CC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {54E77090-9459-4214-9357-760E44D9ECE4}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
116
PrüfungCMSOhneVersion/Program.cs
Normal file
116
PrüfungCMSOhneVersion/Program.cs
Normal file
@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using MySql.Data.MySqlClient;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
class Program
|
||||
{
|
||||
// API Key und MySQL Verbindungseinstellungen
|
||||
const string apiKey = "w41axaew9zz7w5bzunn4ujyk45uitln7ftxyxsm5m7321vputnloh21z6868www0hwwe58";
|
||||
const string connectionString = "Server=192.168.178.201;Database=domainchecker;User ID=root;Password=1td5rugut8;";
|
||||
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
using (MySqlConnection connection = new MySqlConnection(connectionString))
|
||||
{
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
// SQL-Abfrage um alle Domains mit 'Unknown' Version abzurufen
|
||||
string query = "SELECT `domain`, `version`, `letzte_pruefung`, `cms_name` FROM `wp_versionen` WHERE version = 'Unknown'";
|
||||
MySqlCommand command = new MySqlCommand(query, connection);
|
||||
MySqlDataReader reader = command.ExecuteReader();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
string domain = reader["domain"].ToString();
|
||||
string cmsName = reader["cms_name"].ToString();
|
||||
|
||||
// Überprüfe CMS Version mit API
|
||||
string apiResponse = await CheckCMSVersion(domain);
|
||||
|
||||
if (!string.IsNullOrEmpty(apiResponse))
|
||||
{
|
||||
JObject jsonResponse = JObject.Parse(apiResponse);
|
||||
var results = jsonResponse["results"];
|
||||
|
||||
// Überprüfe, ob das ermittelte CMS mit dem in der DB übereinstimmt
|
||||
foreach (var result in results)
|
||||
{
|
||||
string name = result["name"].ToString();
|
||||
string version = result["version"].ToString();
|
||||
|
||||
if (name.Equals(cmsName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
reader.Close();
|
||||
// Aktualisiere die Version in der MySQL Datenbank
|
||||
UpdateCMSVersion(connection, domain, version);
|
||||
reader = command.ExecuteReader();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Warte 10 Sekunden vor der nächsten API-Anfrage
|
||||
await Task.Delay(10000);
|
||||
}
|
||||
|
||||
reader.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Error: " + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static async Task<string> CheckCMSVersion(string domain)
|
||||
{
|
||||
string url = $"https://whatcms.org/API/Tech?key={apiKey}&url={domain}";
|
||||
|
||||
using (HttpClient client = new HttpClient())
|
||||
{
|
||||
try
|
||||
{
|
||||
HttpResponseMessage response = await client.GetAsync(url);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
string responseBody = await response.Content.ReadAsStringAsync();
|
||||
return responseBody;
|
||||
}
|
||||
catch (HttpRequestException e)
|
||||
{
|
||||
Console.WriteLine($"Request error: {e.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void UpdateCMSVersion(MySqlConnection connection, string domain, string version)
|
||||
{
|
||||
try
|
||||
{
|
||||
string updateQuery = "UPDATE `wp_versionen` SET `version` = @version, `letzte_pruefung` = NOW() WHERE `domain` = @domain";
|
||||
MySqlCommand updateCommand = new MySqlCommand(updateQuery, connection);
|
||||
updateCommand.Parameters.AddWithValue("@version", version);
|
||||
updateCommand.Parameters.AddWithValue("@domain", domain);
|
||||
|
||||
int rowsAffected = updateCommand.ExecuteNonQuery();
|
||||
|
||||
if (rowsAffected > 0)
|
||||
{
|
||||
Console.WriteLine($"Domain '{domain}' erfolgreich aktualisiert mit Version '{version}'.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Keine Aktualisierung für Domain '{domain}'.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Update error: " + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
15
PrüfungCMSOhneVersion/PrüfungCMSOhneVersion.csproj
Normal file
15
PrüfungCMSOhneVersion/PrüfungCMSOhneVersion.csproj
Normal file
@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MySql.Data" Version="8.1.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Loading…
Reference in New Issue
Block a user