Entries filed under Misc Scripting

Contribute to wappalyzer

Posted on 20. Mai 2020 Comments

Wappalyzer is an open source website analyzer written in node.js. It basically just parses a big json file and uses regular expressions to find patterns in websites HTML, CSS, JavaScript and Server Headers.

  1. Fork the repository https://github.com/AliasIO/wappalyzer
  2. Clone the fork to your computer
  3. Install Docker
  4. ./run links
  5. Write Regex
  6. Check with regex101.com or similar tool
  7. Add valid json to apps.json
  8. Add a 32×32, 64×64 PNG or SVG to the icons folder
  9. Commit to another branch on your fork
  10. Push
  11. Create Pull Request, showing that it’s a relevant project: 1k+ stars on GitHub, Pages using it etc

I just created a pull request for Alpine.js, A rugged, minimal framework for composing JavaScript behavior in your markup, that I like to pull in when Vue or React would be overkill.

One Click Shadowsocks with no technical knowledge needed

Posted on 23. November 2017 Comments

Shadowsocks is a proxy that has been designed and used to circumvent censorship in China. So if it’s possible to get traffic across the Great Firewall of China it pretty much can be used anywhere, e.g. Egypt where VPNs are blocked since mid 2017.

Digital Ocean offers virtual servers for cheap with an easy to understand pricing model. Basically you pay either $5, $10, $20, $40, $80 or $160 per month, for more have a look at pricing at digitalocean.com. These server are general purpose servers, you can do everything with them, which also means, they don’t have anything installed and you need to do everything yourself.

oneclickshadowsocks.de is a service to install shadowsocks on DigitalOcean servers without having to actually login via SSH and entering lots of technical commands in the commandline. It uses the DigitalOcean API to create a Droplet (=server) with shadowsocks already set up and running. All you have to do is to enter the IP address you get via e-mail in your shadowsocks client and the password given to you on the website.

The code is open source and the website itself is hosted on GitHub Pages, which means, you can see the sourcecode of the page itself, running at that very moment. This way other people can verify they nothing shady is going on.

Delete empty rows in CSV file with sed

Posted on 23. August 2017 Comments

This is for when you have empty lines (so lot’s of ,,,,,,) in your file.

MacOS

sed -i '' -e '/^,*$/d' filename.csv
find ./ -type f -exec sed -i '' -e '/^,*$/d' {} \;

Linux

sed -i '/^,*$/d' filename.csv
find ./ -type f -exec sed -i '/^,*$/d' {} \;

 

^ marks the beginning of a line
,* marks a possible infinite amount of commas
$ marks the end of a line

Simple wget crawler for list of files

Posted on 6. August 2015 Comments

This script could be helpful to download a set of files from a webserver, that you don’t have (S)FTP access to. The input file consists of a list of filenames, one name each line.


#!/bin/bash
file=$1
WEBSERVER="http://webserver.tld/folder/"
while IFS= read -r line; do
FULLURL="$WEBSERVER$line"
wget -nc -R --spider $FULLURL
done < "$file"

At first, the first command line argument is saved into the variable file. Then the Webserver address is saved to the WEBSERVER variable. IFS stands for Internal Field Separator. It’s used to read line by line through the file in the while loop that ends in the last line. Inside of the loop, the read line is concatenated with the webserver address into FULLURL. Then, wget is used with the parameters -nc for checking if the file is not already present in the current folder, -R for downloading and –spider for checking the existence on the webserver.

You can find the script on GitHub.

Using nanoc for podcast feeds

Posted on 23. Juli 2015 Comments

Nanoc is a static site generator much like jekyll or octopress, but with a more minimalistic approach. These generators are not necessarily the most suitable choice for a podcast website, but it’s possible and you might save up on webspace and traffic when you use GitHub or Neocities.

Creating the podcast feed is basically like writing a normal Atom feed for the blog, since podcast feeds ARE indeed feeds with an enclosure tag in which the URL to the audio or video file is placed. This guide does not include the itunes tags. I might add it one day. Follow the instructions and use the documentation for the Helper Blogging. Tag your podcast episodes as kind:article.

The media files are placed in content/mp3 and content/opus, which is where the links in the feeds will point to later.

I invented the fields mp3 and opus, since these are the file formats I want to use. The values are the filenames. The header of a new episode/post would look like

