Converting ASP Classic to PHP5

I posted a while ago that I added a page with ASP Classic to show your current IP. This worked because the site was being hosted in IIS with ASP.NET, ASP Classic, and PHP all enabled but I have now moved to a PHP only host and wanted to quickly get the IP lookup working again (I use it quite often).

I can potter around with PHP and would be able to figure it out but I did a quick search to find a converter and discovered this great online tool which did the work for me!

Here’s the original code.

<%@Language="VBScript"%>
<%
If Request.QueryString("debug") = "1" Then
  Response.Write("<pre>")
  For Each x in Request.ServerVariables
    Response.Write(X & " = " & Request.ServerVariables(X) & vbCrLf)
  Next
  Response.Write("</pre>")
Else
  If Len(Request.ServerVariables("HTTP_X_FORWARDED_FOR")) = 0 Then
    Response.Write Request.ServerVariables("REMOTE_ADDR")
  Else
    Response.Write Request.ServerVariables("HTTP_X_FORWARDED_FOR")
  End If
End If
%>

 

Here’s the converted result.

<? 
if ($_GET["debug"] == "1") {
  echo "<pre>";
  foreach ($_SERVER as $x) {
    echo $X." = ".$_SERVER[$X]."\r\n";
  }
  echo "</pre>";
}
else {
  if (strlen($_SERVER["HTTP_X_FORWARDED_FOR"]) == 0) {
    echo $_SERVER["REMOTE_ADDR"];
  }
  else {
    echo $_SERVER["HTTP_X_FORWARDED_FOR"];
  }
}
?>

 

It works exactly the same as before but this time it’s PHP. You can try it with the same link: What is my IP?

SQ10 Mini DV Camera from GearBest

It’s a nice little camera seemingly perfect to attach to your clothes while biking or whatever you want to record (though not waterproof). But the instructions are not in English!

Here’s some things I’ve found while trying to decipher the broken translation:

Getting Files / Using Webcam

Attaching the camera via the USB cable to your PC while the camera is OFF will let you manage the contents of the MicroSD card. Turning the camera ON will let you use it as a webcam. Transfer seemed to be quite slow over the USB cable reaching a maximum of 5.8MB/s.

Setting the Time

To set the time you need to create a file called TIMEREST.txt in the root of the drive with the new time then unplug from the PC and turn the camera on. The file must have the contents of the timestamp it should use like this:

20171118100800 Y

This is the year, month, day, hour, minute, second, SPACE, Y to show the timestamp or N to hide it. After doing this, Windows will tell you the drive needs to be repaired. This is fine and you can let Windows sort it out. It seems to be caused by the camera failing to delete the TIMEREST.txt file.

Recording Audio & Video at 720p

Hold the power button for two seconds and release. The solid-blue internal light will be visible from the hole where the SD card is. Press and release the power button once and that blue light will flash 3 times then go off. The device is now recording 5 minute long movies onto the card at 30fps in 1280×720 resolution with 512kbps audio at 32kHz.

Recording Audio & Video at 1080p

Hold the power button for two seconds and release. The solid-blue internal light will be visible from the hole where the SD card is. Press and release the mode button once. The blue and red lights will now be visible from the SD card slot. Press and release the power button once more to activate recording, the lights will flash three times then go off. The device is now recording 5 minute long movies onto the card at 30fps in 1920×1080 resolution with 512kbps audio at 32kHz.

Enable/Disable Night Vision

Hold the power button for two seconds and release. The solid-blue internal light will be visible from the whole where the SD card is. Now hold the power button down for two seconds and the red light will flash twice to indicate the infra red lamp is now switched on. Hold the power button down again for two seconds to turn off the lamp, the red light will flash twice to indicate success.

After turning the infra red lamp on for night vision you can then proceed to begin recording as explained above (either press the power button once to record 720p or press mode then power for 1080p).

Stop a Recording & Turn Off Camera

Press and release the power button once while recording. The lights will come on solidly. This means it’s stopped and you can then turn off the device by holding the power button down for 9 seconds.

OpenKeychain and Your E-Mail Identity

A friend introduced me to the OpenKeychain app and explained just how easy it is too set up a key to encrypt and verify your messages.

First, install OpenKeychain from the Google Play store.

Go to Manage My Keys from the options button at the top right of the application.

Now choose Create My Key.

Follow the wizard through to the next few pages which ask for your email address, to specify a password for your key, and finally to actually create and upload it to the public key servers.

Be aware: Your email address will be available for everyone in the world to see if you synchronize with the Internet.

Now that you have your key you can share the public part with your contacts so they can email you securely!

I’m using K9 Mail to use my key with my email which is easy to setup, you simply go into your account settings then cryptography and tap “OpenPGP App” to select OpenKeychain.

Make sure to back up your key to your PC/cloud storage and never share the private key or your passwords!

Monzo Saves the Day!

I had an odd experience at a coffee stall where the barista charged my card then told me it failed and did it again. Both times I had to input my pin but he only gave me the receipt of the final transaction and kept the supposed failed one for himself.

This is dodgey behavior so I checked the Monzo app while I stood next to the cart drinking my coffee and sure enough he had double charged.

