Monday, March 14, 2022

Sitecore Developer Blog Entry #0x01

My day job involves working for a company that uses Sitecore 9 for a CMS. This is used to run a news and continuing education site for medical professionals.

Today I'm working on three tasks. One is for the publish pipeline, when a user tries to access a page for an old item that we usually redirect to a third party site. If the Sitecore item is missing a piece of information in a field used to form the redirect link to the proper 3rd party site page, the user should get a 404. The third task is wrapping up an Extract Transform Load (ETL) project.

I wasn't too familiar with the pipelining process in Sitecore as we have it implemented, so I worked with a more experienced developer, basically pair programming our way though the task.

For the redirect to 404 task, I also worked with a more experienced developer, though instead of pair programming we were both debugging the changes, making different edits, and sharing progress when one of us made it past a particular stumbling block.

My last task of the day was lower priority, but after I finished up the high priority tasks, I wanted to wrap up a project. This is a long-running project, performing an ETL workflow. Basically, it takes survey responses for online and in-person activities which we get in reports as Excel workbooks or CSVs. Some of the Excel workbooks contain only one table, and others contains several. Furthermore, there are variations on where each type of report stores certain pieces of information. I wrote the utility originally in Dot Net Core 2, but have recently upgraded it to Dot Net Framework 6. The program scans the various input files, and collates them into one unified data structure for storing the information we want. Then, the ETL process finishes by loading this data into our Google Big Query data warehouse.

Today was a pretty productive day, and my JIRA lanes are clear. That's a good thing, since the production build for the sprint is tomorrow morning.

Sunday, March 13, 2022

Server-Side Swift Developer Blog Entry #0x01: Hello World in Plot with Vapor

You are going to learn how to use Plot, a DSL for writing HTML from John Sundell, with the Vapor framework.

This Hello World tutorial requires that you have Swift and Vapor installed. This code was written on macOS using Xcode, but should work on Linux as well.

Use the command line to create a new Vapor app:

devdir $: vapor new HelloVaporPlot

With the editor of your choice, pop open ./HelloVaporPlot/Package.swift, and add the following package into your dependencies:

    url: "https://github.com/johnsundell/plot.git

    from: "0.10.0"

Additionally, add the following product to your App .target dependencies

    name: "Plot"

    package: "plot"

Your Package.swift should look something like the code below:

// swift-tools-version:5.5

import PackageDescription


let package = Package(

    name: "HelloPlot",

    platforms: [

       .macOS(.v12)

    ],

    dependencies: [

        // 💧 A server-side Swift web framework.

        .package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),

        .package(url: "https://github.com/johnsundell/plot.git", from: "0.10.0"),

    ],

    targets: [

        .target(

            name: "App",

            dependencies: [

                .product(name: "Vapor", package: "vapor"), .product(name: "Plot" ,package: "plot" )

            ],

            swiftSettings: [

                // Enable better optimizations when building in Release configuration. Despite the use of

                // the `.unsafeFlags` construct required by SwiftPM, this flag is recommended for Release

                // builds. See <https://github.com/swift-server/guides/blob/main/docs/building.md#building-for-production> for details.

                .unsafeFlags(["-cross-module-optimization"], .when(configuration: .release))

            ]

        ),

        .executableTarget(name: "Run", dependencies: [.target(name: "App")]),

        .testTarget(name: "AppTests", dependencies: [

            .target(name: "App"),

            .product(name: "XCTVapor", package: "vapor"),

        ])

    ]

)

Now, we are going to head over to ./HelloVaporPlot/Sources/App/routes.swift
At the bottom of the file, add an extension to HTML so that it conforms to ResponseEncodable. There is probably a more responsible place to stash the extension, but it works here.

extension HTML : ResponseEncodable {

    public func encodeResponse(for request: Request) -> EventLoopFuture<Response> {

        let res = Response(headers: ["content-type": "text/html; charset=utf-8"], body: .init(string: self.render()))

        return res.encodeResponse(for: request)

    }

}

The last step is to add the route with the Plot code to the bottom of the routes function:

