USER AUTORIZATION LISP

USER AUTORIZATION LISP

My_Civil_3D
Advocate Advocate
900 Views
7 Replies
Message 1 of 8

USER AUTORIZATION LISP

My_Civil_3D
Advocate
Advocate

Hi guys i have a lisp file that contains all my custom lisp functions, there are a couple of users in our office i would like to share it with but no everyone. i am trying to use the getenv to get the username of the pc, but i am unsure if you will be able to unload the lisp if the username doesnt match or a way for all the commands in the lisp file to not work?

Civil 3D Certified Professional
0 Likes
901 Views
7 Replies
Replies (7)
Message 2 of 8

paullimapa
Mentor
Mentor

then just do an if test and the username you don't want matches then use the exit function


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 8

Sea-Haven
Mentor
Mentor

You will have to say make it a fas or else the user may get it again if plain text lsp, and remove your check, you dont need a PC check can get current user name. Then if match use (exit) it will do just that bomb out of the lisp.

 

(setq who (strcase (getenv "username")))
(cond 
((= who "AH")(setvar "modemacro" "Do DIALS for Di"))
((= who "MR")(setvar "modemacro" "Mark's computer"))
((= who "RG")(setvar "modemacro" "Robins workstation"))
)

0 Likes
Message 4 of 8

My_Civil_3D
Advocate
Advocate

do i only put it on top of my lisp file once? rememeber that i have all my lisps in one file?

Civil 3D Certified Professional
0 Likes
Message 5 of 8

My_Civil_3D
Advocate
Advocate

im not sure on how to compile it, i dont know if its possible for it to only do the if once, i have all my lisps in one file

Civil 3D Certified Professional
0 Likes
Message 6 of 8

Kent1Cooper
Consultant
Consultant

@My_Civil_3D wrote:

.... i have a lisp file that contains all my custom lisp functions .... i am trying to use the getenv to get the username of the pc, but i am unsure if you will be able to unload the lisp if the username doesnt match or a way for all the commands in the lisp file to not work?


Once the commands and functions defined in the AutoLisp file are loaded in the current session, I don't know of a way to unload them if you find the User is not on the authorized list.  The User check would probably need to come before the loading.  You probably need a different file that does something like:

 

(if (member (getenv "USERNAME") '("Bob" "Carol" "Ted" "Alice")); User name is among those authorized

  (load ;;; then load your main file

 

EDIT:  Another thought occurs to me, if for some reason it's awkward to do the above:  You could have all the things defined in that file re-defined to be nothing if the User is not authorized:

 

(if (not (member (getenv "USERNAME") '("Bob" "Carol" "Ted" "Alice"))); User name is not among those authorized

  (progn

    (defun C:Command1 () ())

    (defun function2 () ())

    ....

 

That way, you could have command and function definitions in the file that are available to all and also some in the same file available to a limited number of people, if the above re-defining-to-nothing only happens to those commands/functions you don't want available to everyone.

 

When I do that with some of my custom commands, if I type in the command name, I get nil returned, not an unknown-command message, so they're not really unloaded, but they wouldn't function.

 

But to me, it seems better to have them not loaded in the first place.  Which could still be all within one file:

 

(if (member (getenv "USERNAME") '("Bob" "Carol" "Ted" "Alice")); User name is among those authorized

  (progn ;;; then define limited-users commands/functions

    (defun C:Command1 () (...define it...))

    (defun function2 () (...define it...))

    ....

 

and define everybody-can-use commands/functions outside that (if) function.

Kent Cooper, AIA
0 Likes
Message 7 of 8

james_moore
Advocate
Advocate

(setq <function name here> nil) could be used in post-processing...

  Whatever (defun C:MYCOMMAND()) or (defun MYFUNCTION ()) may have previously been loaded could be erased from the current session in this manner too.  Use with (getenv "LOGINNAME") for the current OS username.

 

Some form of a loop including (if (eq username (getenv "LOGINNAME"))(setq C:MYCOMMAND nil)) should do the trick.

 

0 Likes
Message 8 of 8

Sea-Haven
Mentor
Mentor

If you open VLIDE it has the compile option to fas.  This would be easiest way. This way users can not look inside, but you need the master somewhere safe as can not un-fas easily.

 

Via lisp

(defun comp ( )
(if (null vlisp-compile) (c:vlide T)) 
(setq fname (getfiled "Pick lisp to be compiled" "D:\\alan\\lisp" "lsp" 8))
(setq len (strlen fname))
(setq diff (- len (+ 15 3)))
(setq fnameout (substr fname 15 diff))
(vlisp-compile 'st  fname  (strcat "d:\\alan\\compiled\\" fnameout ".fas"))
)
(comp)

 

 

 

if you must 

0 Likes