LetsEncrypt your Laravel 5 Application on IIS
The LetsEncrypt service is now publicly available!
You can use the official client only on Linux, but The Lone Coder made a Windows version available on GitHub, the LetsEncrypt-Win-Simple commandline application.
That does its' job perfectly and fast, in only a few seconds the magic is done.

It works by making a Challenge file for the Authorization to a publicly available location on your site (and removing it afterwards).
This file will be written to \.well-known\acme-challenge\[Authorization-hash] under the chosen websites' root.

But by default this location is not available due to the rewriting rule that Laravel uses.
So you need to add one rewrite rule Before that, the order matters so make sure this rule is first in line.

You can use the IIS management console to add one blank url-rewrite rule which uses Wildcards for matching the pattern .well-known/acme-challenge/* and provide "None" under Action, and check Stop processing of subsequen rules.

In the web.config your new rule will look like this
<rewrite>
	<rules>
		<rule name="LetsEncrypt" patternSyntax="Wildcard" stopProcessing="true">
			<match url=".well-known/acme-challenge/*" />
			<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
			<action type="None" />
		</rule>
		<rule name="Laravel 5">
			...
		</rule>
	</rules>
</rewrite>

Something that could come up while running the LetsEncrypt-Win-Simple application when the Authorization fails is how extensionless files are handled.
The steps to fix this are provided in the error details by the application, like this:
This could be caused by IIS not being setup to handle extensionless static
files. Here's how to fix that:
1. In IIS manager goto Site/Server->Handler Mappings->View Ordered List
2. Move the StaticFile mapping above the ExtensionlessUrlHandler mappings.
(like this http://i.stack.imgur.com/nkvrL.png)

You can check these settings before hand to make sure you have an even better experience Securing all your sites.

php , iis , laravel , security , letsencrypt
Niels posted this in 06-12-2015 @ 18:00
Laravel 5 and Lumen 5 running on IIS
Getting Laravel 5 (or Lumen 5 for that matter) running on any IIS server since v6 (Windows Server 2003) is almost too easy.
There are two things that need to be configured for it to work.
- You need to make sure index.php is in the default document list, I would recommend doing this on Server-level to make managing the IIS simpler.
- And make one URL Rewrite rule to point ^.*$ to index.php/{R:0}

You can use the IIS management GUI to add one blank url-rewrite rule which matches the regex pattern ^.*$ with the conditions that it is Not a file and Not a folder, and use the match {R:0} to be appended to index.php/
<?xml version="1.0" encoding="UTF-8"?> 
<configuration>
	<system.webServer>
		<defaultDocument>
			<files>
				<clear />
				<add value="index.php" />
			</files>
		</defaultDocument>
		<rewrite>
			<rules>
				<rule name="Laravel 5">
					<match url="^.*$" ignoreCase="false" />
					<conditions>
						<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
						<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
					</conditions>
					<action type="Rewrite" url="index.php/{R:0}" />
				</rule>
			</rules>
		</rewrite>
	</system.webServer>
</configuration>
php , iis , laravel
Niels posted this in 18-08-2015 @ 23:55
SimpleXML_append
So far the best function to append an xml element from another SimpleXML object.
/***	SimpleXML Class extension
	to easily append an XML as a child to an existing node
***/
function simplexml_append(SimpleXMLElement $to, SimpleXMLElement $from) {
	$toDom = dom_import_simplexml($to);
	$fromDom = dom_import_simplexml($from);
	$toDom->appendChild($toDom->ownerDocument->importNode($fromDom, true));
}
PHP , simplexml
Niels posted this in 11-03-2013 @ 23:05
Generate UUID's with PHP
I found this very useful, fast and complete class to generate UUID's.
By Marius Karthaus
class uuid { 
    /** 
     * This class enables you to get real uuids using the OSSP library. 
     * Note you need php-uuid installed. 
     * On my system 1000 UUIDs are created in 0.0064 seconds. 
     * 
     * @author Marius Karthaus 
     * 
     */ 
    
    protected $uuidobject; 
    
    /** 
     * On long running deamons i've seen a lost resource. This checks the resource and creates it if needed. 
     * 
     */ 
    protected function create() { 
        if (! is_resource ( $this->uuidobject )) { 
            uuid_create ( &$this->uuidobject ); 
        } 
    } 
    
    /** 
     * Return a type 1 (MAC address and time based) uuid 
     * 
     * @return String 
     */ 
    public function v1() { 
        $this->create (); 
        uuid_make ( $this->uuidobject, UUID_MAKE_V1 ); 
        uuid_export ( $this->uuidobject, UUID_FMT_STR, &$uuidstring ); 
        return trim ( $uuidstring ); 
    } 
    
    /** 
     * Return a type 4 (random) uuid 
     * 
     * @return String 
     */ 
    public function v4() { 
        $this->create (); 
        uuid_make ( $this->uuidobject, UUID_MAKE_V4 ); 
        uuid_export ( $this->uuidobject, UUID_FMT_STR, &$uuidstring ); 
        return trim ( $uuidstring ); 
    } 
    
