initial commit

This commit is contained in:
2026-01-17 09:10:20 +00:00
commit 3a845bf532
23 changed files with 1816 additions and 0 deletions

45
legacy/auto-org.sh Executable file
View File

@@ -0,0 +1,45 @@
#!/bin/bash
TL_DIR="/home/zaine/master-folder/org_files/todo"
MASTER_TL="/home/zaine/master-folder/org_files/todo/master-tl.org"
# Determine the weekly file
WEEKLY_FILE="$TL_DIR/$(date +%Y)-week-$(date +%V).org"
# Ensure weekly file exists
if [[ ! -f "$WEEKLY_FILE" ]]; then
touch "$WEEKLY_FILE"
echo "Created new weekly todo file: $WEEKLY_FILE"
fi
inotifywait -m "$TL_DIR" -e create -e moved_to -e modify --format '%w%f' |
while read filepath; do
if [[ "$filepath" == "$MASTER_TL" || "$filepath" =~ ^.*\/\.goutputstream-.*$ || "$filepath" =~ ^.*\/\..* ]]; then
continue
fi
filename=$(basename "$filepath")
echo "Processing $filepath..."
# Ensure it's a valid, non-empty file
if [[ -f "$filepath" && -s "$filepath" ]]; then
TMP_FILE=$(mktemp)
{
echo "* START $filename *"
cat "$filepath"
echo "* END $filename *"
} > "$TMP_FILE"
# Remove old content for this file in `master-tl.org`
sed -i "/\* START $filename \*/,/\* END $filename \*/d" "$MASTER_TL"
# Append new content
cat "$TMP_FILE" >> "$MASTER_TL"
rm "$TMP_FILE"
echo "Updated master task list with $filename."
else
echo "Skipping empty or unreadable file: $filepath"
fi
done

38
legacy/crawler.py Normal file
View File

@@ -0,0 +1,38 @@
import requests
from bs4 import BeautifulSoup
from urllib.parse import urljoin, urlparse
import pandas as pd
# Starting URL
base_url = 'https://zainezq.com/'
visited = set()
to_visit = [base_url]
found_urls = []
def is_internal(link):
return urlparse(link).netloc == urlparse(base_url).netloc or urlparse(link).netloc == ''
while to_visit:
url = to_visit.pop(0)
if url in visited:
continue
try:
print(f'Crawling: {url}')
response = requests.get(url, timeout=10)
visited.add(url)
if response.status_code == 200:
soup = BeautifulSoup(response.text, 'html.parser')
found_urls.append(url)
for a_tag in soup.find_all('a', href=True):
href = a_tag['href']
full_url = urljoin(url, href.split('#')[0])
if is_internal(full_url) and full_url not in visited and full_url not in to_visit:
to_visit.append(full_url)
except Exception as e:
print(f'Error fetching {url}: {e}')
# Export to Excel
df = pd.DataFrame(found_urls, columns=["URL"])
df.to_excel("website_pages.xlsx", index=False)
print("✅ Sitemap saved to website_pages.xlsx")

89
legacy/fetch.py Normal file
View File

