Tweaks
This commit is contained in:
parent
2ce421ce10
commit
951d4aeb79
3
Makefile
3
Makefile
@ -3,14 +3,13 @@
|
||||
# Some changes and tweaks from Menchers
|
||||
|
||||
VERSION = \"0.3.3\"
|
||||
EXTRA ?= dev
|
||||
VERSION_EXTRA = \"$(EXTRA)\"
|
||||
|
||||
PREFIX ?= /usr
|
||||
|
||||
CC ?= gcc
|
||||
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
|
||||
BIN ?= slidescript
|
||||
|
||||
|
147
README.md
147
README.md
@ -1,108 +1,113 @@
|
||||
SlideScript
|
||||
====
|
||||
A simple, user friendly scripting language.
|
||||
===
|
||||
A simple, user friendly scripting language.
|
||||
=====
|
||||
|
||||
Using SlideScript
|
||||
----
|
||||
-----
|
||||
* Compile SS using the make command.
|
||||
* Install SS using make install.
|
||||
* Modify test.ss to learn the basics of SS.
|
||||
* Run ./test.ss to execute the script.
|
||||
|
||||
Documentation
|
||||
----
|
||||
-----
|
||||
Here is a list of functions and features that SlideScript comes with
|
||||
at this moment!
|
||||
|
||||
* Commenting! Examples:
|
||||
* `# Comment is real in this one`
|
||||
* Commenting! Examples:
|
||||
* `# Comment is real in this one`
|
||||
|
||||
* Read and writing to flat files. Examples:
|
||||
* `write "file.txt" "This will be written to file.txt"`
|
||||
* `read "file.txt"`
|
||||
* Read and writing to flat files. Examples:
|
||||
* `write "file.txt" "This will be written to file.txt"`
|
||||
* `read "file.txt"`
|
||||
|
||||
* Delete example:
|
||||
* `delete "file.txt"`
|
||||
* Delete example:
|
||||
* `delete "file.txt"`
|
||||
|
||||
* Execute example:
|
||||
* `exec "ls -al"`
|
||||
* Execute example:
|
||||
* `exec "ls -al"`
|
||||
|
||||
* Print example:
|
||||
* `print "Hi everyone!"`
|
||||
* Print example:
|
||||
* `print "Hi everyone!"`
|
||||
|
||||
* Sleep (Zzz) example (sleeps for 2 seconds):
|
||||
* `sleep 2`
|
||||
* Sleep (Zzz) example (sleeps for 2 seconds):
|
||||
* `sleep 2`
|
||||
|
||||
* Variable setting and passing
|
||||
* `filename=file.txt` -> filename
|
||||
* `filedata=File '%filename%' is being moved to moo` -> %filename% is populated as file.txt
|
||||
* `write "%filename%" "%filedata%"` -> writes filedata contents to file.txt as expected.
|
||||
* Variable setting and passing
|
||||
* `filename=file.txt` -> filename
|
||||
* `filedata=File '%filename%' is being moved to moo` -> %filename% is populated as file.txt
|
||||
* `write "%filename%" "%filedata%"` -> writes filedata contents to file.txt as expected.
|
||||
|
||||
* Decoding and encoding strings
|
||||
* `encrypt "Regular string"` -> Converts to encrypted string 'Uhjvqds#xuulqj'
|
||||
* `decrypt "Uhjvqds#xuulqj"` -> Converts back to 'Regular string'
|
||||
* Decoding and encoding strings
|
||||
* `encrypt "Regular string"` -> Converts to encrypted string 'Uhjvqds#xuulqj'
|
||||
* `decrypt "Uhjvqds#xuulqj"` -> Converts back to 'Regular string'
|
||||
|
||||
* MD5 file checking
|
||||
* `md5 "file.txt"` -> outputs filename and md5 hash
|
||||
* MD5 file checking
|
||||
* `md5 "file.txt"` -> outputs filename and md5 hash
|
||||
|
||||
* 2 Layer piping
|
||||
* `md5 "file.txt" | write "file.txt.md5" "%PIPE%"` -> writes output of md5 to file.txt.md5
|
||||
* 2 Layer piping
|
||||
* `md5 "file.txt" | write "file.txt.md5" "%PIPE%"` -> writes output of md5 to file.txt.md5
|
||||
|
||||
* Networking functions
|
||||
* `netlisten "<port>" "<search>" "<respond>"` -> listens on <port> and replies <respond> on <search> found from outside
|
||||
* `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).
|
||||
|
||||
This will change rapidly as of currently, slidescript is in beavy development!
|
||||
|
||||
* Networking functions
|
||||
* `netlisten "<port>" "<search>" "<respond>"` -> listens on <port> and replies <respond> on <search> found from outside
|
||||
* `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).
|
||||
|
||||
Todo list
|
||||
----
|
||||
* Add in-script functions
|
||||
* New static functions
|
||||
* Network sockets
|
||||
* Function piping between each other
|
||||
------
|
||||
* Add in-script functions
|
||||
* New static functions
|
||||
* Loops, and if statements
|
||||
|
||||
Done
|
||||
----
|
||||
* Simple syntax checking and error reporting
|
||||
* Support for linux system calls
|
||||
* Read and write from file
|
||||
* Some simple functions
|
||||
* Shebang handling
|
||||
* Variable support
|
||||
------
|
||||
* Simple syntax checking and error reporting
|
||||
* 2 layer function piping
|
||||
* 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
|
||||
* Some simple functions
|
||||
* Shebang handling
|
||||
* Variable support
|
||||
|
||||
Changelog
|
||||
----
|
||||
V0.3.3
|
||||
* Added first networking functions: netlisten, nettoss, nethttp.
|
||||
* Embedded web server functionality
|
||||
* Cleaned up code
|
||||
* Improved syntax handling on functions
|
||||
-----
|
||||
* V0.3.3
|
||||
* Added first networking functions: netlisten, nettoss, nethttp.
|
||||
* Embedded web server functionality
|
||||
* Cleaned up code
|
||||
* Improved syntax handling on functions
|
||||
|
||||
V0.3.0
|
||||
* Added simple 2 layer function piping for more useful tasks
|
||||
* Fixed a couple core dump bugs
|
||||
* Now reads files into memory, and then forces text files through SS, allows for in file variables
|
||||
* Added "md5" functionality
|
||||
* Multi-formal working syntax
|
||||
* V0.3.0
|
||||
* Added simple 2 layer function piping for more useful tasks
|
||||
* Fixed a couple core dump bugs
|
||||
* Now reads files into memory, and then forces text files through SS, allows for in file variables
|
||||
* Added "md5" functionality
|
||||
* Multi-formal working syntax
|
||||
|
||||
V0.2.1
|
||||
* Added "decrypt" decode function
|
||||
* Added "encrypt" encode function
|
||||
* Added system "exec" function
|
||||
* Added basic syntax handling, for a more uniform language
|
||||
* V0.2.1
|
||||
* Added "decrypt" decode function
|
||||
* Added "encrypt" encode function
|
||||
* Added system "exec" function
|
||||
* Added basic syntax handling, for a more uniform language
|
||||
|
||||
V0.2.0
|
||||
* Added "delete" function
|
||||
* Added embedded variable handling to SS functions (variables can be used like everywhere!)
|
||||
* Added linux system calls via exec
|
||||
* Some cleaning up.
|
||||
* V0.2.0
|
||||
* Added "delete" function
|
||||
* Added embedded variable handling to SS functions (variables can be used like everywhere!)
|
||||
* Added linux system calls via exec
|
||||
* Some cleaning up.
|
||||
|
||||
V0.1.1
|
||||
* Added variable handling with a buffer size of 2MB per variable, and
|
||||
cap of 2048 variables.
|
||||
* Now operates under the shebang!
|
||||
* V0.1.1
|
||||
* Added variable handling with a buffer size of 2KB per variable, and cap of 2048 variables.
|
||||
* Now operates under the shebang!
|
||||
|
||||
Contributions:
|
||||
Contributions
|
||||
-----
|
||||
Robert (OldCoder) Kiraly -> shebang support and string manipulations
|
||||
|
||||
(C) Copyright 2014-2021 Chris Dorman, some rights reserved (GPLv2)
|
||||
|
@ -1,6 +1,6 @@
|
||||
<html>
|
||||
<body>
|
||||
<h2>Test page</h2>
|
||||
<p>This is an index page hosted by the built in SlideScript HTTP server</p>
|
||||
<h2>SlideScript</h2>
|
||||
<p>This is an index page hosted by the built in SS HTTP server</p>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -6,4 +6,11 @@
|
||||
# * 0 = do not 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" },
|
||||
{"c", "text/plain" },
|
||||
{"h", "text/plain" },
|
||||
{"md", "text/plain" },
|
||||
{"txt", "text/plain" },
|
||||
{"ss", "text/plain" },
|
||||
{"sh", "text/plain" },
|
||||
@ -161,7 +162,7 @@ void snet_toss(char *address, int port, char *string)
|
||||
}
|
||||
|
||||
// Process connection of nethttp
|
||||
void snet_http_process(int fd)
|
||||
void snet_http_process(int fd, int forkval)
|
||||
{
|
||||
int j, file_fd, buflen, len;
|
||||
long i, filesize;
|
||||
@ -173,7 +174,8 @@ void snet_http_process(int fd)
|
||||
if(filesize == 0 || filesize == -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><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");
|
||||
exit(1);
|
||||
}
|
||||
@ -191,9 +193,11 @@ void snet_http_process(int fd)
|
||||
}
|
||||
|
||||
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");
|
||||
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");
|
||||
exit(1);
|
||||
}
|
||||
@ -212,7 +216,8 @@ void snet_http_process(int fd)
|
||||
if(buffer[j] == '.' && buffer[j+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><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");
|
||||
exit(1);
|
||||
}
|
||||
@ -225,7 +230,8 @@ void snet_http_process(int fd)
|
||||
} else {
|
||||
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><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");
|
||||
exit(1);
|
||||
}
|
||||
@ -246,13 +252,25 @@ void snet_http_process(int fd)
|
||||
fstr = "application/octet-stream";
|
||||
}
|
||||
|
||||
printf("ss:net:http request %s, %s\n", &buffer[5], fstr);
|
||||
if(forkval == 0)
|
||||
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
|
||||
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");
|
||||
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");
|
||||
exit(1);
|
||||
}
|
||||
@ -285,7 +303,7 @@ void snet_http(int port, int forkval)
|
||||
if(forkval > 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(SIGHUP, SIG_IGN);
|
||||
@ -295,8 +313,8 @@ void snet_http(int port, int forkval)
|
||||
}
|
||||
|
||||
setpgrp();
|
||||
|
||||
printf("Starting httpd...\n");
|
||||
if(forkval < 1)
|
||||
printf("Starting httpd...\n");
|
||||
|
||||
// Check if socket succeeded to open
|
||||
if((listenfd = socket(AF_INET, SOCK_STREAM,0)) <0) {
|
||||
@ -336,7 +354,7 @@ void snet_http(int port, int forkval)
|
||||
else {
|
||||
if(pid == 0) {
|
||||
close(listenfd);
|
||||
snet_http_process(socketfd);
|
||||
snet_http_process(socketfd, forkval);
|
||||
} else {
|
||||
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_toss(char *address, int port, char *string);
|
||||
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);
|
||||
|
19
src/util.c
19
src/util.c
@ -32,9 +32,22 @@ char *strip_nl (char *string)
|
||||
}
|
||||
|
||||
// Check if a file exists, return code
|
||||
int file_exists(char *fname) {
|
||||
int file_exists(char *path) {
|
||||
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)
|
||||
@ -59,7 +72,7 @@ void parse_args(int argc, char** argv)
|
||||
/* -v flag given, show version */
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
void syn_error(char *message);
|
||||
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);
|
||||
void parse_args(int argc, char** argv);
|
||||
|
Loading…
x
Reference in New Issue
Block a user