Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View ctigeek's full-sized avatar

Steven Swenson ctigeek

View GitHub Profile
@ctigeek
ctigeek / QuartzClustered.config
Created November 28, 2017 21:29
Quartz clustered configuration.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<quartz>
<add key="quartz.scheduler.instanceName" value="test1" />
<add key="quartz.scheduler.instanceId" value="AUTO" />
<add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
<add key="quartz.threadPool.threadCount" value="10" />
@ctigeek
ctigeek / Configure-Https.ps1
Last active September 22, 2017 19:54
Configure self-hosted app for HTTPS
## the cert dns doesn't really matter since it's self-signed.
$certName = "myappname.local"
$cert = New-SelfSignedCertificate -CertStoreLocation Cert:\LocalMachine\My -DnsName $certName
Write-Host "Created self signed cert: $($cert.Thumbprint) "
$guid = [guid]::NewGuid()
$ip = "0.0.0.0:443"
"http add sslcert ipport=$ip certhash=$($cert.Thumbprint) appid={$guid} " | netsh
#### netsh http delete sslcert ipport=$ip
@ctigeek
ctigeek / JsonConverter.cs
Last active September 21, 2017 15:33
TcpAppender for log4net. Also a json converter and example app.config. (I'm using it to write to an instance of logstash.)
/// This code is copywright 2017 by Steven Swenson and released under the MIT open source license.
/// https://opensource.org/licenses/MIT
using System;
using System.IO;
using log4net.Core;
using log4net.Layout.Pattern;
using Newtonsoft.Json;
namespace TestLog4Net
@ctigeek
ctigeek / Enable-DynamicIpThrottling.ps1
Created July 26, 2017 17:57
Enable dynamic IP throttling in IIS.
function Enable-DynamicIpThrottling($webSiteName, [bool] $enabled, [int]$maxRequests, [int]$intervalMilliseconds, [bool] $loggingOnly = $false) {
##https://docs.microsoft.com/en-us/iis/configuration/system.webserver/security/dynamicipsecurity/
Add-Type -Path "$env:SystemRoot\System32\inetsrv\Microsoft.Web.Administration.dll"
$manager = New-Object Microsoft.Web.Administration.ServerManager
$config = $manager.GetApplicationHostConfiguration();
$cpSecConfig = $config.GetSection("system.webServer/security/dynamicIpSecurity", $websiteName)
$cpSecConfig.SetAttributeValue("enableLoggingOnlyMode", $loggingOnly)
$requestRate = $cpSecConfig.ChildElements["denyByRequestRate"]
@ctigeek
ctigeek / Enable-IpSecurityProxyMode.ps1
Created July 26, 2017 16:02
Enable proxy mode in the IP security settings in IIS.
function Enable-IpSecurityProxyMode($websiteName) {
Add-Type -Path "$env:SystemRoot\System32\inetsrv\Microsoft.Web.Administration.dll"
$manager = New-Object Microsoft.Web.Administration.ServerManager
$config = $manager.GetApplicationHostConfiguration();
$cpSecConfig = $config.GetSection("system.webServer/security/ipSecurity", $websiteName)
$cpSecConfig.SetAttributeValue("enableProxyMode",$true)
$manager.CommitChanges();
$manager.Dispose()
@ctigeek
ctigeek / Add-IpToIisBlacklist.ps1
Last active July 26, 2017 14:08
Add an IP address to a black-list for an IIS website.
function Add-IpToIisBlacklist($websiteName, $ip, $subnetMask = $null) {
Add-Type -Path "$env:SystemRoot\System32\inetsrv\Microsoft.Web.Administration.dll"
$manager = New-Object Microsoft.Web.Administration.ServerManager
$config = $manager.GetApplicationHostConfiguration();
$cpSecConfig = $config.GetSection("system.webServer/security/ipSecurity", $websiteName)
$cpSecCollection = $cpSecConfig.GetCollection()
$newAdd = $cpSecCollection.CreateElement("add")
$newAdd["ipAddress"] = $ip
if ($subnetMask) {
@ctigeek
ctigeek / Get-DomainsAltAlias.ps1
Created May 24, 2017 17:48
Get all domains and alias/alternate domains from CP REST API.
function Get-XapiSignature($userAgent, $apiKey, $apiSecret) {
$dateTime = [DateTime]::UtcNow.ToString("yyyyMMddHHmmss");
$dataToSign = [String]::Format("{0}{1}{2}{3}", $apikey, $userAgent, $dateTime, $apiSecret);
$sha1 = [System.Security.Cryptography.SHA1]::Create();
$signedBytes = $sha1.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($dataToSign));
$signature = [System.Convert]::ToBase64String($signedBytes);
$sha1.Dispose()
[String]::Format("{0}:{1}:{2}", $apikey, $dateTime, $signature);
}
@ctigeek
ctigeek / Load-WhoisServers.ps1
Created April 11, 2017 19:32
Load whois servers from @weppos's repo.
if (-not $hostMap) {
$whoisHostMapUrl = "https://raw.githubusercontent.com/weppos/whois/master/data/tld.json"
$raw = Invoke-RestMethod $whoisHostMapUrl
$hostMap = @{}
$raw.psobject.Properties | ?{ $_.Value.host } | Foreach { $hostMap[$_.Name] = $_.Value.host }
}
## $hostMap["com"] will return whois.verisign-grs.com
@ctigeek
ctigeek / MockDatabaseHelper.cs
Last active December 30, 2016 20:41
Helper class for mocking a DbProviderFactory
// I've moved this to a full repo:
// https://github.com/ctigeek/SqlUnitTestHelper
@ctigeek
ctigeek / Periodic.cs
Created December 5, 2016 01:35
Run an Action periodically....
public class Periodic : IDisposable
{
private static readonly object lockObject = new object();
private readonly List<PeriodicEvent> history = new List<PeriodicEvent>();
private readonly Action action;
private readonly Timer timer;
private long id = 0;
public PeriodicEvent LatestEvent { get; private set; }