groot , works like GKSU or pkexec or not

So you have written that new, must have program. Let us see it here.
Post Reply
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

groot , works like GKSU or pkexec or not

Post 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
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
  Me.Close()
  Return
  Endif

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])
End


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 
   Me.Close()
   Return
  Endif
  ' User did not cancel so run without root.
  RunCommand(False)

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


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



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
  Me.Close
  Return
Endif

' 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
Wend

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

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

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

' user pressed RETURN after password
Public Sub mbxPass_Activate()
btnOK_Click()
End
Last edited by BruceSteers on Tuesday 29th September 2020 1:59pm, edited 1 time in total.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: groot , works like GKSU or pkexec or not

Post by BruceSteers »

Edited..

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

Todo:
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
Last edited by BruceSteers on Tuesday 29th September 2020 8:05pm, edited 1 time in total.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: groot , works like GKSU or pkexec or not

Post 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

Then....

Then...

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

Gotta love gambas :)
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: groot , works like GKSU or pkexec or not

Post 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
It also now detects a wrong password entry and offers to retry.
If at first you don't succeed , try doing something differently.
BruceS
Post Reply