    /** 
     * Return a type 5 (SHA-1 hash) uuid 
     * 
     * @return String 
     */ 
    public function v5() { 
        $this->create (); 
        uuid_make ( $this->uuidobject, UUID_MAKE_V5 ); 
        uuid_export ( $this->uuidobject, UUID_FMT_STR, &$uuidstring ); 
        return trim ( $uuidstring ); 
    } 
} 
You need php-uuid installed, which might cause you to not be able to use this class in some cases.
So here is another v4 UUID generator function I found by Andrew Moore.
function create_uuid() {
	return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
		// 32 bits for "time_low"
		mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
		
		// 16 bits for "time_mid"
		mt_rand( 0, 0xffff ),
		
		// 16 bits for "time_hi_and_version",
		// four most significant bits holds version number 4
		mt_rand( 0, 0x0fff ) | 0x4000,
		
		// 16 bits, 8 bits for "clk_seq_hi_res",
		// 8 bits for "clk_seq_low",
		// two most significant bits holds zero and one for variant DCE1.1
		mt_rand( 0, 0x3fff ) | 0x8000,
		
		// 48 bits for "node"
		mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
	);
}
PHP , UUID
Niels posted this in 23-10-2012 @ 23:05
Excel manipulation through Powershell
Everybody is able to provide workbooks full of data, and somebody has got to process that data.
We all know who Somebody is ..

To get started we need to get a Sheet open from the Workbook.
$xl = new-object -com Excel.Application
$xl.visible = $false
$Workbook = $xl.Workbooks.open("c:\excel.xslx")
$ws = $Workbook.Worksheets.item("sheet 1")
$ws.Activate()
You can set visible to $true, but i personally don't like it.

If you are going to loop through rows you need to set the start end rows.
Get the last row in the sheet like this
($ws.usedRange).Rows.Count
And a function to Get and to Set the Value of a cell will come in handy one day.
function getCellValue{
	param([int]$Row
		,[int]$Column
		,[Object]$Sheet)
	
	return $Sheet.Cells.Item($Row,$column).Value()
}

function setCellValue{
	param([int]$Row
		,[int]$Column
		,[Object]$Sheet
		,$Value)
	
	return $Sheet.Cells.Item($Row,$column) = $Value
}
Closing the application after you are done with Excel is not alwyas too subtle.
$wb.Close($false) # close source workbook without saving
$xl.Quit()
That should have done the trick, but often it doesn`t do so.

Close the process by forcing it, just make sure you set a variable with the current time at the start of the script.
$scriptStart = (Get-Date)
#
# script executing part
#
$xlProcess = Get-Process -Name "*excel*" |?{	$scriptStart -gt $_.StartTime	}
if($xlProcess){
	$xlProcess |%{  Stop-Process -Id $_.Id -Force   }
}
Powershell , Excel , rows , rowcount , cellvalue
Niels posted this in 22-10-2012 @ 23:45
No Invoke-Sqlcmd workaround in Powershell
Invoke-Sqlcmd is a SQL Server cmdlet which might not be available on the system that on which your script will run.
With the following function you can execute any query against a server without the Invoke-Sqlcmd cmdlet installed on the device.
function Invoke-Query{
	param([string]$Server
		,[string]$Query
		,[string]$Database
		,[int]$Timeout = 20)
	$return = $null
	$conn = New-Object System.Data.SqlClient.SqlConnection
	if (!$conn){
		Throw "SqlConnection could not be created!"
		return
	}
	
	$conn.ConnectionString = "Server = $($server); Database = $($Database); Integrated Security = True"
	$conn.Open()
	if ($conn.State -eq 1){
		$cmd = New-Object System.Data.SqlClient.SqlCommand $Query, $conn
		$cmd.CommandTimeout = $Timeout
		$data = New-Object System.Data.SqlClient.SqlDataAdapter
		$ds = New-Object System.Data.DataSet
		$data.SelectCommand = $cmd
		$data.Fill($ds) | Out-Null
		
		$return = $ds.Tables[0]
		
		$ds.Dispose()
		$data.Dispose()
		$cmd.Dispose()
		$conn.Close()
	}

	return $return
}
Set CommandTimeout to 0 for infinite.

Powershell , SQL , Invoke/SQL , Timeout
Niels posted this in 22-10-2012 @ 23:05
mSata to 1.8" Micro Sata
Today I found the adapter that i was looking for, since i bought a Crucial m4 256GB mSata SSD foolishly assuming mSata equals Micro-Sata.
Obviously it does not, an adapter was needed, but the internet choose to not provide much choice in 50mm mSata to 1.8" MicroSata adapters.

The SSD is to replace the 120GB HDD that came with my Samsung X360 ultrabook which needed an upgrade after a while.

Because i spent quite some time looking up this adapter I hope to help someone who is looking for the same.
This is the one : Addonics 1.8" mSATA adapter

mSata , Micro-Sata , 1.8" , SSD , adapter , converter , ultrabook
Niels posted this in 16-08-2012 @ 13:05
HTTP-Authentication through powershell
I came across a project where i had to parse an html page that was accesable only through a webserver that requires authentication.
Using HTTP-Authentication is surprisingly easy with powershell :
$httpCred = New-Object net.NetworkCredential
$httpCred.UserName = "superuser"
$httpCred.Password = "superpass"

$http = New-Object net.WebClient
$http.Credentials = $httpCred

$response = $http.DownloadString("http://secure.domain.tld")
powershell , http , authentication , http-auth , security
Niels posted this in 14-08-2012 @ 23:55
Girlfriend promotion mode
www.katrienligt.nl

withneweyes.katrienligt.nl





Niels posted this in 13-10-2011 @ 01:03
Currently working on getting the hosting page up
After that there are some scripts i want to share on the project page, and some games i want to make.

And all must get phpified for to ensure this website will be used by me.

Soon Gadget!! Soooonnnnn ....
Niels posted this in 13-10-2011 @ 01:03
Any information goes here





http://findicons.com !

Niels posted this in 13-10-2011 @ 01:03