groot , works like GKSU or pkexec or not

Post

Posted
Rating:
#1 (In Topic #473)
Banned
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.
(attachment removed)

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..

Code (gambas)

  1. ' Gambas class file
  2.  
  3. Public aArgs As String[]
  4. Public pTermProc As Process
  5.  
  6. Public Sub Form_Open()
  7.   mbxPass.Password = True ' makes the text in the MaskBox show as ***
  8.  
  9. ' If no arguments have been passed then there's nothing to do.
  10.   If Args.Count = 1 Then
  11.     Message("No arguments passed, Exitting.")
  12.   Me.Close()
  13.  
  14. aArgs = Args.All.Copy()  ' Copy the arguments passed
  15. aArgs.Delete(0) ' remove the 1st Argument as it's groot
  16.  
  17. ' Set the label text file info
  18. lblInfo.Text = "Application: " & File.Name(aArgs[0]) & "\nPath: " & File.Dir(aArgs[0])
  19.  
  20.  
  21. Public Sub btnOK_Click()
  22. If mbxPass.Text = "" Then ' No password was entered so see if we want to continue or not
  23.   If Message.Warning("No password entered.\nRun " & File.Name(Args[1]) & " without superuser rights?", "Yes", "No") <> 1 Then
  24.    Me.Close()
  25.    Return
  26.   ' User did not cancel so run without root.
  27.   RunCommand(False)
  28.  
  29.  Else  ' Password has been entered so go for root...
  30.   aArgs.Add("sudo", 0) ' insert 'sudo' as first argument
  31.   RunCommand()
  32.  
  33.  
  34. Public Sub btnNoRoot_Click() ' Just run the command without sudo
  35. RunCommand(False)
  36.  
  37.  
  38.  
  39. Public Sub RunCommand(Optional AsRoot As Boolean = True)
  40.  
  41. Me.Visible = False ' hide window
  42.  
  43. ' if not running as root just Exec the command without teminalview and quit.
  44. If Not AsRoot Then
  45.   Exec aArgs
  46.  
  47. ' create a terminalview object to run sudo in
  48. Dim TermV As TerminalView
  49. TermV = New TerminalView(Me)
  50.  
  51. ' Execute the command creating the Process.
  52. pTermProc = TermV.Exec(aArgs)
  53.  
  54. ' give it a moment then send the root password
  55. Wait 0.8
  56. TermV.Input(mbxPass.Text & gb.Lf)
  57.  
  58. ' Wait for the process to finish before quiting so as not to invalidate the process stream.
  59. While pTermProc.State = Process.Running
  60.   Wait 0.5
  61.  
  62. ' Command has finished so we can clean up and exit.
  63. If pTermProc Then pTermProc.Kill()
  64.  
  65. Public Sub btnCancel_Click()
  66.   Print "User cancelled superuser request."
  67.  
  68. ' Show and hide again the password on holding the button down.
  69. Public Sub btnShow_MouseDown()
  70.   mbxPass.Password = False
  71. Public Sub btnShow_MouseUp()
  72.   mbxPass.Password = True
  73.   mbxPass.SetFocus
  74.  
  75. ' user pressed RETURN after password
  76. Public Sub mbxPass_Activate()
  77. btnOK_Click()
  78.  
Online now: No Back to the top

Post

Posted
Rating:
#2
Banned
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.

(attachment removed)


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
Online now: No Back to the top

Post

Posted
Rating:
#3
Banned
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 :)
Online now: No Back to the top

Post

Posted
Rating:
#4
Banned
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..
(attachment removed)
It also now detects a wrong password entry and offers to retry.
Online now: No Back to the top
1 guest and 0 members have just viewed this.