Code Monkey home page Code Monkey logo

tomato-nvram's Introduction

tomato-nvram

Find the tomato settings changed. Pretty-print the output.

Takes the current nvram dump, nvram.txt:

...
wl2_rateset=default
wl1_txpwr=0
wl1_nmcsidx=-1
tor_iface=br0
mysql_net_buffer_length=2
webmon_bkp=0
wl_macaddr=
wl1_bsd_if_select_policy=eth2 eth3
lan_route=
wl1_rx_amsdu_in_ampdu=off
wl0_mrate=0
wl1_channel=132
mysql_binary=internal
nginx_priority=10
wan3_modem_band=7FFFFFFFFFFFFFFF
wan3_proto=dhcp
qos_inuse=511
wan3_get_dns=
...

Compares it against an nvram dump of the defaults, defaults.txt:

...
lan_route=
wl1_bsd_if_select_policy=eth2 eth3
wl_macaddr=
webmon_bkp=0
mysql_net_buffer_length=2
tor_iface=br0
wl1_nmcsidx=-1
wl1_txpwr=0
wl2_rateset=default
wan3_proto=dhcp
wan3_modem_band=7FFFFFFFFFFFFFFF
nginx_priority=10
mysql_binary=internal
wl1_channel=100
wl0_mrate=0
wl1_rx_amsdu_in_ampdu=off
wan3_get_dns=
...

Generates a readable shell script from the difference, set-nvram.sh:

...

# LAN
nvram set lan_ipaddr=192.168.123.1

# Wireless (2.4 GHz)
nvram set wl0_bw_cap=1
nvram set wl0_channel=1
nvram set wl0_chanspec=1
nvram set wl0_nbw=20
nvram set wl0_nbw_cap=0
nvram set wl0_nctrlsb=lower

# Wireless (5 GHz)
nvram set wl1_channel=132
nvram set wl1_chanspec=132/80
nvram set wl1_radio=0
...

Use

Requires: Python 3.3+

Save the current settings as nvram.txt, from Administration→Debugging→Download NVRAM Dump in the Tomato web UI, in the same directory as tomato-nvram.py.

