Operating System - HP-UX
1846594 Members
1146 Online
110256 Solutions
New Discussion

Script for creating User / Operator Menu ??

 
SOLVED
Go to solution
Chris Fung
Frequent Advisor

Script for creating User / Operator Menu ??

Hi all,

I am thinking to write a menu with either ksh or sh script for the users and operator to use. I am thinking of the security issue right now, how can I restrict them from getting out of the menu ?? Since each menu page options will call other sub-scripts to perform specific functions, what action should I take in order to restrict the users from jump out the shell all the way ??

Appreciated it if anyone can give me some examples.

Thanks,

Chris,
12 REPLIES 12
A. Clay Stephenson
Acclaimed Contributor

Re: Script for creating User / Operator Menu ??

The key to what you want to do is the trap command.

trap "" 1 2 3
tells the shell to ignore those signals

when you are done

trap - 1 2 3
resets the signal handling to its original value.

It's up to you to decide which signals you are going to ignore.

Remember, there might be a legitimate reason to use an interrupt (usually ctrl-c) in a shell script or an executable so know what you want to do.
If it ain't broke, I can fix that.
Fragon
Trusted Contributor

Re: Script for creating User / Operator Menu ??

First I want to thank Clay-the one who teach me how to use trap!
But here I don't think it's good enough to use
trap "" 1 2 3
because sometimes users really want to use "Ctrl+C" to terminate there session.
Maybe
trap "prompt_script" 1 2 3 is better. For example , when users press ^C, your system will give a message "Terminate your job?" and prompt-for yes/no.
If "yes" ,do break function and the user can really terminate there job; if "no" ,do a initial menu function! Thus the users can't exit from the menu.

-Gerald-
U.SivaKumar_2
Honored Contributor

Re: Script for creating User / Operator Menu ??

Hi,
When the users login , they will land at the menu , they should not get the shell prompt at any circumstances. If this is the requirement
then edit the .profile file in home directories of those users and put
this line.

exec /menu/yourmenuscript

Now users will land at the menu when they log in and if they play tricks like ctrl - c etc
they will be logged out of the system.

regards,
U.SivaKumar
Innovations are made when conventions are broken
Chris Fung
Frequent Advisor

Re: Script for creating User / Operator Menu ??

Hi all,

Thanks for the information !! BTW, just want to know what is the meaning of the 1 2 3 for the trape command ?? Any other numbers ?? What they represent ?? Any resources link that help me to master the trap function ??

Many thanks,

Chris,
A. Clay Stephenson
Acclaimed Contributor

Re: Script for creating User / Operator Menu ??

Those number correspond to signals. Do a kill -l and you will see which signals those apply to. As for as ctrl-c the trap command is how you control cntl-c e.g. trap "" 2 will tell your process and child process to ignore a ctrl-c so that the users can't break out. trap "" 3 will do the same to whatever key defines the 'quit' signal. Signal handlers and traps in the shell or C are up to the programmer.
If it ain't broke, I can fix that.
U.SivaKumar_2
Honored Contributor
Solution

Re: Script for creating User / Operator Menu ??

Hi,

Unix provides a mechanism known as signals to inform a process of some event which it may be interested in and wish to deal with or respond to. The shell also generates certain events that a shell programmer may wish to have the shell repond to. Both of these types of events are handled in the shell by a mechanism known as Traps.

Shell procedures can use the trap command to disable a signal or redefine its action. The format of the trap command is,

trap arg signal-list

Arg is a string to be interpreted as a command list and signal-list consists of one or more signal numbers as described by the signal keyword.

Number Signal
0 exit from shell
1 HANGUP
2 INTERRUPT character (DELETE or RUB OUT)
3 QUIT (ctrl-\)
9 KILL (cannot be caught or ignored)
11 segmentation violation
15 software termination signal

regards,
U.SivaKumar




Innovations are made when conventions are broken
A. Clay Stephenson
Acclaimed Contributor

Re: Script for creating User / Operator Menu ??

One other technique that can use is to set the
intr and quit keys to undefined

e.g. stty intr '^_' # undefines the intr signal (2)

stty quit '^_' # undefs the quit signal (3)

Of course, you should first save the original values by calling stty and restore them when you need to.
If it ain't broke, I can fix that.
U.SivaKumar_2
Honored Contributor

Re: Script for creating User / Operator Menu ??

Hi,

Look at this link for examples of how trap command is used.

http://www.ualberta.ca/HELP/unix/scrpt_scrpt2.9.3.html#scrpt2.9.3

regards,
U.SivaKumar

Innovations are made when conventions are broken
Bill Hassell
Honored Contributor

Re: Script for creating User / Operator Menu ??

Another technique is to make the menu script the user's shell, that is, change /etc/passwd so that the login shell is the menu script. Now, if the script is terminated, the user is logged out. The idea is to prevent the user from getting a normal shell prompt.


Bill Hassell, sysadmin
Nick Wickens
Respected Contributor

Re: Script for creating User / Operator Menu ??

You might also consider doing what I did when I set up an Ops menu.

As a lot of things you might want ops to do may require root access so instigate sudo (a search on the forum for sudo should locate the Liverpool archive for this) and fire up all menu options via sudo.

Also has the advantage that the options would only be accessible by entering a password each time the option is selected so if they leave their login active no one else can run the options whilst they are not looking.

Attached is the ops menu I setup if you want any ideas. It also includes an option to be displayed for "advanced" users only which is determined by the users access to a specific user group called "rootusers"
Hats ? We don't need no stinkin' hats !!
Nick Wickens
Respected Contributor

Re: Script for creating User / Operator Menu ??

... and I guess it helps if I attach the menu I mentioned as well :@).
Hats ? We don't need no stinkin' hats !!
Carlo Henrico_1
Regular Advisor

Re: Script for creating User / Operator Menu ??

Chris

Here is a nice script I found somewhere which I use intensively. Nice headers etc.

What is important is to place the same trap commands in the user's .profile also!

Enjoy

Carlo
Live fast, die young - enjoy a good looking corpse!