Skip to content

Instantly share code, notes, and snippets.

View milankragujevic's full-sized avatar

Milan Kragujević milankragujevic

View GitHub Profile
@milankragujevic
milankragujevic / regex_serbian_phone.php
Created August 14, 2025 08:14
Jedan nesveti regex koji validira srpske (fiksne i mobilne) brojeve telefona
<?php
/**
* Jedan nesveti regex koji validira srpske (fiksne i mobilne) brojeve telefona
* Licenca: AGPL v3.0
* Autor: Milan Kragujevic
*/
if (!preg_match('/^(?:(?:\+381|00381)\s*(?:6\d(?:[\s.\/-]?\d){6,7}|(?:1\d|2\d|3\d)(?:[\s.\/-]?\d){5,7})|0\s*(?:6\d(?:[\s.\/-]?\d){6,7}|(?:1\d|2\d|3\d)(?:[\s.\/-]?\d){6,7}))$/', $body['phone'])) {
// telefon je nevalidan
} else {
// telefon je validan
@milankragujevic
milankragujevic / broj_imenica.php
Created August 14, 2025 08:08
PHP funkcija koja vraća broj sa ispravnim oblikom imenice u srpskom jeziku
<?php
/**
* Vraća broj sa ispravnim oblikom imenice u srpskom jeziku
*
* @param int $broj Broj koji se prikazuje
* @param string $oblik1 Jednina (1 kom)
* @param string $oblik2 Množina 2-4
* @param string $oblik5 Množina 5+ i 0
* @return string
* Licenca: AGPL v3.0 - https://www.gnu.org/licenses/agpl-3.0.en.html
@milankragujevic
milankragujevic / iwo9jp32f0p_f23rf2fW
Created June 6, 2024 20:47
iwo9jp32f0p_f23rf2fW
iwo9jp32f0p_f23rf2fW

Introduction

Sometimes you may want to use a DNS server for specific domain requests and another DNS server for all other requests. This is helpful, for instance, when connected to a VPN. For hosts behind that VPN you want to use the VPN's DNS server but all other hosts you want to use Google's public DNS. This is called "DNS splitting."

Here, we run dnsmasq as a background service on macOS. The dnsmasq configuration described below implements DNS splitting.

Install

brew install dnsmasq
@milankragujevic
milankragujevic / enable_sshd.py
Created April 25, 2023 10:32 — forked from andyboeh/enable_sshd.py
Enable SSHD on the Aclatel HH40V (modify backup file)
#!/usr/bin/env python
import os
import sys
import subprocess
import tempfile
import struct
import shutil
import hashlib
@milankragujevic
milankragujevic / reboot.sh
Created May 27, 2022 13:42
Reboot CGA2121 modem via Web UI
#!/bin/bash
SEC=$(curl -s -v 'http://192.168.0.1/goform/logon' -H 'Content-Type: application/x-www-form-urlencoded' --data-raw 'username_login=&password_login=&language_selector=en' --insecure 2>&1 | grep 'Set-Cookie' | cut -d '=' -f 2 | cut -d ';' -f 1)
CSRF=$(curl -s 'http://192.168.0.1/ad_restart_gateway.html' -H "Cookie: sec=${SEC}" --insecure | grep csrftoken | cut -d '"' -f 6)
curl -s 'http://192.168.0.1/goform/ad_restart_gateway' -H "Cookie: sec=${SEC}" --data-raw "csrftoken=${CSRF}&tch_devicerestart=0x00" --insecure >/dev/null 2>&1
echo "Done!"
@milankragujevic
milankragujevic / hpscan.sh
Created October 23, 2021 16:54
Scan over network via SSH on RPI
#!/bin/bash
PAGE_ID="$(date +%Y-%m-%d_%H-%M-%S)"
FILENAME="scan_$PAGE_ID.jpg"
FILENAME_PDF="scan_$PAGE_ID.pdf"
FILENAME_PDF_1="scan_$PAGE_ID.1.pdf"
mkdir -p /home/milan/Documents/Scanned\ Documents/
ssh [email protected] "scanimage --mode Gray --resolution 200 --format=jpeg -l 4 -t 4 -x 207.9 -y 289.011 >/tmp/$FILENAME"
scp [email protected]:/tmp/$FILENAME /home/milan/Documents/Scanned\ Documents/$FILENAME
chmod 0777 /home/milan/Documents/Scanned\ Documents/$FILENAME
chown milan:milan /home/milan/Documents/Scanned\ Documents/$FILENAME
@milankragujevic
milankragujevic / proxy.php
Created July 1, 2021 13:19
PHP streaming proxy with support for Range requests (perfect for proxying video files with progressive download MP4 streaming)
<?php
error_reporting(0);
set_time_limit(0);
ob_end_clean();
$url = $_GET['url'];
if(isset($_SERVER['HTTP_RANGE'])) {
stream_context_set_default([
'http' => [
@milankragujevic
milankragujevic / _update.sh
Last active May 8, 2021 10:53 — forked from lg/angry_wifi.sh
Auto disconnect WiFi clients with a low Received Signal Power on OpenWRT 19.07
rm /root/roaming_assistant.sh; wget http://10.25.100.10/roaming_assistant.sh -O /root/roaming_assistant.sh; chmod +x /root/roaming_assistant.sh
rm /root/monitor-ra.sh; wget http://10.25.100.10/monitor-ra.sh -O /root/monitor-ra.sh; chmod +x /root/monitor-ra.sh
rm /root/restart-ra.sh; wget http://10.25.100.10/restart-ra.sh -O /root/restart-ra.sh; chmod +x /root/restart-ra.sh
/root/restart-ra.sh
@milankragujevic
milankragujevic / iptables.sh
Last active August 6, 2024 03:32
Hijack DNS on OpenWrt to another DNS server
iptables -I FORWARD ! -s 192.168.100.242 -p tcp --dport 53 -j ACCEPT
iptables -I FORWARD ! -s 192.168.100.242 -p udp --dport 53 -j ACCEPT
iptables -t nat -A PREROUTING ! -s 192.168.100.242 -p tcp --dport 53 -j DNAT --to 192.168.100.242:53
iptables -t nat -A PREROUTING ! -s 192.168.100.242 -p udp --dport 53 -j DNAT --to 192.168.100.242:53
iptables -I FORWARD ! -s 192.168.100.242 -p tcp --dport 5353 -j ACCEPT
iptables -I FORWARD ! -s 192.168.100.242 -p udp --dport 5353 -j ACCEPT
iptables -t nat -A PREROUTING ! -s 192.168.100.242 -p tcp --dport 5353 -j DNAT --to 192.168.100.242:53
iptables -t nat -A PREROUTING ! -s 192.168.100.242 -p udp --dport 5353 -j DNAT --to 192.168.100.242:53