To have a simple and quick management tool to edit robots.txt in a WordPress website i realized this plugin that allows you to: add extra content to default robots.txt totally overwrite default robots.txt Plugin can be download from https://www.wordpress.org/plugins/robots-txt-quick-editor/
Category Archives: Software
Walking Light
Walking in low light situations it may be necessary to make yourself more visible, for this reason a flashing light (with a color of your choice between 3 shades) can be really useful With “Walking Light” you have at your disposal a simple and intuitive tool that allows you to have a flashing light in …
openSuse: Apache modules management from shell
To manage Apache Httpd on openSuse we have the classic command a2enmod, shared with many other distros, which allows to: 1) know if a module is enabled, 2) enable a module and 3) disable a module. To extend what already present in a2enmod i have written a simple wrapper to a2enmod in order to have …
Continue reading “openSuse: Apache modules management from shell”
Apache Netbeans for Linux: get latest build
After having seen how to build Apache Netbeans on a Linux box here you can find how to get the latest build (no more compiling!) from Apache servers. It’a all in a couple of shell commands :
Apache NetBeans – building and installation
NetBeans is now an Apache Foundation project, but (as of today) we lost the possibility to download a specific release (Java only, PHP, C/C++, …), the standard version available (release 9+) is only built with Java support. I have created a very simple script that build Apache NetBeans including support for various programming languages (PHP included), getting sources from …
Continue reading “Apache NetBeans – building and installation”
PHP – file encryption/decryption
To have some sort of privacy while sending/receiving messages (or files) using encryption is the first choice. Below you can find a very simple PHP web application that allows you to encrypt/decrypt a file using your web browser (and a web server hosting the page).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
<?php $ALGORITHM = 'AES-128-CBC'; $IV = '12dasdq3g5b2434b'; $error = ''; if (isset($_POST) && isset($_POST['action'])) { $password = isset($_POST['password']) && $_POST['password']!='' ? $_POST['password'] : null; $action = isset($_POST['action']) && in_array($_POST['action'],array('c','d')) ? $_POST['action'] : null; $file = isset($_FILES) && isset($_FILES['file']) && $_FILES['file']['error'] == UPLOAD_ERR_OK ? $_FILES['file'] : null; if ($password === null) { $error .= 'Invalid Password<br>'; } if ($action === null) { $error .= 'Invalid Action<br>'; } if ($file === null) { $error .= 'Errors occurred while elaborating the file<br>'; } if ($error === '') { $contenuto = ''; $nomefile = ''; $contenuto = file_get_contents($file['tmp_name']); $filename = $file['name']; switch ($action) { case 'c': $contenuto = openssl_encrypt($contenuto, $ALGORITHM, $password, 0, $IV); $filename = $filename . '.crypto'; break; case 'd': $contenuto = openssl_decrypt($contenuto, $ALGORITHM, $password, 0, $IV); $filename = preg_replace('#\.crypto$#','',$filename); break; } if ($contenuto === false) { $error .= 'Errors occurred while encrypting/decrypting the file '; } if ($error === '') { header("Pragma: public"); header("Pragma: no-cache"); header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); header("Cache-Control: post-check=0, pre-check=0", false); header("Expires: 0"); header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"" . $filename . "\";"); $size = strlen($contenuto); header("Content-Length: " . $size); echo $contenuto; die; } } } ?> <html> <head> <title>Encrypt/Decrypt file</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"> </head> <body> <div class="container"> <div class="row"> <div class="col-12" > <h1>Utility to encrypt/decrypt a file</h1> </div> </div> <?php if ($error != '') { ?> <div class="row"> <div class="col-12 alert alert-danger" role="alert"> <?php echo ($error); ?> </div> </div> <?php } ?> <form class="form" enctype="multipart/form-data" method="post" id="form1" name="form1" auto-complete="off"> <div class="form-row"> <div class="form-group"> <label for="file">File</label> <input type="file" name="file" id="file" placeholder="Choose a file" required class="form-control-file"/> </div> </div> <div class="form-row"> <div class="form-group"> <label for="password">Password</label> <input type="password" name="password" id="password" placeholder="Insert password" required class="form-control" /> </div> </div> <div class="form-row"> <div class="form-group"> <label for="action">Action</label> <select name="action" id="action" required class="form-control"> <option value="">-- Choose --</option> <option value="c">Encrypt</option> <option value="d">Decrypt</option> </select> </div> </div> <div class="form-row"> <button type="submit" class="btn btn-primary" onclick="setTimeout('document.form1.reset();',1000)">Execute</button> <button type="reset" class="btn btn-reset">Reset</button> </div> </form> </div> <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script> <script type="text/javascript" src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.bundle.min.js"></script> </body> </html> |
Linux: get info about notebook battery
Below you can find a very simple shell script that gets information about every battery present in your notebook and shows a summary. create a new file (es: /usr/local/bin/battery.sh) paste inside the new file the following code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
#!/bin/sh oDIR=$( pwd ) oIFS=$IFS IFS=$'\n' for BATTERY in $( find /sys -name "BAT*" -type d 2>/dev/null ); do cd $BATTERY PRESENT=$( grep 1 present 2>/dev/null) if [ "$PRESENT" != "" ]; then PRESENT="Yes" else PRESENT="No" fi MODEL="$(cat manufacturer 2>/dev/null) $(cat model_name 2>/dev/null) $(cat technology 2>/dev/null)" SERIAL=$(cat serial_number 2>/dev/null | sed -es/\ //g) [ "$SERIAL" != "" ] && MODEL="$MODEL - s/n: $SERIAL" CYCLES=$( cat cycle_count 2>/dev/null ) [ "$CYCLES" = "" ] && CYCLES="N.A." STATUS=$( cat status 2>/dev/null ) [ "$STATUS" = "" ] && STATUS="N.A." CAPACITY=$( cat capacity_level 2>/dev/null) [ "$CAPACITY" = "" ] && CAPACITY="N.A." CAPACITY_PCT=$( cat capacity 2>/dev/null) [ "$CAPACITY_PCT" != "" ] && CAPACITY="${CAPACITY_PCT}% - $CAPACITY" ENERGY=$( cat energy_full 2>/dev/null ) [ "$ENERGY" = "" ] && ENERGY="N.A." ENERGY_DESIGN=$( cat energy_full_design 2>/dev/null ) [ "$ENERGY_DESIGN" = "" ] && ENERGY_DESIGN="N.A." [[ "$ENERGY_DESIGN" != "N.A." && "$ENERGY" != "N.A." ]] && ENERGY=$(( 100*$ENERGY/$ENERGY_DESIGN )) VOLTAGE=$( cat voltage_now 2>/dev/null ) [ "$VOLTAGE" = "" ] && VOLTAGE="N.A." [ "$VOLTAGE" != "N.A." ] && VOLTAGE="$( echo $VOLTAGE | head -c2).$( echo $VOLTAGE | head -c4 | tail -c2)" VOLTAGE_MIN=$( cat voltage_min_design 2>/dev/null ) [ "$VOLTAGE_MIN" = "" ] && VOLTAGE_MIN="N.A." [ "$VOLTAGE_MIN" != "N.A." ] && VOLTAGE_MIN="$( echo $VOLTAGE_MIN | head -c2).$( echo $VOLTAGE_MIN | head -c4 | tail -c2)" echo "Battery $(basename $BATTERY)" echo "- Model: $MODEL" echo "- Present: $PRESENT" echo "- Status: $STATUS" echo "- Capacity: $CAPACITY" [[ "$CYCLES" != "N.A." && "$CYCLES" != "0" ]] && echo "- Cycles: $CYCLES" [[ "$ENERGY" != "N.A." ]] && echo "- Max Energy: ${ENERGY}% of original" echo "- Voltage: $VOLTAGE (Original min: $VOLTAGE_MIN)" echo "" done IFS=$oIFS cd $oDIR |
save the file make the file executable (es: chmod +x /usr/local/bin/battery.sh) use the script (from a terminal execute: /usr/local/bin/battery.sh) …
Automatic Wpa Supplicant restart
If wifi connection used by your Linux box is not stable and goes up&down, with wpa_supplicant requiring some manual restart you could use a simple script that does it for you. Below you can find a script i’m using on a RaspberryPi 3 with Raspian installed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#!/bin/sh WLAN=wlan0 DEAD=$(service wpa_supplicant status 2>/dev/null | grep -i dead) YESIP=$( ip addr show $WLAN | grep "inet\b" | awk '{print $2}' | cut -d/ -f1 ) CMD=$( ps -eo args | grep wpa_suppl | grep -v grep ) if [ "$YESIP" == "" ]; then DEAD="DEAD" else ping 8.8.8.8 -c 5 >/dev/null 2>/dev/null if [ "$?" != "0" ]; then DEAD="DEAD" else DEAD="" fi fi if [ "$DEAD" != "" ]; then pkill -9 wpa_supplicant $CMD & fi |
Remember to use a value for WLAN corresponding to you wifi …
Slackware: keep Gradle up-to-date
Using AndroidStudio to develop mobile apps requires you to always have an updated installation of Gradle, doing so on a Slackware system could lead to quite a lot of manual work. To help me in the process i created a small tool that on its own downloads and makes a Gradle Slackware package (thanks to these SlackBuilds). To use …
Linux: change temporary directory for Android Studio
Using Android Studio the directory used by the system to store temporary files (the default one is /tmp) could be filled by many (big) files, in order to limit this behaviour you can choose another directory to be used by the IDE. To do so you could launch the IDE every time with the following commands (in …
Continue reading “Linux: change temporary directory for Android Studio”