Watcher in my Wordpress:
FINALLY! i got some free time to do my own project that i like.
so hey guys i hope most of you have great months and it is been 1 month since i update my blog, it has been a hectic month for me because the project is keep coming and apparently i only have little time to finish it (i hope i could survive in the end of the months :D #LOL).
So just to make thing quick i just going to straight explaining the "little project" that i just two days ago made.
my pet project is about creating a watcher in my wp login website. so everytime someone try to go to my login page it record their ip address, browser and time to the log file.
I know! most of you think that it is actually useless because the apache already have a log(var/log/apache2) and you can just see it straight away. YES! it is true but the drawback is that you may not have your laptop all the time right?. so just to make things simple i'm just going to make application android that will fetch the log file anytime and anywhere and show it to me without bringing laptop everywhere.
ok so that was the idea, lets make it happen:
because it is pretty simple all i need to do is just creating simple log php page and inserted to the wp-login.php. After i finish making the php script, next is to creating the android application.
First Step: Creating the PHP script
creating log php script require you to use $_SERVER function, according to the official documentation page "is an array containing information such as headers, paths, and script locations" (url:http://php.net/manual/en/reserved.variables.server.php). The entries in this array are created by the web server" so it automatically handle the server request and listed it to us.For the project I only need 2 METHODS from $_SERVER function:
$_SERVER['REMOTE_ADDR'] for to get the ip address of the unknown visitor
$_SERVER['HTTP_USER_AGENT' for to get the browser that they use
and last thing is the date i use:
date('y/m/d G:i:s') format
ok so i have all the part for creating script:
<?php
$ip_address_for = $_SERVER['REMOTE_ADDR'];
$browser = $_SERVER['HTTP_USER_AGENT'];
$datetime = date('y/m/d G:i:s');
$file = "log_login49C03561A170F247B818E3D04B25B29C.txt";
$file = fopen($file,"a");
$data = "ip address: $ip_address_for \nbrowser: $browser \ndate: $datetime \n+======================+ \n";
fwrite($file,$encrypted_data);
fclose($file);
?>
i put the script inside the wp-login.php in my web hosting
and done! once someone go to login page it will create log_login file and you can see it right away. the reason why i put hash value after the name of the file is that i don't want the log file is easily to be spot on my website for security practice ish.
Second and the Last Step: Creating the Android Application
in my android application i created three method that will handle the url connection and putting the log into the interface.openhttpconnection() for initiate the http connection to the website
downloadtext() for download the log text file
downloadtexttask() for asynctask
If you want to see the code fell free to check my github repo,link
the result will be like the snipped picture:
pretty easy right ? you can follow along and try putting new features to the app for yourself. Well, for myself this kind of apps is still need more feature and update. i plan to put some features such as whois query and port scanning to the the apps so it could be function as a mini SOC in the android phone
ok i think that's all folks, i will update the part 2 soon. in part 2 i will show the update of the apps so it will cover a basic network tools to query information about the ip inside the log
peace out yoooo ~
Comments
Post a Comment