Source: openwisp/openwisp-utils
| Icon | Asset |
|---|---|
access-credential.svg |
|
accounting.svg |
|
add.svg |
|
batch-user.svg |
Source: openwisp/openwisp-utils
| Icon | Asset |
|---|---|
access-credential.svg |
|
accounting.svg |
|
add.svg |
|
batch-user.svg |
| #!/usr/bin/env python3 | |
| """ | |
| Extract OpenWrt firmware metadata from firmware images. | |
| Reimplementation of fwtool -i functionality in Python. | |
| """ | |
| import argparse | |
| import json | |
| import struct | |
| import sys |
| firewall: | |
| config rule | |
| option name 'Allow DHCP from LAN' | |
| option src 'lan' | |
| #option dest 'lan' | |
| option proto 'udp' | |
| option dest_port '67' | |
| option target 'ACCEPT' | |
| # 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() |
| 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 |
| { | |
| "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", |
| 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)) |