Blogs

Scripting How-To: Display banner and request login confirmation for SLAX

By Erdem posted 08-10-2015 12:56

  

Display Banner and Request Login Confirmation for SLAX

 

To display the banner and ask for login confirmation for SLAX version 1.0 and higher, configure the script as an op script under [system scripts op], and as a login script under [system login class login-script].

 

The script is executed each time whenever the user of this class logs into system. This feature is available from Junos OS Release 9.5 onwards.

 

Source Code and GitHub Links

 

The source code below is also available from the following GitHub locations:

 

01	/*
02	 *
03	 * Login-script.
04	 *
05	 * Displays the banner and ask for login confirmation.
06	 *
07	 * Should be configured as op-script under [system scripts op] and
08	 * and as login-script under [system login class login-script].
09	 * Script will be executed each time whenever the user of this class login
10	 * into system.
11	 *
12	 * Available from 9.5 onwards.
13	 *
14	 */
15	version 1.0;
16	  
17	ns junos = "http://xml.juniper.net/junos/*/junos";
18	ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
19	ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
20	  
21	import "../import/junos.xsl";
22	  
23	match / {
24	 
25	    var $banner = '
26	* ****************************************************************************
27	*
28	*  Company-xyz - Authorized Access Only
29	*
30	*  This system is for the authorized use of employees of xyz
31	*  and authorized contractors. Individuals using this computer system
32	*  without authority, will be punished.
33	*
34	* ****************************************************************************
35	';
36	    <op-script-results> {
37	    expr jcs:output($banner);
38	 
39	    var $response = {
40	        call get-response();
41	    }
42	 
43	    if ($response == "no") {
44	        /*
45	         * Logging out, Bye, bye
46	         */
47	        var $rpc = <command> "request system logout user " _ $user;
48	        var $noresponse = jcs:invoke($rpc);
49	    }
50	    }
51	}
52	 
53	template get-response()
54	{
55	    var $newline = jcs:printf("\n");
56	 
57	    expr jcs:output($newline);
58	 
59	    var $res = jcs:input("Are you sure you are authorized? (yes/no) ");
60	 
61	    if ($res !=  "yes" && $res != "no") {
62	    call get-response();
63	    } else {
64	    expr $res;
65	    }
66	}

 

XML Script Contents

 

01	<?xml version="1.0"?>
02	<script>
03	  <title>login-script.slax</title>
04	  <author>rsankar</author>
05	  <synopsis>
06	    Display the banner and ask for login confirmation
07	  </synopsis>
08	  <coe>op</coe>
09	  <type>login</type>
10	 
11	  <description>
12	Should be configured as op-script under [system scripts op] and as login-script under [system login class login-script]. Script will be executed each time whenever the user of this class login into system. Available from 9.5 onwards.
13	 
14	  </description>
15	 
16	  <example>
17	    <title>login-script.slax</title>
18	    <description>Login script details</description>
19	  </example>
20	 
21	  <xhtml:script xmlns:xhtml="http://www.w3.org/1999/xhtml"
22	                src="../../../../../web/leaf.js"
23	            type="text/javascript"/>
24	</script>

 


#opscript
#Slax
#How-To
#ScriptingHow-To