First Commit
This commit is contained in:
@@ -0,0 +1,368 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../config/init.php';
|
||||
|
||||
$raw_json = <<<'JSON'
|
||||
[
|
||||
{
|
||||
"title": "Login Egguburt",
|
||||
"description": "Login details",
|
||||
"codes": [
|
||||
{
|
||||
"sub_title": "Eggburt",
|
||||
"code": "I want to Admin Positive Servers!"
|
||||
},
|
||||
{
|
||||
"sub_title": "Timpani",
|
||||
"code": "I want to administer Timpani."
|
||||
},
|
||||
{
|
||||
"sub_title": "## How to connect in Timpani ##",
|
||||
"code": "From Eggburt: ssh timpani@timpops\r\nPassword: 99flak3\r\ntimpss 'servername'"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Varnish",
|
||||
"description": "Varnish collection of commands",
|
||||
"codes": [
|
||||
{
|
||||
"sub_title": "Varnish Domain Clean Cache",
|
||||
"code": "varnishadm \"ban req.http.host ~ DOMAIN\""
|
||||
},
|
||||
{
|
||||
"sub_title": "Check the varnish syntax command:",
|
||||
"code": "varnishd -C -f /etc/varnish/default.vcl"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Find Spam IP",
|
||||
"description": "findspam commands",
|
||||
"codes": [
|
||||
{
|
||||
"sub_title": "Spam in fw-a",
|
||||
"code": "tail -n3000 /var/log/nginx/access.log | awk '{print $1}' | sort -nr | uniq -c | sort -nr | head -n15"
|
||||
},
|
||||
{
|
||||
"sub_title": "Spam in Home Dir",
|
||||
"code": "tail -n3000 /home/*/logs/*access*log | awk '{print $1}' | sort -nr | uniq -c | sort -nr | head -n15"
|
||||
},
|
||||
{
|
||||
"sub_title": "Spam in App (apache2)",
|
||||
"code": "tail -n3000 /var/log/apache2/access.log | awk '{print $1}' | sort -nr | uniq -c | sort -nr | head -n15"
|
||||
},
|
||||
{
|
||||
"sub_title": "Check all kind of logs in nginx",
|
||||
"code": "tail -n3000 /var/log/nginx/*access*log* | awk '{print $1}' | sort -nr | uniq -c | sort -nr | head -n15"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Clean Disks Space",
|
||||
"description": "Cleaning Diskspaces for each kind of VMs",
|
||||
"codes": [
|
||||
{
|
||||
"sub_title": "## Usually for App VM ##",
|
||||
"code": "apt clean; journalctl --vacuum-size=8M; logrotate -vf /etc/logrotate.d/rsyslog; logrotate -vf /etc/logrotate.d/apache2; logrotate -vf /etc/logrotate.d/nginx; logrotate -vf /etc/logrotate.d/varnish;"
|
||||
},
|
||||
{
|
||||
"sub_title": "## Usually for firewall VM ##",
|
||||
"code": "apt clean; journalctl --vacuum-size=8M; logrotate -vf /etc/logrotate.d/rsyslog; logrotate -vf /etc/logrotate.d/nginx; logrotate -vf /etc/logrotate.d/varnish;"
|
||||
},
|
||||
{
|
||||
"sub_title": "## PHP ##",
|
||||
"code": "logrotate -vf /etc/logrotate.d/php5.6-fpm; logrotate -vf /etc/logrotate.d/php7.3-fpm; logrotate -vf /etc/logrotate.d/php7.4-fpm; logrotate -vf /etc/logrotate.d/php8.1-fpm; logrotate -vf /etc/logrotate.d/php8.2-fpm;"
|
||||
},
|
||||
{
|
||||
"sub_title": "## ONLY BASIC ##",
|
||||
"code": "apt clean; journalctl --vacuum-size=8M; logrotate -vf /etc/logrotate.d/rsyslog;"
|
||||
},
|
||||
{
|
||||
"sub_title": "VM + only apache2",
|
||||
"code": "apt clean; journalctl --vacuum-size=8M; logrotate -vf /etc/logrotate.d/rsyslog; logrotate -vf /etc/logrotate.d/apache2;"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Add findspam Script",
|
||||
"description": "This is the findspam from the repository.",
|
||||
"codes": [
|
||||
{
|
||||
"sub_title": "Command:",
|
||||
"code": "apt install -y jq; echo \"\" && echo \"Checking the reachability of the server...\"; ping -c 2 -W 2 scripts.svm.picl.co.uk > /dev/null 2>&1 && echo \"Server reachable. Proceeding with script update.\" || { echo \"Server unreachable. Update canceled.\"; exit 1; }; for i in updatebspamscripts findspam blockspamip spamwhat nobanip unblockspams; do echo \"Updating script $i...\"; curl -s -o /usr/local/sbin/$i https://scripts.svm.picl.co.uk/scripts/$i.sh && chmod 700 /usr/local/sbin/$i && echo \"Script '$i' updated.\" || echo \"Error updating script '$i'.\"; done"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Create New Database",
|
||||
"description": "Command to create new database and database use",
|
||||
"codes": [
|
||||
{
|
||||
"sub_title": "## Create Databases ##",
|
||||
"code": "CREATE DATABASE unixuser;"
|
||||
},
|
||||
{
|
||||
"sub_title": "# Create User For DB #",
|
||||
"code": "grant all privileges on `unixuser`.* to `unixuser`@'%' identified by 'password database';"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Rsync From Server to the other",
|
||||
"description": "Command to rsync between the servers",
|
||||
"codes": [
|
||||
{
|
||||
"sub_title": "## Rsync Command ##",
|
||||
"code": "rsync -avzP /home/user/public_html/ [email protected]:/home/user/public_html/"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "WP-CLI Commands",
|
||||
"description": "Usefully commands for wp-cli. Note that you need to change \"from-website\" and \"to-website\" with the correct domain.",
|
||||
"codes": [
|
||||
{
|
||||
"sub_title": "## Export DB ##",
|
||||
"code": "wp db export"
|
||||
},
|
||||
{
|
||||
"sub_title": "## Change Links for wordpress ##",
|
||||
"code": "wp search-replace 'from-website.Com' 'to-website.com' --all-tables"
|
||||
},
|
||||
{
|
||||
"sub_title": "Add New User (change the '###*' strings with the correct informations)",
|
||||
"code": "wp user create ###USERNAME ###EMAIL@DOMAIN --role=administrator --user_pass=\"###PASSWORD\""
|
||||
},
|
||||
{
|
||||
"sub_title": "Install WP-CLI (Use this as root user)",
|
||||
"code": "curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar; chmod +x wp-cli.phar; sudo mv wp-cli.phar /usr/local/bin/wp"
|
||||
},
|
||||
{
|
||||
"sub_title": "Install varnish-cache plugin:",
|
||||
"code": "wp plugin install varnish-http-purge\r\nwp plugin activate varnish-http-purge"
|
||||
},
|
||||
{
|
||||
"sub_title": "Configuration to add in wp-config.php for the cache plugin",
|
||||
"code": "define('VHP_VARNISH_IP','varnish-vip:6081');"
|
||||
},
|
||||
{
|
||||
"sub_title": "(Run as Root) Checksums verify WP CLI on all /home folders",
|
||||
"code": "for u in /home/*; do user=$(basename \"$u\"); for d in httpdocs public_html; do if [ -d \"$u/$d\" ] && [ -f \"$u/$d/wp-config.php\" ]; then echo \"=== $user ($d) ===\"; sudo -u \"$user\" -H wp --path=\"$u/$d\" core verify-checksums; echo; fi; done; done"
|
||||
},
|
||||
{
|
||||
"sub_title": "verify checksum for a single website",
|
||||
"code": "wp core verify-checksums"
|
||||
},
|
||||
{
|
||||
"sub_title": "restore corefiles",
|
||||
"code": "wp core download --version=$(wp core version) --force"
|
||||
},
|
||||
{
|
||||
"sub_title": "Create posops user",
|
||||
"code": "wp user create posops [email protected] --role=administrator --user_pass='P3dsfj7nYLaMxxXk'"
|
||||
},
|
||||
{
|
||||
"sub_title": "Cambiare la password di un utente",
|
||||
"code": "wp user update posops --user_pass='P3dsfj7nYLaMxxXk'"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Find Killig Process Error",
|
||||
"description": "Command to check what has been killed in the VMs / Machine",
|
||||
"codes": [
|
||||
{
|
||||
"sub_title": "## How to check errors ##",
|
||||
"code": "grep -E '(reaper|oom)' /var/log/syslog"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Generate SSH Key",
|
||||
"description": "Command to generate ssh key",
|
||||
"codes": [
|
||||
{
|
||||
"sub_title": "## ED25519 ##",
|
||||
"code": "ssh-keygen -t ed25519"
|
||||
},
|
||||
{
|
||||
"sub_title": "## RSA ##",
|
||||
"code": "ssh-keygen -t rsa -b 4096"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "User Basic Auth",
|
||||
"description": "How to create / add user for the basicauth.",
|
||||
"codes": [
|
||||
{
|
||||
"sub_title": "## CREATE A FILE / USER (cancel existing one) ##",
|
||||
"code": "htpasswd -c /etc/nginx/.htpasswd-name nuovo_utente"
|
||||
},
|
||||
{
|
||||
"sub_title": "## ADD EXTRA USER ##",
|
||||
"code": "htpasswd /etc/nginx/.htpasswd-name username"
|
||||
},
|
||||
{
|
||||
"sub_title": "Block to add",
|
||||
"code": "auth_basic \"Restricted Access\";\r\n auth_basic_user_file /etc/nginx/.htpasswd;"
|
||||
},
|
||||
{
|
||||
"sub_title": "Ownership and privileges",
|
||||
"code": "htpassloc=\"etc/nginx/.htpasswd\";\r\nchown www-data:www-data $htpassloc;\r\nchmod 644 $htpassloc"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Check DB Size",
|
||||
"description": "Command to check the dimension of the databases; (needs to be specified the databases names)",
|
||||
"codes": [
|
||||
{
|
||||
"sub_title": "## CHECK DB SIZE ##",
|
||||
"code": "SELECT table_schema AS \"Database\", ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS \"Dimension (MB)\" FROM information_schema.tables WHERE table_schema IN (\"dbname1 \", \"dbname2\", \"dbname3\", \"dbname4\") GROUP BY table_schema;"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Remove Files and keep the newest one",
|
||||
"description": "Change the variable keep in base to how much newest file you need to keep!",
|
||||
"codes": [
|
||||
{
|
||||
"sub_title": "## REMOVE OLDEST FILES CODE ##",
|
||||
"code": "count=0; keep=4; echo \"### FILE THAT WILL BE REMOVED: ###\"; echo \"-------------------------------\"; for i in $(ls -t); do if [ $count -lt $keep ]; then echo \"Keeping: $i\"; else echo \"Removing $i\"; fi; ((count++)); done; echo \"-------------------------------\"; echo \"Do you wish to continue?\"; echo \"y - Yes\"; echo \"default - no\"; read check; check=${check,,}; if [ \"$check\" == \"y\" ]; then echo \"#### REMOVING FILE ####\"; echo \"-------------------------------\"; count=0; for i in $(ls -t); do if [ $count -lt $keep ]; then echo \"Keeping: $i\"; else echo \"Removed $i\"; rm \"$i\"; fi; ((count++)); done; echo \"-------------------------------\"; else echo \"Not Removed\"; fi\r\n"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Add Diskspace Command",
|
||||
"description": "After increased the diskspace of the hard disk on proxmox, we can run this command to add the 100% of the diskspace to the root partition.",
|
||||
"codes": [
|
||||
{
|
||||
"sub_title": "Command:",
|
||||
"code": "parted /dev/vda resizepart 1 100%; pvresize /dev/vda1; lvextend -l +100%FREE /dev/vgmain/root; resize2fs /dev/vgmain/root"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "New Certboot Certificate",
|
||||
"description": "Install new certboot Certificate",
|
||||
"codes": [
|
||||
{
|
||||
"sub_title": "Command:",
|
||||
"code": "certbot certonly --webroot -w /var/www/html -d ###DOMAIN"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Extract pfx key",
|
||||
"description": "Use this command to extract the key and the pem files from a .pfx file.\r\nChange the variables before to run the command.",
|
||||
"codes": [
|
||||
{
|
||||
"sub_title": "Command:",
|
||||
"code": "PFX=\"FILE_NAME\";\r\nPASS=\"PASSWORD_PFX\";\r\nopenssl pkcs12 -in \"$PFX\" -passin pass:\"$PASS\" -nocerts -nodes -out server.key && \\\r\nopenssl pkcs12 -in \"$PFX\" -passin pass:\"$PASS\" -nokeys | \\\r\nsed -n '/BEGIN CERTIFICATE/,/END CERTIFICATE/p' > fullchain.pem\r\n"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "check if the ssh-key is valid",
|
||||
"description": "With this command we can check if a ssh key is valid or not",
|
||||
"codes": [
|
||||
{
|
||||
"sub_title": "Command:",
|
||||
"code": "FILENAME=\"path/to/the/file\";\r\nssh-keygen -l -f $FILENAME;\r\n"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "checking valid rules for studiorep-fw",
|
||||
"description": "This command is checking which of the following rules has been accepted for the php-rules",
|
||||
"codes": [
|
||||
{
|
||||
"sub_title": "Command:",
|
||||
"code": "php-fpm8.3 -tt 2>&1 | grep -A50 \"\\[POOL_NAME\\]\""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Add new VM to spa",
|
||||
"description": "Use this to add the new element to the spa command. Specify the Public IP, the port and the hostname",
|
||||
"codes": [
|
||||
{
|
||||
"sub_title": "Command:",
|
||||
"code": "sudoedit /home/posops/ansible/hosts"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "PHP-FPM Scripts",
|
||||
"description": "Script Collection for PHP-FPM",
|
||||
"codes": [
|
||||
{
|
||||
"sub_title": "Restarting all php-fpm existing",
|
||||
"code": "for i in /etc/php/*; do version=$(basename \"$i\"); service=\"php${version}-fpm\"; if systemctl list-units --type=service --all | grep -q \"$service\"; then echo \"[ $service ]\"; systemctl restart \"$service\"; systemctl status \"$service\" | grep Active; fi; done"
|
||||
},
|
||||
{
|
||||
"sub_title": "Check the php-version for the vhost",
|
||||
"code": "VERSION=8.3; for i in *; do socket=$(grep -oP 'SetHandler\\s+\"proxy:unix:\\K[^|\"]+' \"$i\"); if [ -n \"$socket\" ]; then domain=$(basename \"$socket\" .sock); match=$(grep -iRl \"$domain\" /etc/php/*/fpm/pool.d/); if [ -n \"$match\" ]; then phpver=$(echo \"$match\" | sed -n 's|/etc/php/\\([^/]*\\)/fpm/.*|\\1|p' | sort -u); if echo \"$phpver\" | grep -q \"^$VERSION$\"; then echo \"[ $domain ]\"; echo \"php-fpm $phpver\"; fi; fi; fi; done"
|
||||
},
|
||||
{
|
||||
"sub_title": "Check the php-version for the vhost",
|
||||
"code": "exver=\"7.4\" instver=\"8.4\" ; for i in $(dpkg -l *php* | awk '{print $2}' | grep $exver); do apt install php$instver${i:6} -y; done"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "ownership to 755 folder and 644 files",
|
||||
"description": "Changing the ownership from 755 to the folders and 644 to the files (sub-directories included) with find + xarg in the current director.",
|
||||
"codes": [
|
||||
{
|
||||
"sub_title": "Command",
|
||||
"code": "find . -type d -print0 | xargs -0 chmod 755;\r\nfind . -type f -print0 | xargs -0 chmod 644"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
JSON;
|
||||
|
||||
$legacy_data = json_decode($raw_json, true);
|
||||
|
||||
if (!is_array($legacy_data)) {
|
||||
echo "ERROR: Failed to decode legacy JSON: " . json_last_error_msg() . "\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$bn_id = 'bn_positive_internet';
|
||||
$new_bn = [
|
||||
'id' => $bn_id,
|
||||
'title' => 'Positive Internet',
|
||||
'username' => 'admin',
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
'notes' => []
|
||||
];
|
||||
|
||||
foreach ($legacy_data as $n_idx => $legacy_note) {
|
||||
$note_id = 'note_' . ($n_idx + 1) . '_' . uniqid();
|
||||
$subnotes = [];
|
||||
|
||||
if (isset($legacy_note['codes']) && is_array($legacy_note['codes'])) {
|
||||
foreach ($legacy_note['codes'] as $s_idx => $legacy_code) {
|
||||
$subnotes[] = [
|
||||
'id' => 'sub_' . ($s_idx + 1) . '_' . uniqid(),
|
||||
'title' => $legacy_code['sub_title'] ?? 'Comando',
|
||||
'type' => 'command',
|
||||
'content' => $legacy_code['code'] ?? ''
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$new_bn['notes'][] = [
|
||||
'id' => $note_id,
|
||||
'title' => $legacy_note['title'] ?? 'Nota',
|
||||
'description' => $legacy_note['description'] ?? '',
|
||||
'subnotes' => $subnotes
|
||||
];
|
||||
}
|
||||
|
||||
save_blocknote($new_bn);
|
||||
echo "SUCCESS! Converted and saved Positive Internet blocknote with " . count($new_bn['notes']) . " notes.\n";
|
||||
Reference in New Issue
Block a user