Jump to content
Sign in to follow this  
dummzeuch

suggestion for server side command execution on Linux

Recommended Posts

I have got a need to execute some simple Perl scripts on a Ubuntu Linux server on the LAN (no Internet involved).

So far, I am executing them via Putty in an ssh session that shows a small menu written in Perl. But that's cumbersome and I would prefer to have a Delphi client that requests a service to execute them.

As these commands require root privileges (*1) security is a big deal, so at least https and basic authentication should be used.

 

I could probably install Apache or a different web server and execute these commands via cgi, but this feels way overblown.

Some kind of REST API is what I am looking for, but I don't have any experience with the server side of that.

 

Any suggestions?

 

Just in case anybody wants to suggest that: We don't have a Delph license that allows writing Linux programs.

 

(*1: It's about creating zfs datasets and snapshots and changing their mount points.)

Share this post


Link to post

There is an add-on in Cockpit for ZFS Storage.
In the cockpit, you log in with the corresponding Linux user

Share this post


Link to post
1 hour ago, tgbs said:

There is an add-on in Cockpit for ZFS Storage.
In the cockpit, you log in with the corresponding Linux user

Sorry, my fault for not asking properly: I am not looking for a tool to replace Putty + the menu or the Linux shell, I am looking for a tool that allows a Delphi program to initiate starting those scripts, e.g. via a REST service.

Edited by dummzeuch

Share this post


Link to post

You can write your extension (script) to a Cockpit and then perform remotely. Extensions can be written on JavaScript. Can be called through something like this
curl -u 'Username: Password' -x Post \
 -d '{"Script": "/Path/to/your-script.sh", "args": ["arg1", "arg2"]}' \
 https: // <Server-IP>: 9090/My-Scripts/Execute
I think there was also a ready -made feature to access Shell, but I don't remember what it is. Since curl can be used, I see no reason for not writing the Delphi program. There are documentation for existing and new extensions.

 

Edit: A program can be written that performs something like this
ssh user@Server-IP> 'sudo myscript.sh'
The user must have sudo rights and be able to enforce it without a password. This is configured on the server. I think there are a lot of SSH access libraries with keys, not password

 

Edited by tgbs

Share this post


Link to post
23 hours ago, tgbs said:

Edit: A program can be written that performs something like this
ssh user@Server-IP> 'sudo myscript.sh'

That's so obvious that I just asked myself why I didn't think of it.

So, thanks a lot!

 

I could either call plink.exe (from Putty) or even easier, use libssh2 and the pascal bindings from @pyscripter.

In fact I just got the sources, downloaded the libssh2 and openssl dlls from the PHP project page and changed the SshExec demo to bypass the password prompt and call a test script as root. Worked fine. And as a plus I don't even have to install anything on the server, just use the existing ssh server, create some scripts and allow the appropriate users to call them as root without password in the sudoers configuration.

  • Like 4

Share this post


Link to post
3 hours ago, dummzeuch said:

I just got the sources, downloaded the libssh2 and openssl dlls

This is just to say that pyscripter/Ssh-Pascal: Delphi ssh library wrapping libssh2 (github.com) includes binaries that do not require OpenSSL, but use Windows CNG instead.  It also includes scripts that make it very easy to update the binaries.

Edited by pyscripter
  • Like 1
  • Thanks 1

Share this post


Link to post
18 hours ago, pyscripter said:

This is just to say that pyscripter/Ssh-Pascal: Delphi ssh library wrapping libssh2 (github.com) includes binaries that do not require OpenSSL, but use Windows CNG instead.  It also includes scripts that make it very easy to update the binaries.

Unfortunately the included dll did not work for me. I googled the error message (which I no longer recall) and found the advice to switch to the dlls from the PHP project. Those dlls worked fine with the same code and the same ssh server.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×