Skip to content

Commit

Permalink
Add testing cgi with authentication check
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalbox94 committed Apr 18, 2021
1 parent 592c359 commit a45863f
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions cgi-bin/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

int IsUserLogin(char *user, int bufsize)
{
FILE *fp = NULL;
char buf[1024];
int login = 0;

bzero(user, bufsize);
fp = popen("/usr/syno/synoman/webman/modules/authenticate.cgi", "r");
if (!fp) {
return 0;
}

bzero(buf, sizeof(buf));
fread(buf, 1024, 1, fp);

if (strlen(buf) > 0) {
snprintf(user, bufsize, "%s", buf);
login = 1;
}
pclose(fp);

return login;
}

int main(int argc, char **argv)
{
char user[256];
printf("Content-Type: text/html\r\n\r\n");

if (IsUserLogin(user, sizeof(user)) == 1) {
printf("User is authenticated. Name: %s\n", user); }
else {
printf("User is not authenticated.\n");
}

return 0;
}

0 comments on commit a45863f

Please sign in to comment.