Skip to content

Commit 458ae9f

Browse files
authored
Add files via upload
reading files from htdocs//
1 parent 2c9ac9f commit 458ae9f

File tree

10 files changed

+309
-41
lines changed

10 files changed

+309
-41
lines changed

Diff for: hidalgo/draft

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
>> php artisan like shell for hidalgo
2+
>> electron based GUI
3+

Diff for: hidalgo/hidalga.h

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#include<unistd.h>
88
#include<string.h>
99
#include<stdbool.h>
10+
#include<signal.h>
1011

1112
#define Hid_Port 'P'
1213
#define Hid_IP 'I'
14+
int get_integerFs(char *line, int num, int count);
15+
void INThandler(int);

Diff for: hidalgo/htdocs/htdocs.log

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
htdocs.log
2+
index.html
3+
main.html
4+
picture.jpg

Diff for: hidalgo/htdocs/index.html

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
<title>Hidalgo Homepage</title>
4+
</head>
5+
<body>
6+
<p>Working..</p>
7+
</body>
8+
</html>

Diff for: hidalgo/htdocs/picture.jpg

280 KB
Loading

Diff for: hidalgo/http_request.c

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
bool ls_htdocs(char *file){
2+
bool ans=false;
3+
char *line=NULL;
4+
size_t len;
5+
system("cd htdocs && ls > htdocs.log");
6+
FILE *htdocs;
7+
htdocs = fopen("htdocs/htdocs.log", "r");
8+
if(htdocs){
9+
while ((getline(&line, &len, htdocs)) != -1){
10+
if(strcmp(line, file)==0){
11+
return (ans=true);
12+
}else{
13+
return ans;
14+
}
15+
}
16+
}
17+
}
18+
char* request_handler(bool req){
19+
char index[1024] = {0};
20+
FILE *htdocs;
21+
htdocs = fopen("htdocs/index.html", "rb");
22+
fclose(htdocs);
23+
//<<------------------------------ Not reading index.html properly Linux core(dumb) error
24+
puts(string);
25+
fclose(htdocs);
26+
static char* OK =
27+
"HTTP/1.1 200 OK\n"
28+
"Content-type: text/html\n\n";
29+
//strcat(index, OK);
30+
static char* NOT =
31+
"HTTP/1.1 404 NOT FOUND\n"
32+
"Content-type: text/html\n\n"
33+
"<html>"
34+
" <body>"
35+
" <h1>Error 404</h1>"
36+
" <p>The requested URL is not on this server.</p>"
37+
" </body>"
38+
"</html>";
39+
40+
if(req == true){
41+
return OK;
42+
}
43+
else{
44+
return NOT;
45+
}
46+
}

Diff for: hidalgo/httpserver

576 Bytes
Binary file not shown.

Diff for: hidalgo/httpserver.c

+38-40
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,61 @@
11
#include "hidalga.h"
22
#include "config.c"
33
#include "log_generator.c"
4+
#include "http_request.c"
5+
46
//Hidalgo Server Socket MainStream
57
//(c) - 2018 | ALL RIGHT RESERVED
68

