Thread: [Script request] o2 Homebox 6441
View Single Post
  #24  
Old 04.12.2017, 02:04
sumyungguy sumyungguy is offline
JD Fan
 
Join Date: Sep 2012
Posts: 72
Default Verbesserte 6441 Skript für Linux, jetzt auch für Mac

Hier findest du meine verbesserte Version von rbybbls Skript:
  • funktioniert jetz auch mit OS X / macOS , sowie Linux
  • Router IP, Passworthash, und Skript-bearbeiten, sind nicht mehr erforderlich. Einfach das Passwort deines Router in die Parameter-box in JDownloader einstellen.
  • Anleitung inbegriffen, wenn du mein Deutsch nicht verstehst, versuch doch auf English

Here's my improved version of rbybbl's script:
  • now works with OS X / macOS, as well as Linux
  • Router IP, password hashes, and script-editing no longer needed, just put your router password in JDownloader's Parameters box
  • instructions included in German and English

Code:
#!/bin/bash

# O2 Homebox 6441 reconnect script for Linux and macOS

### Anleitung - Instructions ###

# Speicher als Textdatei ab, z.B.:
# Home->Documents->JDownloader->reconnect-6441.sh
# Ausführbar in Terminal machen:
#   cd ~/Documents/JDownloader
#   chmod 755 reconnect-6441.sh
# Test mit:
#   ./reconnect-6441.sh 'routerpasswort'
# JDownloader:
# Einstellungen->Reconnect->Reconnect Methode: Drittanwender-Reconnect
# "Auswählen" Button anclicken, reconnect-6441.sh finden und auswählen.
# Router admin Passwort in die Parameter box einstellen.
# "Test" Button anclicken.

# Save as text file, for example:
# Home->Documents->JDownloader: reconnect-6441.sh
# Make executable in Terminal:
#   cd ~/Documents/JDownloader
#   chmod 755 reconnect-6441.sh
# Test with:
#   ./reconnect-6441.sh 'routerpassword'
# JDownloader:
# Settings->Reconnect->Reconnect Method: External Tool Reconnect
# Click "Select" button, navigate to reconnect-6441.sh and select.
# Enter the router admin password in the Parameter box.
# Click the "Test" button.

### History ###
# original author: rbybbl 2016-06-01
# https://board.jdownloader.org/showpost.php?p=372164&postcount=6
#
# modified by sumyungguy 2017-12-02:
#   made macOS compatible
#   working shell commands to generate hash, for Linux and macOS
#   no user configuration of script necessary:
#      use "o2.box" as router address
#      calculate password hash from argument
#   change for firmware 1.01.30, thanks to Teorax
#   added instructions
#   prints status information during reconnect

print_status () {
	# report current connection status and IP address
	echo "status:"
	ROUTER_STATUS=$(curl -s "$ROUTER_HOST/cgi/cgi_diagnostic.js?_tn=$ROUTER_TOKEN" | grep -o -e '"WANConnectStatus0.*"' -e '"WAN_IP4_Addr0.*"')
	echo "$ROUTER_STATUS"
}

if [ "$#" -gt 1 ]; then
	echo "Reconnect O2 Homebox - usage: reconnect-6441.sh 'routerpass'"
	exit
fi

ROUTER_HOST="o2.box"
CLEARPASS="$1"

if [ -n "$CLEARPASS" ]; then
	UNAMESTR=$(uname)
	if [ "$UNAMESTR" = "Darwin" ]; then
		ROUTER_PASS=$(printf "$CLEARPASS" | md5 | tr -d '\n' | shasum -a 512 | tr -d ' -')
	else
		ROUTER_PASS=$(printf "$CLEARPASS" | md5sum | tr -d '\n -' | shasum -a 512 | tr -d ' -')
	fi
	echo "Router Pass Hash: \n$ROUTER_PASS"
	echo "einloggen - logging in"
	if [ $(curl -s -d "pws=$ROUTER_PASS" "$ROUTER_HOST/login.cgi" | wc -c) -eq 0 ]; then
		echo "login gescheitert: falsches Passwort oder mit Webbrowser noch eingeloggt?"
		echo "login failed: wrong password or logged in with web browser?"
		exit 1
	fi
else
	echo "Warnung: kein Passwort - warning: no password"
fi

# get the token from index page and save as var
ROUTER_TOKEN=$(curl -s "$ROUTER_HOST/" | perl -nle 'print $& if m{data:image/gif;base64,[A-Za-z0-9+/]+///[A-Za-z0-9+/]{31}\K([^"]+)}' | base64 --decode)
echo "router token: $ROUTER_TOKEN"
print_status

# send disconnect post request
echo "WAN stop"
curl -s -d "action=wan_stop&httoken=$ROUTER_TOKEN" "$ROUTER_HOST/apply_abstract.cgi" > /dev/null
sleep 6
print_status

# send connect post request
echo "WAN start"
curl -s -d "action=wan_start&httoken=$ROUTER_TOKEN" "$ROUTER_HOST/apply_abstract.cgi" > /dev/null
sleep 6
print_status

# wait for connected state
while true
do
	if echo "$ROUTER_STATUS" | grep -Eqi '"WANConnectStatus0", "[0-9]+", "Connected"'; then
		break
	fi
	sleep 6
	print_status
done

if [ -n "$CLEARPASS" ]; then
	# send logout request
	echo "logout"
	sleep 2
	curl -s -d "" "$ROUTER_HOST/logout.cgi" > /dev/null
fi

Last edited by sumyungguy; 04.12.2017 at 02:33.
Reply With Quote