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” utilitiesUPSDEV=”usbups@localhost”# chars to be …
Category Archives: Programming
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> |
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”
MultiCopy: copy a file to multiple destinations
Often i have to copy manually a single file into many destination directories (or files), so i decided to create a command line tool to do help me in doing this task: Multicopy (mcp). The program can be used as show below: mcp <src_file> <directory_1> <directory_2> … <directory_n> copy file <src_file> into the given directories …
Continue reading “MultiCopy: copy a file to multiple destinations”
Manage D-Link DCS-960L motion detection using rfid tokens
After having presented RFIDer and after having show you a simple shell script to control motion detecion of a D-Link DCS-960L, i want to describe how to merge those two programs in order to enable/disable motion detection using rfid tokens and a rfid reader. As usually i’m using a RaspberryPI as a central unit.
WP-Disk-Free: WordPress free disk space checker
To monitor free disk space on a server hosting a WordPress website i created a new plugin, a sort of clone of the unix command df, called WP-Disk-Free. This plugin allow you to: define in the Settings page minimum free disk space (MB) to use as a warning quota receive an email, sent to a …
Continue reading “WP-Disk-Free: WordPress free disk space checker”
Send images from RaspberryPI to Google Drive
After having shown a simple way on how to create a “birdwatching station” using a RaspberryPi (see this post, in italian) i am now presenting you how to send images to Google Drive.