Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
434 changes: 434 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions src/PasslickDevelopment.LearnwebNotifier/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using LearnwebNotifier.Library.Domain.Models;
using System;
using System.Collections.Generic;

namespace LearnwebNotifier.Library.Domain.Communication
{
public class ServiceResponse
{
public Guid ExecId { get; }
public DateTime ExecDate { get; }
public ServiceStatus Status { get; }
public List<Activity> Activities { get; }

public ServiceResponse(ServiceStatus status, List<Activity> activities)
{
ExecId = Guid.NewGuid();
ExecDate = DateTime.UtcNow;
Status = status;
Activities = activities;
}
}
}


// (c) Passlick Development 2020. All rights reserved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace LearnwebNotifier.Library.Domain.Communication
{
public enum ServiceStatus
{
Info = 1000,
InfoRequested = 1001,
OK = 2000,
NewActivities = 2001,
NoRecentActivities = 2002,
PushSent = 2003,
Valid = 2005,
Exists = 2006,
Warning = 3000,
WidgetNotFound = 3001,
Fail = 4000,
PushFailed = 4003,
NotFound = 4004,
Invalid = 4005,
Exception = 5000,
Unauthorized = 5001,
CriticalException = 6000,
UnhandledException = 7000
}
}


// (c) Passlick Development 2020. All rights reserved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;

namespace LearnwebNotifier.Library.Domain.Models
{
public class Activity
{
public DateTime? Date { get; }
public Course Course { get; }
public string Type { get; }
public string Name { get; }
public string Url { get; }

public Activity(DateTime? date, Course course, string type, string name, string url)
{
Date = date;
Course = course;
Type = type;
Name = name;
Url = url;
}
}
}


// (c) Passlick Development 2020. All rights reserved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace LearnwebNotifier.Library.Domain.Models
{
public class ConfigStruct
{
[JsonPropertyName("service")]
public ServiceConfig Service { get; set; } = new ServiceConfig(5);
[JsonPropertyName("learnweb")]
public LearnwebConfig Learnweb { get; set; } = new LearnwebConfig("", "", new List<string> { "" });
[JsonPropertyName("pushover")]
public PushoverConfig Pushover { get; set; } = new PushoverConfig("", "");
[JsonPropertyName("sentry")]
public SentryConfig Sentry { get; set; } = new SentryConfig(false, "");

public ConfigStruct(LearnwebConfig learnweb, PushoverConfig pushover)
{
Learnweb = learnweb;
Pushover = pushover;
}
public ConfigStruct() { }


public class ServiceConfig
{
[JsonPropertyName("refresh")]
public uint Refresh { get; set; }

public ServiceConfig(uint refresh)
{
Refresh = refresh;
}
public ServiceConfig() { }
}

public class LearnwebConfig
{
[JsonPropertyName("user")]
public string Username { get; set; }
[JsonPropertyName("password")]
public string Password { get; set; }
[JsonPropertyName("courses")]
public List<string> Courses { get; set; }

public LearnwebConfig(string username, string password, List<string> courses)
{
Username = username;
Password = password;
Courses = courses;
}
public LearnwebConfig() { }
}

public class PushoverConfig
{
[JsonPropertyName("token")]
public string Token { get; set; }
[JsonPropertyName("recipient")]
public string Recipient { get; set; }

public PushoverConfig(string token, string recipient)
{
Token = token;
Recipient = recipient;
}
public PushoverConfig() { }
}

public class SentryConfig
{
[JsonPropertyName("activate")]
public bool Activate { get; set; }
[JsonPropertyName("dsn")]
public string Dsn { get; set; }

public SentryConfig(bool activate, string dsn)
{
Activate = activate;
Dsn = dsn;
}
public SentryConfig() { }
}

}
}


// (c) Passlick Development 2020. All rights reserved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace LearnwebNotifier.Library.Domain.Models
{
public class Course
{
public string Id { get; }
public string Name { get; set; }
public string Abbrev { get; set; }
public string Url { get; set; }

public Course(string id)
{
Id = id;
Name = "N/A";
Abbrev = "N/A";
Url = $"https://sso.uni-muenster.de/LearnWeb/learnweb2/course/view.php?id={Id}&lang=en";
}
}
}


// (c) Passlick Development 2020. All rights reserved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using LearnwebNotifier.Library.Domain.Communication;

namespace LearnwebNotifier.Library.Domain.Services
{
public interface IActivityService
{
public ServiceStatus Init();
public ServiceResponse FetchActivities(string courseId);
public ServiceStatus RefreshSession();
public void ClearCookies();
public void Dispose();
}
}


