You are not logged in.

#226 2020-06-16 12:05:39

damo
....moderator....
Registered: 2015-08-20
Posts: 6,043

Re: The great yad hacking thread

Naik wrote:

...

Sounds easy, but I guess I would not be able to see any of the output this script (or the comand invoked by it) is writing to stdout, right?

Is there any option to do so, other than piping it to a temporary logfile and opening another dialogue afterwards to print it?

naik --greetz

Use tee and pipe it to a terminal?


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#227 2020-06-17 01:25:55

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 6,951
Website

Re: The great yad hacking thread

Naik wrote:

So you are saying I could come up with a little ~/bin/anonsurf-helper.sh
and call it like this in jgmenu:

yad <options> --entry --hide-text | sudo -S $HOME/bin/anonsurf-helper.sh

Well, more like this, in prepend.csv:

^tag(anonsurf)
Back,^back()
Start,x-terminal-emulator -T 'AnonSurf' -e anonsurf-helper.sh --start
Stop,x-terminal-emulator -T 'AnonSurf' -e anonsurf-helper.sh --stop

I guess I would not be able to see any of the output this script (or the comand invoked by it) is writing to stdout, right?

If like above, then you'd open a terminal and then run the helper script in it, so you'd see the output. Also, if you're running the script in a terminal, you can use sudo as normal, no need for yad.


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), idle Twitterings and GitStuff )

Introduction to the Bunsenlabs Lithium Desktop

Offline

#228 2020-06-17 20:07:45

Naik
Member
From: Lipsia
Registered: 2015-10-03
Posts: 243

Re: The great yad hacking thread

johnraff wrote:
Naik wrote:

So you are saying I could come up with a little ~/bin/anonsurf-helper.sh
and call it like this in jgmenu:

yad <options> --entry --hide-text | sudo -S $HOME/bin/anonsurf-helper.sh

Well, more like this, in prepend.csv:

^tag(anonsurf)
Back,^back()
Start,x-terminal-emulator -T 'AnonSurf' -e anonsurf-helper.sh --start
Stop,x-terminal-emulator -T 'AnonSurf' -e anonsurf-helper.sh --stop

I guess I would not be able to see any of the output this script (or the comand invoked by it) is writing to stdout, right?

If like above, then you'd open a terminal and then run the helper script in it, so you'd see the output. Also, if you're running the script in a terminal, you can use sudo as normal, no need for yad.

Running a terminal was exactly what I did at first but didn't find satisfying.
That's when I started thinking about yad in the first place.

With your patient help I put togther this little
anonsurf_helper

#!/bin/bash
#
# kali-anonsurf helper script
# provid a simple YAD-Interface for running Kali-Anonsurf
# provided under
# GNU General Public License v3.0 
# like https://github.com/Und3rf10w/kali-anonsurf itself
# by Naik <naik@nachtlicht.one>
# 
########################################################################

### Help message
function print_help {
		echo "AnonSurf_Helper"
		echo ""
		echo "Usage: anonsurf_help [command] [logfile]"
		echo ""
		echo "[Command] could be one of the following"
		echo "--help		Show this help"
		echo "--start	Start system-wide anonymous"
		echo	"			tunneling under TOR proxy through iptables"		
		echo "--stop 	Reset original iptables settings"
		echo "			and return to clear navigation"
		echo "--restart	Combines \"stop\" and \"start\" options"
		echo "--change	Changes identity restarting TOR"
		echo "--status	Check if AnonSurf is working properly"
		echo "--myip		Show your current IP address"
		echo ""
		echo "If run without arguments, one can be chosen from a yad dialogue later."
		echo "All output will be written to a single logfile [logfile]."
		echo "If none is specified its default is /tmp/anonsurf_helper.log"
		echo ""
		echo "GNU General Public License v3.0 like https://github.com/Und3rf10w/kali-anonsurf itself"
	exit
}
### Choose action via GUI
function choose_action {
	action=$(yad ---title="Anonsurf Helper" --window-icon="/home/naik/.local/share/icons/anon.png" --width=294 --posx=548 --height=184 --posy=133 --entry --button="gtk-ok:0" --button="gtk-close:1" --text "Was willst Du tun?:" --entry-text "Start" "Stop" "Change" "Restart" "Status" "MyIp")	
	echo $action
}

