Skip to content

Instantly share code, notes, and snippets.

View domsie's full-sized avatar

Dominik Siefert domsie

View GitHub Profile
@domsie
domsie / keycloak_impex.sh
Created September 13, 2019 12:08 — forked from giannivh/keycloak_impex.sh
Import/Export Keycloak Config running on Kubernetes
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
show_help() {
cat << EOF
Usage: $(basename "$0") <options>
-h, --help Display help
@domsie
domsie / md5.js
Created April 10, 2018 06:55
PHP's md5 in JavaScript
function md5 (str) {
var hash;
try {
var crypto = require('crypto');
var md5sum = crypto.createHash('md5');
md5sum.update(str);
hash = md5sum.digest('hex');
} catch (e) {
hash = undefined;
@domsie
domsie / nginx_phpfpm_serverstatus.sh
Last active February 23, 2018 10:25
bash script to collect nginx und php-fpm metrics
#!/bin/bash
bold=$(tput bold)
normal=$(tput sgr0)
while true
do
echo -e "---------------------------------------------------------------------------------------------------------------"
echo -e "\n::::::::::${bold} current Nginx Status ${normal}::::::::::\n"
@domsie
domsie / nesting_boolean_query.json
Created November 9, 2017 07:59
elasticsearch nested boolean (filtered) query
{
"fields": [
"msg_id",
"msgid"
],
"query": {
"filtered": {
"query": {
"match_all": {}
},
@domsie
domsie / certainGETparam.js
Last active October 11, 2017 09:12
regex to find a certain get parameter in an query string
const regex = /(\?|&)param(\=[^&]*)?(?=&|$)|^param(\=[^&]*)?(&|$)/g;
const str = `http://website.de?param=sdfffdf&param2=dsfsf`;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
@domsie
domsie / rfc_url.php
Created October 10, 2017 07:29
URL > Valid URL (RFC 3986)
<?php
$re = '/# protocol user host-ip port path path path querystring fragment
^
#protocol
((?:(?<scheme>[a-zA-Z][a-zA-Z\d+-.]*):)?
(?:
(?:
(?:
\/\/
@domsie
domsie / UnixDomainSocketServer.py
Created September 12, 2017 08:07
Unix domain sockets server implemenation in python 2
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import socket
import os
import sys
server_address = '/run/service/server.sock'
# Make sure the socket does not already exist
@domsie
domsie / getCommandLineArguments.py
Created September 12, 2017 08:01
get the command line arguments
import sys, getopt
def main(argv):
inputfile = ''
outputfile = ''
try:
opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="])
except getopt.GetoptError:
print 'test.py -i <inputfile> -o <outputfile>'
sys.exit(2)
@domsie
domsie / README-python-service-on-systemd-activated-socket.md
Created September 6, 2017 10:05 — forked from drmalex07/README-python-service-on-systemd-activated-socket.md
An example network service with systemd-activated socket in Python. #systemd #python #socket #socket-activation

README

The example below creates a TCP server listening on a stream (i.e. SOCK_STREAM) socket. A similar approach can be followed to create a UDP server on a datagram (i.e. SOCK_DGRAM) socket. See man systemd.socket for details.

An example server

Create an simple echo server at /opt/foo/serve.py.

@domsie
domsie / xss_prevention.php
Created August 25, 2017 06:19
CROSS-SITE SCRIPTING (XSS) prevention function
function xss_clean($data)
{
// Fix &entity\n;
$data = str_replace(array('&amp;','&lt;','&gt;'), array('&amp;amp;','&amp;lt;','&amp;gt;'), $data);
$data = preg_replace('/(&#*\w+)[\x00-\x20]+;/u', '$1;', $data);
$data = preg_replace('/(&#x*[0-9A-F]+);*/iu', '$1;', $data);
$data = html_entity_decode($data, ENT_COMPAT, 'UTF-8');
// Remove any attribute starting with "on" or xmlns
$data = preg_replace('#(<[^>]+?[\x00-\x20"\'])(?:on|xmlns)[^>]*+>#iu', '$1>', $data);