Cat

Prints the content of a file on the server.

Command line interface

Syntax

  1. $ cat filename

Arguments

  • filename – (file) The file to print.

Example

cat.php

  1. <?
  2. require("../plugin.php");
  3. if (is_ajax()) {
  4. if ($_POST["action"] == 'cat') {
  5. if (!is_file($_POST['file']) || !is_readable($_POST['file'])) die("1");
  6. $file = file_get_contents($_POST['file']);
  7. die("0".(is_utf8($file) ? $file : utf8_encode($file)));
  8. }
  9. exit;
  10. }
  11. ?>
  12. /**
  13. * Cat file
  14. **/
  15. TinyShell.plugins.cat = new Class({
  16. description: "Show file",
  17. run : function(terminal, args) {
  18. this.t = terminal;
  19. if (args.length) {
  20. this.file = args[0];
  21. this.t.ajax_request(this.print, "<?php echo $_AJAX_URL?>", "action=cat&file="+encodeURIComponent(this.file));
  22. } else {
  23. terminal.print("cat: usage: cat filename");
  24. terminal.resume();
  25. }
  26. },
  27. print: function(r) {
  28. if (r.substring(0, 1) != "0") this.t.print("cat: `"+this.file+"' is not a file");
  29. else this.t.print(r.substring(1));
  30. this.t.resume();
  31. }
  32. });

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>