-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11dcdbc
commit 4d5a931
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Hosts Validation | ||
|
||
on: | ||
push: | ||
paths: | ||
- hosts.txt | ||
pull_request: | ||
paths: | ||
- hosts.txt | ||
|
||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Validate hosts file | ||
run: | | ||
input="hosts.txt" | ||
debug=false | ||
while IFS= read -r line | ||
do | ||
if [[ "$line" =~ ^\# ]]; then | ||
$debug && echo "$line is a comment" | ||
elif [[ "$line" = "" ]]; then | ||
$debug && echo "line is empty" | ||
elif [[ "$line" =~ ^127\.0\.0\.1 ]] || [[ "$line" =~ ^::1 ]]; then | ||
$debug && echo "$line is an allowed redirection" | ||
else | ||
echo "$line is not an allowed redirection" | ||
echo "Only redirection to the loopback interface is allowed (127.0.0.1 for IPv4 or ::1 for IPv6)" | ||
exit 1 | ||
fi | ||
done < "$input" | ||
echo "Hosts file is valid" |