6/1/22

Django add robots.txt

All sites on the internet must have a robots.txt file to tell search engines what they should do with your site.

Default robots.txt structure:

 
User-agent: *
Allow: /

To create such files in the Django app all you need is just add them to the templates folder and update the ulrs.py file.

from django.views.generic.base import TemplateView path("robots.txt",TemplateView.as_view(template_name="robots.txt", content_type="text/plain")),

After that you can test your robots.txt file: 

http://127.0.0.1:8000/robots.txt

5/31/22

Django set up environment variables

 

1. Install Django Environ

pip install django-environ

2. Import environ in settings.py

import environ
env = environ.Env()
environ.Env.read_env()

3. Initialise environ

create a file .env in the same directory as settings.py

4. Create your .env file

SECRET_KEY=gF7zFqX6KOolQuI4EWVfghVIgAfMyCOc
DATABASE_NAME=postgresdatabase
DATABASE_USER=admin
DATABASE_PASS=supersecretpassword

5. Replace all references in settings.py

SECRET_KEY = env(‘SECRET_KEY’)
...

DATABASES = {
‘default’: {
‘ENGINE’: ‘django.db.backends.mysql’,
‘NAME’: env(‘DATABASE_NAME’),
‘USER’: env(‘DATABASE_USER’),
‘PASSWORD’: env(‘DATABASE_PASS’),
}
}

2/1/22

Pi-Hole Ubuntu Server




# Preparation


To find what is using port 53 you can do: 
sudo lsof -i -P -n | grep LISTEN

Stop and disable systemd-resolved service:

systemctl disable systemd-resolved.service
systemctl stop systemd-resolved

Edit resolv.conf
sudo nano /etc/resolv.conf
nameserver 8.8.8.8

# Install

wget https://raw.githubusercontent.com/pi-hole/docker-pi-hole/master/docker_run.sh
chmod +x docker_run.sh
./docker_run.sh

# Add Block Lists (from https://firebog.net/)

Group Management -> Addlists

https://raw.githubusercontent.com/PolishFiltersTeam/KADhosts/master/KADhosts.txt
https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Spam/hosts
https://v.firebog.net/hosts/static/w3kbl.txt
https://adaway.org/hosts.txt
https://v.firebog.net/hosts/AdguardDNS.txt
https://v.firebog.net/hosts/Admiral.txt
https://raw.githubusercontent.com/anudeepND/blacklist/master/adservers.txt
https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt
https://v.firebog.net/hosts/Easylist.txt
https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext
https://raw.githubusercontent.com/FadeMind/hosts.extras/master/UncheckyAds/hosts
https://raw.githubusercontent.com/bigdargon/hostsVN/master/hosts
https://v.firebog.net/hosts/Easyprivacy.txt
https://v.firebog.net/hosts/Prigent-Ads.txt
https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.2o7Net/hosts
https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt
https://hostfiles.frogeye.fr/firstparty-trackers-hosts.txt
https://raw.githubusercontent.com/Zelo72/rpi/master/pihole/blocklists/kees1958.txt
https://raw.githubusercontent.com/DandelionSprout/adfilt/master/Alternate%20versions%20Anti-Malware%20List/AntiMalwareHosts.txt
https://osint.digitalside.it/Threat-Intel/lists/latestdomains.txt
https://s3.amazonaws.com/lists.disconnect.me/simple_malvertising.txt
https://v.firebog.net/hosts/Prigent-Crypto.txt
https://bitbucket.org/ethanr/dns-blacklists/raw/8575c9f96e5b4a1308f2f12394abd86d0927a4a0/bad_lists/Mandiant_APT1_Report_Appendix_D.txt
https://phishing.army/download/phishing_army_blocklist_extended.txt
https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-malware.txt
https://raw.githubusercontent.com/Spam404/lists/master/main-blacklist.txt
https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Risk/hosts
https://urlhaus.abuse.ch/downloads/hostfile/

10/26/21

How to install macOS from a USB

# Preparation

## Get list all the mounted devices available in your system

diskutil list

## Use the following syntax to format the drive:

diskutil erasedisk FILE_SYSTEM DISK_NAME DISK_IDENTIFIER


The file system option depends on your preference. 
The syntax is:.
  • macOS Extended Journaled(JHFS+) - JHFS+
  • macOS Extended (HFS+) - HFS+
  • MS-DOS FAT - FAT32
  • ExFAT - ExFAT

# Download macOS

# Copy on USB
## Run in terminal

Big Sur
sudo /Applications/Install\ macOS\ Big\ Sur.app/Contents/Resources/createinstallmedia --volume /Volumes/MyVolume

Catalina
sudo /Applications/Install\ macOS\ Catalina.app/Contents/Resources/createinstallmedia --volume /Volumes/MyVolume

Mojave
sudo /Applications/Install\ macOS\ Mojave.app/Contents/Resources/createinstallmedia --volume /Volumes/MyVolume

High Sierra
sudo /Applications/Install\ macOS\ High\ Sierra.app/Contents/Resources/createinstallmedia --volume /Volumes/MyVolume

El Capitan
sudo /Applications/Install\ OS\ X\ El\ Capitan.app/Contents/Resources/createinstallmedia --volume /Volumes/MyVolume --applicationpath /Applications/Install\ OS\ X\ El\ Capitan.app


# Restart
To install from USB you need to restart your laptop and hold the "Option" key.


1/18/21

Update docker compose to latest version

 Get the latest version docker-compose from https://github.com/docker/compose/releases


export LATEST_COMPOSE="1.28.0-rc3"

wget https://github.com/docker/compose/releases/download/$LATEST_COMPOSE/docker-compose-`uname -s`-`uname -m`

cp docker-compose-`uname -s`-`uname -m` /usr/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

6/25/20

Install TensorFlow on Jetson Xavier




Installing Dependencies

sudo apt update
sudo apt install libhdf5-serial-dev hdf5-tools libhdf5-dev zlib1g-dev zip libjpeg8-dev liblapack-dev libblas-dev gfortran

sudo apt install python3-dev 
sudo apt install python3-pip
sudo pip3 install -U pip testresources setuptools

sudo pip3 install -U numpy==1.16.1 future==0.17.1 mock==3.0.5 h5py==2.9.0 keras_preprocessing==1.0.5 keras_applications==1.0.8 gast==0.2.2 futures protobuf pybind11


Installing TensorFlow

sudo pip3 install --pre --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v44 tensorflow

sudo pip3 install --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v42 tensorflow-gpu

4/22/20

Install and Deploy Kubernetes on Ubuntu


# Install Docker

sudo apt-get -y remove docker docker-engine docker.io containerd runc
sudo apt-get -y update
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get -y update
sudo apt-get -y install docker-ce docker-ce-cli containerd.io
sudo usermod -a -G docker $USER


# Install Kubernetes

sudo apt-get update && sudo apt-get install -y apt-transport-https
sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl kubernetes-cni

# Disable swap memory

sudo swapoff -a

# Initialize Kubernetes

sudo kubeadm init --pod-network-cidr=192.168.0.0/16

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

# Join Nodes

kubeadm join 192.168.0.10:6443 --token e8dzsm.gtyjl7vlyljn3xyd \
--discovery-token-ca-cert-hash sha256:d6ad7ec4f706b394b0a01b6cba229ab100bc903fdaa33463482e28df5fc28e97

# Get List of Nodes

sudo kubectl get nodes

3/6/20

Kubernetes TLS certificate errors


Error:
Unable to connect to the server: x509: certificate signed by unknown authority

Fix:
unset KUBECONFIG
export KUBECONFIG=/etc/kubernetes/admin.conf

mv  $HOME/.kube $HOME/.kube.bak
mkdir $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

Sudo without password in Ubuntu/Debian



sudo visudo
user ALL=(ALL) NOPASSWD:ALL

3/5/20

MacOS Connect to KVM

Install:
brew tap jeffreywildman/homebrew-virt-manager
brew install virt-manager virt-viewer libvirt

Fix error (g-io-error-quark: Error opening file /usr/local/Cellar/libosinfo/1.7.1/share/libosinfo/pci.ids: No such file or directory (1)):

mkdir -p /usr/local/Cellar/libosinfo/1.7.1/share/libosinfo/
cd /usr/local/Cellar/libosinfo/1.7.1/share/libosinfo/
wget https://pci-ids.ucw.cz/v2.2/pci.ids
wget http://www.linux-usb.org/usb.ids

Copy ssh key:
ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]_address

Connect:
virt-manager -c 'qemu+ssh://[email protected]_address/system?socket=/var/run/libvirt/libvirt-sock'