Issue
I am attempting an exercise given by my instructor. We were tasked with setting up a VirtualHost that could be accessed mon-fri/1-5. On top of that, we must allow access to the site from IP "XX.XX.XX.XXX" at anytime.
Current crontab:
* 13 * * 1-5 root apachectl start
* 17 * * 1-5 root apachectl stop
* * * * * root ./bash
Bash file:
currIP=$(hostname -I)
case "$currIP" in
*XX.XX.XX.XXX*)
???????
;;
esac
Can someone explain to me how I am going to serve this site to the IP without serving it to everyone at once?
Thanks!
Solution
Lets say this is your config file.
/etc/apache2/httpd.conf
Run these commands :
sudo cp /etc/apache2/httpd.conf all.conf
sudo cp /etc/apache2/httpd.conf restricted.conf
Now create this script somewhere in your system :
#!/bin/bash
[[ "$1" = "all" ]] && { ln -s --force /etc/apache2/all.conf /etc/apache2/httpd.conf ;}
[[ "$1" = "restricted" ]] && { ln -s --force /etc/apache2/restricted.conf /etc/apache2/httpd.conf ;}
sudo systemctl restart httpd
And add execution permissions to it :
sudo chmod +x /path/to/your/script.sh
Now modify /etc/apache2/restricted.conf to filter requests by IP. You can find information on that here : https://httpd.apache.org/docs/2.4/es/mod/mod_authz_core.html#require
Now set the root cron as :
sudo crontab -e
And in there add this :
* 13 * * 1-5 /path/to/your/script.sh "all"
* 17 * * 1-5 /path/to/your/script.sh "restricted"
And be happy!
Answered By - Matias Barrios Answer Checked By - Gilberto Lyons (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.