### check if /path/to/logfile is provided as second argument
### otherwise set default logfile to $HOME/tmp/anonsurf_helper.log
LOGFILE="/tmp/anonsurf_helper.log"
if touch $2; then
	LOGFILE=$2
    echo "Log will be written to "$LOGFILE"."
elif [ -f != $LOGFILE ]; then
	touch $LOGFILE
	echo "Log will be written to "$LOGFILE"." 
fi
### choose action
if [ -z "$1" ]; then
	choose_action
else
	action=$1
fi

case $action in

  --start|Start)
    yad --title="Anonsurf Helper" --window-icon="/home/naik/.local/share/icons/anon.png" --width=294 --posx=548 --height=84 --posy=333 --entry --hide-text | sudo -S anonsurf start > $LOGFILE 2>&1
    yad --notification --image="/home/naik/.local/share/icons/anon.png" --text="You are under AnonSurf tunnel." --listen --command="bash -c anonsurf_helper" &
    ;;
  --stop|Stop)
    yad --title="Anonsurf Helper" --window-icon="/home/naik/.local/share/icons/anon.png" --width=294 --height=84 --posx=548 --posy=333 --entry --hide-text | sudo -S anonsurf stop > $LOGFILE 2>&1 && 
    killall yad 2>/dev/null
    ;;
  --restart|Restart)
    yad --title="Anonsurf Helper" --window-icon="/home/naik/.local/share/icons/anon.png" --width=294 --height=84 --posx=548 --posy=333 --entry --hide-text | sudo -S anonsurf restart > $LOGFILE 2>&1
    ;;
  --change|Change)
    yad --title="Anonsurf Helper" --window-icon="/home/naik/.local/share/icons/anon.png" --width=294 --height=84 --posx=548 --posy=333 --entry --hide-text | sudo -S anonsurf change > $LOGFILE 2>&1
    ;;
  --status|Status)
    anonsurf status > $LOGFILE 2>&1
    ;;
  --myip|MyIP)
    anonsurf myip > $LOGFILE 2>&1
    ;;
  *)
    print_help
    ;;
esac
LOG=$( cat $LOGFILE| sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" )
yad --title="Anonsurf Helper" --window-icon="/home/naik/.local/share/icons/anon.png" --width=420 --posx=430 --height=230 --posy=190 --text="$LOG"
exit

It is simply called from jgmenu like

^tag(anonsurf)
Back,^back()
Start,anonsurf_helper --start
Stop,anonsurf_helper --stop
Choose,anonsurf_helper

I really thank you!
The next thing for me is to provide a dialogue for choosing the action to take thus making $1 obsolete and figure out how to invoke a little systray icon together with the start command and kill it with the stop command, but this won't be done with yad I guess.

EDIT: It has been done and the script has been updated. I might take the time to make it click-able, but we will see.

EDIT2: Removed some unnecessary privilege escalations.

EDIT3: All TODOS have been done and the script has been Updated.
It now can be run without arguments directly from jgmenu and the choice will be made via YAD-dialogue. I only ask myself whether it would be better to clean up on exit with a trap. Usually I like clean stuff but there wouldn't be any log left for debugging...
Anyway, I'd say I'm happy for now!

Thanks again @jhonraff and all the others from whom I boroughed some snippet here and there.

naik --greetz

Last edited by Naik (2020-06-18 10:56:36)


"Kaum macht [Mensch]* es richtig, funktioniert es sofort!"
BL-Kitchen on GitHub

Offline

Board footer

Powered by FluxBB