From 9d3c8c0e6e1a7ba43bf3dc19350d1dca68b657a3 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sun, 10 Feb 2019 11:16:07 +0800 Subject: Initial commit. --- cgi/.htaccess | 2 ++ cgi/4or6.c | 14 ++++++++++++++ cgi/4or6.cgi | Bin 0 -> 16712 bytes cgi/hello.c | 19 +++++++++++++++++++ cgi/hello.cgi | Bin 0 -> 8712 bytes 5 files changed, 35 insertions(+) create mode 100755 cgi/.htaccess create mode 100644 cgi/4or6.c create mode 100755 cgi/4or6.cgi create mode 100644 cgi/hello.c create mode 100755 cgi/hello.cgi (limited to 'cgi') diff --git a/cgi/.htaccess b/cgi/.htaccess new file mode 100755 index 0000000..527ad9b --- /dev/null +++ b/cgi/.htaccess @@ -0,0 +1,2 @@ +Options +ExecCGI +AddHandler cgi-script cgi pl diff --git a/cgi/4or6.c b/cgi/4or6.c new file mode 100644 index 0000000..1cf6780 --- /dev/null +++ b/cgi/4or6.c @@ -0,0 +1,14 @@ +#include +#include +#include +int main() +{ + printf("Content-type: text/plain\n\n"); + if(!getenv("REMOTE_ADDR"))return 0; + char* s=getenv("REMOTE_ADDR"); + if(getenv("HTTP_X_FORWARDED_FOR")) + s=getenv("HTTP_X_FORWARDED_FOR"); + if(strchr(s,':')!=NULL)puts("6"); + else puts("4"); + return 0; +} diff --git a/cgi/4or6.cgi b/cgi/4or6.cgi new file mode 100755 index 0000000..80d1ea6 Binary files /dev/null and b/cgi/4or6.cgi differ diff --git a/cgi/hello.c b/cgi/hello.c new file mode 100644 index 0000000..440cf11 --- /dev/null +++ b/cgi/hello.c @@ -0,0 +1,19 @@ +#include +#include +int main(int argc,char **argv,char** envp) +{ + puts("Content-type: text/html\r\n\r\n"); + puts("hello cgi...
\nEnvironment variables:
\n"); + for(char** env=envp;*env;++env){printf("%s
\n",*env);} + if(getenv("CONTENT_LENGTH")) + { + int len=atoi(getenv("CONTENT_LENGTH")); + char* buf=malloc(len+1); + fread(buf,1,len,stdin); + buf[len]=0; + printf("stdin:
\n"); + puts(buf); + } + puts("
"); + return 0; +} diff --git a/cgi/hello.cgi b/cgi/hello.cgi new file mode 100755 index 0000000..7bbd85d Binary files /dev/null and b/cgi/hello.cgi differ -- cgit v1.2.3