79
int main() {
810
int port = get_http_(Hid_Port);
911
int ip = get_http_(Hid_IP);
1012
int create_socket, new_socket;
11-
socklen_t addrlen;
13+
socklen_t addrlen;
14+
1215
int bufsize = 1024;
1316
char *buffer = malloc(bufsize);
1417
struct sockaddr_in address;
15-
static char* page =
16-
"HTTP/1.1 200 OK\n"
17-
"Content-type: text/html\n"
18-
"\n"
19-
"<html>\n"
20-
" <body>\n"
21-
" <h1>WebPAge</h1>\n"
22-
" <p>The requested URL was <?php echo'disk'; ?> on this server.</p>\n"
23-
" </body>\n"
24-
"</html>\n";
18+
2519

26-
if ((create_socket = socket(AF_INET, SOCK_STREAM, 0)) > 0){
27-
printf("The socket was created\n");
28-
}
20+
if ((create_socket = socket(AF_INET, SOCK_STREAM, 0)) > 0){
21+
printf("The socket was created\n");
22+
}
2923

30-
address.sin_family = AF_INET;
31-
address.sin_addr.s_addr = INADDR_ANY;
32-
address.sin_port = htons(port);
24+
address.sin_family = AF_INET;
25+
address.sin_addr.s_addr = INADDR_ANY;
26+
address.sin_port = htons(port);
3327

34-
if (bind(create_socket, (struct sockaddr *) &address, sizeof(address)) == 0){
35-
printf("Binding Socket\n");
36-
}
28+
if (bind(create_socket, (struct sockaddr *) &address, sizeof(address)) == 0){
29+
printf("Binding Socket\n");
30+
}
3731

32+
signal(SIGINT, INThandler);
33+
while (1) {
34+
if (listen(create_socket, 10) < 0) {
35+
perror("server: listen");
36+
exit(1);
37+
}
3838

39-
while (1) {
40-
if (listen(create_socket, 10) < 0) {
41-
perror("server: listen");
42-
exit(1);
43-
}
39+
if ((new_socket = accept(create_socket, (struct sockaddr *) &address, &addrlen)) < 0) {
40+
perror("server: accept");
41+
exit(1);
42+
}
4443

45-
if ((new_socket = accept(create_socket, (struct sockaddr *) &address, &addrlen)) < 0) {
46-
perror("server: accept");
47-
exit(1);
48-
}
49-
50-
if (new_socket > 0){
51-
printf("The Client is connected...\n");
52-
}
44+
if (new_socket > 0){
45+
printf("The Client is connected...\n");
46+
}
5347

54-
recv(new_socket, buffer, bufsize, 0);
55-
//printf("%s\n", buffer);
56-
if(guest_logs(buffer)) printf("\nLogs Saved\n");
57-
else printf("\nLog Writing Err :: log_generator.c\n");
58-
write(new_socket, page, strlen(page));
59-
close(new_socket);
60-
}
48+
recv(new_socket, buffer, bufsize, 0);
49+
//printf("%s\n", buffer);
50+
if(guest_logs(buffer) == true) printf("\nLogs Saved\n");
51+
else printf("\nLog Writing Err :: log_generator.c\n");
52+
53+
printf("\n---->\n");
54+
char *page = request_handler(true);
55+
write(new_socket, page, strlen(page));
56+
close(new_socket);
57+
}
58+
6159
close(create_socket);
6260
return 0;
6361
}

Diff for: hidalgo/log_generator.c

+15-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,22 @@ bool guest_logs(char *data){
55

66
if(guest_log){
77
puts(data);
8-
fwrite(data, sizeof(char), sizeof(data), guest_log);
8+
fputs(data, guest_log);
9+
//fwrite(data, sizeof(char), sizeof(data), guest_log);
910
return (val=true);
1011
}
1112
else return val;
1213
}
14+
void INThandler(int sig){
15+
char c;
16+
17+
signal(sig, SIG_IGN);
18+
printf("\nOUCH, did you hit Ctrl-C?\n"
19+
"Do you really want to quit? [y/n] ");
20+
c = getchar();
21+
if (c == 'y' || c == 'Y')
22+
exit(0);
23+
else
24+
signal(SIGINT, INThandler);
25+
getchar();
26+
}

Diff for: hidalgo/visitors.log