@@ -0,0 +1,89 @@
import json
import subprocess
# Function to fetch JSON data using curl
def fetch_json_data(curl_command):
try:
# Run the curl command and capture output
result = subprocess.run(curl_command, shell=True, capture_output=True, text=True)
if result.returncode != 0:
raise Exception(f"curl command failed: {result.stderr}")
# Parse the JSON output
return json.loads(result.stdout)
except json.JSONDecodeError as e:
print(f"Error parsing JSON: {e}")
return []
except Exception as e:
print(f"Error executing curl: {e}")
return []
# Function to clean and simplify container names
def clean_container_name(name):
# Remove leading slash and any suffixes like '-1' or '-<service>-1'
name = name.lstrip('/')
# Map container names to simplified service names
name_mapping = {
'nextcloud-app-1': 'nextcloud',
'pgadmin': 'pgadmin',
'code-server': 'code',
'glance': 'glance',
'stirling-pdf-stirling-pdf-1': 'pdf',
'technitium-dns': 'dns',
'portainer-portainer-1': 'portainer',
'browserfile-filebrowser-1': 'filebrowser',
'calibre-web': 'calibre',
'miniflux_db': 'miniflux-db', # Note: This is the DB container, may not need a link
'miniflux': 'miniflux',
'jupyterlab': 'jupyter'
}
return name_mapping.get(name, name)
# Function to generate links
def generate_links(data):
base_url = "zserver.zapto.org"
links = []
for container in data:
# Get the first name from the Names list
if container.get("Names"):
container_name = container["Names"][0]
service_name = clean_container_name(container_name)
# Skip internal services like miniflux_db that typically don't have public links
if service_name.endswith('-db'):
continue
# Check if the container has exposed ports
if container.get("Ports"):
for port in container["Ports"]:
# Only include containers with public ports (bound to 0.0.0.0 or ::)
if port.get("IP") in ["0.0.0.0", "::"] and port.get("PublicPort"):
link = f"{base_url}/{service_name}"
links.append({"Service": service_name.capitalize(), "Link": link})
break # Only need one public port per container
return links
# Main function
def main():
# Example curl command to fetch container data (adjust as needed)
# For Docker API, you might use: curl -s --unix-socket /var/run/docker.sock http://localhost/containers/json
# For Portainer, you might use: curl -s -H "Authorization: Bearer <token>" http://<portainer-host>/api/endpoints/<endpoint-id>/docker/containers/json
curl_command = 'curl -X GET "https://zserver.zapto.org/portainer/api/endpoints/2/docker/containers/json?all=true" -H "X-API-Key: ptr_KFQqKse9K4Nc9M5jnpc61fpAvGzdTOXTzswz9CwOF74=" -u "admin:shakkal123"'
# Fetch JSON data
data = fetch_json_data(curl_command)
if not data:
print("No data fetched or invalid JSON.")
return
# Generate links
links = generate_links(data)
# Print links in a table format
print("| Service | Link |")
print("|---------|------|")
for link in links:
print(f"| {link['Service']} | {link['Link']} |")
if __name__ == "__main__":
main()

90
legacy/insert_services.py Normal file
View File

@@ -0,0 +1,90 @@
import pyodbc
import subprocess
import re
from datetime import datetime
conn = pyodbc.connect(
'DRIVER={ODBC Driver 18 for SQL Server};'
'SERVER=localhost;'
'DATABASE=HomelabDB;'
'UID=sa;'
'PWD=Helloadmin123!;'
'Encrypt=no;'
)
cursor = conn.cursor()
output = subprocess.check_output(
["docker", "ps", "--format", "{{.Names}} {{.Ports}} {{.Status}}"]
)
lines = output.decode().splitlines()
for line in lines:
parts = line.split(" ", 2)
name = parts[0]
ports = parts[1] if len(parts) > 1 else ""
raw_status = parts[2] if len(parts) > 2 else "Unknown"
# Extract main status (Up, Exited, etc.)
status_match = re.search(r"\b(Up|Exited|Restarting|Paused|Created|Dead)\b", raw_status)
status = status_match.group(1) if status_match else "Unknown"
# Extract uptime text (e.g. "7 days", "2 hours", etc.)
uptime_match = re.search(r"(?:Up|Exited)\s+(.*?)(?:\s*\(|$)", raw_status)
uptime = uptime_match.group(1).strip() if uptime_match else None
# Extract health (inside parentheses like "(healthy)" or "(unhealthy)")
health_match = re.search(r"\((healthy|unhealthy)\)", raw_status, re.IGNORECASE)
health = health_match.group(1).lower() if health_match else "none"
# Get creation date from `docker inspect`
# Get creation date from `docker inspect`
try:
inspect_out = subprocess.check_output(
["docker", "inspect", "-f", "{{.Created}}", name]
)
created_str = inspect_out.decode().strip() # e.g. "2025-11-07T09:25:03.548912345Z"
# Normalize the timestamp (strip Z, keep only first 6 digits of microseconds)
created_str = created_str.rstrip("Z")
if "." in created_str:
created_str = re.sub(r"\.(\d+)", lambda m: "." + m.group(1)[:6], created_str)
created_dt = datetime.fromisoformat(created_str)
except Exception as e:
print(f"Warning: could not parse creation date for {name}: {e}")
created_dt = None
# Extract all port numbers
port_matches = re.findall(r"(\d+)->", ports)
if not port_matches:
port_matches = re.findall(r"(\d+)/tcp", ports)
if not port_matches:
cursor.execute("""
IF EXISTS (SELECT 1 FROM Services WHERE ServiceName = ? AND Port IS NULL)
UPDATE Services
SET Status = ?, HealthStatus = ?, Uptime = ?, InstalledAt = ?
WHERE ServiceName = ? AND Port IS NULL
ELSE
INSERT INTO Services (ServerID, ServiceName, Port, Status, HealthStatus, Uptime, InstalledAt)
VALUES (?, ?, ?, ?, ?, ?, ?)
""", (name, status, health, uptime, created_dt, name,
1, name, None, status, health, uptime, created_dt))
else:
for port in port_matches:
cursor.execute("""
IF EXISTS (SELECT 1 FROM Services WHERE ServiceName = ? AND Port = ?)
UPDATE Services
SET Status = ?, HealthStatus = ?, Uptime = ?, InstalledAt = ?
WHERE ServiceName = ? AND Port = ?
ELSE
INSERT INTO Services (ServerID, ServiceName, Port, Status, HealthStatus, Uptime, InstalledAt)
VALUES (?, ?, ?, ?, ?, ?, ?)
""", (name, int(port), status, health, uptime, created_dt,
name, int(port),
1, name, int(port), status, health, uptime, created_dt))
conn.commit()
conn.close()

