Page 1 of 1

groot , works like GKSU or pkexec or not

Posted: Tuesday 29th September 2020 3:10am
by BruceSteers
it is GRoot :)

I just made this today.

It occurred to me that i could possibly get an app to launch as root by creating a hidden TerminalView object and running the application with sudo through it, using the TerminalView.Input() method to send the password.

Turns out it can :)
so this app is called groot.
groot.png (93.55 KiB) Viewed 512 times
It's tiny, not much code.

It simply takes any provided arguments , puts 'sudo' in front of it and executes in the hidden terminaview.

Kinda works like that pkAppMan thing i made but without all the flaffing about with pkexec policies :)
Just run the install script to copy it to your /usr/bin folder then you can set menu items and desktop launchers and the like to sudo up your apps.
Has an option to just run as normal user too.
after installing it you could for example copy your pluma text editor menu launcher onto your desktop and change it's command from
'pluma %U' to
'groot pluma %U'
then either clicking the launcher or dragging files onto it will give you the option to run as root or not :)


Like i said not much code to it really..
' Gambas class file

Public aArgs As String[]
Public pTermProc As Process

Public Sub Form_Open()
  mbxPass.Password = True ' makes the text in the MaskBox show as ***

' If no arguments have been passed then there's nothing to do.
  If Args.Count = 1 Then
    Message("No arguments passed, Exitting.")
  Stop Event

aArgs = Args.All.Copy()  ' Copy the arguments passed
aArgs.Delete(0) ' remove the 1st Argument as it's groot

' Set the label text file info
lblInfo.Text = "Application: " & File.Name(aArgs[0]) & "\nPath: " & File.Dir(aArgs[0])

Public Sub btnOK_Click()
If mbxPass.Text = "" Then ' No password was entered so see if we want to continue or not
  If Message.Warning("No password entered.\nRun " & File.Name(Args[1]) & " without superuser rights?", "Yes", "No") <> 1 Then 
  ' User did not cancel so run without root.

 Else  ' Password has been entered so go for root...
  aArgs.Add("sudo", 0) ' insert 'sudo' as first argument

Public Sub btnNoRoot_Click() ' Just run the command without sudo

Public Sub RunCommand(Optional AsRoot As Boolean = True)

Me.Visible = False ' hide window

' if not running as root just Exec the command without teminalview and quit.
If Not AsRoot Then
  Exec aArgs

' create a terminalview object to run sudo in
Dim TermV As TerminalView
TermV = New TerminalView(Me)

' Execute the command creating the Process.
pTermProc = TermV.Exec(aArgs)

' give it a moment then send the root password
Wait 0.8
TermV.Input(mbxPass.Text & gb.Lf)

' Wait for the process to finish before quiting so as not to invalidate the process stream.
While pTermProc.State = Process.Running
  Wait 0.5

' Command has finished so we can clean up and exit.
If pTermProc Then pTermProc.Kill()

Public Sub btnCancel_Click()
  Print "User cancelled superuser request."

' Show and hide again the password on holding the button down.
Public Sub btnShow_MouseDown()
  mbxPass.Password = False
Public Sub btnShow_MouseUp()
  mbxPass.Password = True

' user pressed RETURN after password
Public Sub mbxPass_Activate()

Re: groot , works like GKSU or pkexec or not

Posted: Tuesday 29th September 2020 1:57pm
by BruceSteers

It's actually quite functional this app so i prettied it up a bit.
Gave it some changeable/saveable settings ( font and colours)
Made it pop up at Mouse position instead of center screen.
A little opacity too :)
Compiled 3 different versions. QT only, GTK only, or both.
(this is because gtk does not set the text field background colour but QT does so i want to have the QT version on mt gtk desktop.)

Gave a saveable option to just run normally if no password is entered.
Made the "Run Nomally" button hide if above method used.
made the password box regain focus on activate.
groot_screenshot.png (666.93 KiB) Viewed 503 times

May look into encryption to save the root password as a setting and allow you to let some apps to auto-run as root without asking for the password.

Probably add some default start position option Ie, select center-screen, top-left or Mouse pos

Re: groot , works like GKSU or pkexec or not

Posted: Tuesday 29th September 2020 7:37pm
by BruceSteers
Tell you what's hilarious....

For years i used GKSU then it disappeared.
so after much searching i found the .deb installers for GKSU and it's libraries that worked and had to manually install it on each linux install,
Then it just disapeared completely and i had to move onto figuring out using pkexec and setting policy rules.
Then i made gambas apps and scripts so others could more easily accomplish the same thing with pkexec and wrote instructions and stuff



In just a few hours i knocked up a program that's doing Everything GKSU did and more :D :lol:

Gotta love gambas :)

Re: groot , works like GKSU or pkexec or not

Posted: Monday 05th October 2020 5:30pm
by BruceSteers
A few changes to this...
I found on some linux configs the window height was wrong so changed the way it lays out.

Also now it tries to show the icon of the app you are running..
groot_screenshot.png (667.85 KiB) Viewed 438 times
It also now detects a wrong password entry and offers to retry.