forked from Skycrab/Linux-C-Web-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ec2c82f
Showing
46 changed files
with
17,098 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
CC = gcc | ||
#CFLAGS = -O2 -Wall -I . | ||
CFLAGS = -g -I . | ||
|
||
#If you support https,then LIB=-DHTTPS -lpthread -lssl -lcrypto | ||
#else LIB=-lpthread | ||
LIB = -DHTTPS -lpthread -lssl -lcrypto | ||
#LIB = -lpthread | ||
|
||
all: webd | ||
|
||
webd: main.c wrap.o parse_config.o daemon_init.o parse_option.o log.o secure_access.o cgi | ||
$(CC) $(CFLAGS) -o $@ main.c wrap.o parse_config.o daemon_init.o parse_option.o log.o secure_access.o $(LIB) | ||
|
||
wrap.o: wrap.c | ||
$(CC) $(CFLAGS) -c wrap.c | ||
|
||
parse_config.o: parse_config.c parse.h | ||
$(CC) $(CFLAGS) -c parse_config.c | ||
|
||
daemon_init.o: daemon_init.c parse.h | ||
$(CC) $(CFLAGS) -c daemon_init.c | ||
|
||
parse_option.o: parse_option.c parse.h | ||
$(CC) $(CFLAGS) -c parse_option.c $(LIB) | ||
|
||
log.o: log.c parse.h | ||
$(CC) $(CFLAGS) -c log.c | ||
|
||
secure_access.o: secure_access.c parse.h | ||
$(CC) $(CFLAGS) -c secure_access.c | ||
|
||
cgi: | ||
(cd cgi-bin; make) | ||
|
||
clean: | ||
rm -f *.o main access.log *~ | ||
(cd cgi-bin; make clean) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
Webd uses the GET/POST method to serve static content | ||
(text, HTML, GIF, and JPG ....files) out of ./ and to serve dynamic | ||
content by running CGI programs out of ./cgi-bin. | ||
|
||
webd provides following functions: | ||
1.provide GET/POST method to view static content and run cgi script | ||
2.provide HTTP and HTTPS connection | ||
3.provide dircetory view function | ||
4.provide some access control based by ip address | ||
5.provide easy logging function | ||
|
||
To run Webd: | ||
Run "webd" on the server machine, | ||
e.g., "webd" | ||
Maybe you should type "./webd" if current directory is not in your $PATH | ||
|
||
There are several argument option: | ||
-d --daemon -> webd run in the background | ||
-p --port -> assigned http port | ||
-s --sslport -> assigned https port | ||
-l --log -> assigned log path | ||
-e --extent -> provide https function | ||
-h --help -> help | ||
-v --version -> some other informations | ||
|
||
|
||
So,you can also do this: | ||
webd -d -p 8888 -s 4444 -e | ||
|
||
If your port is less then 1024,you must have the root permission,or use the sudo command. | ||
|
||
|
||
Point your browser at webd: for example,http port is 8888,and https port is 4444 | ||
you can view following page: | ||
http: | ||
127.0.0.1:8000 home page | ||
|
||
127.0.0.1:8000/dir view dir | ||
-> you can point the file name to view file contents | ||
or point the directory name to view the directory content | ||
|
||
127.0.0.1:8888/getAuth.html | ||
-> a GET method page,login with email and password, | ||
you will see you email and password content | ||
|
||
127.0.0.1:8888/postAuth.html | ||
-> a POST method page,login with email and password, | ||
you will see you email and password content | ||
|
||
https: the same function as to http,just uri has a litter changes | ||
https://127.0.0.1:4444 | ||
https://127.0.0.1:4444/dir | ||
https://127.0.0.1:4444/getAuth.html | ||
https://127.0.0.1:4444/postAuth.html | ||
|
||
Files: | ||
cert.pem -> the https CA,use openssl to create, | ||
so you must accept the CA to continue | ||
cgi-bin -> cgi script directory | ||
getAuth.c -> the get method cgi script | ||
postAuth.c -> the post method cgi script | ||
Makefile -> cgi/bin/*.c Makefile | ||
config.ini -> configuration file | ||
daemon_init.c -> daemon process | ||
doc -> the web page root directory | ||
log.c -> provide logging | ||
main.c -> the main source file | ||
Makefile -> *.c Makefile | ||
parse_config.c -> read the config.ini | ||
parse.h -> the main head file | ||
parse_option.c -> parse the argv | ||
README -> it's me | ||
secure_access.c -> provide easy access control | ||
webserver.sh -> a shell script,to provide start/stop/restart/status the webd | ||
e.g. webserver.sh start/stop/restart/status | ||
wrap.c -> must functions wrap file | ||
wrap.h -> the wrap.c's head file | ||
|
||
Bugs: | ||
If openssl lib library isn't accessible in your computer,you should change the | ||
Makefile.For datail,you could see Makefile. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
-----BEGIN RSA PRIVATE KEY----- | ||
MIICXAIBAAKBgQDgtpALf512661nz40CA9IMgXItnbfcGBkheK3ivKIvbdQ9gzs+ | ||
hnghBkhIKMGxDvXzkBb5rIZoouIXQH6rbz6JyFBxhHi5diS8x6t1OomYNp5Sco0d | ||
6s9yfSAmkLNRNvlqg5aLXlif9ptQg6pHM1/vVqinTuy/KuPaus9v53p7VwIDAQAB | ||
AoGARJKRbGDaDXMn7Hjin83IqHZMAG2TsL9N0+/+qCVGHNEYJllIl/Dy8aj4H8UI | ||
Ll7RYS0ERdaHAaFK+yt8PBZrb4/hmPcXxZbA+ibCiU0SxyrOS9e4eQahCJL28Gp7 | ||
z6Wk1JH0MLckQm22oeZ/pqzkhgV4FREDM/PEsl5axrWAvjECQQDzjFYMpSpK15e7 | ||
fJFiPeZUTfheINNzISnNeBivlLx6EY57wSiGa1imJ5lJZlFko9/tU48kcdzqkLIJ | ||
fHgk8BZZAkEA7DO0isZT1Nnz9eNxOF0MqKDVgNprBKqRs3boXjrhrT6Re4DRBvGm | ||
KtfLy+q5hbriNmW3L+QoHhZuU9bTjl9JLwJAY1KdGSUWfVU1DQH9LGqAD2uI2aJb | ||
eX1R1fifYKOwxbt5NyEMDN2kVoaZreRrVza5sMi9/Kfu5z5BTTsUqEO9aQJBAOPx | ||
6hPa3eAWDjeHrSXltmet/x0ArDKuoTl+UTVOwae9MAzt/csjvWavJr+94BhMiC5S | ||
7vxKxOR0ZTiHo1ZMYoUCQCzAX1AZsT0yRWb9RVY5r3lw47syeEBryPrRVvRvbSy7 | ||
FoqUCC9Gi9TB1OHLyVn3vcd7+CoKxX6QqauhtU/PG0Y= | ||
-----END RSA PRIVATE KEY----- | ||
-----BEGIN CERTIFICATE----- | ||
MIIC0TCCAjoCCQCd7jWupY/ZPDANBgkqhkiG9w0BAQUFADCBrDELMAkGA1UEBhMC | ||
eWwxEDAOBgNVBAgMB2ppYW5nc3UxEDAOBgNVBAcMB25hbmppbmcxJTAjBgNVBAoM | ||
HGNvbXB1dGVyIGNvbW11bmljYXRpb24gb2YgbmcxHjAcBgNVBAsMFWNvbXB1dGVy | ||
IGNtbXVuaWNhdGlvbjEQMA4GA1UEAwwHeWloYWlibzEgMB4GCSqGSIb3DQEJARYR | ||
eWloYWlib2JiQDE2My5jb20wHhcNMTIxMjA1MDg0NjMzWhcNMTMxMjA1MDg0NjMz | ||
WjCBrDELMAkGA1UEBhMCeWwxEDAOBgNVBAgMB2ppYW5nc3UxEDAOBgNVBAcMB25h | ||
bmppbmcxJTAjBgNVBAoMHGNvbXB1dGVyIGNvbW11bmljYXRpb24gb2YgbmcxHjAc | ||
BgNVBAsMFWNvbXB1dGVyIGNtbXVuaWNhdGlvbjEQMA4GA1UEAwwHeWloYWlibzEg | ||
MB4GCSqGSIb3DQEJARYReWloYWlib2JiQDE2My5jb20wgZ8wDQYJKoZIhvcNAQEB | ||
BQADgY0AMIGJAoGBAOC2kAt/nXbrrWfPjQID0gyBci2dt9wYGSF4reK8oi9t1D2D | ||
Oz6GeCEGSEgowbEO9fOQFvmshmii4hdAfqtvPonIUHGEeLl2JLzHq3U6iZg2nlJy | ||
jR3qz3J9ICaQs1E2+WqDloteWJ/2m1CDqkczX+9WqKdO7L8q49q6z2/nentXAgMB | ||
AAEwDQYJKoZIhvcNAQEFBQADgYEAQnlRL1pLK6nPyvpVvBoqlXVrmutxHLVUWfyT | ||
d7FvFk3RgV7IgYh3bEsB8Wc/dzzwc5wW+HMCbkTjtcf1wkRhbIxeiXl3OrmlZkZ8 | ||
aquROQ9Ac1K9D61DsAM2k69cQBRKkCdxf8pHYHo/vtdrfA/6JVr89yX8WZKzI+rt | ||
tTIQ+zM= | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CC = gcc | ||
CFLAGS = -O2 -Wall -I .. | ||
|
||
all: getAuth postAuth | ||
|
||
getAuth: getAuth.c | ||
$(CC) $(CFLAGS) -o getAuth getAuth.c | ||
|
||
postAuth: postAuth.c | ||
$(CC) $(CFLAGS) -o postAuth postAuth.c | ||
|
||
clean: | ||
rm -f getAuth postAuth *~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "wrap.h" | ||
#include "parse.h" | ||
|
||
int main(void) { | ||
char *buf, *p; | ||
char name[MAXLINE], passwd[MAXLINE],content[MAXLINE]; | ||
|
||
/* Extract the two arguments */ | ||
if ((buf = getenv("QUERY_STRING")) != NULL) { | ||
p = strchr(buf, '&'); | ||
*p = '\0'; | ||
strcpy(name, buf); | ||
strcpy(passwd, p+1); | ||
} | ||
|
||
|
||
/* Make the response body */ | ||
sprintf(content, "Welcome to auth.com:%s and %s\r\n<p>",name,passwd); | ||
sprintf(content, "%s\r\n", content); | ||
|
||
sprintf(content, "%sThanks for visiting!\r\n", content); | ||
|
||
/* Generate the HTTP response */ | ||
printf("Content-length: %d\r\n", strlen(content)); | ||
printf("Content-type: text/html\r\n\r\n"); | ||
printf("%s", content); | ||
fflush(stdout); | ||
exit(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "wrap.h" | ||
#include "parse.h" | ||
|
||
int main(void) { | ||
char *buf,*p; | ||
int length=0; | ||
char content[MAXLINE],data[MAXLINE]; | ||
|
||
|
||
if ((buf = getenv("CONTENT-LENGTH")) != NULL) | ||
{ | ||
length=atol(buf); | ||
} | ||
|
||
p=fgets(data,length+1,stdin); | ||
if(p==NULL) | ||
sprintf(content, "Something is wrong\r\n"); | ||
else | ||
sprintf(content, "Info:%s\r\n",data); | ||
|
||
printf("Content-length: %d\r\n", strlen(content)); | ||
printf("Content-type: text/html\r\n\r\n"); | ||
printf("%s", content); | ||
fflush(stdout); | ||
exit(0); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#config.ini | ||
|
||
#the web is daemon or not | ||
daemon = yes | ||
|
||
#port set | ||
http=8000 | ||
https=4444 | ||
|
||
#default certifile | ||
ca= cert.pem | ||
|
||
#show dir or not | ||
dir= yes | ||
|
||
#dossl or not | ||
dossl=yes | ||
|
||
#the web root position | ||
root =doc | ||
|
||
#log position | ||
log = access.log | ||
|
||
#access ip mask | ||
mask =0.0.0.0/0.0.0.0 | ||
|
||
#cgi-bin dir location | ||
cgi =cgi-bin | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "parse.h" | ||
|
||
void init_daemon(void) | ||
{ | ||
int i; | ||
pid_t pid; | ||
struct sigaction sa; | ||
umask(0); | ||
if(pid=fork()) | ||
exit(0); | ||
else if(pid<0) | ||
exit(1); | ||
setsid(); | ||
|
||
sa.sa_handler=SIG_IGN; | ||
sigemptyset(&sa.sa_mask); | ||
sa.sa_flags=0; | ||
sigaction(SIGHUP,&sa,NULL); | ||
|
||
|
||
if(pid=fork()) | ||
exit(0); | ||
else if(pid<0) | ||
exit(1); | ||
|
||
for(i=0;i<NOFILE;++i) | ||
close(i); | ||
|
||
chdir("/"); | ||
} |
Oops, something went wrong.