Login Vars
This commit is contained in:
152
login.c
152
login.c
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "net.h"
|
||||
#include "nwcrypt.h"
|
||||
#include <time.h>
|
||||
|
||||
#ifndef BLACK
|
||||
#define BLACK 0
|
||||
@@ -159,18 +160,100 @@ static void strip_quotes(char *s)
|
||||
*d = '\0';
|
||||
}
|
||||
|
||||
|
||||
static void script_get_timevar(char *name, char *out, int outlen)
|
||||
{
|
||||
time_t now;
|
||||
struct tm *tmv;
|
||||
int hour;
|
||||
static char *months[] = {
|
||||
"JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE",
|
||||
"JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"
|
||||
};
|
||||
static char *days[] = {
|
||||
"SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY",
|
||||
"THURSDAY", "FRIDAY", "SATURDAY"
|
||||
};
|
||||
|
||||
*out = '\0';
|
||||
|
||||
time(&now);
|
||||
tmv = localtime(&now);
|
||||
if (!tmv) return;
|
||||
|
||||
upstr(name);
|
||||
|
||||
if (!strcmp(name, "GREETING_TIME")) {
|
||||
if (tmv->tm_hour < 12) strcpy(out, "MORNING");
|
||||
else if (tmv->tm_hour < 18) strcpy(out, "AFTERNOON");
|
||||
else strcpy(out, "EVENING");
|
||||
} else if (!strcmp(name, "MONTH_NAME")) {
|
||||
strmaxcpy(out, months[tmv->tm_mon], outlen - 1);
|
||||
} else if (!strcmp(name, "MONTH")) {
|
||||
sprintf(out, "%02d", tmv->tm_mon + 1);
|
||||
} else if (!strcmp(name, "DAY")) {
|
||||
sprintf(out, "%02d", tmv->tm_mday);
|
||||
} else if (!strcmp(name, "YEAR")) {
|
||||
sprintf(out, "%04d", tmv->tm_year + 1900);
|
||||
} else if (!strcmp(name, "DAY_OF_WEEK")) {
|
||||
strmaxcpy(out, days[tmv->tm_wday], outlen - 1);
|
||||
} else if (!strcmp(name, "HOUR")) {
|
||||
hour = tmv->tm_hour % 12;
|
||||
if (!hour) hour = 12;
|
||||
sprintf(out, "%d", hour);
|
||||
} else if (!strcmp(name, "MINUTE")) {
|
||||
sprintf(out, "%02d", tmv->tm_min);
|
||||
} else if (!strcmp(name, "SECOND")) {
|
||||
sprintf(out, "%02d", tmv->tm_sec);
|
||||
} else if (!strcmp(name, "AM_PM")) {
|
||||
strcpy(out, tmv->tm_hour >= 12 ? "PM" : "AM");
|
||||
}
|
||||
}
|
||||
|
||||
static void script_expand_var(char *name, char *out, int outlen)
|
||||
{
|
||||
upstr(name);
|
||||
*out = '\0';
|
||||
|
||||
if (!strcmp(name, "LOGIN_NAME")) {
|
||||
strmaxcpy(out, script_login_name, outlen - 1);
|
||||
} else if (!strcmp(name, "FILE_SERVER")) {
|
||||
strmaxcpy(out, script_file_server, outlen - 1);
|
||||
} else if (!strcmp(name, "P_STATION") || !strcmp(name, "STATION")) {
|
||||
strcpy(out, "000000000000");
|
||||
} else {
|
||||
script_get_timevar(name, out, outlen);
|
||||
if (!*out) {
|
||||
strcpy(out, "%");
|
||||
strncat(out, name, outlen - strlen(out) - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void script_put_expanded(char *s)
|
||||
{
|
||||
while (s && *s) {
|
||||
if (!strncmp(s, "%LOGIN_NAME", 11) || !strncmp(s, "%login_name", 11)) {
|
||||
fprintf(stdout, "%s", script_login_name);
|
||||
s += 11;
|
||||
} else if (!strncmp(s, "%FILE_SERVER", 12) || !strncmp(s, "%file_server", 12)) {
|
||||
fprintf(stdout, "%s", script_file_server);
|
||||
s += 12;
|
||||
} else if (!strncmp(s, "%P_STATION", 10) || !strncmp(s, "%p_station", 10)) {
|
||||
fprintf(stdout, "000000000000");
|
||||
s += 10;
|
||||
if (*s == '%') {
|
||||
char name[64];
|
||||
char value[128];
|
||||
int i = 0;
|
||||
|
||||
s++;
|
||||
while ((*s == '_' ||
|
||||
(*s >= 'A' && *s <= 'Z') ||
|
||||
(*s >= 'a' && *s <= 'z') ||
|
||||
(*s >= '0' && *s <= '9')) &&
|
||||
i < (int)sizeof(name) - 1) {
|
||||
name[i++] = *s++;
|
||||
}
|
||||
name[i] = '\0';
|
||||
|
||||
if (i) {
|
||||
script_expand_var(name, value, sizeof(value));
|
||||
fprintf(stdout, "%s", value);
|
||||
} else {
|
||||
fputc('%', stdout);
|
||||
}
|
||||
} else {
|
||||
fputc(*s++, stdout);
|
||||
}
|
||||
@@ -241,30 +324,52 @@ static int script_eval_if(char *line)
|
||||
|
||||
if (q != NULL) {
|
||||
char want[64];
|
||||
char *v;
|
||||
char have[64];
|
||||
int i = 0;
|
||||
|
||||
q += neg ? 2 : 1;
|
||||
q = skip_spaces(q);
|
||||
if (*q == '"' || *q == '\'') q++;
|
||||
|
||||
while (*q && *q != '"' && *q != '\'' && *q != 32 && *q != '\t' && i < 63) {
|
||||
while (*q && *q != '"' && *q != '\'' && *q != 32 && *q != '\t' && i < 63)
|
||||
want[i++] = *q++;
|
||||
}
|
||||
want[i] = '\0';
|
||||
|
||||
strmaxcpy(tmp, script_login_name, sizeof(tmp) - 1);
|
||||
upstr(tmp);
|
||||
strmaxcpy(have, script_login_name, sizeof(have) - 1);
|
||||
upstr(have);
|
||||
|
||||
if (neg) return(strcmp(tmp, want) != 0);
|
||||
else return(strcmp(tmp, want) == 0);
|
||||
if (neg) return(strcmp(have, want) != 0);
|
||||
return(strcmp(have, want) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
p = strstr(tmp, "DAY_OF_WEEK");
|
||||
if (p != NULL) {
|
||||
q = strchr(p, '=');
|
||||
if (q != NULL) {
|
||||
char want[64];
|
||||
char have[64];
|
||||
int i = 0;
|
||||
|
||||
q++;
|
||||
q = skip_spaces(q);
|
||||
if (*q == '"' || *q == '\'') q++;
|
||||
|
||||
while (*q && *q != '"' && *q != '\'' && *q != 32 && *q != '\t' && i < 63)
|
||||
want[i++] = *q++;
|
||||
want[i] = '\0';
|
||||
|
||||
strcpy(have, "DAY_OF_WEEK");
|
||||
script_get_timevar(have, have, sizeof(have));
|
||||
upstr(have);
|
||||
|
||||
return(strcmp(have, want) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
static int login_strnicmp(char *a, char *b, int n)
|
||||
{
|
||||
while (n-- > 0) {
|
||||
@@ -289,7 +394,7 @@ static int script_execute_line(char *line)
|
||||
strmaxcpy(work, line, sizeof(work) - 1);
|
||||
p = skip_spaces(work);
|
||||
|
||||
if (!*p) return(0);
|
||||
if (!*p || *p == ';') return(0);
|
||||
|
||||
i = 0;
|
||||
while (p[i] && p[i] != 32 && p[i] != '\t' && i < 31) {
|
||||
@@ -347,6 +452,13 @@ static int script_execute_line(char *line)
|
||||
return(0);
|
||||
}
|
||||
|
||||
if (!strncmp(up, "ROOT ", 5)) {
|
||||
char callbuf[512];
|
||||
sprintf(callbuf, "MAP %s", skip_spaces(arg + 5));
|
||||
script_call_line(callbuf);
|
||||
return(0);
|
||||
}
|
||||
|
||||
if (!strncmp(up, "INS ", 4) || !strncmp(up, "INSERT ", 7)) {
|
||||
char callbuf[512];
|
||||
char *a = arg;
|
||||
@@ -368,6 +480,10 @@ static int script_execute_line(char *line)
|
||||
}
|
||||
}
|
||||
|
||||
if (!strcmp(cmd, "ATTACH")) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
if (!strcmp(cmd, "EXIT")) {
|
||||
return(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user