app.get("helloplot") { req -> HTML in

        HTML(

            .head(

                .title("Plot on Vapor")

            ),

            .body(

                .div(

                    .h1("Hello Swift Developer!")

                )

            )

        )

    }

Now, build and run, and hit the endpoint http://127.0.0.1:8080/helloplot to see your work in action!

Citations:

I got some help from the following pages:

    • https://inuk.blog/posts/plot-and-vapor/
    • https://medium.com/@andreabellotto88/how-to-use-plot-in-vapor-3-0-404316ce24c0
    • https://github.com/johnsundell/plot 

Wednesday, March 2, 2022

Homelab Hacker Blog Entry #0x11: Nextcloud plugin on TrueNAS

 Maybe this works out of the box for you if you leave it configured for NAT instead of switching it to DHCP.

I get this error when navigating to the IP address for Nextcloud:

Access through untrusted domain

Please contact your administrator. If you are an administrator, edit the "trusted_domains" setting in config/config.php like the example in config.sample.php.

That means we need to break into the jail and modify some config.

open a shell into the jail

vi /usr/local/www/netcloud/config/config.php

move down to the section where 'localhost' and the IP address of the truenas box are listed, and change the list to include the proper IP address and any hostnames that might be mapped to it.

How to exit Vi: press escape, then type colon (:) then wq enter (write to file, quit)

Monday, February 14, 2022

Homelab Hacker Blog Entry #0x10: GRUB command line

 https://askubuntu.com/questions/833006/how-can-i-manually-boot-windows-from-the-grub2-terminal

booting windows from GRUB prompt

GRUB> insmod ntfs

GRUB> set root=(hdX,gptX)

GRUB> chainloader (${root})/EFI/Microsoft/Boot/bootmgfw.efi

GRUB> boot


https://www.ubuntubuzz.com/2016/03/booting-gnulinux-manually-with-grub-prompt.html

booting ubuntu from GRUB prompt

GRUB> ls

GRUB> set root=(hd0,X)

GRUB> linux /boot/vmlinuz-4.2.0-16-generic root=/dev/sdb3

GRUB> initrd /boot/initrd.img-4.2.0-16-generic

GRUB> boot

Sunday, January 16, 2022

Server-Side Swift Developer Blog Entry #0x00: Vapor on Windows with Windows Subsystem for Linux

 Server-Side Swift (Vapor) on Windows 11 inside WSL with Visual Studio Code

Install Ubuntu via the Microsoft store or WSL command line. This may require rebooting.

Open an ubuntu/bash terminal.

Check for any updates:

    sudo apt-get update

    sudo apt-get upgrade -y

Install prerequesites

    sudo apt-get install -y binutils git gnupg2 libc6-dev libcurl4 libedit2 libgcc-9-dev libpython2.7 libsqlite3-0 libstdc++-9-dev libxml2 libz3-dev pkg-config tzdata uuid-dev zlib1g-dev make

Grab the latest swift 5.5 as of this writing

    wget https://download.swift.org/swift-5.5-branch/ubuntu2004/swift-5.5-DEVELOPMENT-SNAPSHOT-2021-12-07-a/swift-5.5-DEVELOPMENT-SNAPSHOT-2021-12-07-a-ubuntu20.04.tar.gz

untar it

    tar xzf swift-5.5-DEVELOPMENT-SNAPSHOT-2021-12-07-a-ubuntu20.04.tar.gz 

set the swift path

    export PATH=/home/YOURLINUXUSERNAME/swift-5.5-DEVELOPMENT-SNAPSHOT-2021-12-07-a-ubuntu20.04/usr/bin:"{$PATH}"

test that swift works

    swift --version

install vapor toolbox

    git clone https://github.com/vapor/toolbox.git

    cd toolbox

    git checkout 18.3.3

    make install

check that vapor worked

    vapor --help

make a project directory and try out a vapor demo app
    mkdir vapordevprojects
    cd vapordevprojects
    vapor new HelloVaporDeveloper
        <I selected Fluent, with SQLite, and did not opt to use leaf>
    cd HelloVaporDeveloper
    vapor run

you may encounter an issue with sqlite, to fix it try
    sudo apt-get install libsqlite3-dev

