Netanjahu expects the EU to accept Jerusalem as Israel’s capital, sticking to his plan that the best way to make peace is to ignore the other side and just do what you want. Nevermind the UN resolution 242. While we’re at it, we could also accept the annexation of Crimea by Russia and give South Korea to North Korea. That ought to help. Nikki Haley, the US repesentative to the United Nations, even said that this decision could fastball the peace process, as everyone knows that in order to put out the fire it helps if you give it a good splurge of gasoline. Where’s Picard when you are in desperate need of a giant facepalm?

I’ve been looking for a simple way to utilize RTMP streaming with OBS Studio without having to resort to bloated websites like twitch. RTMP streams you can just play using your media player of choice (usually), for example VLC. In addition this can be useful to collaborate with colleagues, as you can stream not just a single window but also your whole desktop. nginx has access to a RTMP module (surprisingly called nginx-rtmp-module ^^) which they say does not do authentication but just the streaming. However, it features certain event calls like on_publish or on_play. After digging into it for a bit there is actually a super easy way to do a very simple authentication scheme which could be extended by any script you like.

All you need is first the RTMP block in your nginx config file:

rtmp {
  server {
    listen 1935;
	ping 30s;
	notify_method get;
			  
	application stream {
	  live on;
      on_publish http://localhost[:port]/auth;
      on_play http://localhost[:port]/auth;
	  record off;
	}
  }
}

This just sets up the stream and then forces to trigger a certain url on_publish (i.e. if someone wants to stream to the server) and on_play (i.e. someone trying to play back the stream). Now, the stream or play request will only be accepted if the url given returns a HTTP 2xx status code, else the connection will be dropped.

We can work this to our advantage and just set up a quick and dirty server in the http section of nginx that directly checks for a given secret:

