1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Save configuration file to FTP

Discussion in 'Tomato Firmware' started by landa, Nov 4, 2010.

  1. landa

    landa LI Guru Member

    Can anyone make a script to save the router configuration on the FTP server? I'm going to put this script in Custom script area.

    Thanks,
     
  2. ~nephelim~

    ~nephelim~ LI Guru Member

    Please let me know if this works.
    Code:
    ftpserver="0.0.0.0"
    ftpuser="user"
    ftppassword="password"
    ftppath="upload"
    
    cfg="/tmp/cfg.tmp"
    
    a=0
    for i in et0macaddr http_enable http_username http_passwd lan_ipaddr http_lanport http_id; do
    eval "A$a=$(nvram get $i)"
    let a=a+1 
    done
    
    [ "$A0" != "" ] && name="$(echo $A0 |sed 's|:||g')-$(date +%s).cfg" || name="tomato-$(date +%s).cfg"
    [ "$A2" == "" ] && A2="root"
    if [ "$A1" == "1" ]; then 
    logger Configuration $name backup
    wget -O - http://$A2:$A3@$A4:$A5/cfg/$name?_http_id=$A6 > $cfg 
    logger Configuration $name upload
    ftpput  -u $ftpuser -p $ftppassword $ftpserver $ftppath/$name $cfg
    rm -f  $cfg 
    else 
    logger Tomato HTTP configuration interface is not enabled. Aborting Configuration upload script
    fi
    
    This is a shorter version

    Code:
    ftpserver="0.0.0.0"
    ftpuser="user"
    ftppassword="password"
    ftppath="upload"
    
    cfg="/tmp/cfg.tmp"
    
    A0=$(nvram get et0macaddr)
    [ "$A0" != "" ] && name="$(echo $A0 |sed 's|:||g')-$(date +%s).cfg" || name="tomato-$(date +%s).cfg"
    
    nvram backup $cfg
    
    if [[ -f $cfg ]]; then
    logger Configuration $name upload
    ftpput  -u $ftpuser -p $ftppassword $ftpserver $ftppath/$name $cfg
    rm -f  $cfg 
    else
    logger Configuration backup command unsupported
    fi
    
    I'm not using Victek builds at the moment and I appreciate if you would provide the output of this script (Execute System Commands in Tomato tools >System).

    These diagnostic informations might come in handy for other scripts.
    Code:
    #!/bin/sh
    nvram get os_version
    
    if type uudecode  >> /dev/null 2>&1 ; then
    echo YmFzZTY0IGRlY29kaW5nIHN1cHBvcnRlZA0K |uudecode
    else
    echo uudecode not available
    fi
    if type md5sum >> /dev/null 2>&1 ; then
    echo md5sum available
    else
    echo md5sum not available
    fi
    if type nc >> /dev/null 2>&1 ; then
    echo nc available
    else
    echo nc not available
    fi
    if [[ "$(echo WQ==|openssl enc -base64 -d)" == "Y" ]]; then
    echo openssl encoding supported
    else
    echo openssl encoding unsupported
    fi
    if type ftpput >> /dev/null 2>&1 ; then
    echo ftpput available
    else
    echo ftpput not available
    fi
    [ "$(nvram get et0macaddr)" != "" ]; then
    echo et0macaddr variable available
    else
    echo et0macaddr variable unavailable
    fi
    
    testfile="/tmp/b64tst"
    
    echo -n WQ== > $testfile 
    nvram set testb64=$(cat $testfile)
    nvram getfb64 testb64 $testfile.dec
    
    [[ "$(cat $testfile.dec)" == "Y" ]] && echo getfb64 supported || echo setfile  unsupported 
    nvram unset testb64
    
    echo -n Y> $testfile 
    nvram setfb64 testb64 $testfile
    nvram get testb64 > $testfile.enc
    [[ "$(cat $testfile.enc)" == "WQ==" ]] && echo setfb64 supported || echo setfb64 unsupported 
    nvram unset testb64
    
    rm -f $testfile
    rm -f $testfile.dec
    rm -f $testfile.enc
    
    Thanks. :)
     

Share This Page