PHP Access Control List

A quick little Access Control List (ACL) snippet I made for PHP/HTML. Enjoy!

$acl = array(
// Populate with IP/Subnet Mask pairs.
// Any zero bit in the subnet mask acts as a wildcard in the IP address check.

$acl_allow = false;
for ($i = 0; $i < count($acl); $i++) {
$ip2chk = (ip2long($acl[$i][0]) & ip2long($acl[$i][1]));

if ((ip2long($_SERVER['REMOTE_ADDR']) & $ip2chk) == $ip2chk) {

if ($acl_allow) {
// Put all test stuff here!! Only visible to ACL.
} else {
echo "<a href='' target='_blank'>This page intentionally left blank.</a>";


Linux - find what is preventing you from unmounting a drive

Disclaimer: I've had this problem for probably four months, ever since I started running Plex Media Server on my headless linux machine at home, whilst storing all my actual media on a nice external portable drive. Usually I just yank it, but then I watch the drive letters run themselves up obscenely high before I need to reboot.
So you've gone through the process of mounting your drive in Linux:
> sudo fdisk -l
Device Boot = /dev/sdb1 (and a bunch of other technical information regarding drive size, id, and such)

> sudo mount -t ntfs-3g /dev/sdb1 /media/TOSHIBA

You run a bunch of stuff, get it all working, then find you need to take the drive to work the next day, so you try to unmount it.

 > sudo umount /media/TOSHIBA
umount: /media/TOSHIBA: device is busy.
(In some cases useful info about processes that use the device is found by lsof(8) or fuser(1))

Well, being a Windows guy at heart, and not really understanding why everything here needs to be so technical, this message never told me ANYTHING. I would try typing just plain "lsof" or "lsof(8)" or "fuser(1)" with no useful results.

Then I asked a friend.

"lsof | grep <stuff>," he said.

"Like, <stuff> would be the /dev/sdb1?"


So I tried it:
> sudo lsof | grep /dev/sdb1
mount.ntf     2096      root     3u     BLK    8,33 0x1d1ba997e00       2897182   /dev/sdb1

"Oh," he said. "Try the mount path. /dev/sdb1 is the device which is mounted somewhere else."

> sudo lsof | grep /media/TOSHIBA

"Nothing," I said. "Just a blank line."

"Looks like no program has any file open on it?"

"Let me try again."

bash     2068     daniel    cwd    DIR    8,33     8192    17459  /media/TOSHIBA
grep     2254     root       cwd    DIR    8,33     8192     17459  /media/TOSHIBA
lsof     2255     root       cwd    DIR    8,33     8192     17459  /media/TOSHIBA

"Ahh...It may have been because I was still cd'd into it."


So lessons learned:
  • grep, no matter how weird and complicated it looks with all those pipes and stuff, is still VERY useful. 
  • lsof is the command of choice for figuring this out. 
  • Use the mount point rather than the drive itself when searcing the lsof output text. 
  • Even just navigating into a drive will lock it from being unmounted - it's not like in Windows where if you "Safely Remove Hardware" or yank the USB cable, the computer conveniently closes the explorer window for you.

Pentax Camera Accessories - The Expensive Joy of Brand Loyalty

Last April, after months of researching and stressing over whether or not I should (or could), I finally bit the bullet and spent $1300 on a nice 24Mpx Pentax K-3 DSLR. This is a super camera that I really have been enjoying and getting some high quality photos with. Most of all I like the standard ability you get with any DSLR of a fully manual photograph, something you just don't get with a snapshot like my old Fujifilm A820. Sure the good snapshot cameras come with that little pseudo-manual exposure mode where you set one or two preferred manual settings and the rest remain automatic, but a nice DSLR will give you the ability to adjust everything about both exposure AND focus.

The one biggest drawback I've discovered with expensive DSLR cameras are the equally-as-expensive accessories. Sure, I can justify paying $400+ for a nicer lens, because I understand the need for accurately-ground and polished glass, spherical aberration, and the like to produce a decent to high-quality photo.

However, the minor accessories themselves are atrociously overpriced, especially for the Pentax brand.

To date, 8 months later, in addition to the two Wasabi-brand batteries+charger I felt were a good idea to have ($25), I am now a semi-proud owner of a second brand-name focusing screen ($45) (I didn't realize the camera already came with the exact one I ordered separately), a brand-name battery-grip ($125), a brand-name electronic cable release ($40), a brand-name flash-mountable GPS unit ($200), a brand-name K-mount to 42mm threaded adapter ($50), a 62mm Hoya circular polarizer ($70), a 62mm Hoya skylight filter ($35), and a 62mm Tiffen 0.3 neutral density filter ($26). Doing some quick calculator math because I'm too lazy to spend two minutes doing it in my head this brings my total cost for accessories that I've purchased in the last eight months to $616, which is an additional 60% of the cost of the camera itself (which came with a stock lens)!

Now the one thing that I don't have for this thing, which I probably ought to have if I want to do any of the long-term stuff I've already pushed my batteries to the limit with is the AC adapter. Except for one thing. The OEM AC adapter for the K-3 camera is a mindblowing $100.

Not only does the AC adapter use a somewhat-obscure Japanese connector - a Hirose H10485, but the voltage requirements (8.3V) for this camera are EXACTLY the same as that for the Pentax K10D for which a DIYer created a decent tutorial for a number of years ago, as well that of the K-5 which an eBay seller offered power supplies for a mere $16.

I've examined the K-3's AC connector and it looks exactly the same as previous models. Why then, for this model, did Pentax decide to create a completely new part number for yet another 'official' AC adapter and charge $100 for it when I can get what LOOKS like an equivalent for $16? Actually the only two questions regarding this that I have are:
  • Are the pinouts the same as on previous models (+8.3V on the connector's keyed pin, ground on the opposite end and unconnected in the middle)?
  • Is the current rating for the K-3's adapter for some reason higher than the 1.5A spec'd for the K10D? Why can't we just beef up this power supply to handle 2A? Or 2.5A?
The only reason I could see to paying the full $100 for a simple 8.3V DC power supply is that people don't want to risk plugging something whose material cost is less than $16 sold by a third party into their $1000+ camera when the $100 OEM version is guaranteed to work. Oh, and it keeps any warranty valid.

By the way, the cable release, which connects to the camera via a simple 2.5mm stereo headphone jack is the one of the simplest of DPST circuits:

Expired Domains - A headache, but a learning experience!

Hey all! It's been a few months, I know. But I wanted to share an experience I had with my recent domain name headache.

So as you may or may not know, I've owned since May 2013. I purchased it via Google Apps which in turn set my registrar to eNom. Both are useful services and work reasonably well. I was attracted mostly to the (back in 2013) $10/year with free ID protection deal that Google Apps offered. Since then they've gone up to $12/year, but that's not really an issue.

The process was relatively simple. Reserve your name, run through Google's checkout system, enter your card number and registration info and within seconds you have it!

The confusing thing is realizing that Google Apps doesn't just give you the domain. It gives you a portal for your employees or professional team to collaborate, brings a huge suite of tools to your disposal including a Gmail account that ties directly into your new domain name, a Google Drive account for online storage, user permissions and a ton of other possibilities. None of which I actually needed.

However, a few months later I also purchased another domain for a MUSH game I actively host. I thought, this is going to be just as easy. I'll go to Google Apps and buy the domain from them again. Well, for some reason the process hiccuped. I was not able to get the email (mx) service working. I don't know why, and frankly I don't care. But I have a feeling it had to do with the fact that Google Apps for Business had this clause that the first account is free and any others tied to your main Google Account will cost you so much per year ($50 I think) charged on a monthly basis. Nowadays, I think it's outright $50/year which I'll explain my experiences with later.

So this last April I started getting the feeling that, you know, is not really utilizing any of my Google Apps for Business features. eNom seems to be the most useful tool, as it can tie the domain to a Google Sites account I made just for it, plus this blog on the subdomain, and then my personal website I host from my computer at home. eNom is doing all the work! Why don't I just try to transfer the domain to a full-out eNom account that I create myself? Why should I be locked into Google Apps with a bunch of features I'm not using?

Not really knowing anything about the DNS system and the little marketing loopholes that registrars like eNom put you through, I decided, well I'll just create a user account on eNom, then DELETE my Google Apps for Business account (which should release the domain to the public, right), and then re-purchase it on eNom.


Google Apps still hung onto that domain. It would not let go! And now that my Apps account was dead, I couldn't log in to retreive it. I started looking into my second domain and found out there was a transfer process I could go through to give eNom permission to pull the domain away from Google (which, by the way, I did and it worked for THAT one).

But I was stuck! was just plain locked down. Sure I could still get into my eNom access control and edit the host records and point subdomains to various locations. Everything I cared about still worked, but I could not actually prove I was the owner of the domain and transfer it over.

So I made up my mind. Well, the only thing I can do is let it expire. It'll go back to unregistered and  I can re-purchase it. This turned out to be the biggest headache I've had with the DNS system to date.

eNom (and all big-name registrars I've come to realize) has this little game. When a domain expires from the user not pay the annual renewal fee to keep it in their account, it immediately goes into some form of public auction. eNom (or one of its partners) takes control of the domain and points it to one of those annoying advertizing websites that says, "This domain up for public auction! Click here to bid on it! Or you can click here for dancing uniforms, or here for cheap airline tickets, or here for luxury backyard swimming pools!"

I followed the links through. Turns out to recover a domain that's gone from "registered to an actual person" to "public auction" you have to pay a minimum of $60, but the entire public can start bidding on it and raise the price to some crazy amount! I was not going to go through this process and give my payment information to yet another service (eNom doesn't handle the actual bidding. It passes that off to a partner company or something).

I'd wait it out. 

For 30 whole days.

Or maybe I can recover it if I re-create my Google Apps account. Oh wait. I have to pay a $50 annual fee to belong to Google Apps now? It's not a free for the first domain deal anymore? Okay..fine. Paid the $50, to be charged on a $4.17 per month basis, got a transfer code from Google, and sent the transfer request to eNom (they SAID I was in charge of again).

Your Tranfer Request is Denied.

This amount of mixed messages tells me, I need to just give up on Google Apps. This is why I'm my own web developer. So I don't have to rely on third parties to host my site and its development tools!

I'll just...delete that Google Apps account. Wait I have to pay the remaining balance of that $50, even if I've only had the account for 30 minutes and don't want it anymore? Yes, I did read the Terms of Service for both services. Yes, it was the usual legal jungle of flowery language to make sure that in no way, shape, or form would anything actually be THEIR fault. Even if their system is the most confusing thing I've ever dealt with online.

Well, granted, the domain would have sat there for 30 days anyway, being bid upon. But what I did learn (again the hard way) is that if nobody does bids on it after the 30 day public auction period, it goes into something called "recovery mode" which, from what I read, allows the ORIGINAL owner to buy it back at an inflated price. And the host records are FINALLY deleted, which means visiting took me to the standard browser 404 page instead of a fore-mentioned advertising garbage. At least it's making progress!!

This is a personal domain. I don't NEED it. Yeah, I've changed all my forum signatures and online account "Website" fields to point to and all, but I am not suffering because I can't access this domain. Besides that, guess what! Recovery Mode is a moot point. I deleted that account. I can't get it back. I already tried that. There is no way for me to recover it, and I'm not going to risk paying ANOTHER $60+ to re-create the Google Apps account and attempt recovery which may or may not (probably will not) work. So I have to wait ANOTHER 30 days for it to drop out of recovery mode.

The umpteenth headache: after recovery mode it didn't get deleted. It went into Pending Delete status. Thank God this, for eNom anyway, is only five days. But I have no idea why they have Pending Delete. At the rate they originally grabbed that domain away from me after it had expired back in May and rerouted it to their advertising site during public auction, I have high doubts that they "simply didn't have enough server speed to delete it right away, and needed to put it into a five-day waiting line for the DNS guillotine."

But I had to just shrug my shoulders, say, "oh well," and wait it out.

Then last night I checked. I went to the eNom front page and typed into the "Register  a New Domain" box like I'd been doing for the past three months and...

"This Domain is Available! Click here to purchase now."


After a reasonably easy checkout process, I now have back in my possession, under one single account with a company that has been a leading registrar for decades. And I can even point it back to my old Google accounts like Blogger and Sites!

Welcome back PPSStudios!

Integer Math - Converting to Binary

Yes, I realize this is a beginning digital logic concept, but I need somewhere to write this so I don't forget again.

Unsigned Integer to Binary and Back

You are given a number: 25382
Take the modulo of it to test if it is even or odd: 25382 % 2 = 0 <= ???? ???? ???? ???0
Divide by two to get a new integer: 25382 / 2 = 12691
Take the modulo of the new number to test if it is even or odd: 12691 % 2 = 1 <= ???? ???? ???? ??10
Divide by two to get a new integer: 12691 / 2 = 6345
Take the modulo of the new number to test if it is even or odd: 6345 % 2 = 1 <= ???? ???? ???? ?110
Divide by two to get a new integer: 6345 / 2 = 3172
Take the modulo of the new number to test if it is even or odd: 3172 % 2 = 0 <= ???? ???? ???? 0110
Divide by two to get a new integer: 3172 / 2 = 1586
Take the modulo of the new number to test if it is even or odd: 1586 % 2 = 0 <= ???? ???? ???0 0110
Divide by two to get a new integer: 1586 / 2 = 793
Take the modulo of the new number to test if it is even or odd: 793 % 2 = 1 <= ???? ???? ??10 0110
Divide by two to get a new integer: 793 / 2 = 396
Take the modulo of the new number to test if it is even or odd: 396 % 2 = 0 <= ???? ???? ?010 0110
Divide by two to get a new integer: 396 / 2 = 198
Take the modulo of the new number to test if it is even or odd: 198 % 2 = 0 <= ???? ???? 0010 0110
Divide by two to get a new integer: 198 / 2 = 99
Take the modulo of the new number to test if it is even or odd: 99 % 2 = 1 <= ???? ???1 0010 0110
Divide by two to get a new integer: 99 / 2 = 49
Take the modulo of the new number to test if it is even or odd: 49 % 2 = 1 <= ???? ??11 0010 0110
Divide by two to get a new integer: 49 / 2 = 24
Take the modulo of the new number to test if it is even or odd: 24 % 2 = 0 <= ???? ?011 0010 0110
Divide by two to get a new integer: 24 / 2 = 12
Take the modulo of the new number to test if it is even or odd: 12 % 2 = 0 <= ???? 0011 0010 0110
Divide by two to get a new integer: 12 / 2 = 6
Take the modulo of the new number to test if it is even or odd: 6 % 2 = 0 <= ???0 0011 0010 0110
Divide by two to get a new integer: 6 / 2 = 3
Take the modulo of the new number to test if it is even or odd: 3 % 2 = 1 <= ??10 0011 0010 0110
Divide by two to get a new integer: 3 / 2 = 1
Take the modulo of the new number to test if it is even or odd: 1 % 2 = 1 <= ?110 0011 0010 0110
Divide by two to get a new integer: 1 / 2 = 0
Take the modulo of the new number to test if it is even or odd: 0 % 2 = 0 <= 0110 0011 0010 0110

25382 = 0110 0011 0010 0110

With a bit of programming, this can be highly consolidated:

int decVal = 25382;
char binVal[16];
printf("Integer: = Binary: ");
for (int i = 0; i < 16; i++) {
binVal[i] = (decVal % 2);
decVal /= 2;
printf("%d", binVal[i]);

Note however that the binary value's lowest-order bit is expressed on the right-hand side whereas an array's lowest-order element is expressed on the left-hand side. This will result in the direct output of the array being displayed as the reverse of the binary string it represents.

binInt = 0110001100100110;
= B15 B14 B13 ... B2 B1 B0;

binVal[16] = {0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0};
= {I0, I1, I2, ... , I13, I14, I15};

Thus, we will need to parse through the array in reverse order when using its values to either print to the standard output or convert back into the regular integer:

// binVal is calculated from for loop above.
// binVal[16] = {0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0};
int decVal;
printf("Binary String: ");
for (int i = 0; i < 16; i++) {
if (binVal[16-(i+1)] == 1) {
decVal += pow(2,i);
printf(" = Integer: %d",decVal);