Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

improve -l, add -a

  • Loading branch information...
commit de84aba976fd28145f06515bd181f1b10ff14e98 1 parent 41f93d4
@krakjoe krakjoe authored
Showing with 39 additions and 9 deletions.
  1. +1 −0  README.md
  2. +27 −8 phpdbg.c
  3. +11 −1 phpdbg_help.c
View
1  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
View
35 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 @@ int main(int argc, char **argv) /* {{{ */
/* 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 @@ int main(int argc, char **argv) /* {{{ */
}
}
} break;
+
+ case 'a': { /* set bind address */
+ free(address);
+ if (!php_optarg) {
+ address = strdup("*");
+ } else address = strdup(php_optarg);
+ } break;
#endif
}
}
@@ -892,7 +904,7 @@ int main(int argc, char **argv) /* {{{ */
/* 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 @@ int main(int argc, char **argv) /* {{{ */
/* 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 @@ int main(int argc, char **argv) /* {{{ */
goto phpdbg_interact;
}
#endif
+
if (ini_entries) {
free(ini_entries);
}
@@ -1115,6 +1128,12 @@ int main(int argc, char **argv) /* {{{ */
/* bugggy */
/* tsrm_shutdown(); */
#endif
+
+#ifndef _WIN32
+ if (address) {
+ free(address);
+ }
+#endif
free(bp_tmp_file);
View
12 phpdbg_help.c
@@ -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;
} /* }}} */
Please sign in to comment.
Something went wrong with that request. Please try again.