Skip to content

Instantly share code, notes, and snippets.

View cyanide-burnout's full-sized avatar

Artem Prilutskiy cyanide-burnout

View GitHub Profile
@cyanide-burnout
cyanide-burnout / asterisk-hook.php
Last active October 12, 2024 17:29
Retreive VoIP configuration from SFP ONU and MikroTik, then apply to Asterisk (triggered by dhcp-voip.rsc)
<?php
define('PJSIP_PEER_NAME', 'mgts');
define('PJSIP_PEER_FILE', '/etc/asterisk/pjsip-mgts.conf');
define('ONU_ADDRESS', '192.168.1.1');
define('ONU_USER', 'admin');
define('ONU_PASSWORD', 'admin');
define('ONU_COMMAND', '/sbin/omcicli mib get 00148');
@cyanide-burnout
cyanide-burnout / dhcp-voip.rsc
Last active October 8, 2024 16:39
MikroTik DHCP script for VoIP telephony: get server list from Option 120, update routes, provision server list to PBX
:global list ""
:if ($bound=1) do={
:local alphabet "\00\01\02\03\04\05\06\07\08\09\0A\0B\0C\0D\0E\0F\10\11\12\13\14\15\16\17\18\19\1A\1B\1C\1D\1E\1F\
\20\21\22\23\24\25\26\27\28\29\2A\2B\2C\2D\2E\2F\30\31\32\33\34\35\36\37\38\39\3A\3B\3C\3D\3E\3F\
\40\41\42\43\44\45\46\47\48\49\4A\4B\4C\4D\4E\4F\50\51\52\53\54\55\56\57\58\59\5A\5B\5C\5D\5E\5F\
\60\61\62\63\64\65\66\67\68\69\6A\6B\6C\6D\6E\6F\70\71\72\73\74\75\76\77\78\79\7A\7B\7C\7D\7E\7F\
\80\81\82\83\84\85\86\87\88\89\8A\8B\8C\8D\8E\8F\90\91\92\93\94\95\96\97\98\99\9A\9B\9C\9D\9E\9F\
\A0\A1\A2\A3\A4\A5\A6\A7\A8\A9\AA\AB\AC\AD\AE\AF\B0\B1\B2\B3\B4\B5\B6\B7\B8\B9\BA\BB\BC\BD\BE\BF\
\C0\C1\C2\C3\C4\C5\C6\C7\C8\C9\CA\CB\CC\CD\CE\CF\D0\D1\D2\D3\D4\D5\D6\D7\D8\D9\DA\DB\DC\DD\DE\DF\
\E0\E1\E2\E3\E4\E5\E6\E7\E8\E9\EA\EB\EC\ED\EE\EF\F0\F1\F2\F3\F4\F5\F6\F7\F8\F9\FA\FB\FC\FD\FE\FF"
@cyanide-burnout
cyanide-burnout / bridge.sh
Last active October 28, 2024 09:13
Automate switching Sagem F@ST DOCSIS modem to bridge mode on power cycling
#!/bin/bash
if ping -c 1 -t 5 192.168.0.1 2>&1 >/dev/null; then
KEY=$(curl -s http://192.168.0.1/login.html | grep 'var sessionkey' | grep -o -E '[0-9]+')
COOKIE=$(curl -s -d 'loginUsername=admin&loginPassword=PASSWORD' -X POST http://192.168.0.1/postlogin.cgi?sessionKey=$KEY -c - -O /dev/null | grep -m 1 web_cookie | awk '{print $7}')
CONTENT=$(mktemp)
curl -s -b "web_cookie=$COOKIE" http://192.168.0.1/reseau.html > $CONTENT
KEY=$(grep 'var sessionkey' $CONTENT | grep -o -E '[0-9]+')
grep -q "enblBridging = '0'" $CONTENT && curl -s -b "web_cookie=$COOKIE" -d 'PrimSecurity2GRadio=1' -X POST http://192.168.0.1/reseau-pa1-eRouterMode.cgi?sessionKey=$KEY -m 5
@cyanide-burnout
cyanide-burnout / taco-toolkit.dockerfile
Last active October 1, 2023 07:42
Tableau WDC 3.0 taco-toolkit in Docker
FROM debian:bullseye-slim
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get install -y ca-certificates curl gnupg python3 build-essential
RUN mkdir -p /etc/apt/keyrings
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
RUN apt-get update
@cyanide-burnout
cyanide-burnout / helper-spirv.dockerfile
Last active November 14, 2022 15:53
SPIR-V in Docker (clang 15 + libclcxx / clang 14)
FROM debian:bullseye-slim
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y \
build-essential apt-utils python3 git curl \
libxml2-dev zlib1g-dev libedit-dev
RUN git config --global user.email "[email protected]" && git config --global user.name "Your Name"
@cyanide-burnout
cyanide-burnout / snapshot.ps1
Last active September 24, 2022 07:21
Create a shadow copy of disk
$drive = "F:"
# Create and mount shadow copy
$snapshot = (Get-WmiObject -List Win32_ShadowCopy).Create("$drive\\", "ClientAccessible")
$copy = Get-WmiObject Win32_ShadowCopy | Where-Object { $_.ID -eq $snapshot.ShadowID }
cmd /C mklink /d $drive\ShadowCopy "$($copy.DeviceObject)\\"
@cyanide-burnout
cyanide-burnout / graph-group.php
Last active September 21, 2022 09:09
Check user group membership in Azure AD (including inheritance)
<?php
if (array_key_exists("access_token", $_SESSION))
{
$handle = curl_init();
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_URL, "https://graph.microsoft.com/v1.0/me/checkMemberGroups");
curl_setopt($handle, CURLOPT_HTTPHEADER, array("Authorization: Bearer " . $_SESSION["access_token"], "Content-Type: application/json"));
curl_setopt($handle, CURLOPT_POSTFIELDS, "{\"groupIds\":[" . GRAPH_GROUP_LIST . "]}");
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
@cyanide-burnout
cyanide-burnout / graph-membership.php
Last active September 21, 2022 09:10
Check user membership in Azure AD (direct membership)
<?php
// https://learn.microsoft.com/en-us/graph/api/user-list-memberof?view=graph-rest-1.0&tabs=http
if (array_key_exists("access_token", $_SESSION))
{
$handle = curl_init();
curl_setopt($handle, CURLOPT_HTTPHEADER, array("Authorization: Bearer " . $_SESSION["access_token"]));
curl_setopt($handle, CURLOPT_URL, "https://graph.microsoft.com/v1.0/me/memberOf");
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
@cyanide-burnout
cyanide-burnout / auth.php
Last active November 24, 2023 14:58
Authentication in Azure AD
<?php
// https://katystech.blog/projects/php-azuread-oauth-login
// https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow
// Configuration settings: OAUTH_TENANT_ID, OAUTH_CLIENT_ID, OAUTH_CLIENT_SECRET
require_once("config.php");
session_start();
@cyanide-burnout
cyanide-burnout / guard.lua
Last active November 12, 2023 00:53
IP- and cookie-based authorization guard for haproxy
--[[
IP- and cookie-based authorization guard for haproxy
https://www.haproxy.com/blog/5-ways-to-extend-haproxy-with-lua/
Guard checks permit in memcached, any value of key 'Allow-Address-<Address>' or 'Allow-Session-<Session>' will be accepted
Where:
<Address> is client's IP-address
<Session> is value of cookie 'XGuardKey'
Parameter 'action' can be: