some remote tunnel stuff

#!/bin/sh
export sshchk=`ps auxwww |grep remo@groupware|wc -l`
if [ $sshchk -gt 1 ] 
  then exit 
else
  export mac=`/sbin/ifconfig | grep eth | awk {'print $5'}`
  wget --no-check-certificate https://x.y.ch/getid.php?mac=$mac -O /tmp/id
  export remo_id=`cat /tmp/id`
  ssh remo@groupware.vmk.zhdk.ch -i /home/c1audio/.ssh/id_rsa -o ExitOnForwardFailure=yes -NR $remo_id:localhost:22 &
fi

# m h dom mon dow command
* * * * * /home/c1audio/remo.sh

root@groupware:/var/www-ssl# cat getid.php 

<?
    /*
         *      getid.php
         *
     *    Script to assign ports to remote workstations
     *
     *    yogi808, 21.6.2011
     *
     */
    $macdb="./macs";
    if(array_key_exists("mac",$_GET)) {
        $ret=0;
        $ln=0;
        $mac=$_GET["mac"];
        $s=file($macdb);
        foreach ($s as $line_num => $line) {
            if($line==$mac."\n") {
                $ret=10000+$line_num;
            }
            $ln=$line_num;
        }
        if($ret==0) {
            file_put_contents($macdb,$mac."\n",FILE_APPEND);
            $ret=$ln+10000+1;
        }
        echo $ret;
    }
?>

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.