https stuff and cert generator for the webserver

This commit is contained in:
lukeIam committed 2013-12-13 17:43:09 +01:00
1 parent 3f18832b38
commit 33252ab19c
16 files changed
+2270 -226

No files matched your search

+196 -140
View File
@@ -1,140 +1,196 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Web;
namespace ClientServerLib
{
public class CServer
{
private ServiceHost host;
private Uri baseAddress;
private static SendKeyEventDelegate sendKeyEvent;
public static SendKeyEventDelegate SendKeyEvent
{
internal get { return CServer.sendKeyEvent; }
set { CServer.sendKeyEvent = value; }
}
#region profile
private static GetProfileDataDelegate getProfileData;
public static GetProfileDataDelegate GetProfileData
{
internal get { return CServer.getProfileData; }
set { CServer.getProfileData = value; }
}
private static SendProfileDataDelegate sendProfileData;
public static SendProfileDataDelegate SendProfileData
{
internal get { return CServer.sendProfileData; }
set { CServer.sendProfileData = value; }
}
private static GetProfileListDelegate getProfileList;
public static GetProfileListDelegate GetProfileList
{
internal get { return CServer.getProfileList; }
set { CServer.getProfileList = value; }
}
#endregion
#region photo
private static SendPhotoDelegate sendPhoto;
public static SendPhotoDelegate SendPhoto
{
get { return CServer.sendPhoto; }
set { CServer.sendPhoto = value; }
}
#endregion
#region website
private static GetSiteFileDelegate getSiteFile;
public static GetSiteFileDelegate GetSiteFile
{
internal get { return CServer.getSiteFile; }
set { CServer.getSiteFile = value; }
}
#endregion
#region songs
private static GetSongDelegate getSong;
public static GetSongDelegate GetSong
{
internal get { return CServer.getSong; }
set { CServer.getSong = value; }
}
private static GetAllSongsDelegate getAllSongs;
public static GetAllSongsDelegate GetAllSongs
{
get { return CServer.getAllSongs; }
set { CServer.getAllSongs = value; }
}
private static GetCurrentSongIdDelegate getCurrentSongId;
public static GetCurrentSongIdDelegate GetCurrentSongId
{
get { return CServer.getCurrentSongId; }
set { CServer.getCurrentSongId = value; }
}
#endregion
public CServer(int port)
{
baseAddress = new Uri("http://localhost:" + port + "/");
host = new WebServiceHost(typeof(CWebservice), baseAddress);
WebHttpBinding wb = new WebHttpBinding();
wb.MaxReceivedMessageSize = 10485760;
wb.MaxBufferSize = 10485760;
wb.MaxBufferPoolSize = 10485760;
wb.ReaderQuotas.MaxStringContentLength = 10485760;
wb.ReaderQuotas.MaxArrayLength = 10485760;
wb.ReaderQuotas.MaxBytesPerRead = 10485760;
host.AddServiceEndpoint(typeof(ICWebservice), wb, "");
}
public void Start()
{
try
{
// Step 4 Enable metadata exchange.
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
//smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
//smb.HttpGetEnabled = true;
host.Description.Behaviors.Add(smb);
// Step 5 Start the service.
host.Open();
}
catch (CommunicationException ce)
{
host.Abort();
}
}
public void Stop()
{
try
{
host.Close();
}
catch (CommunicationException ce)
{
host.Abort();
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Web;
using System.Security.Cryptography.X509Certificates;
using System.Diagnostics;
using System.Net;
namespace ClientServerLib
{
public class CServer
{
private ServiceHost host;
private Uri baseAddress;
private bool encrypted = false;
private static SendKeyEventDelegate sendKeyEvent;
public static SendKeyEventDelegate SendKeyEvent
{
internal get { return CServer.sendKeyEvent; }
set { CServer.sendKeyEvent = value; }
}
#region profile
private static GetProfileDataDelegate getProfileData;
public static GetProfileDataDelegate GetProfileData
{
internal get { return CServer.getProfileData; }
set { CServer.getProfileData = value; }
}
private static SendProfileDataDelegate sendProfileData;
public static SendProfileDataDelegate SendProfileData
{
internal get { return CServer.sendProfileData; }
set { CServer.sendProfileData = value; }
}
private static GetProfileListDelegate getProfileList;
public static GetProfileListDelegate GetProfileList
{
internal get { return CServer.getProfileList; }
set { CServer.getProfileList = value; }
}
#endregion
#region photo
private static SendPhotoDelegate sendPhoto;
public static SendPhotoDelegate SendPhoto
{
get { return CServer.sendPhoto; }
set { CServer.sendPhoto = value; }
}
#endregion
#region website
private static GetSiteFileDelegate getSiteFile;
public static GetSiteFileDelegate GetSiteFile
{
internal get { return CServer.getSiteFile; }
set { CServer.getSiteFile = value; }
}
#endregion
#region songs
private static GetSongDelegate getSong;
public static GetSongDelegate GetSong
{
internal get { return CServer.getSong; }
set { CServer.getSong = value; }
}
private static GetAllSongsDelegate getAllSongs;
public static GetAllSongsDelegate GetAllSongs
{
get { return CServer.getAllSongs; }
set { CServer.getAllSongs = value; }
}
private static GetCurrentSongIdDelegate getCurrentSongId;
public static GetCurrentSongIdDelegate GetCurrentSongId
{
get { return CServer.getCurrentSongId; }
set { CServer.getCurrentSongId = value; }
}
#endregion
public CServer(int port, bool encrypted)
{
init(port, encrypted);
}
private void init(int port, bool encrypted)
{
string hostname = Dns.GetHostName();
if (encrypted)
{
baseAddress = new Uri("https://" + hostname + ":" + port + "/");
}
else
{
baseAddress = new Uri("http://" + hostname + ":" + port + "/");
}
this.encrypted = encrypted;
host = new WebServiceHost(typeof(CWebservice), baseAddress);
WebHttpBinding wb = new WebHttpBinding();
wb.MaxReceivedMessageSize = 10485760;
wb.MaxBufferSize = 10485760;
wb.MaxBufferPoolSize = 10485760;
wb.ReaderQuotas.MaxStringContentLength = 10485760;
wb.ReaderQuotas.MaxArrayLength = 10485760;
wb.ReaderQuotas.MaxBytesPerRead = 10485760;
if (encrypted)
{
wb.Security.Mode = WebHttpSecurityMode.Transport;
wb.Security.Transport = new HttpTransportSecurity { ClientCredentialType = HttpClientCredentialType.None };
}
host.AddServiceEndpoint(typeof(ICWebservice), wb, "");
}
public void Start()
{
try
{
/*ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
smb.HttpGetEnabled = true;
host.Description.Behaviors.Add(smb);*/
host.Open();
}
catch (CommunicationException e)
{
if (e is AddressAccessDeniedException || e is AddressAlreadyInUseException)
{
registerUrlAndCert(baseAddress.Port);
try
{
host.Abort();
init(baseAddress.Port, encrypted);
host.Open();
}
catch (CommunicationException e2)
{
host.Abort();
}
}
else
{
host.Abort();
}
}
}
public void Stop()
{
try
{
host.Close();
}
catch (CommunicationException e)
{
host.Abort();
}
}
private void registerUrlAndCert(int port)
{
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = "WebserverInitalConfig.exe";
info.Arguments = port.ToString() + " " + encrypted.ToString();
info.UseShellExecute = true;
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
info.Verb = "runas";
Process p = Process.Start(info);
if (p != null)
{
p.WaitForExit();
p.Close();
}
}
}
}
@@ -1,70 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ClientServerLib</RootNamespace>
<AssemblyName>ClientServerLib</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.ServiceModel.Web" />
<Reference Include="System.Web.Services" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CClient.cs" />
<Compile Include="CConnection.cs" />
<Compile Include="CDiscover.cs" />
<Compile Include="CServer.cs" />
<Compile Include="CWebservice.cs" />
<Compile Include="DataStructs.cs" />
<Compile Include="DeffieHellman\BigInt.cs" />
<Compile Include="DeffieHellman\DeffieHellman.cs" />
<Compile Include="DeffieHellman\StrongNumberProvider.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Structs.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ClientServerLib</RootNamespace>
<AssemblyName>ClientServerLib</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.ServiceModel.Web" />
<Reference Include="System.Web.Services" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CClient.cs" />
<Compile Include="CConnection.cs" />
<Compile Include="CDiscover.cs" />
<Compile Include="CServer.cs" />
<Compile Include="CWebservice.cs" />
<Compile Include="DataStructs.cs" />
<Compile Include="DeffieHellman\BigInt.cs" />
<Compile Include="DeffieHellman\DeffieHellman.cs" />
<Compile Include="DeffieHellman\StrongNumberProvider.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Structs.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
-->
</Project>