You are not logged in.

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

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

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: 7,286
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: 262

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

#229 2020-08-04 07:42:05

yadbash
Member
From: Nevada, USA
Registered: 2017-12-27
Posts: 7
Website

Re: The great yad hacking thread

Hello all, I have not been on here for quite sometime as I have been focusing my work on a new easy Remaster process that only requires Gparted (or parted), rsync and dd commands. I am looking for some guidance as I want to build a YAD GUI / bash interface that will automate the manual process that I am using. Should I use a very large one file program where I can import source from config files like this:

. /file01.source

Or, should I call sub yad / bash files for the various steps ?

Here are the steps I take to remaster any Debian Based system that uses Grub Boot Loader.


The Process in detail copy using either rsync or dd with partitioning resizing using Gparted. Then syncing uuid=number in /etc/fstab & /etc/initramfs-tools/conf.d/resume files. then updating initramfs & updating /boot/grub/grub.cfg using sudo commands.

boot to 2nd partition
mount partition to be Re-spinned.

Copy from hard drive to hard drive (partition file system copy) using rsync (For example: sda2 --> sdb1)
NOTE: Shrink source partition using Gparted (rsync copy) or Fdisk to find byte sector count number (dd count=number)

sudo rsync -qaHAXS --progress /media/mounted-partition/ /media/target-partition/

dd command can be used to create a img file and it can be compressed with gzip for maximum compression:

sudo dd if=/dev/sdxX of=./dd-image-file-of-custom-build-partiton.img bs=4M status=progress && sync

dd img file can then be compressed for maximum comp[/ression. (Example 5GB --> 1.4GB)

gzip -k -9 ./dd-image-file-of-custom-build-partition.img

resulting file is: dd-image-file-of-custom-build-partition.img.gz

To decompress file:

gzip -d ./dd-image-file-of-custom-build-partition.img

Using dd command to copy custom build respin img file to hard drive or USB Stick partition:

sudo dd if=./dd-image-file-of-custom-build-partition.img of=/dev/sdxX bs=4M status=progress && sync

Note: When copying a partition it retains same uuid=number as source partition and this can not occur on same computer. The uuid=number needs to be changed in fstab & resume file. Then needs to be update in grub.cfg file:

Find correct uuid=number

sudo blkid

Hard Drive:
Insert correct uuid=number in the new target partition /etc/fstab & /etc/initiramfs-tools/conf.d/resume files

USB Stick - Change uuid=number using Gparted (also do swap partition if applicable)
Insert correct uuid=number in the new target partition /etc/fstab & /etc/initiramfs-tools/conf.d/resume files

Run Grub update on 2nd partition on hard drive & Reboot

Highlight new partition sdxX Grub Menu & Press "e" key. Verify the last uuid=number is same as other top uuid=number. Press "F10" key.

When booted in to new partiton: (dev/sdxX = new partitoin)

sudo update-initramfs -u && sudo grub-install /dev/sdxX && sudo update-grub

DONE !

NOTE: Special configuration for USB Stick.

I use a prebuilt USB Stick build from a 1 Megabyte dd img file that has MBR, Grub, 12GB ext4 & 3GB+ linux-swap partitions.

I suggest using Gparted and Grub commands to build a base bootable USB Stick. For exmaple on a 16GB USB Stick
12GB ext4 root partition & 3GB+ linux-swap partition.

Then use dd command to place your custom Q4OS Build image .img file in the root partition on USB Stick. /dev/sdxX   (not /dev/sdb)

Or the 1MB image and detailed instructions are here: https://github.com/godistros/GoDistrOS

Offline

#230 2020-08-04 13:31:30

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

Re: The great yad hacking thread

^ This sounds like a topic for a thread all on its own in eg Help & Support (Other).

And it sounds like a great project smile


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

#231 2020-08-05 06:39:11

ohnonot
...again
Registered: 2015-09-29
Posts: 4,875
Website

Re: The great yad hacking thread

Since you want this to work for (all) Debain based ditros you'll be busy ironing out the functionality and making it more robust for the next year or so.
Asuming a yad-driven GUI means more work, I'd focus on CLI functionality first, and write it in a way that a gui "frontend" can be created for it evtl.

All in all, yes, this should be a thread all on its own.


BL quote proposals to this thread please.
how to ask smart questions | my repos / my repos | my blog
---
Thank you for posting direct image links!

Offline

#232 2020-08-05 07:03:00

Grover
New Member
Registered: 2020-08-03
Posts: 4

Re: The great yad hacking thread

>debian ISO remaster script Tomas Matejicek no need reinvent wheel

Offline

#233 2020-08-05 07:22:58

ohnonot
...again
Registered: 2015-09-29
Posts: 4,875
Website

Re: The great yad hacking thread

Grover wrote:

>debian ISO remaster script Tomas Matejicek no need reinvent wheel

But there is a need to add links to your statements.
I guess you mean this but I could not find that script as a separate application.


BL quote proposals to this thread please.
how to ask smart questions | my repos / my repos | my blog
---
Thank you for posting direct image links!

Offline

#234 2020-08-05 07:26:12

Grover
New Member
Registered: 2020-08-03
Posts: 4

Re: The great yad hacking thread

Offline

#235 2020-08-05 17:56:10

ohnonot
...again
Registered: 2015-09-29
Posts: 4,875
Website

Re: The great yad hacking thread

^ Looking good, thanks!


BL quote proposals to this thread please.
how to ask smart questions | my repos / my repos | my blog
---
Thank you for posting direct image links!

Offline

Board footer

Powered by FluxBB