Skip to content

Instantly share code, notes, and snippets.

@bohwaz
bohwaz / dns_get_record_from.php
Last active May 6, 2024 19:50
PHP script to retrieve a DNS record from a custom nameserver
<?php
/**
* Make a DNS a request to a custom nameserver, this is similar to dns_get_record, but allows you to query any nameserver
* Usage: dns_get_record_from('ns.server.tld', 'A', 'mydomain.tld');
* => ['42.42.42.42']
* @author bohwaz
*/
function dns_get_record_from(string $server, string $type, string $record): array
{
@bohwaz
bohwaz / php-8.1-strftime.php
Last active April 26, 2024 12:09
strftime() replacement function for PHP 8.1
<?php
namespace PHP81_BC;
/**
* Locale-formatted strftime using \IntlDateFormatter (PHP 8.1 compatible)
* This provides a cross-platform alternative to strftime() for when it will be removed from PHP.
* Note that output can be slightly different between libc sprintf and this function as it is using ICU.
*
* Usage:
* use function \PHP81_BC\strftime;
@bohwaz
bohwaz / lcp_download.php
Created June 29, 2023 20:10
Transform LCP/LCPL files to regular EPUB/PDF/ZIP
#!/usr/bin/php
<?php
// Note: this code does not contain any DRM removal, DRM removal is made by https://notabug.org/NewsGuyTor/DeDRM_tools-LCP
//
// Install steps:
// Debian/Ubuntu/Mint: apt install php-cli python3 python3-cryptodome python3-lxml zip unzip
//
// How to use?
// Just run: php lcp_download.php FILE.LCPL PASSWORD
// A new FILE_decrypted.epub will be created in the same directory
@bohwaz
bohwaz / check_ine.php
Last active January 10, 2024 10:41
Vérification de validité de numéro INE d'étudiant (BEA/Scolarix/APOGEE)
<?php
// Licence : domaine public ou WTFPL
// 2018 BohwaZ <http://bohwaz.net/>
function check_ine($ine)
{
if (!function_exists('bcmod'))
{
throw new \LogicException('bcmath is required');
@bohwaz
bohwaz / cert_expiry_check.php
Last active September 15, 2023 05:41
Check if certificate expiry is in more than 30 days
<?php
$domain = 'mydomain.tld';
if (get_ssl_certificate_expiry($domain) < 30) {
throw new \Exception('Certificate expires in less than 30 days!');
}
function get_ssl_certificate_expiry(string $domain): ?int
{
@bohwaz
bohwaz / csv2sqlite.php
Created April 23, 2017 10:52
Import CSV file in a SQLite table, including column headers
<?php
$fp = fopen($argv[1], 'r');
$db = new SQLite3($argv[1] . '.sqlite');
$db->exec('BEGIN;');
$header = null;
$i = 0;
@bohwaz
bohwaz / cavites.php
Created July 4, 2022 12:13
Téléchargement et conversion en GPX de la BDCavité (liste des cavités souterraines du BRGM)
<?php
// Mode d'emploi : créer un répertoire vierge et lancer "php cavites.php"
const JSON_URL = 'https://www.georisques.gouv.fr/webappReport/ws/telechargement/cavites?anneemin=2003';
const PROJECTIONS = [
1 => 'LambertI',
2 => 'LambertII',
3 => 'LambertIII',
@bohwaz
bohwaz / pdf2cbz.sh
Last active July 29, 2023 11:08
pd2cbz.sh - Convert a PDF file (eg. a comic) to a CBZ file
#!/bin/bash
which mutool &> /dev/null || (echo "mutool is not installed" && exit 1)
which convert &> /dev/null || (echo "imagemagick is not installed" && exit 1)
which zip &> /dev/null || (echo "zip is not installed" && exit 1)
if [ "$1" = "" ]
then
echo "Usage: $0 File.pdf"
exit
@bohwaz
bohwaz / get_ssl_expiry.php
Created September 8, 2022 15:21
PHP function to get number of days before SSL/TLS certificate expiry from a HTTPS URL
<?php
/**
* Return number of days before certificate expiry from a HTTPS URL
* Usage: get_ssl_certificate_expiry('https://www.framasoft.net/')
* => int(45)
* @author bohwaz
*/
function get_ssl_certificate_expiry(string $url): ?int
{
@bohwaz
bohwaz / extract-credit-mutuel-csv-garradin.php
Last active June 2, 2023 11:14
Extraction de relevé de compte Crédit Mutuel pour Garradin
<?php
/**
* Extracteur de données des relevés de compte du Crédit Mutuel
* à destination de Garradin (ou autre logiciel de compta)
*
* https://garradin.eu/
*
* Ce script prend en argument un répertoire contenant des extraits
* de compte en PDF (ou un seul extrait de compte) et crée un fichier
* CSV importable directement dans Garradin.