-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Banner] Add new feature including config, yang and tests #16957
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[Unit] | ||
Description=Update banner config based on configdb | ||
Requires=config-setup.service | ||
After=config-setup.service | ||
Before=systemd-logind.service sshd.service | ||
BindsTo=database.service | ||
BindsTo=sonic.target | ||
|
||
[Service] | ||
Type=oneshot | ||
RemainAfterExit=no | ||
ExecStart=/usr/bin/banner-config.sh | ||
|
||
[Install] | ||
WantedBy=sonic.target | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash -e | ||
|
||
STATE=$(sonic-cfggen -d -v 'BANNER_MESSAGE["global"]["state"]') | ||
LOGIN= | ||
MOTD= | ||
LOGOUT= | ||
|
||
if [[ $STATE == "enabled" ]]; then | ||
LOGIN=$(sonic-cfggen -d -v 'BANNER_MESSAGE["global"]["login"]') | ||
MOTD=$(sonic-cfggen -d -v 'BANNER_MESSAGE["global"]["motd"]') | ||
LOGOUT=$(sonic-cfggen -d -v 'BANNER_MESSAGE["global"]["logout"]') | ||
|
||
echo -e "$LOGIN" > /etc/issue.net | ||
echo -e "$LOGIN" > /etc/issue | ||
echo -e "$MOTD" > /etc/motd | ||
echo -e "$LOGOUT" > /etc/logout_message | ||
fi | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If state is disabled, are you planning clear banner files? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we do not clean banner messages. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
LOGOUT_MESSAGE_PATH="/etc/logout_message" | ||
LOGOUT_MESSAGE= | ||
|
||
if [[ -f "$LOGOUT_MESSAGE_PATH" ]]; then | ||
LOGOUT_MESSAGE=$(cat $LOGOUT_MESSAGE_PATH) | ||
fi | ||
|
||
if [[ -n "$LOGOUT_MESSAGE" ]]; then | ||
# Print logout message | ||
echo $LOGOUT_MESSAGE | ||
fi | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"BANNER_MESSAGE_TEST_STATE": { | ||
"desc": "Configure Banner feature state." | ||
}, | ||
"BANNER_MESSAGE_TEST_LOGIN" : { | ||
"desc": "Banner login messages configuration in BANNER_MESSAGE table." | ||
}, | ||
"BANNER_MESSAGE_TEST_MOTD" : { | ||
"desc": "Banner MOTD messages configuration in BANNER_MESSAGE table." | ||
}, | ||
"BANNER_MESSAGE_TEST_LOGOUT" : { | ||
"desc": "Banner logout messages configuration in BANNER_MESSAGE table." | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"BANNER_MESSAGE_TEST_STATE": { | ||
"sonic-banner:sonic-banner": { | ||
"sonic-banner:BANNER_MESSAGE": { | ||
"global": { | ||
"state": "enabled", | ||
"login": "Some login message", | ||
"motd": "Some message of the day", | ||
"logout": "Some logout message" | ||
} | ||
} | ||
} | ||
}, | ||
"BANNER_MESSAGE_TEST_LOGIN": { | ||
"sonic-banner:sonic-banner": { | ||
"sonic-banner:BANNER_MESSAGE": { | ||
"global": { | ||
"state": "enabled", | ||
"login": "Some login message", | ||
"motd": "Some message of the day", | ||
"logout": "Some logout message" | ||
} | ||
} | ||
} | ||
}, | ||
"BANNER_MESSAGE_TEST_MOTD": { | ||
"sonic-banner:sonic-banner": { | ||
"sonic-banner:BANNER_MESSAGE": { | ||
"global": { | ||
"state": "enabled", | ||
"login": "Some login message", | ||
"motd": "Some message of the day", | ||
"logout": "Some logout message" | ||
} | ||
} | ||
} | ||
}, | ||
"BANNER_MESSAGE_TEST_LOGOUT": { | ||
"sonic-banner:sonic-banner": { | ||
"sonic-banner:BANNER_MESSAGE": { | ||
"global": { | ||
"state": "enabled", | ||
"login": "Some login message", | ||
"motd": "Some message of the day", | ||
"logout": "Some logout message" | ||
} | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module sonic-banner { | ||
yang-version 1.1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
namespace "http://github.com/sonic-net/sonic-banner"; | ||
prefix banner_message; | ||
|
||
import sonic-types { | ||
prefix stypes; | ||
} | ||
|
||
description "BANNER_MESSAGE YANG Module for SONiC-based OS"; | ||
revision 2023-05-18 { | ||
description "First Revision"; | ||
} | ||
container sonic-banner { | ||
container BANNER_MESSAGE { | ||
description "BANNER_MESSAGE part of config_db.json"; | ||
container global { | ||
leaf state { | ||
type stypes:admin_mode; | ||
description "Banner feature state"; | ||
default disabled; | ||
} | ||
leaf login { | ||
type string; | ||
description "Banner message displayed to user before login prompt"; | ||
default "Debian GNU/Linux 11"; | ||
} | ||
leaf motd { | ||
type string; | ||
description "Banner message displayed to user after login prompt"; | ||
default "You are on | ||
____ ___ _ _ _ ____ | ||
/ ___| / _ \\| \\ | (_)/ ___| | ||
\\___ \\| | | | \\| | | | | ||
___) | |_| | |\\ | | |___ | ||
|____/ \\___/|_| \\_|_|\\____| | ||
-- Software for Open Networking in the Cloud -- | ||
Unauthorized access and/or use are prohibited. | ||
All access and/or use are subject to monitoring. | ||
Help: https://sonic-net.github.io/SONiC/ | ||
"; | ||
} | ||
leaf logout { | ||
type string; | ||
description "Banner message dispalyed to the users on logout"; | ||
default ""; | ||
} | ||
} /* end of container MESSAGE */ | ||
} /* end of container BANNER_MESSAGE */ | ||
} /* end of top level container */ | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a later comment on HLD https://github.com/sonic-net/SONiC/pull/1361/files#r1451662677 #Closed