Skip to content

A Python module for remotely managing an OpenWRT instance

License

Notifications You must be signed in to change notification settings

rkhamis/openwrt-remote-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Latest Version

OpenWRT Remote Manager

A Python module for remotely managing an OpenWRT instance via its Luci-exported JSONRPC interface.

See the module specifications for information about the implemented functionality.

Usage

Note: This module requires that the package luci-mod-rpc is installed on all your managed OpenWRT installations.

Create a manager for a particular OpenWRT installation:

>>> import openwrt
>>> manager = openwrt.create_manager(hostname='10.0.0.5', username='root', password='root')

Managing forwarded ports

# List all the forwarded ports
>>> port_forwarding_rules = manager.port_forwarding.all
>>> for rule in port_forwarding_rules:
>>>     print rule

# Modify a specific rule
>>> rule = port_forwarding_rules[1]
>>> updated_rule = rule.updated(dest_port=9080)
>>> manager.port_forwarding.update(updated_rule)

# Create a new rule
>>> from openwrt import PortForwardingRule
>>> new_rule = PortForwardingRule.create(name='My awesome forwarded port',
>>>     src='wan', src_dport=80, proto='tcp', dest='lan', dest_ip='192.168.1.10')
>>> manager.port_forwarding.add(new_rule)

Managing the network

Managing the network interfaces

>>> network_profiles = manager.network.profiles
>>> for profile in network_profiles:
>>>   print(profile)
lan on eth0
loopback on lo
>>> lan_profile = network_profiles[0]
>>> updated_lan_profile = lan_profile.updated(dns=('8.8.8.8', '8.8.4.4')) 
>>> manager.network.set_profile(updated_lan_profile)
>>> # Check out the functionality provided by the NetworkProfile class
>>> help(updated_lan_profile)

Pinging an external host

>>> manager.network.ping_host('example.org')
True

Managing system users

>>> manager.users.usernames
('root', 'daemon', 'network', 'ftp', 'nobody')
>>> manager.users.create_user('test_user')
>>> assert 'test_user' in manager.users.usernames
>>> manager.users.change_password('test_user', 'supersecretpassword')
>>> assert manager.users.check_password('test_user', 'supersecretpassword')
>>> assert not manager.users.check_password('test_user', 'anotherpassword')
>>> manager.users.delete('test_user')

Doing backups

>>> import time
>>> open('config-backup-{}.tar.gz'.format(int(time.time())), mode='wb').write(manager.backup.config_dir())
# Now there's a config-backup-TIMESTAMP.tar.gz file in your CWD.

For more information, see help(openwrt).

About

A Python module for remotely managing an OpenWRT instance

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages