Last active
August 27, 2015 15:25
-
-
Save asimzeeshan/882ca003743843e177b0 to your computer and use it in GitHub Desktop.
A scriplet to update SVN from web + log the output and client IP (just rename this to some random script)
This file contains hidden or 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
| <?php | |
| # ====================================================================== | |
| # Update SVN from web invoke script | |
| # ---------------------------------------------------------------------- | |
| # Basic functions | |
| # ====================================================================== | |
| function _appendLog($data) { | |
| file_put_contents("svn.log", $data."\n", FILE_APPEND | LOCK_EX); | |
| } | |
| # ====================================================================== | |
| # Let's BEGIN | |
| # ====================================================================== | |
| // Ensure that SVN credentials are already saved else modify the command below to add those credentials explicitly | |
| exec("svn co http://usvn.vteamslabs.com/svn/asimzeeshan/trunk /home/asim/svn-test", $output); | |
| // if there is output | |
| if (!empty($output)) { | |
| // ensure that you get the IP regardless of local-network, proxy or public ip | |
| if (!empty($_SERVER['HTTP_CLIENT_IP'])) { | |
| $client_ip = $_SERVER['HTTP_CLIENT_IP']; | |
| } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { | |
| $client_ip = $_SERVER['HTTP_X_FORWARDED_FOR']; | |
| } elseif (!empty($_SERVER['REMOTE_ADDR'])) { | |
| $client_ip = $_SERVER['REMOTE_ADDR']; | |
| } else { // if executed through php5-cli, none of the above variables will have any data. We need a filler hence the "filler" below | |
| $client_ip = "php5-cli"; | |
| } | |
| // prepend the transaction | |
| _appendLog("\nSVN UPDATE INITIATED FROM $client_ip on ".date('Y-m-d H:i:s')); | |
| // add the multiline output | |
| // I hope PHP7 adds support for array() as $data | |
| foreach ($output as $row) { | |
| echo $row."<br />"; | |
| _appendLog($row); // log it | |
| } | |
| } |
Author
Author
Linear approach, added a function _appendLog() to centralize the logging
Author
Added <br /> instead of \n because in the browser, it will be a mess
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output in the logs would be