Jump to content

AutoSSH Tile tweak


phibertap

Recommended Posts

Hey Guys, I wanted to have a way to make autossh autostart from the web interface so I found a few code modes that you can do to your Pineapple to allow for this.

These are very simple and should not cause any problems to your device. I used the small_tile code from karma and its working great!

Your web interface will add the following:

Autostart Disabled | Enable

Easy stuff!

First thing is to modify the following file:

/pineapple/components/system/autossh/small_tile.php

to this:

<?php include_once('/pineapple/includes/api/tile_functions.php'); ?>

<?php

echo "AutoSSH ";

if(get_autossh_status()) {

echo "<font color=\"lime\"><b>Connected</b></font> | <a href='#sys/autossh/action/stop_autossh/autossh_reload_tile'>Disconnect</a>";

} else {

echo "<font color=\"red\"><b>Disconnected</b></font> | <a href='#sys/autossh/action/start_autossh/autossh_reload_tile'>Connect</a>";

}

echo "<br />";

echo "Autostart ";

if (get_autostart_status()) {

echo "<font color=\"lime\"><b>Enabled</b></font> | <a href='#sys/autossh/action/stop_autostart/autossh_reload_tile'>Disable</a>";

} else {

echo "<font color=\"red\"><b>Disabled</b></font> | <a href='#sys/autossh/action/start_autostart/autossh_reload_tile'>Enable</a>";

}

function get_autossh_status(){

exec('pgrep autossh', $pids);

if(empty($pids)){

return false;

}

return true;

}

function get_autostart_status(){

if(exec('ls /etc/rc.d/ | grep autossh') == ''){

return false;

}else{

return true;

}

}

?>

<script type="text/javascript">

function autossh_reload_tile(){

refresh_small('autossh', 'sys');

}

</script>

Then modify the following file:

/pineapple/components/system/autossh/functions.php

to this:

<?php include_once('/pineapple/includes/api/tile_functions.php'); ?>

<?php

if(isset($_GET['action'])){

switch ($_GET['action']) {

case 'generate':

generate_key();

break;

case 'edit':

echo edit_command($_POST['host'], $_POST['port'], $_POST['listen']);

break;

case 'knownhost_add':

echo knownhost($_POST['knownhost_user'], $_POST['knownhost_host']);

break;

case 'authorizedkeys':

echo authorizedkeys($_POST['authorizedkeys']);

break;

case 'keycopy':

echo keycopy($_POST['ak_user'], $_POST['ak_host'], $_POST['ak_password']);

break;

case 'start_autossh':

exec('/etc/init.d/autossh start');

break;

case 'stop_autossh':

exec('/etc/init.d/autossh stop');

break;

case 'start_autostart':

autostart('enable');

break;

case 'stop_autostart':

autostart('disable');

default:

# code...

break;

}

}

function autostart($mode){

if($mode == "enable"){

exec("/etc/init.d/autossh enable");

}else{

exec("/etc/init.d/autossh disable");

}

}

function generate_key(){

exec('ssh-keygen -N "" -f /root/.ssh/id_rsa');

return "<font color='lime'>Key pair generated. Refresh Tab.</font>";

}

function edit_command($host, $port, $listen){

exec('uci set autossh.@autossh[0].ssh="-i /etc/dropbear/id_rsa -N -T -R '.$port.':localhost:'.$listen.' '.$host.'"');

exec('uci commit autossh');

return "<font color='lime'>AutoSSH configuration updated.</font>";

}

function knownhost($knownhost_user, $knownhost_host){

exec('/pineapple/components/system/autossh/includes/knownhost.sh '.$knownhost_user.' '.$knownhost_host);

return "<font color='lime'>Known Host added. Refresh Tab.</font>";

}

function authorizedkeys($authorizedkeys){

file_put_contents('/root/.ssh/authorized_keys', str_replace("\r", "", $authorizedkeys));

return '<font color="lime">Authorized Keys updated. Refresh Tab.</font>';

}

function keycopy($ak_user, $ak_host, $ak_password){

exec('/pineapple/components/system/autossh/includes/copykey.sh '.$ak_user.' '.$ak_host.' '.$ak_password);

return '<font color="lime">Authorized Key replaced on Remote Host.</font>';

}

?>

Enjoy,

PT

Edited by phibertap
Link to comment
Share on other sites

How about modifying it so you can forward more than one port? I currently ignore the tile and setup autossh in rc.local to automatically foward more than one port. Note that I need to sleep about 20 seconds between autossh commands for it to work. I also configured dip switches to connect/disconnect ssh as well.

Link to comment
Share on other sites

How about modifying it so you can forward more than one port? I currently ignore the tile and setup autossh in rc.local to automatically foward more than one port. Note that I need to sleep about 20 seconds between autossh commands for it to work. I also configured dip switches to connect/disconnect ssh as well.

Ya sweet idea, have the entries for two different ports one for the web and one for ssh etc.

Okay I will try this, but I think since this is moding a system tile and not an infusion, I wonder if the devs could add this as an update :). In the background I will play with my own tile.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...