Skip to content

Instantly share code, notes, and snippets.

@NanoDano
NanoDano / openfire_create_user.py
Created April 9, 2021 22:44
Use Openfire REST API to create a user
"""
Create a user on the Openfire XMPP server
Enable REST API by logging into admin portal (e.g. https://xmpp.devdungeon.com:9090) and go to `Plugins` and then `Available Plugins`. Enable the `REST API`.
Then go to `Server | Server Settings | REST API` and change it to `Enabled`.
Choose `Secret key auth` option and store that key.
(http 9090, https 9091)
POST https://example.org:9091/plugins/restapi/v1/users
@NanoDano
NanoDano / cpanel_create_email.py
Last active June 16, 2024 20:45
Create email account using cPanel API in Python
from requests import get # pip install requests
"""
Examples:
Docs:
- Create email (add_pop): https://documentation.cpanel.net/display/DD/UAPI+Functions+-+Email%3A%3Aadd_pop
- Delete email (delete_pop): https://documentation.cpanel.net/display/DD/UAPI+Functions+-+Email%3A%3Adelete_pop
- Change pass (passwd_pop): https://documentation.cpanel.net/display/DD/UAPI+Functions+-+Email%3A%3Apasswd_pop
@NanoDano
NanoDano / mount-smb.sh
Created March 22, 2021 06:58
Mount SMB Drive in Debian Linux
#!/usr/bin/bash
sudo apt install -y cifs-utils
# `uid` and `gid` is the local Linux user and group you want to mount as
# `user` and `password` are the SMB drive credentials. Wrap password with quotes if necessary.
sudo mount -t cifs -o uid=dano,gid=sudo,user=dano,password="my password" \\\\10.0.0.99\\home /mnt
@NanoDano
NanoDano / 99_dano_grub_colors
Created March 9, 2021 04:29
My custom config file to set GRUB menu colors
#!/bin/sh
# Requires executable bit
# Move to `/etc/grub.d/99_dano_grub_colors`
# and run `sudo update-grub`
echo "set menu_color_normal=light-cyan/dark-gray"
echo "set menu_color_highlight=dark-gray/light-cyan"
echo "set color_normal=white/black"
echo "set color_highlight=black/white"
# To change image, update `/etc/default/grub` with the image path
@NanoDano
NanoDano / serve_gz_files.php
Created August 6, 2020 01:36
PHP list & serve gzipped files from dir
<?php
/**
* Given a directory full of gzipped AVI files,
* outpu a JSON array with the list of zipped video files in the dir.
*
* If a GET query param is provided for `file` then that specific
* file is returned, uncompressed, with the .gz extension removed
*/
if (isset($_GET['file'])) {
@NanoDano
NanoDano / http_download.py
Created August 3, 2020 06:39
Download a file with Python requests
import requests # pip install requests
# Adapted from answer at: https://stackoverflow.com/questions/16694907/download-large-file-in-python-with-requests
def download(url, filepath):
with requests.get(url, stream=True) as response:
response.raise_for_status()
with open(filepath, 'wb') as output_file:
for chunk in response.iter_content(chunk_size=8192):
# If you have chunk encoded response, then uncomment
# the `if` statement and set chunk_size parameter to `None`.
@NanoDano
NanoDano / nssm_create_service.bat
Created August 3, 2020 03:48
Create Windows Service with Non-Sucking Service Manager NSSM
REM http://nssm.cc
nssm.exe install "MyCustomService" "C:\Users\nanodano\venv\Scripts\python.exe" "C:\Users\nanodano\myscript.py"
nssm.exe start MyCustomService
nssm.exe stop MyCustomService
nssm.exe remove "MyCustomService"
@NanoDano
NanoDano / waitress-serve-local.sh
Created August 3, 2020 03:45
Run a Python WSGI app with waitress-serve command-line
# pip install waitress
waitress-serve --listen=127.0.0.1:8001 my_wsgi_project:app --url-prefix=/my-app
@NanoDano
NanoDano / waitress-serve.py
Created August 3, 2020 03:45
Run a Python WSGI app with Waitress
# pip install waitress
import os
from waitress import serve
from my_wsgi_project import app # Import your app
# Run from the same directory as this script
this_files_dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(this_files_dir)
# `url_prefix` is optional, but useful if you are serving app on a sub-dir
@NanoDano
NanoDano / open-firewall-port.sh
Created August 3, 2020 03:43
Open Firewall port in Fedora/CentOS/RedHat with firewall-cmd
# Open a TCP port
firewall-cmd --add-port=8009/tcp --permanent
firewall-cmd --reload
# Inspect current rules and zones
firewall-cmd --list-all
firewall-cmd --list-ports
firewall-cmd --list-services
firewall-cmd --list-all-zones