Skip to content

Instantly share code, notes, and snippets.

View nemesifier's full-sized avatar
🎯
Focusing on @openwisp full time!

Federico Capoano nemesifier

🎯
Focusing on @openwisp full time!
View GitHub Profile
@nemesifier
nemesifier / openwrt-lan-wifi-repeater.uci
Created November 30, 2021 16:15
OpenWrt: route/NAT all traffic coming from the LAN to a WiFI station
# this conf allows to connect an OpenWrt device to any WiFi WPA2/3 network which has internet connection
# then allows to connect other routers / devices to the LAN switch of the OpenWrt router or to its WiFi AP.
# The traffic is NATted.
# /etc/config/network
config interface 'lan'
option type 'bridge'
option ifname '<INTERFACES OF BR-LAN HERE>'
option ip6assign '60'
#!/usr/bin/env python
from openwisp2.celery import app
import os
import sys
import django
import time
from django.conf import settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'openwisp2.settings')
#!/bin/sh
reboot=false
# updates opkg lists only if necessary
opkg_update(){
(
test -d /tmp/opkg-lists/ && \
test -f /tmp/opkg-lists/openwrt_base && \
test -f /tmp/opkg-lists/openwrt_packages && \
test -f /tmp/opkg-lists/openwrt_core
import codecs
from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PrivateKey
from cryptography.hazmat.primitives import serialization
# generate private key
private_key = X25519PrivateKey.generate()
bytes_ = private_key.private_bytes(
encoding=serialization.Encoding.Raw,
format=serialization.PrivateFormat.Raw,
encryption_algorithm=serialization.NoEncryption()
@nemesifier
nemesifier / average_entry.py
Created June 15, 2020 14:19
Calculate average entry of a trade
def avg_position(positions):
assert type(positions) in (list, tuple)
total_value = 0
total_quantity = 0
for position in positions:
quantity, price = position
total_quantity += quantity
total_value += quantity / price
return total_quantity / total_value
@nemesifier
nemesifier / openwisp-monitoring-template.json
Last active March 24, 2021 18:14
OpenWISP Monitoring Template
{
"files": [
{
"path": "/usr/sbin/openwisp-monitoring",
"mode": "0744",
"contents": "uuid=$(uci get openwisp.http.uuid)\nkey=$(uci get openwisp.http.key)\nbase_url=$(uci get openwisp.http.url)\nverify_ssl=$(uci get openwisp.http.verify_ssl)\nincluded_interfaces=$(uci get openwisp.monitoring.included_interfaces)\nurl=\"$base_url/api/v1/monitoring/device/$uuid/?key=$key\"\ndata=$(/usr/sbin/netjson-monitoring \"$included_interfaces\")\nif [ \"$verify_ssl\" = 0 ]; then\n curl_command='curl -k'\nelse\n curl_command='curl'\nfi\n# send data via POST\n$curl_command -H \"Content-Type: application/json\" \\\n -X POST \\\n -d \"$data\" \\\n -v $url\n"
},
{
"path": "/usr/sbin/netjson-monitoring",
"mode": "0744",
@nemesifier
nemesifier / find_monthly_interest.py
Created August 24, 2018 09:04
Prints out monthly interest in the specified range
def find_monthly_interest(minimum, maximum, interest, find_round=False):
interest = interest / 100.0
counter = minimum
while counter <= maximum:
amount = counter
counter += 1
monthly = amount * interest / 12
if find_round and amount * interest % 12.0 != 0:
continue
print('{0} yelds {1} per month'.format(amount, monthly))
@nemesifier
nemesifier / netjson-monitoring.lua
Created February 28, 2018 11:35
Retrieves information of wireless interfaces in NetJSON format
#!/usr/bin/env lua
-- retrieve monitoring information
-- and return it as NetJSON Output
ubus_lib = require('ubus')
cjson = require('cjson')
-- takes ubus wireless.status clients output and converts it to NetJSON
function netjson_clients(clients)
local data = {}
for mac_address, properties in pairs(clients) do
@nemesifier
nemesifier / rml_rest.conf
Last active December 11, 2022 13:01
rml_rest module configuration example (/etc/freeradius/mods-enabled/rest)
# /etc/freeradius/mods-enabled/rest
rest {
#
# This subsection configures the tls related items
# that control how FreeRADIUS connects to a HTTPS
# server.
#
tls {
# ca_file = ${certdir}/cacert.pem
@nemesifier
nemesifier / freeradius-rest-example.conf
Last active July 11, 2017 15:17
sample freeradius configuration showing how to delegate authorization and authentication to the rml_rest module
# /etc/freeradius/sites-enabled/default
# ... other sections omitted for brevity ...
authorize {
# enable rml_rest module
if (&User-Password) {
update control {
Auth-Type := 'rest'
}
}