void Doorbot::run() { wdog.feed(); door.maybeClose(); led.run(); cardPresent((void (Role::*)(Card c))&Doorbot::handleCardPresent); if (door.isOpen()) { led.solid(GREEN); } else { led.solid(BLUE); } int poll = button.poll(); switch (poll) { case SHORT_PRESS: case LONG_PRESS: announcer->BELL(); Serial.println("BING BONG "); led.solid(ORANGE); delay(ACCESS_DENIED_LED_ON_TIME/2); led.solid(BLUE); delay(ACCESS_DENIED_LED_ON_TIME/2); led.solid(ORANGE); break; } int poll_release = door_release_button.poll(); switch (poll_release) { case SHORT_PRESS: case LONG_PRESS: announcer->EXIT(); Serial.println("Door release"); grantAccess(); } announcer->run(); };
void Doorbot::handleCardPresent(Card c) { int status; Card cached = cache->get(c); if (cached.compare_uid(c) && cached.is_valid()) { status = 1; } else if(lwIPLinkActive()) { led.solid(MAUVE); status = networking::querycard(c); switch (status) { case 2: c.set_maintainer(true); case 1: c.set_user(true); } } else { Serial.println("No network link - not querying server"); status = -127; } if(status >= 0) { cache->set(c); grantAccess(); announceCard(c,1); } else if(status == -1) { announceCard(c,0); denyAccess(); } else { networkingError(); announceCard(c,-1); } }
int main(int argc, char **argv, char **envp) { struct ReadBuffer * buf = newReadBuffer(fileno(stdin)); char * line = NULL; size_t linesz = 0; int act = 0; setupSignals(); openlog("squidGuard", LOG_PID | LOG_NDELAY | LOG_CONS, SYSLOG_FAC); if (!parseOptions(argc, argv)) { closelog(); exit(1); } registerSettings(); //sgSetGlobalErrorLogFile(); sgReadConfig(configFile); sgSetGlobalErrorLogFile(); sgLogInfo("squidGuard %s started", VERSION); if (globalUpdate || globalCreateDb != NULL) { sgLogInfo("db update done"); sgLogInfo("squidGuard stopped."); closelog(); freeAllLists(); exit(0); } sgLogInfo("squidGuard ready for requests"); while ((act = doBufferRead(buf, &line, &linesz)) >= 0) { struct AccessList *acl; static struct SquidInfo request; if (act == 0) { sgReloadConfig(configFile); continue; } if (authzMode == 1) { if (parseAuthzLine(line, &request) != 1) { sgLogError("Error parsing squid acl helper line"); denyOnError("Error parsing squid acl helper line"); continue; } } else { if (parseLine(line, &request) != 1) { sgLogError("Error parsing squid redirector line"); denyOnError("Error parsing squid redirector line"); continue; } } if (inEmergencyMode) { const char *message = "squidGuard is in emergency mode, check configuration"; if (passthrough) allowOnError(message); else denyOnError(message); continue; } for (acl = getFirstAccessList(); acl; acl = acl->next) { char *redirect = NULL; enum AccessResults access = checkAccess(acl, &request, &redirect); if (access == ACCESS_UNDEFINED) continue; if (access == ACCESS_GRANTED) { grantAccess(acl); break; } denyAccess(acl, redirect, &request); sgFree(redirect); break; } fflush(stdout); } sgLogNotice("squidGuard stopped"); closelog(); freeAllLists(); sgFree(line); freeReadBuffer(buf); exit(0); }