diff --git a/LEMP.md b/LEMP.md deleted file mode 100644 index 9e1a136..0000000 --- a/LEMP.md +++ /dev/null @@ -1,272 +0,0 @@ -# Fedora Super-LEMP setup: - -*Based on https://www.howtoforge.com/how-to-install-nginx-with-php-and-mariadb-lemp-stack-on-fedora-32/* - -## Install packages - -### Massive swiss-army knife setup -``` -dnf install certbot certbot-nginx cockpit htop iftop iptraf nano openssh-server net-tools nginx* rsync screen vim wget && dnf groupinstall "Development Tools" "Web Server" "Mysql" "php" -``` -### Or Less Extra - -`dnf install certbot certbot-nginx nginx ` - -`dnf install vim nano rsync screen vim wget net-tools htop iftop iptraf openssh-server bash-completion` - -`dnf groupinstall "Development Tools" "Web Server" "Mysql" "php"` - - -### More butter Rocky variant - -`dnf install epel-release` - -`dnf install git vim nano rsync screen vim wget net-tools htop iftop iptraf openssh-server bash-completion mariadb mariadb-server certbot python3-certbot-nginx nginx php-fpm` - -`dnf groupinstall "Development Tools"` - -## Add non-root administrator - -`adduser user` - -`usermod -aG wheel user` - -`passwd user` - -`vi /etc/sudoers` - -`sudo -i -u user` - -## Configure SSH - -`ssh-keygen -t rsa -b 4096` - -### Change port and root login settings - -`vi /etc/ssh/sshd_config` - -### Add keys ( also see `ssh-copy-id` ) - -`vi .ssh/authorized_keys` - -## Firewall settings - -``` -systemctl enable firewalld -systemctl start firewalld -systemctl stop firewalld -systemctl restart firewalld -firewall-cmd --state -firewall-cmd --set-default-zone=public -firewall-cmd --zone=public --permanent --list-services -firewall-cmd --zone=public --permanent --add-service=http -firewall-cmd --zone=public --permanent --add-service=https -firewall-cmd --add-port 20022/tcp -firewall-cmd --permanent --add-port 20022/tcp -firewall-cmd --permanent --add-port YOUR_PORT_HERE/tcp -firewall-cmd --remove-service ssh --permanent -firewall-cmd --reload -systemctl reload firewalld - -``` - -## MariaDB -``` -systemctl enable mariadb -systemctl start mariadb -mysql_secure_installation # Y-N-Y-Y-Y-Y -mysql -u root -p -CREATE USER 'user1'@localhost IDENTIFIED BY 'password1'; -CREATE USER 'namenode'@localhost IDENTIFIED BY ':passwd'; -GRANT ALL PRIVILEGES ON *.* TO 'user1'@localhost IDENTIFIED BY 'password1'; -GRANT ALL PRIVILEGES ON *.* TO 'user2'@localhost IDENTIFIED BY 'passwd2'; -FLUSH PRIVILEGES; -SHOW GRANTS FOR 'user1'@localhost; -SHOW GRANTS FOR 'user2'@localhost; -CREATE DATABASE 'yourDB'; -SHOW DATABASES; -DROP USER 'user1'@localhost; # Just for example to show how to delete a user -``` - -## Redis Setup - -`dnf install redis php-redis` - -`sudo systemctl enable --now redis` - -`vi /etc/redis/redis.conf` - -Change bind (0.0.0.0), `requirepass`, `port (2*)`, `maxmemory` (256mb), and `maxmemory-policy allkeys-lru`. - -`systemctl restart redis` - -``` -firewall-cmd --zone=public --permanent --add-port=26379/tcp -firewall-cmd --reload -``` - -## NGINX - -### Important working directories: -``` -/usr/share/nginx/ - -/etc/nginx/ - -``` -### Create user working directory for custom configuration files: -``` -mkdir /etc/nginx/sites-available # Create a directory for nginx.conf files - -mkdir /usr/share/nginx/example.com/html -p # Create new webroot with specified structure -``` - -### Now we can create a new config file to start with: - -`vi /etc/nginx/sites-available/example.com.conf` - - -### Link it to active conf directory - -`ln -s /etc/nginx/sites-available/example.com.conf /etc/nginx/conf.d/` - -### If it is required at some point, removing that symlink is as easy as: - -`rm /etc/nginx/conf.d/example.com.conf` - - -### Now we edit the nginx.conf - -`vi /etc/nginx/nginx.conf` - - -### Set the following lines after the line "include /etc/nginx/conf.d/*.conf" (if not already set): -``` -server_names_hash_bucket_size 64; # Should already exist in recent versions - -types_hash_max_size 4096; ## Should already be set - -``` -### Comment out the root location directive (Can uncomment after setup so as not to confuse cache while testing?) - -**To test and reload the configuration:** - -`nginx -t` -`systemctl reload nginx` - -### Simple recap moving forward: -``` -systemctl start nginx -systemctl restart nginx -systemctl enable nginx -systemctl status nginx -systemctl reload nginx -nginx -t -mkdir /etc/nginx/sites-available -mkdir /usr/share/nginx/example.com/html -p -vi /etc/nginx/sites-available/example.com.conf -ln -s /etc/nginx/sites-available/example.com.conf /etc/nginx/conf.d/ -vi /etc/nginx/nginx.com # comment out the root in default server block (troubleshooting) -systemctl reload nginx -``` - -## PHP-FPM setup - -### Change user in configuration (nginx): - -`vi /etc/php-fpm.d/www.conf` - -`systemctl enable php-fpm` - -`systemctl restart php-fpm` - -### PHP-OPCache setup - -`vi /etc/php.d/10-opcache.ini` - -``` -opcache.enable_cli=1 -opcache.memory_consumption=128 -opcache.interned_strings_buffer=8 -opcache.max_accelerated_files=4000 -opcache.revalidate_freq=60 -``` - -`systemctl restart php-fpm` - -`systemctl reload nginx` - -### phpMyAdmin setup - -`dnf install phpmyadmin ` - -`ln -s /usr/share/phpMyAdmin/ /usr/share/nginx/hosting.namenode.xyz/dbpma` - -`chown -R nginx:nginx /var/lib/php/session` - -`chown -R nginx:nginx /var/lib/phpMyAdmin` - -`chown -R nginx:nginx /etc/phpMyAdmin` - -`vi /etc/phpMyAdmin/config.inc.php` - -``` -$cfg['Servers'][$i]['AllowNoPassword'] = false; -$cfg['Servers'][$i]['AllowRoot'] = false; - -$cfg['TempDir'] = '/var/lib/phpMyAdmin/temp'; - -``` -`systemctl reload php-fpm` - -`systemctl reload nginx` - - -### Securing phpMyAdmin further -``` -vi pass-infile ## make a password for openssl to encrypt - one line no spaces -``` -``` -openssl passwd -in pass-infile ## Copy the output (your encrypted password) -``` -``` -vi /etc/nginx/pma_pass # Create a user/pass pair for the authentication gateway. -``` -### Format: -``` -user:p@s$w0Rd # one line -``` -### Add the required "dbpma" section - -`vi /etc/nginx/sites-available/example.com.conf` - -`systemctl reload nginx` - -[Install and secure PMA with NGINX Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-phpmyadmin-with-nginx-on-an-ubuntu-18-04-server) - - -## Cockpit Setup - -`vi /etc/cockpit/cockpit.conf` - -`vi /etc/nginx/sites-available/example.com.conf` - -[Proxying Cockpit over NGINX](https://github.com/cockpit-project/cockpit/wiki/Proxying-Cockpit-over-nginx) - -[Reverse proxy Cockpit over NGINX](https://www.freesoftwareservers.com/display/FREES/Reverse+Proxy+Cockpit+over+NGinX) - - -## Certbot setup (Examples) -``` -certbot --nginx -d example.com -d www.example.com - -certbot --nginx --agree-tos -d example.com -d www.example.com --email your-email-address - -certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --must-staple -d example.com -d www.example.com --email your-email-address -``` - -`$ EDITOR=vim crontab -e` - -``` -25 2 * * 0 /usr/bin/certbot renew --quiet # Every Sunday 2:25am -``` diff --git a/README.md b/README.md index e0a220f..8e75c9d 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ #### ***A compendium of various technical information.*** ## Cheat Sheets +- [AWK]((https://git.namenode.xyz/CSnap/cheetsheetz/src/branch/main/awk.md) +- [AWKWARD- AWK and SED examples](https://git.namenode.xyz/CSnap/cheetsheetz/src/branch/main/awkward.md)) - [BASH - The Bourne Again Shell](https://git.namenode.xyz/CSnap/cheetsheetz/src/branch/main/BASH.md) - [CSS - Cascading Style Sheets](https://git.namenode.xyz/CSnap/cheetsheetz/src/branch/main/CSS.md) - [HTML - The HyperText Markup Language](https://git.namenode.xyz/CSnap/cheetsheetz/src/branch/main/HTML.md) @@ -12,6 +14,7 @@ - [Perl - Practical Extraction and Reporting Language](https://git.namenode.xyz/CSnap/cheetsheetz/src/branch/main/perl.md) - [PHP - Proper Hypertext Pre-processor](https://git.namenode.xyz/CSnap/cheetsheetz/src/branch/main/PHP.md) - [Python - High-level, general-purpose programming language](https://git.namenode.xyz/CSnap/cheetsheetz/src/branch/main/python.md) +- [SED - The Stream Editor](- [AWK]((https://git.namenode.xyz/CSnap/cheetsheetz/src/branch/main/sed.md)) - [SQL - Structured Query Language](https://git.namenode.xyz/CSnap/cheetsheetz/src/branch/main/SQL.md) ## Guides diff --git a/awk.md b/awk.md new file mode 100644 index 0000000..7971f2e --- /dev/null +++ b/awk.md @@ -0,0 +1,158 @@ + +# AWK Cheat Sheet + +## Table of Contents + +1. [AWK Basics](#awk-basics) +2. [Patterns and Actions](#patterns-and-actions) +3. [Variables](#variables) +4. [Operators](#operators) +5. [Built-in Variables](#built-in-variables) +6. [Control Structures](#control-structures) +7. [Functions](#functions) +8. [Text Processing](#text-processing) +9. [Regular Expressions](#regular-expressions) +10. [Arrays](#arrays) +11. [User-Defined Functions](#user-defined-functions) +12. [Command Execution](#command-execution) + +## AWK Basics + +### Print Lines + +```awk +awk '{print}' filename +``` + +### Print Specific Column + +```awk +awk '{print $2}' filename +``` + +### Filter with Condition + +```awk +awk '$1 > 10 {print}' filename +``` + +## Patterns and Actions + +```awk +# Pattern with Action +pattern1 { action1 } +pattern2 { action2 } +``` + +## Variables + +```awk +# Assigning Variables +variable = value + +# Accessing Variables +print variable +``` + +## Operators + +```awk +# Arithmetic Operators ++, -, *, /, % + +# Relational Operators +==, !=, >, <, >=, <= + +# Logical Operators +&&, || +``` + +## Built-in Variables + +```awk +# NR: Record Number +NR > 1 {print "Line Number: " NR} + +# NF: Number of Fields +{print "Number of Fields: " NF} +``` + +## Control Structures + +```awk +# if Statement +if (condition) { + # Commands +} + +# if-else Statement +if (condition) { + # Commands for true condition +} else { + # Commands for false condition +} +``` + +## Functions + +```awk +# Built-in Functions +{ + result = sqrt(9) + print "Square Root: " result +} +``` + +## Text Processing + +### Field Separator + +```awk +# Change Field Separator +awk -F',' '{print $2}' filename +``` + +### Output Formatting + +```awk +# Formatting Output +awk '{printf "Name: %-10s Age: %d\n", $1, $2}' filename +``` + +## Regular Expressions + +```awk +# Match Pattern +awk '/pattern/ {print}' filename +``` + +## Arrays + +```awk +# Declare an Array +array[1] = "apple" +array[2] = "banana" + +# Access Array Element +print array[1] +``` + +## User-Defined Functions + +```awk +# Define a Function +function my_function(parameter) { + # Commands +} + +# Call the Function +my_function(value) +``` + +## Command Execution + +```awk +# Execute Command +awk '{cmd = "echo " $1; system(cmd)}' filename +``` + diff --git a/awkward.md b/awkward.md new file mode 100644 index 0000000..db762aa --- /dev/null +++ b/awkward.md @@ -0,0 +1,700 @@ +# AWK and SED Examples + +These examples explore the combined use of AWK and SED for text processing tasks. + +## Example 1: AWK and SED for Text Transformation + +### Input File (input.txt) + +``` +John Doe,25,Engineer +Jane Smith,30,Designer +Bob Johnson,22,Developer +``` + +### Goal + +We want to transform the CSV data into a formatted table with headers. + +### Solution + +```bash +awk -F',' '{printf "%-15s %-3s %-10s\n", $1, $2, $3}' input.txt | sed '1i\ +Name Age Job\ +--------------- --- ----------' +``` + +### Output + +``` +Name Age Job +--------------- --- ---------- +John Doe 25 Engineer +Jane Smith 30 Designer +Bob Johnson 22 Developer +``` + +## Example 2: AWK and SED for Selective Printing + +### Input File (input.txt) + +``` +apple +banana +cherry +date +``` + +### Goal + +Print lines containing "a" or "e" using AWK and SED. + +### Solution + +```bash +awk '/a|e/' input.txt | sed -n '/a\|e/p' +``` + +### Output + +``` +apple +banana +date +``` + +## Example 3: AWK and SED for Filtering and Sorting + +### Input File (input.txt) + +``` +apple,5 +banana,2 +cherry,8 +date,1 +``` + +### Goal + +Filter lines with the second column greater than 2, sort by the second column, and add a header. + +### Solution + +```bash +awk -F',' '$2 > 2' input.txt | sort -t',' -k2n | sed '1i\ +Fruit,Quantity' +``` + +### Output + +``` +Fruit,Quantity +apple,5 +cherry,8 +``` + +## Example 4: AWK and SED for Text Extraction + +### Input File (input.txt) + +``` +Lorem ipsum dolor sit amet, consectetur adipiscing elit. +Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. +Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris. +``` + +### Goal + +Extract sentences containing the word "sed" and replace "sed" with "AWK". + +### Solution + +```bash +awk 'BEGIN{RS="\\."} /sed/' input.txt | sed 's/sed/AWK/g' +``` + +### Output + +``` +Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua +``` + +## Example 5: AWK and SED for HTML Tag Extraction + +### Input File (input.html) + +```html +
This is a paragraph.
+ Visit our website +