This commit is contained in:
rald 2023-08-06 20:04:55 +08:00
parent 2f27b8e8a1
commit 3814d2c6ea
6 changed files with 0 additions and 98 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,62 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#define GUESTBOOK_FILE "/home/fria/gemini/guestbook.gmi"
int ishex(int x) {
return (x >= '0' && x <= '9') ||
(x >= 'a' && x <= 'f') ||
(x >= 'A' && x <= 'F');
}
int urldecode(const char *s, char *dec)
{
char *o;
const char *end = s + strlen(s);
int c;
for (o = dec; s <= end; o++) {
c = *s++;
if (c == '+') c = ' ';
else if (c == '%' && ( !ishex(*s++) ||
!ishex(*s++) ||
!sscanf(s - 2, "%2x", &c)))
return -1;
if (dec) *o = c;
}
return o - dec;
}
int main() {
char *input=getenv("QUERY_STRING");
FILE *fp=NULL;
time_t t = time(NULL);
struct tm tm = *localtime(&t);
char *output=NULL;
if(!(input && *input)) {
printf("10 Enter message?\r\n");
exit(0);
}
output=malloc(sizeof(*output)*strlen(input)+1);
if(output==NULL) exit(1);
if(urldecode(input,output)==-1) exit(1);
if((fp=fopen(GUESTBOOK_FILE,"a"))==NULL) exit(1);
fprintf(fp,"### %d-%02d-%02d %02d:%02d:%02d\n%s\n",tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,output);
fclose(fp);
free(output);
output=NULL;
printf("30 /cgi-bin/guestbook/view.cgi\r\n");
return 0;
}

Binary file not shown.

View File

@ -1,36 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#define GUESTBOOK_FILE "/home/fria/gemini/guestbook.gmi"
int main() {
FILE *fp=NULL;
char *line=NULL;
size_t llen=0;
ssize_t rlen=0;
printf("20 text/gemini\r\n");
printf("# Pantasya\n");
printf("=> /pantasya/index.gmi Pantasya Online Computer School\n\n");
printf("## Guestbook\n\n");
if((fp=fopen(GUESTBOOK_FILE,"r"))) {
while((rlen=getline(&line,&llen,fp))!=-1) {
puts(line);
free(line);
line=NULL;
llen=0;
rlen=0;
}
free(line);
line=NULL;
llen=0;
rlen=0;
fclose(fp);
}
return 0;
}

Binary file not shown.