server {
  listen <port>;
  location /auth {
  if ($arg_psk = 'totallysecretpassword') {
    return 201;
  }
  return 404;
}

You could also implement multiple urls with different secrets for streaming and playing or you could let a script of your choosing answer the url request and check for a username and a password or id in a database. Once all is done you can access the stream via rtmp://host.tld/stream/user?psk=totallysecretpassword. Of course this sends your password via plaintext so you should take precautions and if your software supports it use rtmp via ssl/TLS.

UPDATE: there is now a followup article on how to realize a slightly more sophisticated authentication setup

Using Windows? The art of process doppelgänging can now be yours no matter your flavour of Windows. Security researchers presented their work at BlackHat and according to their presentation they are able to circumvent detection by AV (another nail in the coffin for those) by using NTFS operations to write to a file, turn part of the file into a transaction section, and create a process from it. Afterwards they roll back the transaction and there is no trace left of what they did.

Even better, apparently this attack is unpatchable as it “exploits fundamental features and core design of the process loading mechanism in Windows”. It does rely on undocumented functions which bleepingcomputer lists as something positive. I’d say it’s just a matter of time before this stuff will be documented for those who are interested in it. Since when has “Only a few people know about this” ever been a good defense?

In order to get the new site up and running and switching to Hugo a few things were missing.

Pagination

I did not want a Next and Previous navigation as this gets really annoying with lots of pages. I wanted a list of pages, not too long through, and the ability to quickly traverse pages.

First we define the parameters for number of shown pages and at which position the active page is supposed to be located. This neatly describes the number of previous and following pages to generate. This goes into the config.toml site configuration:

[params]
	pgtrspan = 6
	pgtractive = 3

Then this goes into a partial template which you can include to show the paginator, lets call this pagenav.html:

<div id="page-bar">
  {{ $curpage := .Paginator.PageNumber }}
  {{ $lastpage := .Paginator.TotalPages }}

  <!-- if we have previous pages show quick rewind buttons -->
  {{ if .Paginator.HasPrev }}
  <div class="pagenumber">
   <a href="{{ .Paginator.First.URL }}"><span class="oi" data-glyph="caret-left" title="previous page" aria-hidden="true"></span><span class="oi" data-glyph="caret-left" title="previous page" aria-hidden="true"></span></a>
  </div>
  <div class="pagenumber">
   <a href="{{ .Paginator.Prev.URL }}"><span class="oi" data-glyph="caret-left" title="previous page" aria-hidden="true"></span></a>
  </div>
  {{ end }}

  <!-- get the width of the navpage in number of pages -->
  {{ $pgtrspan := $.Site.Params.pgtrspan }}

  <!-- get the index of the active page -->
  {{ $pgtractive := $.Site.Params.pgtractive }}

  
  {{ $lowerbound := sub $curpage (sub $pgtrspan (add $pgtractive 1)) }}
  {{ $upperbound := add $curpage (sub $pgtrspan $pgtractive) }}

  {{ if le $upperbound $pgtrspan }}
    {{ $.Scratch.Set "lowerbound" 1 }}
    {{ $.Scratch.Set "upperbound" $pgtrspan }}
  {{ else if gt $upperbound $lastpage }}
    {{ $.Scratch.Set "lowerbound" (add (sub $lastpage $pgtrspan) 1) }}
    {{ $.Scratch.Set "upperbound" $lastpage }}
  {{ else }}
    {{ $.Scratch.Set "lowerbound" $lowerbound }}
    {{ $.Scratch.Set "upperbound" $upperbound }}
  {{ end }}

  <!-- loop through paginator pages and only display stuff within the boundaries -->
  {{ range $id, $pager := .Paginator.Pagers }}
  {{ if and (ge $pager.PageNumber ($.Scratch.Get "lowerbound")) (le $pager.PageNumber ($.Scratch.Get "upperbound")) }}
  <div class="pagenumber">
    {{ if eq $curpage $pager.PageNumber }}
      {{ $pager.PageNumber }}
    {{ else }}
      <a href="{{ $pager.URL }}">{{ $pager.PageNumber }}</a>
    {{ end }}
  </div>
  {{ end }}
  {{ end }}

  <!-- if we have following pages show quick forward buttons -->
  {{ if .Paginator.HasNext }}
  <div class="pagenumber">
   <a href="{{ .Paginator.Next.URL }}"><span class="oi" data-glyph="caret-right" title="next page" aria-hidden="true"></span></a>
  </div>
  <div class="pagenumber">
   <a href="{{ .Paginator.Last.URL }}"><span class="oi" data-glyph="caret-right" title="previous page" aria-hidden="true"></span><span class="oi" data-glyph="caret-right" title="previous page" aria-hidden="true"></span></a>
  </div>
  {{ end }}
</div>

So, finally just put this below whatever paginator range you like:

{{ $paginator := .Paginate .Data.Pages }}
{{ range $paginator.Pages }}
<article>
    <h2><a href="{{ .Permalink }}">{{ .Title }}</a></h2>
    {{ .Content }}
</article>
{{ end }}
{{ partial "pagenav.html" . }}

And presto! Proper pagination bar.

Post Archive

Now the archive business is rather simple but took me a while to figure out as the documentation is really lacking in this regard. There are a couple of examples you can find online but none of them really did it the exact way I wanted it. Yearly archives are fairly easy to do but scrolling through a year worth of posts can be just as annoying if the post volume is high enough. So, ideally I want monthly archives but grouped by year. Leveraging this with Hugo’s taxonomy system is a tiny bit annoying but once it works it is perfectly serviceable.

First of all, add an archive taxonomy to your site’s config.toml

[taxonomies]
	archive = "archive"

Next, on all your posts, add the year and month as seperate taxonomy terms in the front matter

+++
title = "Wabbit"
date = 2017-12-09T16:59:48+01:00
archive = ["2017","2017-12"]
+++

So, the problem is how do we separate the YYYY terms from the YYYY-MM terms? Simple answer is, we don’t. When do we want the archive to start? That’s right, from the year and month we made the first post. When do we want it to end? How about at the latest post? So we create the termlisting taxonomy file as archive.terms.html which goes into one of the proper folders, in my case I use the layouts/taxonomy folder in the theme.

We then loop over all the years between the oldest and the newest post and after printing the list item for said year we loop through the terms. Only if a term matches the YYYY-MM format with YYYY matching the year we are currently indexing will it be printed. And since printing the term as is would be redundant as it contains the year again, we beautify it by use of dateFormat.

By the way, if someone knows a more elegant way in Hugo/Go-Template syntax to return true or false depending on whether a RegEx matches a string please drop me a line. The combination of len, findRE and a comparison operation was the shortest way I could think of with the limited toolset you get.

{{ partial "header.html" . }}

<section id="archive">
  <h1>Archive</h1>
  <ul>
    {{ $data := .Data }}
    {{ $firstyear := (index .Data.Pages.ByDate 1).Date.Format "2006" }}
    {{ $currentyear := now.Format "2006" }}

    {{ range $i,$year := (seq $currentyear $firstyear) }}
      <li><a href="/{{ $data.Plural }}/{{ $year }}">{{ $year }}</a><ul>
      {{ range $key, $value := $data.Terms.Alphabetical.Reverse }}
        {{ if gt (len (findRE (print "^" $year "-\\d\\d$") $value.Name)) 0 }}
          <li><a href="/{{ $data.Plural }}/{{ $value.Name }}">{{ dateFormat "January" (print $value.Name "-01") }}</a> ({{ $value.Count }})</li>
	{{ end }}
      {{ end }}
      </ul></li>
    {{ end }}
  </ul>
</section>

{{ partial "footer.html" . }}

Now, all that is left is to create archive.html which will be used to actually display the paginated list of articles for a year or for a month, depending on which gets selected by the viewer. We only check whether the term is in the YYYY or YYYY-MM format and output a header which is formatted accordingly. The rest is just simple iterating through the posts.

{{ partial "header.html" . }}

{{ $paginator := .Paginate (where .Data.Pages "Type" "musings") 10 }}
{{ $data := .Data }}

{{ if gt (len (findRE "\\d\\d\\d\\d-\\d\\d$" .Data.Term)) 0 }}
{{ $.Scratch.Set "heading" (print (dateFormat "January" (print $data.Term "-01")) " " (replaceRE "-\\d\\d$" "" $data.Term)) }}
{{ else }}
{{ $.Scratch.Set "heading" $data.Term }}
{{ end }}

<h1>Archive for {{ $.Scratch.Get "heading" }}</h1>
{{ range $paginator.Pages }}
<article>
  <h2><a href="{{ .Permalink }}">{{ .Title }}</a></h2>
    {{ .Content }}
</article>
{{ end }}
{{ partial "pagenav.html" . }}

{{ partial "footer.html" . }}

And we’re done.

6
7
8
9
10
11