17
legacy/move_rss.py Normal file
View File

@@ -0,0 +1,17 @@
import os
import shutil
# Define source and destination paths
downloads_path = os.path.join(os.path.expanduser('~'), 'Downloads', 'rss-feed.xml')
destination_path = '/home/zaine/Documents/projects/web-port/src/assets/rss-feed.xml'
# Check if the file exists in Downloads
if os.path.exists(downloads_path):
try:
# Move and overwrite the file
shutil.move(downloads_path, destination_path)
print(f"Successfully moved and overwrote: {destination_path}")
except Exception as e:
print(f"Error moving file: {e}")
else:
print("rss.xml not found in Downloads folder.")

26
legacy/pc_runner.sh Executable file
View File

@@ -0,0 +1,26 @@
#!/bin/bash
# Bash Script To Power On PC and SSH into it.
MAC_ADDRESS="00:d8:61:c5:e8:69"
USER="zaine"
IP="192.168.0.135"
echo "Hang tight..."
# Call wakeonlan and capture the output
OUTPUT=$(wakeonlan "$MAC_ADDRESS" 2>&1) # 2>&1 captures both stdout and stderr
echo "wakeonlan output: $OUTPUT"
# Analyze the output (simple example)
if [[ $OUTPUT == *"Sending magic packet"* ]]; then
echo "Wake-on-LAN packet sent successfully."
else
echo "Error sending magic packet or no response: $OUTPUT"
fi
# Sleep for 15 seconds so that the PC can wake up
sleep 45
echo "Attempting to SSH into $USER@$IP..."
# Start SSH and let it take over the terminal
ssh -X "$USER@$IP"

View File

@@ -0,0 +1,31 @@
#!/bin/bash
# Bash Script To Power On PC and SSH into it.
# AUTHOR: Zaine Qayyum
# replace with mac address of pc you want to ssh into
MAC_ADDRESS="xx:xx:xx:xx:xx:xx"
# replace with username of the pc you want to ssh into
USER=""
# replace with ip address of the pc you want to ssh into
IP="xxx.xxx.xxx.xxx"
echo "Hang tight..."
# Call wakeonlan and capture the output
OUTPUT=$(wakeonlan "$MAC_ADDRESS" 2>&1) # 2>&1 captures both stdout and stderr
echo "wakeonlan output: $OUTPUT"
# Ouput analysis, with if-else checks
if [[ $OUTPUT == *"Sending magic packet"* ]]; then
echo "Wake-on-LAN packet sent successfully."
else
echo "Error sending magic packet or no response: $OUTPUT"
fi
# Sleep for x seconds so that the PC can wake up
# Replace with the time it'll take for pc to boot, 15 sec is set as default
sleep 15
echo "Attempting to SSH into $USER@$IP..."
# Start SSH and let it take over the terminal
ssh -X "$USER@$IP"

BIN
legacy/website_pages.xlsx Normal file

Binary file not shown.