]> granicus.if.org Git - php/commitdiff
improve -l, add -a
authorkrakjoe <joe.watkins@live.co.uk>
Fri, 29 Nov 2013 19:42:41 +0000 (19:42 +0000)
committerkrakjoe <joe.watkins@live.co.uk>
Fri, 29 Nov 2013 19:42:41 +0000 (19:42 +0000)
README.md
phpdbg.c
phpdbg_help.c

index c4427127f3390eb7974313abbbb50c083e14fb27..9b4ce0f893a76310764ef629aa6e116921a6de81 100644 (file)
--- a/README.md
+++ b/README.md
@@ -17,6 +17,7 @@ Features
  - PHP Configuration File Support
  - JIT Super Globals - Set Your Own !!
  - Optional readline Support - Comfortable Terminal Operation
+ - Remote Debugging Support - Bundled Java GUI
  - Easy Operation - See Help :)
 
 Planned
index 2cedaf4d64cdfe9eaa0c030485e9501e63fea7ba..af3a1179ad36437e4706470850685cd6f295cf68 100644 (file)
--- a/phpdbg.c
+++ b/phpdbg.c
@@ -489,6 +489,7 @@ const opt_struct OPTIONS[] = { /* {{{ */
        {'E', 0, "step-through-eval"},
 #ifndef _WIN32
        {'l', 1, "listen"},
+       {'a', 1, "address-or-any"},
 #endif
        {'-', 0, NULL}
 }; /* }}} */
@@ -549,7 +550,7 @@ static inline void phpdbg_sigint_handler(int signo) /* {{{ */
 } /* }}} */
 
 #ifndef _WIN32
-int phpdbg_open_socket(short port) /* {{{ */
+int phpdbg_open_socket(const char *interface, short port) /* {{{ */
 {
        int fd = socket(AF_INET, SOCK_STREAM, 0);
        
@@ -573,7 +574,9 @@ int phpdbg_open_socket(short port) /* {{{ */
                                        address.sin_port = htons(port);
                                        address.sin_family = AF_INET;
                                        
-                                       if (!inet_pton(AF_INET, "127.0.0.1", &address.sin_addr)) {
+                                       if ((*interface == '*')) {
+                                               address.sin_addr.s_addr = htonl(INADDR_ANY);                                            
+                                       } else if (!inet_pton(AF_INET, interface, &address.sin_addr)) {
                                                close(fd);
                                                return -3;
                                        }
@@ -618,11 +621,11 @@ static inline void phpdbg_close_sockets(int (*socket)[2], FILE *streams[2]) /* {
 
 /* don't inline this, want to debug it easily, will inline when done */
 
-int phpdbg_open_sockets(int port[2], int (*listen)[2], int (*socket)[2], FILE* streams[2]) /* {{{ */
+int phpdbg_open_sockets(char *address, int port[2], int (*listen)[2], int (*socket)[2], FILE* streams[2]) /* {{{ */
 {
        if (((*listen)[0]) < 0 && ((*listen)[1]) < 0) {
-               ((*listen)[0]) = phpdbg_open_socket((short)port[0]);
-               ((*listen)[1]) = phpdbg_open_socket((short)port[1]);
+               ((*listen)[0]) = phpdbg_open_socket(address, (short)port[0]);
+               ((*listen)[1]) = phpdbg_open_socket(address, (short)port[1]);
        }
 
        streams[0] = NULL;
@@ -715,6 +718,7 @@ int main(int argc, char **argv) /* {{{ */
        int step = 0;
        char *bp_tmp_file;
 #ifndef _WIN32
+       char *address;
        int listen[2];
        int server[2];
        int socket[2];
@@ -726,6 +730,7 @@ int main(int argc, char **argv) /* {{{ */
 #endif
 
 #ifndef _WIN32
+       address = strdup("127.0.0.1");
        socket[0] = -1;
        socket[1] = -1;
        listen[0] = -1;
@@ -873,7 +878,7 @@ phpdbg_main:
                        /* if you pass a listen port, we will accept input on listen port */
                        /* and write output to listen port * 2 */
                        
-                       case 'l': { /* set listen settings */
+                       case 'l': { /* set listen ports */
                                if (sscanf(php_optarg, "%d/%d", &listen[0], &listen[1]) != 2) {
                                        if (sscanf(php_optarg, "%d", &listen[0]) != 1) {
                                                /* default to hardcoded ports */
@@ -884,6 +889,13 @@ phpdbg_main:
                                        }
                                }
                        } break;
+                       
+                       case 'a': { /* set bind address */
+                               free(address);
+                               if (!php_optarg) {
+                                       address = strdup("*");
+                               } else address = strdup(php_optarg);
+                       } break;
 #endif
                }
        }
@@ -892,7 +904,7 @@ phpdbg_main:
        /* setup remote server if necessary */
        if (!cleaning &&
                (listen[0] > 0 && listen[1] > 0)) {
-               if (phpdbg_open_sockets(listen, &server, &socket, streams) == FAILURE) {
+               if (phpdbg_open_sockets(address, listen, &server, &socket, streams) == FAILURE) {
                        remote = 0;
                        exit(0);
                }
@@ -1047,7 +1059,7 @@ phpdbg_interact:
 
                                        /* renegociate connections */
                                        phpdbg_open_sockets(
-                                               listen, &server, &socket, streams);
+                                               address, listen, &server, &socket, streams);
                                        
                                        /* set streams */
                                        if (streams[0] && streams[1]) {
@@ -1074,6 +1086,7 @@ phpdbg_out:
                        goto phpdbg_interact;
                }
 #endif
+               
                if (ini_entries) {
                        free(ini_entries);
                }
@@ -1115,6 +1128,12 @@ phpdbg_out:
        /* bugggy */
        /* tsrm_shutdown(); */
 #endif
+
+#ifndef _WIN32
+       if (address) {
+               free(address);  
+       }
+#endif
        
        free(bp_tmp_file);
 
index d402d23d56283baa8b6f29ee59b24abb31667215..6ae77fd99be1d4efd47b322546f5d469be527542 100644 (file)
@@ -564,8 +564,18 @@ PHPDBG_HELP(options) /* {{{ */
        phpdbg_writeln(" -O\t-Omy.oplog\t\tSets oplog output file");
        phpdbg_writeln(" -r\tN/A\t\t\tRun execution context");
        phpdbg_writeln(" -E\tN/A\t\t\tEnable step through eval, careful !");
-       phpdbg_writeln(" -l\t-l4000\t\t\tSetup remote console, see docs");
+#ifndef _WIN32
+       phpdbg_writeln(" -l\t-l4000\t\t\tSetup remote console ports");
+       phpdbg_writeln(" -a\t-a192.168.0.3\t\tSetup remote console bind address");
+#endif
        phpdbg_notice("Passing -rr will quit automatically after execution");
+#ifndef _WIN32
+       phpdbg_writeln("Remote Console Mode");
+       phpdbg_notice("For security, phpdbg will bind only to the loopback interface by default");
+       phpdbg_writeln("-a without an argument implies all; phpdbg will bind to all available interfaces.");
+       phpdbg_writeln("specify both stdin and stdout with -lstdin/stdout; by default stdout is stdin * 2.");
+       phpdbg_notice("Steps should be taken to secure this service if bound to a public interface/port");
+#endif
        phpdbg_help_footer();
        return SUCCESS;
 } /* }}} */