This website makes use of technical and anonymized analytical cookies, for more info read the full Privacy and Cookies Policy.
WordPress – Plugin to manage robots.txt
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/
Linux: get UPS remaining battery time
If you have a UPS connected to your Linux box maybe you need some simple way to get how much power is left in the batteries, i’ve written a simple tool to get this information (note: you need Nut to be installed, configured and running).
#!/bin/bash
# device to check using "nut" utilities
UPSDEV="usbups@localhost"
# chars to be added at the end of output
CHARS=" | "
# displays battery remaining %
# echo "$( LANG= upsc $UPSDEV | grep battery.charge: | awk '{print $2}' )${CHARS}"
#displays battery time remaining, or "infinite" if battery is not discharging
STS=$(LANG= upsc $UPSDEV | grep ups.status: | awk '{print $2}' | grep -i DISCHRG )
SEC=$(LANG= upsc $UPSDEV | grep battery.runtime: | awk '{print $2}' )
if [ "$STS" = "" ]; then
echo "∞${CHARS}"
else
echo "$(date -d@$SEC -u +%Hh:%Mm)${CHARS}"
fi
I saved (and set as executable) the script in /usr/local/bin/ups-status and then i used the script as source information for xfce4–genmon-plugin to have data visible in my main Xfce panel.
Just a final note: do not forget to customize the code according to you needing (set ups identification in UPSDEV, set extra text to be displayed in CHARS and comment/decomment code to get the info you want – battery % or battery time – )
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 a color of your choice between red, orange and white.
Application can be downloaded from Google Play Store: https://play.google.com/store/apps/details?id=net.airaghi.walkinglight&hl=en
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 mote functionalities: 1) get the list of every module available on the system, 2) get the list of every module enabled, 3) check if a module has been enabled or not, 4) enable one or more modules and 5) disable one or more module.
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 :
1 2 3 4 |
NBURL=$( wget https://builds.apache.org/view/Incubator%20Projects/job/incubator-netbeans-linux/lastSuccessfulBuild/artifact/nbbuild/ -qO- | grep -o -e "NetBeans-dev-incubator-netbeans-linux-.*-on-.*-release.zip\"" | sed -es/\"$// ) [ "$NBURL" != "" ] && wget -nc https://builds.apache.org/view/Incubator%20Projects/job/incubator-netbeans-linux/lastSuccessfulBuild/artifact/nbbuild/$NBURL -O ./netbeans-latest.zip |
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 the latest tree hosted on GitHub.
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354#!/bin/shoDIR=$( pwd )oIFS=$IFSIFS=$'\n'for BATTERY in $( find /sys -name "BAT*" -type d 2>/dev/null );docd $BATTERYPRESENT=$( grep 1 present 2>/dev/null)if [ "$PRESENT" != "" ]; thenPRESENT="Yes"elsePRESENT="No"fiMODEL="$(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 ""doneIFS=$oIFScd $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 interface.
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 this tool you only have to execute the script, wait for it to finish and the upgrade Gradle using the packages created.