// (c) Passlick Development 2020. All rights reserved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using LearnwebNotifier.Library.Domain.Communication;
using System.Net.Http;

namespace LearnwebNotifier.Library.Domain.Services
{
public interface IClientService
{
public ServiceStatus Init();
public ServiceStatus Authorize();
public ServiceStatus RefreshSession();
public HttpClient GetClient();
public void ClearCookies();
public void Dispose();
}
}


// (c) Passlick Development 2020. All rights reserved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using LearnwebNotifier.Library.Domain.Communication;
using LearnwebNotifier.Library.Domain.Models;

namespace LearnwebNotifier.Library.Domain.Services
{
public interface IConfigService
{
public ServiceStatus LoadConfig();
public ServiceStatus GenerateConfig(ConfigStruct config);
public ServiceStatus CheckConfigExistence();
public (ServiceStatus status, string value) GetLearnwebPassword();
public ServiceStatus ConfigAssistant();
}
}


// (c) Passlick Development 2020. All rights reserved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using LearnwebNotifier.Library.Domain.Communication;
using LearnwebNotifier.Library.Domain.Models;
using System.Collections.Generic;

namespace LearnwebNotifier.Library.Domain.Services
{
public interface ICrawlerService
{
public (ServiceStatus status, List<Activity> activities) ParseCourse(Course course);
}
}


// (c) Passlick Development 2020. All rights reserved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.Reflection;

namespace LearnwebNotifier.Library.Helper
{
public static class HelperFunctions
{

public static void ConsoleWrite(string text, ConsoleColor fgcolor = ConsoleColor.Gray, ConsoleColor bgcolor = ConsoleColor.Black)
{
Console.ForegroundColor = fgcolor;
Console.BackgroundColor = bgcolor;
Console.Write(text);
Console.ResetColor();
}


public static void ConsoleWriteLine(string text, ConsoleColor fgcolor = ConsoleColor.Gray, ConsoleColor bgcolor = ConsoleColor.Black)
{
Console.ForegroundColor = fgcolor;
Console.BackgroundColor = bgcolor;
Console.WriteLine(text);
Console.ResetColor();
}


public static string ReadPassword()
{
string password = string.Empty;
ConsoleKey key;
do
{
var keyInfo = Console.ReadKey(true);
key = keyInfo.Key;

if (key == ConsoleKey.Backspace && password.Length > 0)
{
Console.Write("\b \b");
password = password[0..^1];
}
else if (!char.IsControl(keyInfo.KeyChar))
{
Console.Write("∗");
password += keyInfo.KeyChar;
}
} while (key != ConsoleKey.Enter);
return password;
}


public static void PrintConsoleHeader()
{
Console.Clear();
Console.WriteLine("\n***************************************************************************\n");
Console.WriteLine($" WWU Learnweb Notifier Service v{Assembly.GetEntryAssembly().GetName().Version}");
Console.WriteLine($" (c) Passlick Development {DateTime.UtcNow.Year}. All rights reserved.");
Console.WriteLine("\n***************************************************************************\n");
}


// Hardcoded encryption key for weak string protection against easy plaintext read -- does not serve safety-critical purpose
private static readonly string encryptionKey = "d7z8jhL5uvPFbsMzyfobhwHdoEeovkUGlztcTVFrdp86NwItxK9VN6kvNDhaAtIo";

public static string EncryptString(string value) => SimpleAES.AES256.Encrypt(value, encryptionKey);
public static string DecryptString(string value) => SimpleAES.AES256.Decrypt(value, encryptionKey);

}
}


// (c) Passlick Development 2020. All rights reserved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>lwnotif-lib</AssemblyName>
<OutputType>Library</OutputType>
<Authors>Passlick Development</Authors>
<Product>WWU Learnweb Notifier</Product>
<Copyright>Copyright © Passlick Development 2020. All rights reserved.</Copyright>
<NeutralLanguage>en-US</NeutralLanguage>
<ApplicationIcon>passlickdev.ico</ApplicationIcon>
<AssemblyVersion>1.3.0.0</AssemblyVersion>
<FileVersion>1.3.0.0</FileVersion>
<Version>1.3.0</Version>
<SignAssembly>false</SignAssembly>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<Optimize>false</Optimize>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.11.24" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.7" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.7" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.7" />
<PackageReference Include="Sentry" Version="2.1.5" />
<PackageReference Include="Sentry.Extensions.Logging" Version="2.1.5" />
<PackageReference Include="SimpleAES" Version="1.1.1" />
</ItemGroup>

</Project>
Loading