Skip to content

Instantly share code, notes, and snippets.

View hosni's full-sized avatar

Hossein Hosni hosni

View GitHub Profile
@hosni
hosni / cust_openlitespeed.CUSTOM.5.pre
Last active July 11, 2024 10:08
Directadmin OpenLiteSpeed WordPress Hardening
###
# File: /usr/local/directadmin/data/templates/custom/cust_openlitespeed.CUSTOM.5.pre
###
# block all access to wordpress xmlrpc.php and wp-trackback.php file
RewriteRule ^/(wp-config|wp-config-sample|xmlrpc|wp-trackback)\.php - [F,L,NC]
# Patch for CVE-2023-40000
# https://wpscan.com/vulnerability/dd9054cc-1259-427d-a4ad-1875b7b2b3b4/
@hosni
hosni / ghcr.yaml
Last active December 16, 2023 11:23
name: Build Image
on:
push:
pull_request:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
permissions:
@hosni
hosni / yes-no.sh
Created September 24, 2023 20:30
Want to ask Yes/No question in shell?
read -r YN
YN=$(printf '%s' "$YN" | tr '[:upper:]' '[:lower:]')
case "$YN" in
y | yes )
;;
* )
exit 1
;;
esac
@hosni
hosni / fix-postgress-duplicate-key-error.php
Created September 17, 2023 20:01
Postgres: Unique violation: 7 ERROR: duplicate key value violates unique constraint
// Get all the tables from your database
$tables = \DB::select('SELECT table_name FROM information_schema.tables WHERE table_schema = \'public\' ORDER BY table_name;');
// Set the tables in the database you would like to ignore
$ignores = array('admin_setting', 'model_has_permissions', 'model_has_roles', 'password_resets', 'role_has_permissions', 'sessions');
//loop through the tables
foreach ($tables as $table) {
// if the table is not to be ignored then:
@hosni
hosni / list_gcp_iprange.sh
Created March 30, 2023 22:24 — forked from n0531m/list_gcp_iprange.sh
Google Cloud Platform : ip address range
#!/bin/bash
# https://cloud.google.com/compute/docs/faq#find_ip_range
# nslookup -q=TXT _cloud-netblocks.googleusercontent.com 8.8.8.8
myarray=()
for LINE in `dig txt _cloud-netblocks.googleusercontent.com +short | tr " " "\n" | grep include | cut -f 2 -d :`
do
myarray+=($LINE)
for LINE2 in `dig txt $LINE +short | tr " " "\n" | grep include | cut -f 2 -d :`
@hosni
hosni / ssh-using-socks5-proxy
Created November 13, 2022 17:36
ssh using socks5 proxy
We need to use ProxyCommand option of ssh client like this:
`ProxyCommand /usr/bin/nc -x SOCKS5_PROXY_HOST:SOCKS5_PROXY_PORT %h %p`
The ssh command is something like this:
ssh SSH_USER@SSH_HOST -o "ProxyCommand /usr/bin/nc -x SOCKS5_PROXY_HOST:SOCKS5_PROXY_PORT %h %p"
for example:
ssh -T [email protected] -o "ProxyCommand /usr/bin/nc -x 127.0.0.1:9050 %h %p"
@hosni
hosni / curl_time.bash
Created January 30, 2022 07:45
A function to measure the request time to a server, put it in your .zshrc or .bashrc
curl_time() {
curl -so /dev/null -w "\
namelookup: %{time_namelookup}s\n\
connect: %{time_connect}s\n\
appconnect: %{time_appconnect}s\n\
pretransfer: %{time_pretransfer}s\n\
redirect: %{time_redirect}s\n\
starttransfer: %{time_starttransfer}s\n\
-------------------------\n\
total: %{time_total}s\n" "$@"
#!/bin/bash
################################
# OS X Install ISO Creater #
# #
# Author: shela #
################################
#######################################
# Declarations
@hosni
hosni / aria.sh
Created September 21, 2021 19:34 — forked from amrza/aria.sh
Download List of files with aria2
#!/bin/sh
aria2c --dir=./ --input-file=urls.txt --max-concurrent-downloads=1 --connect-timeout=60 --max-connection-per-server=16 --split=16 --min-split-size=1M --human-readable=true --download-result=full --file-allocation=none
date
# Now create this file in the same directory and paste all urls in it: urls.txt
@hosni
hosni / KeyGenerateCommand.php
Last active September 13, 2021 07:40
key:generate command for lumen application
<?php
namespace App\Console\Commands;
use RuntimeException;
use Illuminate\Console\Command;
use Illuminate\Console\ConfirmableTrait;
class KeyGenerateCommand extends Command
{