Reset the router's NVRAM. Try to ensure that all the default settings have been set. This is how I do it:

  • Erase all data in NVRAM. Wait for the router to boot.
  • Reboot (because on my RT-AC66U, the 5 GHz radio doesn't show up otherwise).
  • Click Save without changing anything on at least these sections:
    • Basic→Network
    • Advanced→Wireless
    • Administration→Admin Access

Save the defaults as defaults.txt, from Administration→Debugging→Download NVRAM Dump in the Tomato web UI, in the same directory as tomato-nvram.py.

Run tomato-nvram.py:

$ python3 tomato-nvram.py
102 settings written to set-nvram.sh

View/Edit output file set-nvram.sh to choose which settings to reapply.

Reapply settings over SSH:

> "C:\Program Files\PuTTY\plink.exe" -ssh [email protected] -pw admin -m set-nvram.sh

Or

$ ssh [email protected] 'sh -s' < set-nvram.sh

Options

$ python3 tomato-nvram.py --help
usage: tomato-nvram.py [-h] [-i INPUT] [-b BASE] [-o OUTPUT] [-c CONFIG] [-e ENCODING] [--erase] [--reboot] [--linux]

Generate NVRAM setting shell script.

options:
  -h, --help            show this help message and exit
  -i INPUT, --input INPUT
                        input filename (default: nvram.txt)
  -b BASE, --base BASE  base filename (default: defaults.txt)
  -o OUTPUT, --output OUTPUT
                        output filename (default: set-nvram.sh)
  -c CONFIG, --config CONFIG
                        config filename (default: config.ini)
  -e ENCODING, --encoding ENCODING
                        file encoding (default: latin-1)
  --erase               erase nvram first (default: False)
  --reboot              reboot after (default: False)
  --linux               output linux line endings (default: False)

tomato-nvram's People

Contributors

notvaryclever avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tomato-nvram's Issues

Python on Windows adding Window EOL

Hi,

I have used this tool a number of times, and find it very useful. Thanks for taking the time to create this!

I recently decided to run this from my windows machine for a number of reasons and found that the set-nvram.sh scripts were unnusable due to the EOL characters.

I played around a bit and found a simple change to your code gets rid of the problem.

Simple change line 404 from:
with open(args.output, 'w') as outfile:
to:
with open(args.output, 'w', newline='\n') as outfile:

I don;t know if you wish to make this change in your official version, but it worked for me.

Thanks again!

Keith.

ValueError: not enough values to unpack (expected 2, got 0)

Hi,

I'm getting this error when trying to run tomato-nvram.py:

Traceback (most recent call last):
  File "./tomato-nvram.py", line 416, in <module>
    main(sys.argv[1:])
  File "./tomato-nvram.py", line 402, in main
    config = Config(args.config)
  File "./tomato-nvram.py", line 362, in __init__
    self.names, patterns = zip(*((name, section['pattern']) for name, section in parser.items() if 'pattern' in section))
ValueError: not enough values to unpack (expected 2, got 0)

Update instructions to be less vague

I had it until I tried to run tomato-nvram.py. I’m not sure how or with what. I’ve tried power shell, cmd and terminal. Nothing works. I’m obviously new to this so please be aware. Please help.

Should have instruction for how to use the generated output file (set-nvram.sh)

Last line of the "Use" (should it be "Usage"?) section says

View/Edit output set-nvam.sh to choose which settings to reapply.

but there is no information about what should be done with the output file. I'm guessing it should be uploaded to some directory on the router file system and then you should open a shell console on the router and execute the file. It would be nice if the readme.md had at least an outline of what steps to take.

Also, since this script is likely to be use in connection with a firmware upgrade of the router, maybe that (optional) step could be included in the instructions.

Found an issue with DNSMASQ

dnsmasq_custom=address=/jb.domain.net/192.168.10.10
address=/weather.domain.net/192.168.10.10
address=/speedtest.domain.net/192.168.10.10
address=/phpmyadmin.domain.net/192.168.10.10
address=/mythweb.domain.net/192.168.10.10
address=/camera1.domain.net/192.168.10.41
address=/camera2.domain.net/192.168.10.42
address=/camera3.domain.net/192.168.11.117

Turned into a single line. It didn't see the lines after it.

nvram set address=/speedtest.domain.net/192.168.10.10

Generated nvram output truncates Dnsmasq Custom Configuration

I noticed that the generated output in the set-nvram.sh file was missing many lines of my dnsmasq custom configuration text.

For example, my nvram.txt (input):

dnsmasq_custom=
#whitelist example for dns rebinding
rebind-domain-ok=/example.direct/

#static dns entries
address=/my-router/192.168.1.1
address=/example-service1/192.168.1.2
address=/example-service2/192.168.1.2
address=/example-service3/192.168.1.2
address=/example-service4/192.168.1.2
address=/example-service5/192.168.1.2
address=/example-service6/192.168.1.2
address=/example-service7/192.168.1.2
address=/example-service8/192.168.1.2
address=/example-service9/192.168.1.2
address=/example-service10/192.168.1.2
address=/example-service11/192.168.1.2
address=/example-service12/192.168.1.2
address=/example-service13/192.168.1.2
address=/example-service14/192.168.1.2

#static dns entries as work around for modem lack of nat loopback support
#address=/example.example.net/99.99.999.99
#address=/example2.example.net/99.99.999.99
#address=/example3.example.net/99.99.999.99

For example, my defaults.txt (input):

dnsmasq_custom=

For example, my set-nvram.sh (output):

# DNS
nvram set dnsmasq_custom="
#whitelist example for dns rebinding
rebind-domain-ok=/example.direct/

#static dns entries"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.