Browse Source

Added basic IRC web interface that connects to a specific server specified in the config.

tags/3.0.0
Teknikode 2 years ago
parent
commit
b7e00579b5

+ 21
- 0
Teknik/Areas/IRC/Controllers/IRCController.cs View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Teknik.Controllers;
using Teknik.Attributes;
using Teknik.Areas.IRC.ViewModels;

namespace Teknik.Areas.IRC.Controllers
{
[TeknikAuthorize]
public class IRCController : DefaultController
{
public ActionResult Index()
{
ClientViewModel model = new ClientViewModel();
return View(model);
}
}
}

+ 36
- 0
Teknik/Areas/IRC/IrcAreaRegistration.cs View File

@@ -0,0 +1,36 @@
using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Optimization;
using Teknik.Configuration;
using Teknik.Utilities;

namespace Teknik.Areas.IRC
{
public class IRCAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "IRC";
}
}

public override void RegisterArea(AreaRegistrationContext context)
{
Config config = Config.Load();
context.MapSubdomainRoute(
"IRC.Index", // Route name
new List<string>() { "irc" },
new List<string>() { config.Host },
"", // URL with parameters
new { controller = "IRC", action = "Index" }, // Parameter defaults
new[] { typeof(Controllers.IRCController).Namespace }
);

// Register Script Bundle
BundleTable.Bundles.Add(new CdnScriptBundle("~/bundles/irc", config.CdnHost).Include(
"~/Areas/IRC/Scripts/IRC.js"));
}
}
}

+ 18
- 0
Teknik/Areas/IRC/Scripts/IRC.js View File

@@ -0,0 +1,18 @@
$(document).ready(function () {
/* ----------------------------------------
Websocket for the irc client
-----------------------------------------*/
var irc = $.connection.ircClient;

irc.client.rawMessageReceived = function (message) {
var txt = $('#clientOutput');
txt.val(txt.val() + '\n' + message);
};

$.connection.hub.start();

$('#sendMessage').click(function () {
irc.server.sendRawMessage($('#message').val());
$('#message').val('');
});
});

+ 12
- 0
Teknik/Areas/IRC/ViewModels/ClientViewModel.cs View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Teknik.ViewModels;

namespace Teknik.Areas.IRC.ViewModels
{
public class ClientViewModel : ViewModelBase
{
}
}

+ 35
- 0
Teknik/Areas/IRC/Views/IRC/Index.cshtml View File

@@ -0,0 +1,35 @@
@model Teknik.Areas.IRC.ViewModels.ClientViewModel

@using Teknik.Utilities

@Scripts.Render("~/bundles/signalr")
@Scripts.Render("~/signalr/hubs")
@Scripts.Render("~/bundles/irc")

<div class="container">
@if (User.Identity.IsAuthenticated)
{
<div class="row">
<div class="col-sm-10">
<textarea class="form-control" name="clientOutput" id="clientOutput" rows="20"></textarea>
</div>
</div>
<br />
<div class="row">
<div class="col-sm-10">
<input type="text" class="form-control" name="message" id="message">
</div>
<div class="col-sm-2">
<button type="button" class="btn btn-primary" id="sendMessage">Submit</button>
</div>
</div>
}
else
{
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<p>You need to be authenticated to view this page.</p>
</div>
</div>
}
</div>

+ 3
- 0
Teknik/Areas/IRC/Views/_ViewStart.cshtml View File

@@ -0,0 +1,3 @@
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}

+ 36
- 0
Teknik/Areas/IRC/Views/web.config View File

@@ -0,0 +1,36 @@
<?xml version="1.0"?>

<configuration>
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>

<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="Teknik.BaseViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.Optimization" />
<add namespace="Teknik" />
</namespaces>
</pages>
</system.web.webPages.razor>

<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>

<system.webServer>
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>

+ 72
- 0
Teknik/Hubs/IRCClientHub.cs View File

@@ -0,0 +1,72 @@
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Teknik.Attributes;
using Teknik.SignalR;
using System.Threading.Tasks;

namespace Teknik.Hubs
{
[HubName("ircClient")]
[TeknikAuthorize]
public class IRCClientHub : Hub
{
private static Dictionary<string, IRCClient> _Clients = new Dictionary<string, IRCClient>();

public IRCClientHub()
{
}

public override Task OnConnected()
{
if (Context != null)
{
if (!_Clients.ContainsKey(Context.ConnectionId))
{
if (Context.User.Identity.IsAuthenticated)
{
// Add the new connection to the main list
_Clients.Add(Context.ConnectionId, new IRCClient(Clients.Caller));

// Auto Connect to the server at startup
Connect();
}
}
}

return base.OnConnected();
}

public override Task OnDisconnected(bool stopCalled)
{
if (_Clients.ContainsKey(Context.ConnectionId))
{
// Disconnect from the IRC session
_Clients[Context.ConnectionId].Disconnect();

// Remove the irc client
_Clients.Remove(Context.ConnectionId);
}
return base.OnDisconnected(stopCalled);
}

public void Connect()
{
if (_Clients.ContainsKey(Context.ConnectionId))
{
_Clients[Context.ConnectionId].Connect(Context.User.Identity.Name);
}
}

public void SendRawMessage(string message)
{
if (_Clients.ContainsKey(Context.ConnectionId))
{
_Clients[Context.ConnectionId].SendRawMessage(message);
}
}
}
}

BIN
Teknik/Scripts/_references.js View File


+ 114
- 0
Teknik/SignalR/IRCClient.cs View File

@@ -0,0 +1,114 @@
using IRCSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using IRCSharp.Messaging;
using Microsoft.AspNet.SignalR;
using Teknik.Hubs;
using Microsoft.AspNet.SignalR.Hubs;
using Teknik.Configuration;
using System.Net;
using Teknik.Utilities;

namespace Teknik.SignalR
{
public class IRCClient
{
private IRC _IRC;
private dynamic _CallerContext;

// State Variables
private bool _Connected = false;
public bool Connected
{
get
{
return _Connected;
}
set
{
_Connected = value;
}
}

public IRCClient(dynamic callerContext)
{
Config config = Config.Load();
_CallerContext = callerContext;

_IRC = new IRC(config.IRCConfig.MaxMessageLength);

_IRC.ConnectEvent += HandleConnectEvent;
_IRC.DisconnectEvent += HandleDisconnectEvent;
_IRC.ExceptionThrown += HandleIrcExceptionThrown;

_IRC.Message.RawMessageEvent += Message_RawMessageEvent;
}

public void Connect(string username)
{
if (!_Connected)
{
Config config = Config.Load();
IPAddress[] ipList = Dns.GetHostAddresses(config.IRCConfig.Host);
foreach (IPAddress ip in ipList)
{
_Connected = _IRC.Connect(ip, config.IRCConfig.Port);
if (_Connected)
{
break;
}
}

if (_Connected)
{
_IRC.Login("Teknik-WebClient", new Nick()
{
Nickname = username,
Host = Dns.GetHostName(),
Realname = username,
Username = username
});
}
}
}

public void Disconnect()
{
if (_Connected)
{
_IRC.Disconnect();
}
}

public void SendRawMessage(string message)
{
if (_Connected)
{
_IRC.Command.SendRaw(message);
}
}

private void Message_RawMessageEvent(object sender, string message)
{
_CallerContext.rawMessageReceived(message);
}

private void HandleIrcExceptionThrown(Exception obj)
{
_CallerContext.exception(obj.GetFullMessage(true));
}

private void HandleDisconnectEvent()
{
_CallerContext.disconnected();
}

private void HandleConnectEvent()
{
_CallerContext.connected();
}
}
}

+ 19
- 4
Teknik/Teknik.csproj View File

@@ -61,6 +61,10 @@
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="IRCSharp, Version=1.0.0.1, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\IRCSharp.1.0.0.1\lib\net462\IRCSharp.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MarkdownDeep, Version=1.5.4615.26275, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MarkdownDeep.NET.1.5\lib\.NetFramework 3.5\MarkdownDeep.dll</HintPath>
<Private>True</Private>
@@ -103,16 +107,16 @@
<HintPath>..\packages\MySql.Data.6.9.9\lib\net45\MySql.Data.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NBitcoin, Version=3.0.2.4, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NBitcoin.3.0.2.4\lib\net45\NBitcoin.dll</HintPath>
<Reference Include="NBitcoin, Version=3.0.2.10, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NBitcoin.3.0.2.10\lib\net45\NBitcoin.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nClam, Version=2.0.6.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\nClam.2.0.6.0\lib\net40-Client\nClam.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
@@ -249,6 +253,9 @@
<Compile Include="Areas\Home\Controllers\HomeController.cs" />
<Compile Include="Areas\Home\HomeAreaRegistration.cs" />
<Compile Include="Areas\Home\ViewModels\HomeViewModel.cs" />
<Compile Include="Areas\IRC\Controllers\IRCController.cs" />
<Compile Include="Areas\IRC\IRCAreaRegistration.cs" />
<Compile Include="Areas\IRC\ViewModels\ClientViewModel.cs" />
<Compile Include="Areas\Paste\Controllers\PasteController.cs" />
<Compile Include="Areas\Paste\Models\Paste.cs" />
<Compile Include="Areas\Paste\PasteHelper.cs" />
@@ -297,6 +304,7 @@
<Compile Include="Areas\Vault\ViewModels\PasteItemViewModel.cs" />
<Compile Include="Areas\Vault\ViewModels\VaultItemViewModel.cs" />
<Compile Include="Attributes\TeknikAuthorizeAttribute.cs" />
<Compile Include="Hubs\IRCClientHub.cs" />
<Compile Include="Security\ITeknikPrincipal.cs" />
<Compile Include="Security\TeknikPrincipal.cs" />
<Compile Include="Filters\CORSActionFilter.cs" />
@@ -360,6 +368,7 @@
<Compile Include="Areas\User\ViewModels\LoginViewModel.cs" />
<Compile Include="Areas\User\ViewModels\RegisterViewModel.cs" />
<Compile Include="Modules\PerformanceMonitorModule.cs" />
<Compile Include="SignalR\IRCClient.cs" />
<Compile Include="SignalR\ServerUsageTicker.cs" />
<Compile Include="Startup.cs" />
<Compile Include="ViewModels\ViewModelBase.cs" />
@@ -384,6 +393,7 @@
<Content Include="Areas\Help\Content\Help.css" />
<Content Include="Areas\Home\Content\Home.css" />
<Content Include="Areas\Home\Scripts\Home.js" />
<Content Include="Areas\IRC\Scripts\IRC.js" />
<Content Include="Areas\Paste\Content\Paste.css" />
<Content Include="Areas\Paste\Scripts\Paste.js" />
<Content Include="Areas\Podcast\Content\Podcast.css" />
@@ -645,6 +655,9 @@
<Content Include="Areas\User\Views\User\GetPremium.cshtml" />
<Content Include="Areas\Admin\Views\Admin\UploadSearch.cshtml" />
<Content Include="Areas\Admin\Views\Admin\UploadResult.cshtml" />
<Content Include="Areas\IRC\Views\web.config" />
<Content Include="Areas\IRC\Views\IRC\Index.cshtml" />
<Content Include="Areas\IRC\Views\_ViewStart.cshtml" />
<None Include="Properties\PublishProfiles\Teknik Dev.pubxml" />
<None Include="Properties\PublishProfiles\Teknik Production.pubxml" />
<None Include="Scripts\jquery-2.1.4.intellisense.js" />
@@ -740,6 +753,8 @@
<Folder Include="Areas\Help\Views\Shared\" />
<Folder Include="Areas\Home\Models\" />
<Folder Include="Areas\Home\Views\Shared\" />
<Folder Include="Areas\IRC\Models\" />
<Folder Include="Areas\IRC\Views\Shared\" />
<Folder Include="Areas\Paste\Views\Shared\" />
<Folder Include="Areas\Podcast\Views\Shared\" />
<Folder Include="Areas\Privacy\Models\" />