install visual studio code for windows (if you install it in ubuntu and then try launching it, it tells you to uninstall it and then use the windows version

at the terminal you should be able to type
    code .

and open the source code on windows

Wednesday, March 31, 2021

Homelab Hacker Blog Entry #0x01: XRDP fixes

 So, after installing ubuntu's desktop environment on a server base, I like to install XRDP so that I can easily access my system via RDP (from a windows box, usually, but the mac and ios clients for windows rdp work great too).

sudo apt-get install xrdp

That's it!

Not quite... On Ubuntu 20.10, this results in some annoying popups.

"Authentication is required to create a color managed device"

There is a simple fix! We need to create a file:
 /etc/polkit-1/localauthority/50-local.d/45-allow-colord.pkla
With the following contents:
[Allow Colord all Users]
Identity=unix-user:*
Action=org.freedesktop.color-manager.create-device;org.freedesktop.color-manager.create-profile;org.freedesktop.color-manager.delete-device;org.freedesktop.color-manager.delete-profile;org.freedesktop.color-manager.modify-device;org.freedesktop.color-manager.modify-profile
ResultAny=no
ResultInactive=no
ResultActive=yes

Boom! Done!

Homelab Hacker Blog Entry #0x00: Installing Ubuntu Desktop Minimal via Server Base

Hey there. Not sure how you arrived at this page, but I hope you find this a useful read.

This post is about how I like to set up my favorite version of GNU/Linux, Ubuntu!

Whenever the new version drops (it's like Christmas, but twice a year!), I like to try it out.

I'm a multi-os kind of guy.

I like to use Mac OS (this keyboard though lol) on Apple hardware, an extension of my use of their tablets and phones (which i havent jailbroken in years). Havent tried any M1 hardware yet, but I'm (painfully!) typing this on a Macbook Pro from 2016 or so. Have an older MBP from 2007 that was my first baby. Had a older MBP that i overnighted to a friend a year back because he needed a mac for freelance work. I have two apple tvs. I dont know objective-c or swift but i buy a new mac every once in a while with the plan to write an app for my watch or carplay or anything to break into the ultra profitable apple store lol.

At work, I use Windows 10 for web development. I work in a CMS called sitecore. Enough about that. Today I wrote JavaScript, TypeScript, and T-SQL, to implement a new feature for the company. I dont want to say that I enjoy Windows, but its a fact of my life. It is what it is. I could find a job that didnt require using it but its not that big of a sticking point for me. I wont say I "put up with it" because I love my job.

My home "router" if you want to call it that is a cheap dual core Walmart PC with an add in pcie dual port gigabit NIC. It runs PFSense, a version of FreeBSD engineered for networking. I learned about it when I worked for New York Internet, a company that managed colocation datacenters. I learned a lot there. Also, maybe two years ago, I invested in a NAS with ECC memory, and ran FreeNAS on it, until it became TrueNAS, and I eventually reinstalled after I was certain I could migrate my pool without issue.

My servers are generally ubuntu. Sometimes CentOS, or Fedora, or Debian. I like to virtualize with VMWare workstation, though its lost some of the features i like over the years. I used to run a Proxmox cluster, but found it difficult to remove nodes when i wanted to repurpose a host into a dedicated server for something else.

Anyway. Back to ubuntu.

I grab a server iso, usually from bit torrent.

Then I install the base system, without selecting any add on package groups, and always opt to install openssh server. I am always frustrated to find out that I've forgotten to install or enable it, and usually at the worst time (trying to remote in from another box, across the room, in another room, or across the internet)!

Even if I want a desktop system, I've found it more satisfying to install the base ubuntu os from a server disk, reboot, and then install the minimal desktop.

sudo apt-get install tasksel

sudo tasksel install ubuntu-desktop-minimal

That's it! Those two lines are why i wrote this post lol


edit:

I have found the following helpful to enable network manager to manage all interfaces

backup /etc/netplan/*whatever*.yaml

sudo vi /etc/netplan/01-network-manager-all.yaml

make it look like

network:

  version: 2

  renderer: NetworkManager

sudo netplan generate

sudo netplan apply

sudo service network-manager restart

sudo systemctl restart network-manager