SHARE
TWEET

tt.redacted.php

a guest Jul 25th, 2014 23 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?
  2. /*
  3. CVS: http://server/viewvc/tickettool/?root=barn
  4. Spark: https://ticket/?reqid=116286
  5. function: writes logs, awesomely
  6. */
  7.  
  8. $t = isset($_REQUEST['tx']) ? $_REQUEST['tx'] : null;
  9. $d = isset($_REQUEST['tool']) ? $_REQUEST['tool'] : null;
  10. $m = isset($_REQUEST['msg']) ? $_REQUEST['msg'] : null;
  11. $i = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
  12. $s = isset($_REQUEST['ts']) ? $_REQUEST['ts'] : null;
  13. $h = isset($_REQUEST['help']) ? $_REQUEST['help'] : null;
  14.  
  15.  
  16. // variables
  17. $toollist = array("sql", "alpha", "bravo", "charlie", "delta", "echo", "foxtrot", "golf", "hotel", "india", "juliet", "kilo", "lima", "mike", "november", "oscar", "papa", "quebec");
  18. $b = "tickettool/sym/";
  19. $y = date('Y');
  20. $z = date('D M d H:i:s T Y');
  21. $n = "\n";
  22.  
  23. // help mode
  24. if ( $h == "yes" ) {
  25.         echo "Welcome to the Ticket Tool web api <br>";
  26.         echo "<hr>";
  27.         echo "<strong>Variables</strong><br>";
  28.         echo "<ul>";
  29.         echo "<li>tx = ticket (req)</li>";
  30.         echo "<li>tool = your tool name, must be in list: alpha, bravo, charlie (req)</li>";
  31.         echo "<li>id = a process identifier, mostly useful to the tool author (req)</li>";
  32.         echo "<li>msg = your message (req)</li>";
  33.         echo "<li>ts = if value is 'yes' then script will prefix timestamp to your entry (optional) </li>";
  34.         echo "<li>help = if value is 'yes' then show this help screen (exclusive)</li>";
  35.         echo "</ul>";
  36.         echo "<hr>";
  37.         echo "<strong>Narration</strong><br>";
  38.         echo "The script should work in GET or POST mode.  It checks for the existence of all required variables.<br>";
  39.         echo "A \\n will be added to your message.<br><br>";
  40.         echo "Your TicketTool will be located at the following URL:<br>";
  41.         echo "<em>http://server/tickettool/sym/{tool}/{current year}/{ticket}.txt</em>";
  42.         echo "<hr>";
  43.         echo "<strong>Valid Tools</strong><br>";
  44.         var_dump($toollist);
  45.         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>";
  46.         echo "<hr>";
  47.         echo "<strong>Exit Codes</strong><br>";
  48.         echo "Within the body of the response will be the following values:<br>";
  49.         echo "<ul>";
  50.         echo "<li> 0 - Success</li>";
  51.         echo "<li> 5 - Failure - ticket not defined</li>";
  52.         echo "<li>15 - Failure - tool not defined</li>";
  53.         echo "<li>25 - Failure - message not defined</li>";
  54.         echo "<li>35 - Failure - id not defined</li>";
  55.         echo "<li>45 - Failure - tool not valid directory</li>";
  56.         echo "<li>55 - Failure - could not write to file</li>";
  57.         echo "</ul>";
  58.         echo "You will need to check the exit status.  Codes 5 through 35 are you.  Code 45 and higher are SysEng";
  59.         exit(0);
  60. }
  61.  
  62. // evaluations
  63. if ( is_null($t) ) {
  64.         echo "5"; // ticket not defined
  65.         die;
  66. }
  67.  
  68. if ( is_null($d) ) {
  69.         echo "15"; // tool not defined
  70.         die;
  71. }
  72.  
  73. if ( is_null($m) ) {
  74.         echo "25"; // msg not defined
  75.         die;
  76. }
  77.  
  78. if ( is_null($i) ) {
  79.         echo "35"; // id not defined
  80.         die;
  81. }
  82.  
  83.  
  84. if (! array_key_exists($d, array_flip($toollist)) &&
  85.      !array_key_exists($d, $template_list)) {
  86.         echo "45"; // not in toollist
  87.         die;
  88. }
  89.  
  90. // build (e)ntry for log, if request for t(s)=yes, then add time stamp (z)
  91. if ( $s == "yes" ) {
  92.         $e = $z." ".$i." ".$m.$n;
  93. } else {
  94.         $e = $i." ".$m.$n;
  95. }
  96. $e = $i." ".$m.$n;
  97. if ( $s == "yes" ) {
  98.         $e = $z." ".$e;
  99. }
  100.  
  101. if (array_key_exists($d, array_flip($toollist))) {
  102.         $filename = "$b".$d."/".$y."/".$t.".txt";
  103. } else {
  104.         $filename = $b.$y."/".$t.".txt";
  105. }
  106.  
  107. $l = fopen($filename, 'a+');
  108. if (! $l ) {
  109.         echo "55"; // file cannot be opened
  110.         die;
  111. } else {
  112.         fwrite($l, stripslashes($e));
  113.         fclose($l);
  114.         echo "0";
  115. }
  116. ?>
RAW Paste Data
Top