---
title: 001 - Podcast Episode Title
created_at: 2015-03-14 09:00:00 +0000
kind: article
tags: [podcast,topic]
mp3: 001-podcast-episode-title.mp3
opus: 001-podcast-episode-title.opus
---

This has to be filled manually everytime, so make sure you have the exact filename, as some podcast clients won’t allow correction of the URL.

The next step is to write different feeds for the formats. For that, I’m using the new field format, which will be interpreted by the Helper class later on. For example, I called my normal feed blogfeed and the podcast feeds mp3feed and opusfeed. Create the file blogfeed.erb in the content folder and fill it with the following:

<%= atom_feed :title => 'repats podcast blog', :author_name => 'repat',
:author_uri => 'http://repat.de', :limit => 10, :format => 'blog' %>

The mp3feed.erb and opusfeed.erb are filled accordingly:

<%= atom_feed :title => 'repats podcast mp3', :author_name => 'repat',
:author_uri => 'http://repat.de', :limit => 10, :format => 'mp3' %>

<%= atom_feed :title => 'repats podcast opus', :author_name => 'repat',
:author_uri => 'http://repat.de', :limit => 10, :format => 'opus' %>

The next step is to use the Blogging locally in your nanoc installation. To do that you need to copy it from the gems folder into your lib folder. For me, that was

$ cp /var/lib/gems/1.9.1/gems/nanoc-3.7.5/lib/nanoc/helpers/blogging.rb lib/

It should be included like this in the lib/default.rb

include Nanoc3::Helpers::Blogging

Add the following attribute to the AtomFeedBuilder class

attr_accessor :format

If you don’t trust yourself to always remember the files you might want to  add this exception to the validate_feed_item function

if format.nil?
raise Nanoc::Errors::GenericTrivial.new('Cannot build Atom feed: no format(mp3,opus,blog) in params, item or site config')
end

After the # Add link comment is a good place to insert the  enclosure tag. File.size() will only work if the files are there and the exact same name. This code could probably be written a bit more safely, but I’m not a ruby developer and since I will have an mp3 file and and opus file in every post it’s not a problem this way.

# Add podcast enclosure
if format == 'mp3'
xml.link(href:"http://yourpodcast.com/mp3/" + a[:mp3],length:File.size("content/mp3/" + a[:mp3]), type:"audio/mpeg", rel:"enclosure")
elsif format == 'opus'
xml.link(href:"http://yourpodcast.com/opus/" + a[:opus],length:File.size("content/opus/" + a[:opus]), type:"audio/mpeg", rel:"enclosure")
end

To interpret the mp3 and opus attribute from earlier in the actual post, the last step is to add this line to the atom_feed function:

      builder.format            = params[:format]

You might need to install builder to let this run

$ sudo gem install builder

The only thing left to do is to edit the Rules file:

compile '/blogfeed' do
filter :erb
end
compile '/mp3feed' do
filter :erb
end
compile '/opusfeed' do
filter :erb
end
[...]
route '/blogfeed' do
'/blogfeed.xml'
end
route '/mp3feed' do
'/mp3feed.xml'
end
route '/opusfeed' do
'/opusfeed.xml'
end

 

You can find the blogging.rb and the Rules file on GitHub.

Morsecode As A Service: node.js app with restify and Heroku

Posted on 22. Januar 2015 Comments

I wanted to play around with node.js and REST APIs. Heroku is widely used for deploying node.js app, last but not least because they give you one free instance to test your code and the possibility to use your own domain name (via CNAME).

Until now the code is rather trivial. This for example is the encode function (plaintext->morsecode). It uses the npm module morse to encode the given string in the request parameters and returns it with the plaintext in an array. The requests are handled by restify.
function encode(req, res, next) {
var answer = {}
answer.plaintext = req.params.string.toUpperString();
answer.morsecode = morse.encode(req.params.string);
res.send(answer);
next();
}

This function gets called later here.
server.get('/encode/:string', app.encode);

This starts the server on the port from the Heroku instance.
var port = process.env.PORT || 8080;
server.listen(port, function() {
console.log('%s listening at %s', server.name, server.url);
});

The decode function is equivalent, except that I test if there are only „.“, „-“ and white spaces in the request.

I wrote the documentation with the automatic page generator from GitHub Pages in the repository and so with the following code the user is redirected there when entering the root „/“.

 

function redirectToDocumentation(req,res,next) {
res.send(302, null, {
Location: API_DOKU
});
next();
}

It’s reachable under morsecode-api.de or morsecodeapi.herokuapp.com.

How to change nano syntax highlighting for arbitrary filename extensions

Posted on 17. Dezember 2014 Comments

The text editor nano manages syntax highlighting through .nanorc files. Say, we have files with the ending .phpx, but would like PHP syntax highlighting.

$ sudo nano /usr/share/nano/php.nanorc

Change this line

syntax "php" "\.php[2345s~]?$"

to this regex:

syntax "php" "\.php[x2345s~]?$".

Alternativly, e.g. if you don’t have sudo rights for /usr/share/nano/php.nanorc, you can do the following

$cp /usr/share/nano/php.nanorc ~/.phpx.nanorc

Then enter the following line in ~/.nanorc:

include ~/.phpx.nanorc

Then, change the line as mentioned above and syntax „php“ into syntax „phpx“

Alle norwegischen Sonderzeichen in Dateinamen ersetzen

Posted on 15. Juli 2014 Comments

Wenn Dateien von einem norwegischen PC stammen, könnte es sein, dass die Dateinamen nicht mit UTF-8 Zeichen geschrieben sind. Man sieht dann ein Fragezeichen Symbol bei der ls-Ausgabe. Dieser Weg ist alles andere als elegant, aber funktioniert, wenn es einfach nur schnell und vielleicht nur einmal überhaupt erledigt werden soll. Wenn das öfter vorkommt, wäre ein Skript angebrachter. Vom User Gilles von Stack Exchange habe ich dieses Skript kopiert:

 

grep-invalid-utf8 (){
  perl -l -ne '/^([\000-\177]|[\300-\337][\200-\277]|[\340-\357][\200-\277]{2}|[\360-\367][\200-\277]{3}|[\370-\373][\200-\277]{4}|[\374-\375][\200-\277]{5})*$/ or print'}
find | grep-invalid-utf8

Das kann man so einfach in der Konsole absetzen. Danach habe ich wie vorgeschlagen mit diesem Skript, find und rename alle Dateien UTF-8 Dateinamen gegeben.

find | grep-invalid-utf8 |
rename 'BEGIN {binmode STDIN, ":encoding(latin1)"; use Encode;}
        $_=encode("utf8", $_)' 

Jetzt habe ich mir mit ls > ls.txt alle Dateinamen in eine Textdatei geschrieben und diese in Libre Office Calc kopiert. In die A-Spalte und die B-Spalte kommen die Dateinamen. Dann wird auf die B-Spalte ein Makro angewandt, dass alle Sonderzeichen entfernt. Anschließend kommt in die C Spalte der folgende Befehl:

="mv "&A1&" "&B1

und in die D Spalte:

=WENN(A1=B1;"";C1)

Jetzt kann man die D-Spalte kopieren und in ein Shellskript einfügen und im Ordner ausführen. Nicht vergessen das Skript mit chmod +x ausführbar zu machen.

 

Libre Office Calc Makro zum Ersetzen von Sonderzeichen in BASIC

Posted on 22. Mai 2014 Comments

Dieses Makro ersetzt in einem LibreOffice Calc Sheet alle norwegischen Sonderzeichen (å, ø, æ) durch ASCII kompatible Zeichen.

Sub NO_WITHOUT_SPECIAL_CHARS()

    dim oSheet as object, mySuche as Object
    'erste Tabelle
    oSheet = thisComponent.Sheets.getByIndex(0)
    mySuche=oSheet.createReplaceDescriptor()
    
    With mySuche
    .SearchRegularExpression = False
    .setSearchString("å")
    .setReplaceString("a")
    end With
    oSheet.replaceAll(mySuche)
    
    With mySuche
    .SearchRegularExpression = False
    .setSearchString("ø")
    .setReplaceString("o")
    end With
    oSheet.replaceAll(mySuche)

    With mySuche
    .SearchRegularExpression = False
    .setSearchString("æ")
    .setReplaceString("ae")
    end With
    oSheet.replaceAll(mySuche)
End Sub

Eine Anleitung, wie man das Makro in die Symbolleiste bekommt, findet sich im OpenOffice Wiki.