+ 1
- 1
Teknik/Web.config View File

@@ -77,7 +77,7 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />

+ 3
- 2
Teknik/packages.config View File

@@ -9,6 +9,7 @@
<package id="FontAwesome" version="4.7.0" targetFramework="net462" userInstalled="true" />
<package id="GitVersionTask" version="3.6.5" targetFramework="net462" developmentDependency="true" />
<package id="Inferno" version="1.4.0" targetFramework="net452" userInstalled="true" />
<package id="IRCSharp" version="1.0.0.1" targetFramework="net462" />
<package id="jQuery" version="3.1.1" targetFramework="net452" userInstalled="true" />
<package id="jQuery.Validation" version="1.16.0" targetFramework="net462" userInstalled="true" />
<package id="MarkdownDeep.Full" version="1.5" targetFramework="net452" />
@@ -32,9 +33,9 @@
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net46" userInstalled="true" />
<package id="Modernizr" version="2.8.3" targetFramework="net452" userInstalled="true" />
<package id="MySql.Data" version="6.9.9" targetFramework="net452" />
<package id="NBitcoin" version="3.0.2.4" targetFramework="net462" />
<package id="NBitcoin" version="3.0.2.10" targetFramework="net462" />
<package id="nClam" version="2.0.6.0" targetFramework="net462" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" userInstalled="true" />
<package id="Newtonsoft.Json" version="10.0.1" targetFramework="net462" userInstalled="true" />
<package id="Owin" version="1.0" targetFramework="net462" />
<package id="Piwik.Tracker" version="2.16.0.0" targetFramework="net452" />
<package id="QRCoder" version="1.2.3" targetFramework="net462" />

+ 1
- 1
TeknikStreaming/App.config View File

@@ -25,7 +25,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />

+ 5
- 0
Utilities/Configuration/Config.cs View File

@@ -43,6 +43,7 @@ namespace Teknik.Configuration
private StatusConfig _StatusConfig;
private LoggingConfig _LoggingConfig;
private PiwikConfig _PiwikConfig;
private IRCConfig _IRCConfig;

public bool DevEnvironment { get { return _DevEnvironment; } set { _DevEnvironment = value; } }
public bool Migrate { get { return _Migrate; } set { _Migrate = value; } }
@@ -105,6 +106,9 @@ namespace Teknik.Configuration
// Piwik Configuration
public PiwikConfig PiwikConfig { get { return _PiwikConfig; } set { _PiwikConfig = value; } }

// Piwik Configuration
public IRCConfig IRCConfig { get { return _IRCConfig; } set { _IRCConfig = value; } }

public Config()
{
_ConfigRWLock = new ReaderWriterLockSlim();
@@ -145,6 +149,7 @@ namespace Teknik.Configuration
StatusConfig = new StatusConfig();
LoggingConfig = new LoggingConfig();
PiwikConfig = new PiwikConfig();
IRCConfig = new IRCConfig();
}

public static Config Deserialize(string text)

+ 1
- 0
Utilities/Configuration/Configuration.csproj View File

@@ -46,6 +46,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="IRCConfig.cs" />
<Compile Include="ApiConfig.cs" />
<Compile Include="BlogConfig.cs" />
<Compile Include="Config.cs" />

+ 26
- 0
Utilities/Configuration/IRCConfig.cs View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Teknik.Configuration
{
public class IRCConfig
{
public bool Enabled { get; set; }

public string Host { get; set; }

public int Port { get; set; }

public int MaxMessageLength { get; set; }

public IRCConfig()
{
Host = string.Empty;
Port = 0;
MaxMessageLength = 400;
}
}
}

Loading…
Cancel
Save