+192
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
GET / HTTP/1.1
2+
Host: localhost:1500
3+
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
4+
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
5+
Accept-Language: en-US,en;q=0.5
6+
Accept-Encoding: gzip, deflate
7+
Connection: keep-alive
8+
Upgrade-Insecure-Requests: 1
9+
10+
GET /favicon.ico HTTP/1.1
11+
Host: 192.168.10.4:1500
12+
Connection: keep-alive
13+
User-Agent: Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36
14+
Accept: image/webp,image/apng,image/*,*/*;q=0.8
15+
Referer: http://192.168.10.4:1500/
16+
Accept-Encoding: gzip, deflate
17+
Accept-Language: en-US,en;q=0.9
18+
19+
-Language: en-US,en;q=0.9
20+
21+
GET / HTTP/1.1
22+
Host: 192.168.10.4:1500
23+
Connection: keep-alive
24+
Upgrade-Insecure-Requests: 1
25+
User-Agent: Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36
26+
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
27+
Accept-Encoding: gzip, deflate
28+
Accept-Language: en-US,en;q=0.9
29+
30+
GET / HTTP/1.1
31+
Host: localhost:1500
32+
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
33+
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
34+
Accept-Language: en-US,en;q=0.5
35+
Accept-Encoding: gzip, deflate
36+
Connection: keep-alive
37+
Upgrade-Insecure-Requests: 1
38+
39+
GET /sd HTTP/1.1
40+
Host: localhost:1500
41+
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
42+
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
43+
Accept-Language: en-US,en;q=0.5
44+
Accept-Encoding: gzip, deflate
45+
Connection: keep-alive
46+
Upgrade-Insecure-Requests: 1
47+
48+
GET / HTTP/1.1
49+
Host: localhost:1500
50+
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
51+
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
52+
Accept-Language: en-US,en;q=0.5
53+
Accept-Encoding: gzip, deflate
54+
Connection: keep-alive
55+
Upgrade-Insecure-Requests: 1
56+
57+
GET / HTTP/1.1
58+
Host: localhost:1500
59+
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
60+
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
61+
Accept-Language: en-US,en;q=0.5
62+
Accept-Encoding: gzip, deflate
63+
Connection: keep-alive
64+
Upgrade-Insecure-Requests: 1
65+
66+
67+
GET /sd HTTP/1.1
68+
Host: localhost:1500
69+
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
70+
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
71+
Accept-Language: en-US,en;q=0.5
72+
Accept-Encoding: gzip, deflate
73+
Connection: keep-alive
74+
Upgrade-Insecure-Requests: 1
75+
76+
GET / HTTP/1.1
77+
Host: localhost:1500
78+
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
79+
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
80+
Accept-Language: en-US,en;q=0.5
81+
Accept-Encoding: gzip, deflate
82+
Connection: keep-alive
83+
Upgrade-Insecure-Requests: 1
84+
85+
GET /file HTTP/1.1
86+
Host: localhost:1500
87+
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
88+
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
89+
Accept-Language: en-US,en;q=0.5
90+
Accept-Encoding: gzip, deflate
91+
Connection: keep-alive
92+
Upgrade-Insecure-Requests: 1
93+
94+
GET /file HTTP/1.1
95+
Host: localhost:1500
96+
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
97+
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
98+
Accept-Language: en-US,en;q=0.5
99+
Accept-Encoding: gzip, deflate
100+
Connection: keep-alive
101+
Upgrade-Insecure-Requests: 1
102+
103+
GET /file HTTP/1.1
104+
Host: localhost:1500
105+
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
106+
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
107+
Accept-Language: en-US,en;q=0.5
108+
Accept-Encoding: gzip, deflate
109+
Connection: keep-alive
110+
Upgrade-Insecure-Requests: 1
111+
112+
GET / HTTP/1.1
113+
Host: localhost:1500
114+
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
115+
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
116+
Accept-Language: en-US,en;q=0.5
117+
Accept-Encoding: gzip, deflate
118+
Connection: keep-alive
119+
Upgrade-Insecure-Requests: 1
120+
121+
GET / HTTP/1.1
122+
Host: localhost:1500
123+
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
124+
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
125+
Accept-Language: en-US,en;q=0.5
126+
Accept-Encoding: gzip, deflate
127+
Connection: keep-alive
128+
Upgrade-Insecure-Requests: 1
129+
130+
GET / HTTP/1.1
131+
Host: localhost:1500
132+
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
133+
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
134+
Accept-Language: en-US,en;q=0.5
135+
Accept-Encoding: gzip, deflate
136+
Connection: keep-alive
137+
Upgrade-Insecure-Requests: 1
138+
139+
GET / HTTP/1.1
140+
Host: localhost:1500
141+
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
142+
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
143+
Accept-Language: en-US,en;q=0.5
144+
Accept-Encoding: gzip, deflate
145+
Connection: keep-alive
146+
Upgrade-Insecure-Requests: 1
147+
148+
GET / HTTP/1.1
149+
Host: localhost:1500
150+
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
151+
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
152+
Accept-Language: en-US,en;q=0.5
153+
Accept-Encoding: gzip, deflate
154+
Connection: keep-alive
155+
Upgrade-Insecure-Requests: 1
156+
157+
GET / HTTP/1.1
158+
Host: localhost:1500
159+
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
160+
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
161+
Accept-Language: en-US,en;q=0.5
162+
Accept-Encoding: gzip, deflate
163+
Connection: keep-alive
164+
Upgrade-Insecure-Requests: 1
165+
166+
GET / HTTP/1.1
167+
Host: localhost:1500
168+
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
169+
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
170+
Accept-Language: en-US,en;q=0.5
171+
Accept-Encoding: gzip, deflate
172+
Connection: keep-alive
173+
Upgrade-Insecure-Requests: 1
174+
175+
GET / HTTP/1.1
176+
Host: localhost:1500
177+
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
178+
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
179+
Accept-Language: en-US,en;q=0.5
180+
Accept-Encoding: gzip, deflate
181+
Connection: keep-alive
182+
Upgrade-Insecure-Requests: 1
183+
184+
GET / HTTP/1.1
185+
Host: localhost:1500
186+
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0
187+
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
188+
Accept-Language: en-US,en;q=0.5
189+
Accept-Encoding: gzip, deflate
190+
Connection: keep-alive
191+
Upgrade-Insecure-Requests: 1
192+

0 commit comments

Comments
 (0)