Tweaks
This commit is contained in:
parent
2ce421ce10
commit
951d4aeb79
3
Makefile
3
Makefile
@ -3,14 +3,13 @@
|
|||||||
# Some changes and tweaks from Menchers
|
# Some changes and tweaks from Menchers
|
||||||
|
|
||||||
VERSION = \"0.3.3\"
|
VERSION = \"0.3.3\"
|
||||||
EXTRA ?= dev
|
|
||||||
VERSION_EXTRA = \"$(EXTRA)\"
|
VERSION_EXTRA = \"$(EXTRA)\"
|
||||||
|
|
||||||
PREFIX ?= /usr
|
PREFIX ?= /usr
|
||||||
|
|
||||||
CC ?= gcc
|
CC ?= gcc
|
||||||
CFLAGS += -O2 -pedantic -g -Wall -Wextra --param=ssp-buffer-size=2 -fstack-protector-all
|
CFLAGS += -O2 -pedantic -g -Wall -Wextra --param=ssp-buffer-size=2 -fstack-protector-all
|
||||||
CPPFLAGS += -DVERSION=$(VERSION) -DVERSION_EXTRA=$(VERSION_EXTRA) -D_FORTIFY_SOURCE=2
|
CPPFLAGS += -DVERSION=$(VERSION) -D_FORTIFY_SOURCE=2
|
||||||
LDFLAGS += -Wl,-O1,--sort-common,--hash-style=gnu,-z,relro
|
LDFLAGS += -Wl,-O1,--sort-common,--hash-style=gnu,-z,relro
|
||||||
BIN ?= slidescript
|
BIN ?= slidescript
|
||||||
|
|
||||||
|
39
README.md
39
README.md
@ -1,17 +1,17 @@
|
|||||||
SlideScript
|
SlideScript
|
||||||
====
|
|
||||||
A simple, user friendly scripting language.
|
|
||||||
===
|
===
|
||||||
|
A simple, user friendly scripting language.
|
||||||
|
=====
|
||||||
|
|
||||||
Using SlideScript
|
Using SlideScript
|
||||||
----
|
-----
|
||||||
* Compile SS using the make command.
|
* Compile SS using the make command.
|
||||||
* Install SS using make install.
|
* Install SS using make install.
|
||||||
* Modify test.ss to learn the basics of SS.
|
* Modify test.ss to learn the basics of SS.
|
||||||
* Run ./test.ss to execute the script.
|
* Run ./test.ss to execute the script.
|
||||||
|
|
||||||
Documentation
|
Documentation
|
||||||
----
|
-----
|
||||||
Here is a list of functions and features that SlideScript comes with
|
Here is a list of functions and features that SlideScript comes with
|
||||||
at this moment!
|
at this moment!
|
||||||
|
|
||||||
@ -54,55 +54,60 @@ at this moment!
|
|||||||
* `nettoss "<address>" "<port>" "<data>"` -> binds to outside server at <address>:<port> and pushes <data> thus, disconnecting
|
* `nettoss "<address>" "<port>" "<data>"` -> binds to outside server at <address>:<port> and pushes <data> thus, disconnecting
|
||||||
* `nethttp "<port>" "<forkval>"` -> throws up a web server on <port> in the current working directory, forkval (0 or 1, 0 don't fork into background / 1 do).
|
* `nethttp "<port>" "<forkval>"` -> throws up a web server on <port> in the current working directory, forkval (0 or 1, 0 don't fork into background / 1 do).
|
||||||
|
|
||||||
|
This will change rapidly as of currently, slidescript is in beavy development!
|
||||||
|
|
||||||
|
|
||||||
Todo list
|
Todo list
|
||||||
----
|
------
|
||||||
* Add in-script functions
|
* Add in-script functions
|
||||||
* New static functions
|
* New static functions
|
||||||
* Network sockets
|
* Loops, and if statements
|
||||||
* Function piping between each other
|
|
||||||
|
|
||||||
Done
|
Done
|
||||||
----
|
------
|
||||||
* Simple syntax checking and error reporting
|
* Simple syntax checking and error reporting
|
||||||
|
* 2 layer function piping
|
||||||
* Support for linux system calls
|
* Support for linux system calls
|
||||||
|
* Network listen socket, toss function
|
||||||
|
* Builtin HTTP server for disposeable use, can be ran in the foreground or forked into the background
|
||||||
* Read and write from file
|
* Read and write from file
|
||||||
* Some simple functions
|
* Some simple functions
|
||||||
* Shebang handling
|
* Shebang handling
|
||||||
* Variable support
|
* Variable support
|
||||||
|
|
||||||
Changelog
|
Changelog
|
||||||
----
|
-----
|
||||||
V0.3.3
|
* V0.3.3
|
||||||
* Added first networking functions: netlisten, nettoss, nethttp.
|
* Added first networking functions: netlisten, nettoss, nethttp.
|
||||||
* Embedded web server functionality
|
* Embedded web server functionality
|
||||||
* Cleaned up code
|
* Cleaned up code
|
||||||
* Improved syntax handling on functions
|
* Improved syntax handling on functions
|
||||||
|
|
||||||
V0.3.0
|
* V0.3.0
|
||||||
* Added simple 2 layer function piping for more useful tasks
|
* Added simple 2 layer function piping for more useful tasks
|
||||||
* Fixed a couple core dump bugs
|
* Fixed a couple core dump bugs
|
||||||
* Now reads files into memory, and then forces text files through SS, allows for in file variables
|
* Now reads files into memory, and then forces text files through SS, allows for in file variables
|
||||||
* Added "md5" functionality
|
* Added "md5" functionality
|
||||||
* Multi-formal working syntax
|
* Multi-formal working syntax
|
||||||
|
|
||||||
V0.2.1
|
* V0.2.1
|
||||||
* Added "decrypt" decode function
|
* Added "decrypt" decode function
|
||||||
* Added "encrypt" encode function
|
* Added "encrypt" encode function
|
||||||
* Added system "exec" function
|
* Added system "exec" function
|
||||||
* Added basic syntax handling, for a more uniform language
|
* Added basic syntax handling, for a more uniform language
|
||||||
|
|
||||||
V0.2.0
|
* V0.2.0
|
||||||
* Added "delete" function
|
* Added "delete" function
|
||||||
* Added embedded variable handling to SS functions (variables can be used like everywhere!)
|
* Added embedded variable handling to SS functions (variables can be used like everywhere!)
|
||||||
* Added linux system calls via exec
|
* Added linux system calls via exec
|
||||||
* Some cleaning up.
|
* Some cleaning up.
|
||||||
|
|
||||||
V0.1.1
|
* V0.1.1
|
||||||
* Added variable handling with a buffer size of 2MB per variable, and
|
* Added variable handling with a buffer size of 2KB per variable, and cap of 2048 variables.
|
||||||
cap of 2048 variables.
|
|
||||||
* Now operates under the shebang!
|
* Now operates under the shebang!
|
||||||
|
|
||||||
Contributions:
|
Contributions
|
||||||
|
-----
|
||||||
Robert (OldCoder) Kiraly -> shebang support and string manipulations
|
Robert (OldCoder) Kiraly -> shebang support and string manipulations
|
||||||
|
|
||||||
(C) Copyright 2014-2021 Chris Dorman, some rights reserved (GPLv2)
|
(C) Copyright 2014-2021 Chris Dorman, some rights reserved (GPLv2)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<h2>Test page</h2>
|
<h2>SlideScript</h2>
|
||||||
<p>This is an index page hosted by the built in SlideScript HTTP server</p>
|
<p>This is an index page hosted by the built in SS HTTP server</p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -6,4 +6,11 @@
|
|||||||
# * 0 = do not fork to background
|
# * 0 = do not fork to background
|
||||||
# * 1 = fork to background
|
# * 1 = fork to background
|
||||||
|
|
||||||
nethttp "8080" "0"
|
port1=8081
|
||||||
|
port2=8080
|
||||||
|
|
||||||
|
# Daemonize
|
||||||
|
nethttp "%port1%" "1"
|
||||||
|
nethttp "%port1%" "0"
|
||||||
|
|
||||||
|
print "Server on %port1% still running in the background"
|
||||||
|
@ -31,6 +31,7 @@ struct {
|
|||||||
{"css", "text/css" },
|
{"css", "text/css" },
|
||||||
{"c", "text/plain" },
|
{"c", "text/plain" },
|
||||||
{"h", "text/plain" },
|
{"h", "text/plain" },
|
||||||
|
{"md", "text/plain" },
|
||||||
{"txt", "text/plain" },
|
{"txt", "text/plain" },
|
||||||
{"ss", "text/plain" },
|
{"ss", "text/plain" },
|
||||||
{"sh", "text/plain" },
|
{"sh", "text/plain" },
|
||||||
@ -161,7 +162,7 @@ void snet_toss(char *address, int port, char *string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process connection of nethttp
|
// Process connection of nethttp
|
||||||
void snet_http_process(int fd)
|
void snet_http_process(int fd, int forkval)
|
||||||
{
|
{
|
||||||
int j, file_fd, buflen, len;
|
int j, file_fd, buflen, len;
|
||||||
long i, filesize;
|
long i, filesize;
|
||||||
@ -173,7 +174,8 @@ void snet_http_process(int fd)
|
|||||||
if(filesize == 0 || filesize == -1) {
|
if(filesize == 0 || filesize == -1) {
|
||||||
sprintf(buffer,"HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n");
|
sprintf(buffer,"HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n");
|
||||||
if(write(fd,buffer,strlen(buffer)) < 0) syn_error("ss:net:http socket write error");
|
if(write(fd,buffer,strlen(buffer)) < 0) syn_error("ss:net:http socket write error");
|
||||||
sprintf(buffer,"<html><h2>Error reading requested file.</h2></html>");
|
sprintf(buffer,"<html><head><title>ss:http:missed header</title></head><body><h2>301: Missed header call</h2>" \
|
||||||
|
"<p>Could not locate file</p><br /><br /><center>ss:http:%s</center></body></html>", VERSION);
|
||||||
if(write(fd,buffer,strlen(buffer)) < 0) syn_error("ss:net:http socket write error");
|
if(write(fd,buffer,strlen(buffer)) < 0) syn_error("ss:net:http socket write error");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -191,9 +193,11 @@ void snet_http_process(int fd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(strncmp(buffer,"GET ",4) && strncmp(buffer,"get ",4)) {
|
if(strncmp(buffer,"GET ",4) && strncmp(buffer,"get ",4)) {
|
||||||
sprintf(buffer,"HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n");
|
sprintf(buffer,"HTTP/1.0 501 Not Implemented\r\nContent-Type: text/html\r\n\r\n");
|
||||||
if(write(fd,buffer,strlen(buffer)) < 0) syn_error("ss:net:http socket write error");
|
if(write(fd,buffer,strlen(buffer)) < 0) syn_error("ss:net:http socket write error");
|
||||||
sprintf(buffer,"<html><h2>Simple HTTP get support only.</h2></html>");
|
sprintf(buffer,"<html><head><title>ss:http: server not implemented</title></head><body>" \
|
||||||
|
"<h2>501: Not Implemented</h2><p>ss:http only supports simple GET requests via HTTP/1.0</p>" \
|
||||||
|
"<br /><br /><center>ss:http:%s</center></body></html>", VERSION);
|
||||||
if(write(fd,buffer,strlen(buffer)) < 0) syn_error("ss:net:http socket write error");
|
if(write(fd,buffer,strlen(buffer)) < 0) syn_error("ss:net:http socket write error");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -212,7 +216,8 @@ void snet_http_process(int fd)
|
|||||||
if(buffer[j] == '.' && buffer[j+1] == '.') {
|
if(buffer[j] == '.' && buffer[j+1] == '.') {
|
||||||
sprintf(buffer,"HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n");
|
sprintf(buffer,"HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n");
|
||||||
if(write(fd,buffer,strlen(buffer)) < 0) syn_error("ss:net:http socket write error");
|
if(write(fd,buffer,strlen(buffer)) < 0) syn_error("ss:net:http socket write error");
|
||||||
sprintf(buffer,"<html><h2>Parent directories (..) not supported</h2></html>");
|
sprintf(buffer,"<html><head><title>ss:http: parent directory not available</title></head><body><h2>FORBIDDEN: parent directory</h2>" \
|
||||||
|
"<p>You do not have access to view ../. Blocked.</p><br /><br /><center>ss:http:%s</center></body></html>", VERSION);
|
||||||
if(write(fd,buffer,strlen(buffer)) < 0) syn_error("ss:net:http socket write error");
|
if(write(fd,buffer,strlen(buffer)) < 0) syn_error("ss:net:http socket write error");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -225,7 +230,8 @@ void snet_http_process(int fd)
|
|||||||
} else {
|
} else {
|
||||||
sprintf(buffer,"HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n");
|
sprintf(buffer,"HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n");
|
||||||
if(write(fd,buffer,strlen(buffer)) < 0) syn_error("ss:net:http socket write error");
|
if(write(fd,buffer,strlen(buffer)) < 0) syn_error("ss:net:http socket write error");
|
||||||
sprintf(buffer,"<html><h2>Index not found</h2></html>");
|
sprintf(buffer,"<html><head><title>ss:http: file not found</title></head><body><h2>File not found</h2>" \
|
||||||
|
"<p>Could not locate index.html</p><br /><br /><center>ss:http:%s</center></body></html>", VERSION);
|
||||||
if(write(fd,buffer,strlen(buffer)) < 0) syn_error("ss:net:http socket write error");
|
if(write(fd,buffer,strlen(buffer)) < 0) syn_error("ss:net:http socket write error");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -246,13 +252,25 @@ void snet_http_process(int fd)
|
|||||||
fstr = "application/octet-stream";
|
fstr = "application/octet-stream";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(forkval == 0)
|
||||||
printf("ss:net:http request %s, %s\n", &buffer[5], fstr);
|
printf("ss:net:http request %s, %s\n", &buffer[5], fstr);
|
||||||
|
|
||||||
|
if(is_dir(&buffer[5]) == 1)
|
||||||
|
{
|
||||||
|
sprintf(buffer,"HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n");
|
||||||
|
if(write(fd,buffer,strlen(buffer)) < 0) syn_error("ss:net:http socket write error");
|
||||||
|
sprintf(buffer,"<html><head><title>ss:http: directory</title></head><body><h2>Directory</h2>" \
|
||||||
|
"<p>No directory listings at this time...</p><br /><br /><center>ss:http:%s</center></body></html>", VERSION);
|
||||||
|
if(write(fd,buffer,strlen(buffer)) < 0) syn_error("ss:net:http socket write error");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
// See if the web server can open requested file from browser
|
// See if the web server can open requested file from browser
|
||||||
if(( file_fd = open(&buffer[5],O_RDONLY)) == -1) {
|
if(( file_fd = open(&buffer[5],O_RDONLY)) == -1) {
|
||||||
sprintf(buffer,"HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n");
|
sprintf(buffer,"HTTP/1.0 404 Not Found\r\nContent-Type: text/html\r\n\r\n");
|
||||||
if(write(fd,buffer,strlen(buffer)) < 0) syn_error("ss:net:http socket write error");
|
if(write(fd,buffer,strlen(buffer)) < 0) syn_error("ss:net:http socket write error");
|
||||||
sprintf(buffer,"<html><h2>Error, file cound not be retrieved</h2></html>");
|
sprintf(buffer,"<html><head><title>ss:http:file not found</title></head><body><h2>404: File not found</h2>" \
|
||||||
|
"<p>Could not locate file</p><br /><br /><center>ss:http:%s</center></body></html>", VERSION);
|
||||||
if(write(fd,buffer,strlen(buffer)) < 0) syn_error("ss:net:http socket write error");
|
if(write(fd,buffer,strlen(buffer)) < 0) syn_error("ss:net:http socket write error");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -285,7 +303,7 @@ void snet_http(int port, int forkval)
|
|||||||
if(forkval > 0)
|
if(forkval > 0)
|
||||||
{
|
{
|
||||||
if(fork() != 0)
|
if(fork() != 0)
|
||||||
syn_error("ss:net:http failed to fork to background");
|
syn_error("ss:net:http forked");
|
||||||
|
|
||||||
signal(SIGCLD, SIG_IGN);
|
signal(SIGCLD, SIG_IGN);
|
||||||
signal(SIGHUP, SIG_IGN);
|
signal(SIGHUP, SIG_IGN);
|
||||||
@ -295,7 +313,7 @@ void snet_http(int port, int forkval)
|
|||||||
}
|
}
|
||||||
|
|
||||||
setpgrp();
|
setpgrp();
|
||||||
|
if(forkval < 1)
|
||||||
printf("Starting httpd...\n");
|
printf("Starting httpd...\n");
|
||||||
|
|
||||||
// Check if socket succeeded to open
|
// Check if socket succeeded to open
|
||||||
@ -336,7 +354,7 @@ void snet_http(int port, int forkval)
|
|||||||
else {
|
else {
|
||||||
if(pid == 0) {
|
if(pid == 0) {
|
||||||
close(listenfd);
|
close(listenfd);
|
||||||
snet_http_process(socketfd);
|
snet_http_process(socketfd, forkval);
|
||||||
} else {
|
} else {
|
||||||
close(socketfd);
|
close(socketfd);
|
||||||
}
|
}
|
||||||
|
@ -13,5 +13,5 @@ void snet_process_connection(int sockfd, char *srch, char *resp);
|
|||||||
void snet_listen(int port, char *srch, char *resp);
|
void snet_listen(int port, char *srch, char *resp);
|
||||||
void snet_toss(char *address, int port, char *string);
|
void snet_toss(char *address, int port, char *string);
|
||||||
void snet_process(int sockfd);
|
void snet_process(int sockfd);
|
||||||
void snet_http_process(int fd);
|
void snet_http_process(int fd, int forkval);
|
||||||
void snet_http(int port, int fork);
|
void snet_http(int port, int fork);
|
||||||
|
19
src/util.c
19
src/util.c
@ -32,9 +32,22 @@ char *strip_nl (char *string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if a file exists, return code
|
// Check if a file exists, return code
|
||||||
int file_exists(char *fname) {
|
int file_exists(char *path) {
|
||||||
struct stat buffer;
|
struct stat buffer;
|
||||||
return (stat (fname, &buffer) == 0);
|
return (stat (path, &buffer) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int is_dir(char *path)
|
||||||
|
{
|
||||||
|
struct stat buffer;
|
||||||
|
|
||||||
|
stat(path, &buffer);
|
||||||
|
|
||||||
|
// Check for file existence
|
||||||
|
if (S_ISDIR(buffer.st_mode))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *ss_concat(char *str1, char *str2)
|
char *ss_concat(char *str1, char *str2)
|
||||||
@ -59,7 +72,7 @@ void parse_args(int argc, char** argv)
|
|||||||
/* -v flag given, show version */
|
/* -v flag given, show version */
|
||||||
else if(argc == 2 && strncmp("-v", argv[1], 2) == 0)
|
else if(argc == 2 && strncmp("-v", argv[1], 2) == 0)
|
||||||
{
|
{
|
||||||
printf("SlideScript %s-%s, Chris Dorman (cddo@riseup.net), 2021\n", VERSION, VERSION_EXTRA);
|
printf("SlideScript %s, Chris Dorman (cddo@riseup.net), 2021\n", VERSION);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
void syn_error(char *message);
|
void syn_error(char *message);
|
||||||
char *strip_nl(char *string);
|
char *strip_nl(char *string);
|
||||||
int file_exists(char *fname);
|
int file_exists(char *path);
|
||||||
|
int is_dir(char *path);
|
||||||
char *ss_concat(char *str1, char *str2);
|
char *ss_concat(char *str1, char *str2);
|
||||||
void parse_args(int argc, char** argv);
|
void parse_args(int argc, char** argv);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user