Less than 5 minutes later showing him & his manager the app I had my refund! All was handled very politely and swiftly and I believe it was an honest mistake but this proves to me the values of using my Monzo card and app.

If I had used a different card I’d never have known the problem had happened and been down £10!

Which .NET Version is Installed?

I’ve found myself needing to know which version(s) of the .NET are installed on a server and the easiest way I’ve discovered is to browse to the directory and check the version on mscor*.dll files.

Browse to this directory which is the same on all versions of Windows currently in use.

C:\Windows\Microsoft.NET\

Go into the Framework or Framework64 directories and you’ll see the overview of versions installed. For example, you might have a directory called v4.0.30319 and you would be forgiven for thinking that is the version installed. But what if you know you have .NET 4.5 or even 4.7 installed?

You can go into the directory and find the DLLs whose name begins mscor then right-click -> Properties -> Details tab and see the file version. This matches the version of .NET.

Ubuntu Static IP

Linux is a varied operating system with myriad ways of accomplishing a single task. Here is the cleanest, quickest, way I use to set a static IP for Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-96-generic x86_64).

sudo nano /etc/network/interfaces

After entering your password you will be presented with a nano session showing the current configuration of your interfaces. If this is a fresh install you’ll see something like this.

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp0s3
iface enp0s3 inet dhcp

Note! My interface is enp0s3 but yours may have a different name.

Comment out the current configuration for the interface you want to set to a static IP and edit in the new information.

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
#auto enp0s3
#iface enp0s3 inet dhcp
auto enp0s3
iface enp0s3 inet static
 address 10.10.10.20
 netmask 255.255.255.0
 gateway 10.10.10.3
 network 10.10.10.0
 dns-nameservers 10.10.10.3

In this example I have set it to:

auto enp0s3 Automatically bring the interface online
iface enp0s3 inet static Told the interface it will use a static IP
address 10.10.10.20 Set the static IP I want this VM to use
netmask 255.255.255.0 Set the subnet mask
gateway 10.10.10.3 Set the IP of the gateway to other networks
network 10.10.10.0 Set the network address
dns-nameservers 10.10.10.3 Set the DNS server to the router’s IP

The simplest way to test the configuration is to reboot the machine but you can turn the interface off and back on again if you know the commands for your specific version of Linux.

WordPress

I decided to move to WordPress because I wasn’t getting enough time to develop any new features for the blog software I made. Also, WordPress is a full-featured system that has a slick interface and is nice to use.

I installed it on a fresh install of Server 2012 R2 with IIS 8.5 using the Microsoft Web Platform which helpfully popped up when I opened IIS. This took care of installing PHP, MySQL, and WordPress itself by turning the whole process into little more than a wizard.

However… I later decided to move the installation to a different folder so had to change WordPress Address and Site Address under Settings within WordPress then move the files and reset the permissions.

IMPORTANT: Make sure IIS IUSRS has Read & Execute on all the WordPress folders and Write & Modify pm wp-content. You should also add IIS AppPool/ApplicationPoolName with the same permissions to each folder. Check your website’s application pool name and fill in the “ApplicationPoolName” part.

I then discovered I had to edit the C:\Program Files (x86)PHP\v5.6\php.ini file and change upload_tmp_dir to a directory where IIS IUSRS had Read, Write, Modify, and Execute. This enabled editing of images which is needed if you crop images to use as part of the theme.

One plugin I find extremely useful is Enlighter which does all sorts of syntax highlighting for code.

Let’s Encrypt Free SSL on Windows!

Letsencrypt had been around for a while now and is supported by very big names in tech such as Facebook, Mozilla, Cisco, and a lot more. The free service is there to allow anyone to have a secure website which helps the whole web by making sure things like login details are encrypted.

The system had been designed with Linux in mind and some very kind people have offered up Windows variants to make use of it. You can see a full list of recognized bots/programs and websites under the documentation ACME Client Implementations.

I use letsencrypt-win-simple which is a project started by Bryan Livingston which is easy to use and can automatically keep the certificates up to date with a scheduled task.

The main step to remember is adding a mime type on the acme-challenge folder so the verification keys will be served by IIS when the Let’s Encrypt service tried to check your site. Verification will fail without this because IIS will present a 404 error for unknown for types.

. Text/Plain

For example, if your site is located at C:\inetpub\wwwroot you will be guided to create some directories:

C:\inetpub\wwwroot\.well-known\acme-challenge\

NOTE: Windows prevents you from starting a directory with a dot so you can create it through Command Prompt/Powershell with mkdir. There are other ways to fiddle with it but this is the quickest and easiest.

Once that’s done you can run letsencryptwinsimple and get your free certificates! They’ll be saved to:

C:\ProgramData\letsencrypt-win-simple\httpsacme-v01.api.letsencrypt.org

Get Computer Model with WMIC

Windows Management Instrumentation can be a crucial tool in day to day IT tasks. One thing I often use it for is getting the model of a server or PC because it’s quicker to type the query than go to the documentation and open the spreadsheet.

wmic /node:SomePC computersystem get model

Simply run that as an account that has enough privilege to do so and you’ll get the model number of the Windows machine you’re querying. You can get a lot of useful information this way including all the performance stats which could be queried programatically.

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