Skip to content
This repository
Browse code

Merge branch 'php_dependencies' of http://github.com/whatthejeff/phpsh

…into stufffromgithub
  • Loading branch information...
commit c481110a16dfd27390bfde99eef475872477715c 2 parents 572f632 + eeff837
authored September 14, 2010
13  README.md
Source Rendered
... ...
@@ -1,5 +1,18 @@
1 1
 Mailing list at: [http://groups.google.com/group/phpsh]([http://groups.google.com/group/phpsh])
2 2
 
  3
+PHP Dependencies
  4
+===================
  5
+__Version:__
  6
+
  7
+ * PHP 5+
  8
+
  9
+__Modules:__
  10
+
  11
+ * [pcntl](http://php.net/manual/en/book.pcntl.php)
  12
+ * [pcre](http://php.net/manual/en/book.pcre.php)
  13
+ * [posix](http://php.net/manual/en/book.posix.php)
  14
+ * [tokenizer](http://php.net/manual/en/book.tokenizer.php)
  15
+
3 16
 Python Dependencies
4 17
 ===================
5 18
 * sqlite  
38  src/__init__.py
@@ -630,12 +630,8 @@ def php_open_and_check(self):
630 630
 phpsh failed to initialize PHP.
631 631
 Fix the problem and hit enter to reload or ctrl-C to quit.""")
632 632
 
633  
-                if e.stdout_lines:
634  
-                   print("PHP output: %(output)s" %
635  
-                         {'output' : "\n".join(e.stdout_lines)})
636  
-                if e.stderr_lines:
637  
-                   print("PHP error output: %(output)s" %
638  
-                         {'output' : "\n".join(e.stderr_lines)})
  633
+                print self.clr_err
  634
+                print "".join(filter(lambda x: x != "", e.stdout_lines + e.stderr_lines))
639 635
 
640 636
                 if e.line_num:
641 637
                     print("\
@@ -692,32 +688,20 @@ def php_open(self):
692 688
             err_lines = self.p.stderr.readlines()
693 689
             out_lines = self.p.stdout.readlines()
694 690
 
695  
-            err_str = "\
696  
-UNKNOWN ERROR (maybe php build does not support signals/tokenizer?)"
697 691
             parse_error_re = re.compile(
698 692
                 "PHP Parse error: .* in (.*) on line ([0-9]*)")
699 693
             m = None
700 694
             for line in reversed(err_lines):
701  
-                err_line = line.rstrip()
702  
-                m = parse_error_re.match(err_line)
  695
+                m = parse_error_re.match(line)
703 696
                 if m:
704  
-                    err_str = err_line
705  
-                    break
706  
-
707  
-            print self.clr_err
708  
-            for err_line in err_lines:
709  
-                print err_line,
710  
-            print self.clr_default
711  
-
712  
-            if m:
713  
-                file_name, line_num = m.groups()
714  
-                raise ProblemStartingPhp(file_name,
715  
-                                         line_num,
716  
-                                         stdout_lines=out_lines,
717  
-                                         stderr_lines=err_lines)
718  
-            else:
719  
-                raise ProblemStartingPhp(stdout_lines=out_lines,
720  
-                                         stderr_lines=err_lines)
  697
+                    file_name, line_num = m.groups()
  698
+                    raise ProblemStartingPhp(file_name,
  699
+                                             line_num,
  700
+                                             stdout_lines=out_lines,
  701
+                                             stderr_lines=err_lines)
  702
+
  703
+            raise ProblemStartingPhp(stdout_lines=out_lines,
  704
+                                    stderr_lines=err_lines)
721 705
 
722 706
         while True:
723 707
             p_line = self.p.stdout.readline().rstrip()
10  src/phpsh.php
@@ -20,6 +20,16 @@
20 20
 //  this is probably not the right fix, but we need it for now
21 21
 ini_set('memory_limit', ini_get('memory_limit') * 2 . 'M');
22 22
 
  23
+if (version_compare(PHP_VERSION, '5.0.0', '<')) {
  24
+  fwrite(STDERR, 'Fatal error: phpsh requires PHP 5 or greater');
  25
+  exit;
  26
+}
  27
+
  28
+if ($missing = array_diff(array('pcntl','pcre','posix','tokenizer'), get_loaded_extensions())) {
  29
+  fwrite(STDERR, 'Fatal error: phpsh requires the following extensions: ' . implode(', ', $missing));
  30
+  exit;
  31
+}
  32
+
23 33
 // we buffer the output on includes so that output that gets generated by
24 34
 // includes doesn't interfere with the secret messages we pass between php and
25 35
 // python we'll capture any output and show it when we construct the shell

0 notes on commit c481110

Please sign in to comment.
Something went wrong with that request. Please try again.