Category: Web

stuff about web design, development, trends, and tricks

  • pi-hole in a Container

    Man, what a struggle! I’ve been running close to the datacap for most of the year and figured, if I block the ads, and particularly the video ads, I gotta same some data. You can see how I’ve slowly been building out my containerized workload; this should be a snap!

    I found a ton of great resources that were collected into my final Docker Compose file:

    So I gathered snippets of this and that and made a configuration for myself. But when I tried to deploy the Stack, only errors! First was the volumes, totally messed up but reread my page on it and looked at the Wundertech example. The container would start but I couldn’t reach it. I learned that having both MACVLAN and Bridge network would allow Portainer/Docker to talk to the container while giving me the unique IP needed for the domain controller to point towards on Port 53. Then I watched this guy. He mentioned, in passing, how he selected the values for his MACVLAN network.

    Well, in the end, I was trying to be too fancy. When I wrote the subnet description to fit in between my Unifi gateway address on 192.168.1.1 and the majority of my servers on 192.168.1.100+, it worked. This matched the subnet already on eth0 of my docker host. This seems to explain the technical bits of why – https://github.com/moby/libnetwork/blob/master/docs/macvlan.md. When I was trying to use 192.168.60.0/24, it was not routable. There might have been a solution manually adding a route on the gateway, that’s outside of my knowledge now.

    If you look at the github readme in my repo, you can see a diagram of what I made. Once the container was up, could talk to the internet, could talk to the local network, a change to the DC to only use the PiHole was trivial. Last, I added a DNS entry so I can find the webpage for managing it. In the first day, it’s dropped 25-30% of all DNS lookups, mostly known ad and tracking URL. In a few weeks I’ll know if I actually get any data savings…

    The only thing to edit, once this was running, adding a jetpack URL to the white list so I could even get to the editor page in WordPress.

  • Password Generator

    I was playing with this a year ago when I started a new job. The boss said to use two words, a number, and a symbol- this would make a easy to remember password for users, including us! With that in mind, I grabbed a list of 4 and 5 letter words. Put them in an array and built a little something in PowerShell to spit out passwords.

    Then, I thought, why not put this on the web?! With Cloudflare workers, I can put some javascript out there, run it on their servers, fast connections, easy to manage- why not! So I built https://passwords.chinkes.com/. It was a page that pulled the password from a static list. There was some API access and you could chose to have symbols or not, numbers or not, or 6 letter words for a longer password.

    After 9 months, I returned to it and was able to add the slider to allow dynamic password lengths, as well as checkboxes to subtract symbols or numbers from the password.

    I hope you can make a better password with this!

  • PowerShell Regex Matching

    I was working on a project where I needed to understand the naming convention for the servers. Since they had been made by several teams over several years, there was no convention. It was a giant pain in the ass.

    I wrote a function that would accept the server name and then try to parse it out. While there was not a strong standard, there was a few soft standards I could guess at. It took a while to figure out but PowerShell -match returns an array, if you use regex groups. All I needed was a few regex patterns and then I could start to decode these server names!

    The servers were in different data centers, so some had DEN, ’cause they were in Denver data center (see?). But some were in CINC (with four letters, not even keeping three letters) as they were in the Cincinnati data center. The next few characters in the name gave some hint as to purpose; WEB, or SQL or something more obscure like OTOPS, again with varying number of letters. Last, the server could have a number, 01, 02, etc. or a letter, A, B, C if it was part of a set. But then we had a few that were part of 01 set but there were several of those so you got 01A, 01B, 01C.

    There are several great regex tools on-line to show you how your pattern is working and what the rules are. For the server names I wound up with:

    (?<datacenter>den|cinc)(?<role>\w+)(?<countNum>\d{2})(?<countLet>[a-d])

    PowerShell isn’t case sensitive, so we’ll ignore those differences. Also, I’m using named groups, those are defined with ?<datacenter> where the name of the group is data center. Then everything that matches within the ( ) for that group winds up in $Matches.datacenter. $Matches is a built-in variable and can be referenced by index number if not using named groups.

    switch -regex ($serverName){
      "(?<datacenter>den|cinc)(?<role>\w+)(?<countNum>\d{2})(?<countLet>[a-f])" {
        $datacenter = $Matches.datacenter
        $role       = $Matches.role
        $countNum   = $Matches.countNum
        $countLet   = $Matches.countLet
        break
      }
      "(?<datacenter>den|cinc)(?<role>\w+)(?<countNum>\d{2})" {
        $datacenter = $Matches.datacenter
        $role       = $Matches.role
        $countNum   = $Matches.countNum
        $countLet   = "None"
        break
      }
    }

    This is what I wound up with; the switch takes the name of the server passed to my function, checks it against a few different regex patterns, and where there is a match for all groups of the pattern, executes the code block.

    In the code block I’m pulling the named group and assigning to my values to spit out at the end of the function. Additionally, you see the second pattern is for when there are only numbers in the name. In the running code I had a few more patterns to match all the options used when creating servers. Note the break in the script block, that’s because the switch will keep matching patterns all the way down the statement! The second pattern will give me “None” for my count letter value and not an error or something unexpected.

    I didn’t figure all this out on my own, Kevin’s article on Regex showed me the way. You can get the details on named groups here.