Dipak Documentation

website·Indexed 32 days ago

https://docs.dipak.tech/

Searchable website documentation for Dipak from https://docs.dipak.tech/.

Tokens
15.7K
Snippets
132
Records
148
Agent score
60%

What's inside Dipak Documentation

  1. Query PostgreSQL server activity and users

    Use SQL statements to retrieve detailed information about server users and active connections.
    -- List users and their attributes (superuser, create database)
    SELECT usename AS role_name,
      CASE
         WHEN usesuper AND usecreatedb THEN
    	   CAST('superuser, create database' AS pg_catalog.text)
         WHEN usesuper THEN
    	    CAST('superuser' AS pg_catalog.text)
         WHEN usecreatedb THEN
    	    CAST('create database' AS pg_catalog.text)
         ELSE
    	    CAST('' AS pg_catalog.text)
      END role_attributes
    FROM pg_catalog.pg_user
    ORDER BY role_name desc;
    
    -- Check active connections to the PostgreSQL server
    select pid as process_id,
           usename as username,
           datname as database_name,
           client_addr as client_address,
           application_name,
           backend_start,
           state,
           state_change
    from pg_stat_activity;
  2. Build Cloudflared agent from source for mips64 architecture

    Since Cloudflare does not provide a binary for mips64 architecture (used in devices like UniFi Edge Routers), you must build the agent from source. This process involves cloning the repository, cross-compiling for Linux mips64, and manually installing the binary and configuration on the target router. Note that firmware upgrades on the router will remove the binary, requiring a re-installation.
    # 1. Build the binary on a development machine
    git clone https://github.com/cloudflare/cloudflared.git
    cd cloudflared
    GOOS=linux GOARCH=mips64 go build github.com/cloudflare/cloudflared/cmd/cloudflared
    
    # 2. Transfer to router
    scp cloudflared [router_username]@[router_ip]:/tmp/
    
    # 3. Install on router via SSH
    ssh [router_username]@[router_ip]
    cd /tmp
    sudo chown root:root cloudflared
    sudo chmod +x cloudflared
    sudo mv cloudflared /usr/bin/
    
    # 4. Configure and Start
    sudo mkdir /etc/cloudflared
    sudo vi /etc/cloudflared/config.yml
    # Add to config.yml:
    # proxy-dns: true
    # proxy-dns-upstream:
    #   - https://1.1.1.1/dns-query
    #   - https://1.0.0.1/dns-query
    # proxy-dns-port: 8853
    
    sudo /usr/bin/cloudflared service install [token-from-cloudflare]
  3. Reset Portainer admin password for Docker Swarm

    If Portainer is running as a stack or service on Docker Swarm, scale the service to zero before running the password reset helper to ensure the data volume is not in use.
    # 1. Scale the Portainer service to zero
    docker service scale portainer_portainer=0
    
    # 2. Run the reset helper using the service's data volume
    docker run --rm -v portainer_portainer_data:/data portainer/helper-reset-password
    
    # 3. Scale the service back to 1
    docker service scale portainer_portainer=1
  4. Perform extended cleanup of Rancher 2.x including network interfaces and iptables

    For a deep clean of a node previously running Rancher, use an extended cleanup approach. This involves unmounting kubelet paths, deleting CNI network interfaces, and optionally flushing iptables rules.

    Warning: This process is destructive. Backup your data before proceeding. To flush iptables, pass the flush argument to the script.

    #!/bin/bash
    # Usage: ./extended-cleanup-rancher2.sh [flush]
    
    # Remove all docker resources
    docker rm -f $(docker ps -qa)
    docker rmi -f $(docker images -q)
    docker volume rm $(docker volume ls -q)
    
    # Unmount kubelet and rancher paths
    for mount in $(mount | grep '/var/lib/kubelet' | awk '{ print $3 }') /var/lib/kubelet /var/lib/rancher; do 
      umount $mount
    done
    
    # Remove system directories
    cleanupdirs="/etc/ceph /etc/cni /etc/kubernetes /opt/cni /opt/rke /run/secrets/kubernetes.io /run/calico /run/flannel /var/lib/calico /var/lib/etcd /var/lib/cni /var/lib/kubelet /var/lib/rancher/rke/log /var/log/containers /var/log/pods /var/run/calico"
    for dir in $cleanupdirs; do
      rm -rf $dir
    done
    
    # Delete network interfaces
    cleanupinterfaces="flannel.1 cni0 tunl0"
    for interface in $cleanupinterfaces; do
      ip link delete $interface
    done
    
    # Optional: Flush iptables
    if [ "$1" = "flush" ]; then
      iptables -F -t nat
      iptables -X -t nat
      iptables -F -t mangle
      iptables -X -t mangle
      iptables -F
      iptables -X
      service docker restart
    fi
  5. Install and enable QEMU Guest Agent on Debian/Ubuntu

    To enable communication between the host and the guest VM, install the qemu-guest-agent package and manage its lifecycle using systemctl. This allows the host to perform tasks like graceful shutdowns and freezing the filesystem for backups.
    # Install the package
    apt -y install qemu-guest-agent
    
    # Enable the service to start on boot
    systemctl enable qemu-guest-agent
    
    # Start the service immediately
    systemctl start qemu-guest-agent
    
    # Verify the service is running
    systemctl status qemu-guest-agent
  6. Create and apply an Access Control List (ACL) on Cisco/FS switches

    Access lists control network traffic by specifying which IP addresses are permitted or denied. This process requires a terminal emulator (like PuTTY) and SSH access to the switch.
    # 1. Enter privileged mode
    enable
    
    # 2. Enter global configuration mode
    configure terminal
    
    # 3. Create a standard access list
    ip access-list standard my-access-list
    
    # 4. Add entries (Permit/Deny)
    permit host 192.168.1.10
    deny host 192.168.1.20
    # Deny a range using wildcard mask (e.g., 10.10.10.1/29)
    deny 10.10.10.1 0.0.0.7
    
    # 5. Apply to an interface (e.g., GigabitEthernet 0/1)
    interface GigabitEthernet 0/1
    ip access-group my-access-list in
    exit
    
    # 6. Save changes
    exit
    write memory
    # OR
    copy running-config startup-config
  7. Manage macOS Dock position on multiple monitors

    In multi-monitor setups, the macOS Dock may jump between screens. This is a built-in feature: you can move the Dock to a specific monitor by moving the mouse cursor to the center of that screen and continuing to move it downward against the bottom edge for 2-4 seconds.

    Alternatively, you can prevent the Dock from moving by disabling 'Displays have separate Spaces' in Mission Control settings, though this removes the ability to have independent desktops/spaces for each monitor.

  8. Convert a PEM key to an RSA private key

    Convert a certificate in PEM format (Base64 encoded ASCII files containing BEGIN/END statements) to an RSA private key using OpenSSL.
    openssl rsa -in key.pem -out id_rsa
  9. Manage Docker as a non-root user

    To run Docker commands without using sudo, add your user to the docker group. Note that the docker group grants privileges equivalent to the root user. After running these commands, log out and log back in for the changes to take effect.
    sudo groupadd docker
    sudo usermod -aG docker $USER