Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- /*
- CVS: http://server/viewvc/tickettool/?root=barn
- Spark: https://ticket/?reqid=116286
- function: writes logs, awesomely
- */
- $t = isset($_REQUEST['tx']) ? $_REQUEST['tx'] : null;
- $d = isset($_REQUEST['tool']) ? $_REQUEST['tool'] : null;
- $m = isset($_REQUEST['msg']) ? $_REQUEST['msg'] : null;
- $i = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
- $s = isset($_REQUEST['ts']) ? $_REQUEST['ts'] : null;
- $h = isset($_REQUEST['help']) ? $_REQUEST['help'] : null;
- // variables
- $toollist = array("sql", "alpha", "bravo", "charlie", "delta", "echo", "foxtrot", "golf", "hotel", "india", "juliet", "kilo", "lima", "mike", "november", "oscar", "papa", "quebec");
- $b = "tickettool/sym/";
- $y = date('Y');
- $z = date('D M d H:i:s T Y');
- $n = "\n";
- // help mode
- if ( $h == "yes" ) {
- echo "Welcome to the Ticket Tool web api <br>";
- echo "<hr>";
- echo "<strong>Variables</strong><br>";
- echo "<ul>";
- echo "<li>tx = ticket (req)</li>";
- echo "<li>tool = your tool name, must be in list: alpha, bravo, charlie (req)</li>";
- echo "<li>id = a process identifier, mostly useful to the tool author (req)</li>";
- echo "<li>msg = your message (req)</li>";
- echo "<li>ts = if value is 'yes' then script will prefix timestamp to your entry (optional) </li>";
- echo "<li>help = if value is 'yes' then show this help screen (exclusive)</li>";
- echo "</ul>";
- echo "<hr>";
- echo "<strong>Narration</strong><br>";
- echo "The script should work in GET or POST mode. It checks for the existence of all required variables.<br>";
- echo "A \\n will be added to your message.<br><br>";
- echo "Your TicketTool will be located at the following URL:<br>";
- echo "<em>http://server/tickettool/sym/{tool}/{current year}/{ticket}.txt</em>";
- echo "<hr>";
- echo "<strong>Valid Tools</strong><br>";
- var_dump($toollist);
- echo "<br>You'll need to create a directory with the right permissions on the server and modify the toollist array in the PHP file<br>";
- echo "<hr>";
- echo "<strong>Exit Codes</strong><br>";
- echo "Within the body of the response will be the following values:<br>";
- echo "<ul>";
- echo "<li> 0 - Success</li>";
- echo "<li> 5 - Failure - ticket not defined</li>";
- echo "<li>15 - Failure - tool not defined</li>";
- echo "<li>25 - Failure - message not defined</li>";
- echo "<li>35 - Failure - id not defined</li>";
- echo "<li>45 - Failure - tool not valid directory</li>";
- echo "<li>55 - Failure - could not write to file</li>";
- echo "</ul>";
- echo "You will need to check the exit status. Codes 5 through 35 are you. Code 45 and higher are SysEng";
- exit(0);
- }
- // evaluations
- if ( is_null($t) ) {
- echo "5"; // ticket not defined
- die;
- }
- if ( is_null($d) ) {
- echo "15"; // tool not defined
- die;
- }
- if ( is_null($m) ) {
- echo "25"; // msg not defined
- die;
- }
- if ( is_null($i) ) {
- echo "35"; // id not defined
- die;
- }
- if (! array_key_exists($d, array_flip($toollist)) &&
- !array_key_exists($d, $template_list)) {
- echo "45"; // not in toollist
- die;
- }
- // build (e)ntry for log, if request for t(s)=yes, then add time stamp (z)
- if ( $s == "yes" ) {
- $e = $z." ".$i." ".$m.$n;
- } else {
- $e = $i." ".$m.$n;
- }
- $e = $i." ".$m.$n;
- if ( $s == "yes" ) {
- $e = $z." ".$e;
- }
- if (array_key_exists($d, array_flip($toollist))) {
- $filename = "$b".$d."/".$y."/".$t.".txt";
- } else {
- $filename = $b.$y."/".$t.".txt";
- }
- $l = fopen($filename, 'a+');
- if (! $l ) {
- echo "55"; // file cannot be opened
- die;
- } else {
- fwrite($l, stripslashes($e));
- fclose($l);
- echo "0";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement