Skip to content

Instantly share code, notes, and snippets.

View tguruslan's full-sized avatar

Ruslan Lopushan tguruslan

  • USPU
  • Ukraine
  • 17:54 (UTC +03:00)
View GitHub Profile
@tguruslan
tguruslan / script.py
Created March 26, 2024 17:29
convert pfsense to routeros
import xml.etree.ElementTree as ET
import re, sys
def round_to_ten(number):
num=int(re.sub("[^0-9]", "", number))
if num < 10:
return 5
else:
return (num // 10) * 10
@tguruslan
tguruslan / telegram
Created February 22, 2024 09:10
mikrotik telegram send dhcp address
:global botToken ""
:global chatId ""
:global interfaceName "ether1"
while ([/ping 8.8.8.8 interval=3 count=1]=0) do={
delay 5
};
/tool fetch url=("https://api.telegram.org/bot".$botToken."/sendMessage\?chat_id=".$chatId."&text=#".[/system identity get name]."+".[/ip address get [find interface=$interfaceName] address])
@tguruslan
tguruslan / discord
Created February 22, 2024 09:04
mikrotik discord send dhcp address
:global discordWebhookUrl "https://discordapp.com/api/webhooks/..."
:global interfaceName "ether1"
:while ([/ping 8.8.8.8 interval=3 count=1] = 0) do={
:delay 5
}
/tool fetch url=($discordWebhookUrl . "?wait=true") http-method=post http-data=("content=" . "#".[/system identity get name]."+" . [/ip address get [find interface=$interfaceName] address])
@tguruslan
tguruslan / plugin.php
Created February 12, 2024 12:31
udpu folder tree
<?php
/*
Plugin Name: udpu folder tree
Plugin URI: #
Description: для додавання використайте: [udpu_folder_tree path=""]
Author: Tgu
Version: 1.0.0
Author URI: #
*/
@tguruslan
tguruslan / yii2controller.php
Created January 19, 2024 08:52
Показати помилку валідації моделі yii2
<?php
public function action(Create|Update)(){
// ...
// ajax
}else if($model->load($request->post()) && !$model->validate()) {
return ['title'=>'Помилка','content'=>json_encode($model->getErrors(),JSON_UNESCAPED_UNICODE),'footer'=> Html::button(Yii::t('app', 'Закрити'),['class'=>'btn btn-default pull-left','data-dismiss'=>"modal"])];
}else{
// no ajax
}else if($model->load($request->post()) && !$model->validate()) {
die(json_encode($model->getErrors(),JSON_UNESCAPED_UNICODE));
@tguruslan
tguruslan / search_strings.php
Last active January 11, 2024 12:04
Пошук в базі движка небажаних доменів
<?php
//wordpress
if (file_exists('wp-config.php')) {
preg_match_all('/define\s*\(\s*[\'"](.*?)[\'"]\s*,\s*[\'"](.*?)[\'"]\s*\)\s*;/', file_get_contents('wp-config.php'), $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
if(in_array($match[1],['DB_HOST','DB_USER','DB_PASSWORD','DB_NAME'],false)){
define($match[1], $match[2]);
}
@tguruslan
tguruslan / db_search_strings.php
Last active January 11, 2024 12:05
Пошук в базах небажаних доменів
<?php
// Параметри для підключення до MySQL серверу
$servername = "127.0.0.1";
$username = "";
$password = "";
error_reporting(E_DEBUG);
ini_set('display_errors', 'on');
@tguruslan
tguruslan / update_cloudflare_iptables.sh
Last active November 20, 2023 14:35
update cloudflare ips list
#!/bin/bash -x
for app in iptables ip6tables; do
if [[ $app =~ 6 ]]; then
index=6
else
index=4
fi
for chain in $($app -t filter -L -v -n | grep Chain | awk '{print $2}'); do
for id in $($app -t filter -L --line-numbers -n -Z $chain | egrep "\:(443|80)" | awk '{print $1}' | sort -r); do
@tguruslan
tguruslan / update_cloudflare.sh
Last active November 14, 2023 13:44
update cloudflare ips list
#!/bin/bash -x
firewall-cmd --zone=public --remove-service=http --permanent
firewall-cmd --zone=public --remove-service=https --permanent
for ipv in v4 v6; do
for i in $(firewall-cmd --zone=public --list-all | grep http | grep "ip${ipv}" | awk '{print $4}' | awk -F '"' '{print $2}' | sort -u); do
firewall-cmd --zone=public --permanent --remove-rich-rule "rule family="ip${ipv}" source address="$i" service name="http" accept"
firewall-cmd --zone=public --permanent --remove-rich-rule "rule family="ip${ipv}" source address="$i" service name="https" accept"
firewall-cmd --zone=public --permanent --remove-rich-rule "rule family="ip${ipv}" source address="$i" port port="80" protocol="tcp" accept"
@tguruslan
tguruslan / yiiquery.php
Last active November 4, 2023 09:42
yii2 or activequery
<?php
$query->andFilterWhere(['OR', ['is', $key, new \yii\db\Expression('null')], ['<=','LENGTH('.$key.')',0]])->all();