Script: Webbasiertes mldonkey start/stop

tr0nix

tr0nix

der-mit-dem-tux-tanzt
Hallo Jungs

Meine Freundin regt sich immer auf, wenn ich vom Geschaeft aus mldonkey deaktiviere (damit ich meinen cgi-Proxy benutzen kann weil die hier einige Seiten sperren im Geschaeft *hrhr*). Weil ich natuerlich immer wieder vergesse das Teil zu aktivieren, und ich meiner Freundin kein remote Zugriff auf die Maschine zumuten will (sie benutzt nen Fatclient fuer den Zugriff von ihrer Workstation aus), habe ich ein winziges start/stop Script in PHP geschrieben. Bedingung: Webserver muss unter dem mldonkey-User laufen und PHP supporten. Sollte jedoch kein Problem sein fuer die meisten hier.

Falls jemand noch Fragen/Probleme oder Anregungen hat, bitte melden ;).

Gruss
Joel

Code:
<?php
/*
* Fast and stupid mldonkey stop/starter. It's so simple, that it doesn't need to be w3c-compliant ;)
* 2004 - Joel Wiesmann, [url]www.secuserv.ch[/url]
*/

/*
* CONFIGURATION
*
* MLDONKEY_STARTDIR = Directory where mldonkey should be started. Usually haves "temp" and "incoming" there.
* MLDONKEY_BINARY = Absolute Path to binary. Just type "mldonkey" if it's in your $PATH
*/
$MLDONKEY_STARTDIR = "/home/shares/Daten/MLDonkey";
$MLDONKEY_BINARY = "/usr/local/bin/mldonkey";

/*
* Is MLDonkey running? This will return the PID of the donkey if it's running.
* Else it will be empty.
*/
function checkDonkey()
{
        return( exec("ps -C mldonkey | grep mldonkey | awk '{ print $1 }'") );
}

$MLDONKEY_STATUS = checkDonkey();

/*
* Action requested?
*/
switch( $_POST['control'] )
{
        case "start":
                if( empty( $MLDONKEY_STATUS ) )
                {
                        chdir( $MLDONKEY_STARTDIR );
                        system( "nohup $MLDONKEY_BINARY >/dev/null 2>&1 &" );
                }

                sleep(2);
                $MLDONKEY_STATUS = checkDonkey();
                empty( $MLDONKEY_STATUS ) ? $STATUS = "START KONNTE NICHT DURCHGEFUEHRT WERDEN!" : header("location: index.php");
        break;
        case "stop":
                if( ! empty( $MLDONKEY_STATUS ) )
                        system( "kill -9 $MLDONKEY_STATUS" );

                sleep(2);
                $MLDONKEY_STATUS = checkDonkey();
                ! empty( $MLDONKEY_STATUS ) ? $STATUS = "STOP KONNTE NICHT DURCHGEFUEHRT WERDEN!" : header("location: index.php");
        break;
}
?>

 <head>
  <title>MLDonkey remote control</title>
 </head>
 <body>
  <b>MLDonkey remote console</b><br>
  <br>
  MLDonkey is: <?php empty($MLDONKEY_STATUS) ? print "inactive" : print "active, PID: " .$MLDONKEY_STATUS; ?>!<br>
  <form method="post">
   <input type="submit" name="control" value="<?php empty($MLDONKEY_STATUS) ? print "start" : print "stop"; ?>">
  </form>
  <br>
  <?php empty($STATUS) ? true : print "Meldung: " .$STATUS; ?>
 </body>
</html>
(Einfach kopieren, in <name>.php reinkopieren, ins Webroot ablegen und ggf. Variablen MLDONKEY_STARTDIR und MLDONKEY_BINARY anpassen)
 

Ähnliche Themen

Nginx als Reverse Proxy für Nextcloud und Emby

Problem mit HSPA+ Modem Huawei E353 - Installation unmöglich?

Windows clients können nicht mehr auf lange laufendes System zugreifen

dovecot und postfix Konfiguration Problem

Debian squeeze, Webmin, Samba Freigaben

Zurück
Oben