Skip to content

Instantly share code, notes, and snippets.

View serverok's full-sized avatar
🎯
Focusing

Yujin Boby serverok

🎯
Focusing
View GitHub Profile
@serverok
serverok / gist:712b85432d188f16c9d32e44455b419a
Created October 25, 2024 20:45
netplan bridge network config
before
root@ns5028044:~# cat /etc/netplan/50-cloud-init.yaml
network:
version: 2
ethernets:
eno1np0:
match:
macaddress: "9c:6b:00:3f:4f:f9"
addresses:
@serverok
serverok / gist:03d39aa0fcdabb24ac4df0e8006a7477
Created September 8, 2024 07:03
PHP function to identify Mobile Users
function is_mobile()
{
if (empty($_SERVER["HTTP_USER_AGENT"])) {
return false;
}
return @preg_match("/(android|webos|avantgo|iphone|ipad|ipod|blackberry|iemobile|bolt|boost|cricket|docomo|fone|hiptop|mini|opera mini|kitkat|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", ''.$_SERVER["HTTP_USER_AGENT"]);
}
function is_iphone()
{
@serverok
serverok / gist:a6c084d6b6a11a674c93dd2b89bf46bf
Created September 8, 2024 06:59
PHP function to find visitor IP
function find_user_ip()
{
foreach (array('HTTP_CF_CONNECTING_IP', 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key) {
if (array_key_exists($key, $_SERVER) && !empty($_SERVER[$key])) {
foreach (@explode(',', ''.$_SERVER[$key]) as $ip) {
$ip = trim($ip);
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false) {
return $ip;
}
}
@serverok
serverok / gist:2043ad4e171127387f0eb3d8aaabcc55
Last active September 7, 2024 10:54
Server to Server File Transfer with PHP script
<?php
# Author: ServerOK
# Web: https://serverok.in/server-to-server-file-transfer-with-php-script
# URL of the file to be downloaded
$source_url = 'https://example.com/backup.zip';
$filename = basename(parse_url($source_url, PHP_URL_PATH));
$destination_path = __DIR__ . '/' . $filename;
Reaplce YOUR-DOMAIN.EXT with you actual domain or subdomain. Point domain to server IP by editing DNS.
To create a new wordpress site, create a dirctory
/var/www/YOUR-DOMAIN.EXT/public_html
Upload wordpress files inside.
Create nginx config
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<title>Under Construction</title>
<style>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<title>Under Construction</title>
<style>
# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;
# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
@serverok
serverok / nomachine.sh
Created April 8, 2024 16:33
install nomachine on ubuntu
#!/bin/bash
sudo apt update
sudo apt install xfce4 -y
wget https://download.nomachine.com/download/8.11/Linux/nomachine_8.11.3_4_amd64.deb
sudo dpkg -i nomachine_8.11.3_4_amd64.deb
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
sudo apt update
sudo apt install google-chrome-stable
curl 'https://www.fastcartapp.com/sitemap.xml' \
-H 'authority: www.fastcartapp.com' \
-H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' \
-H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8,it;q=0.7' \
-H 'cache-control: no-cache' \
-H 'cookie: secure_customer_sig=; localization=US; cart_currency=USD; _y=fd18e78d-a7a3-4d81-ace9-39e698a4a91c; _s=6fab5005-349f-4347-be62-63ca8f3503f3; _shopify_y=fd18e78d-a7a3-4d81-ace9-39e698a4a91c; _shopify_s=6fab5005-349f-4347-be62-63ca8f3503f3' \
-H 'pragma: no-cache' \
-H 'sec-ch-ua: "Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"' \
-H 'sec-ch-ua-mobile: ?1' \
-H 'sec-ch-ua-platform: "Android"' \