コード例 #1
0
ファイル: newuser.cpp プロジェクト: insidenothing/wwiv
static int find_new_usernum(const WUser* pUser, uint32_t* qsc) {
  File userFile(syscfg.datadir, USER_LST);
  for (int i = 0; !userFile.IsOpen() && (i < 20); i++) {
    if (!userFile.Open(File::modeBinary | File::modeReadWrite | File::modeCreateFile)) {
      Wait(0.1);
    }
  }
  if (!userFile.IsOpen()) {
    return -1;
  }

  int nNewUserNumber = static_cast<int>((userFile.GetLength() / syscfg.userreclen) - 1);
  userFile.Seek(syscfg.userreclen, File::seekBegin);
  int nUserNumber = 1;

  if (nNewUserNumber == application()->GetStatusManager()->GetUserCount()) {
    nUserNumber = nNewUserNumber + 1;
  } else {
    while (nUserNumber <= nNewUserNumber) {
      if (nUserNumber % 25 == 0) {
        userFile.Close();
        for (int n = 0; !userFile.IsOpen() && (n < 20); n++) {
          if (!userFile.Open(File::modeBinary | File::modeReadWrite | File::modeCreateFile)) {
            Wait(0.1);
          }
        }
        if (!userFile.IsOpen()) {
          return -1;
        }
        userFile.Seek(static_cast<long>(nUserNumber * syscfg.userreclen), File::seekBegin);
        nNewUserNumber = static_cast<int>((userFile.GetLength() / syscfg.userreclen) - 1);
      }
      WUser tu;
      userFile.Read(&tu.data, syscfg.userreclen);

      if (tu.IsUserDeleted() && tu.GetSl() != 255) {
        userFile.Seek(static_cast<long>(nUserNumber * syscfg.userreclen), File::seekBegin);
        userFile.Write(&pUser->data, syscfg.userreclen);
        userFile.Close();
        write_qscn(nUserNumber, qsc, false);
        InsertSmallRecord(nUserNumber, pUser->GetName());
        return nUserNumber;
      } else {
        nUserNumber++;
      }
    }
  }

  if (nUserNumber <= syscfg.maxusers) {
    userFile.Seek(static_cast<long>(nUserNumber * syscfg.userreclen), File::seekBegin);
    userFile.Write(&pUser->data, syscfg.userreclen);
    userFile.Close();
    write_qscn(nUserNumber, qsc, false);
    InsertSmallRecord(nUserNumber, pUser->GetName());
    return nUserNumber;
  } else {
    userFile.Close();
    return -1;
  }
}
コード例 #2
0
ファイル: sysopf.cpp プロジェクト: bhaggerty/wwiv
void auto_purge() {
  char s[80];
  unsigned int days = 0;
  int skipsl = 0;

  IniFile iniFile(FilePath(GetApplication()->GetHomeDir(), WWIV_INI), INI_TAG);
  if (iniFile.IsOpen()) {
    days = iniFile.GetNumericValue("AUTO_USER_PURGE");
    skipsl = iniFile.GetNumericValue("NO_PURGE_SL");
  }
  iniFile.Close();

  if (days < 60) {
    if (days > 0) {
      sysoplog("!!! WARNING: Auto-Purge canceled [AUTO_USER_PURGE < 60]", false);
      sysoplog("!!! WARNING: Edit WWIV.INI and Fix this", false);
    }
    return;
  }

  time_t tTime = time(NULL);
  int nUserNumber = 1;
  sysoplogfi(false, "Auto-Purged Inactive Users (over %d days, SL less than %d)", days, skipsl);

  do {
    WUser user;
    GetApplication()->GetUserManager()->ReadUser(&user, nUserNumber);
    if (!user.IsExemptAutoDelete()) {
      unsigned int d = static_cast<unsigned int>((tTime - user.GetLastOnDateNumber()) / SECONDS_PER_DAY_FLOAT);
      // if user is not already deleted && SL<NO_PURGE_SL && last_logon
      // greater than AUTO_USER_PURGE days ago
      if (!user.IsUserDeleted() && user.GetSl() < skipsl && d > days) {
        sprintf(s, "*** AUTOPURGE: Deleted User: #%3.3d %s", nUserNumber, user.GetName());
        sysoplog(s, false);
        deluser(nUserNumber);
      }
    }
    ++nUserNumber;
  } while (nUserNumber <= GetApplication()->GetStatusManager()->GetUserCount());
}
コード例 #3
0
void multimail(int *pnUserNumber, int numu) {
    mailrec m, m1;
    char s[255], s2[81];
    WUser user;

    if (freek1(syscfg.msgsdir) < 10) {
        bout.nl();
        bout << "Sorry, not enough disk space left.\r\n\n";
        return;
    }
    bout.nl();

    int i = 0;
    if (getslrec(session()->GetEffectiveSl()).ability & ability_email_anony) {
        i = anony_enable_anony;
    }
    bout << "|#5Show all recipients in mail? ";
    bool show_all = yesno();
    int j = 0;
    string s1 = StringPrintf("\003""6CC: \003""1");

    m.msg.storage_type = EMAIL_STORAGE;
    strcpy(irt, "Multi-Mail");
    irt_name[0] = 0;
    File::Remove(QUOTES_TXT);
    std::string t;
    inmsg(&m.msg, &t, &i, true, "email", INMSG_FSED, "Multi-Mail", MSGED_FLAG_NONE);
    if (m.msg.stored_as == 0xffffffff) {
        return;
    }
    strcpy(m.title, t.c_str());

    bout <<  "Mail sent to:\r\n";
    sysoplog("Multi-Mail to:");

    lineadd(&m.msg, "\003""7----", "email");

    for (int cv = 0; cv < numu; cv++) {
        if (pnUserNumber[cv] < 0) {
            continue;
        }
        application()->users()->ReadUser(&user, pnUserNumber[cv]);
        if ((user.GetSl() == 255 && (user.GetNumMailWaiting() > (syscfg.maxwaiting * 5))) ||
                ((user.GetSl() != 255) && (user.GetNumMailWaiting() > syscfg.maxwaiting)) ||
                user.GetNumMailWaiting() > 200) {
            bout << user.GetUserNameAndNumber(pnUserNumber[cv]) << " mailbox full, not sent.";
            pnUserNumber[cv] = -1;
            continue;
        }
        if (user.IsUserDeleted()) {
            bout << "User deleted, not sent.\r\n";
            pnUserNumber[cv] = -1;
            continue;
        }
        strcpy(s, "  ");
        user.SetNumMailWaiting(user.GetNumMailWaiting() + 1);
        application()->users()->WriteUser(&user, pnUserNumber[cv]);
        if (pnUserNumber[cv] == 1) {
            ++fwaiting;
        }
        strcat(s, user.GetUserNameAndNumber(pnUserNumber[cv]));
        WStatus* pStatus = application()->GetStatusManager()->BeginTransaction();
        if (pnUserNumber[cv] == 1) {
            pStatus->IncrementNumFeedbackSentToday();
            session()->user()->SetNumFeedbackSentToday(session()->user()->GetNumFeedbackSentToday() + 1);
            session()->user()->SetNumFeedbackSent(session()->user()->GetNumFeedbackSent() + 1);
            ++fsenttoday;
        } else {
            pStatus->IncrementNumEmailSentToday();
            session()->user()->SetNumEmailSent(session()->user()->GetNumEmailSent() + 1);
            session()->user()->SetNumEmailSentToday(session()->user()->GetNumEmailSentToday() + 1);
        }
        application()->GetStatusManager()->CommitTransaction(pStatus);
        sysoplog(s);
        bout << s;
        bout.nl();
        if (show_all) {
            sprintf(s2, "%-22.22s  ", user.GetUserNameAndNumber(pnUserNumber[cv]));
            s1.assign(s2);
            j++;
            if (j >= 3) {
                lineadd(&m.msg, s1, "email");
                j = 0;
                s1 = "\003""1    ";
            }
        }
    }
    if (show_all) {
        if (j) {
            lineadd(&m.msg, s1, "email");
        }
    }
    s1 = StringPrintf("\003""2Mail Sent to %d Addresses!", numu);
    lineadd(&m.msg, "\003""7----", "email");
    lineadd(&m.msg, s1, "email");

    m.anony = static_cast< unsigned char >(i);
    m.fromsys = 0;
    m.fromuser = static_cast<unsigned short>(session()->usernum);
    m.tosys = 0;
    m.touser = 0;
    m.status = status_multimail;
    m.daten = static_cast<unsigned long>(time(nullptr));

    unique_ptr<File> pFileEmail(OpenEmailFile(true));
    int len = pFileEmail->GetLength() / sizeof(mailrec);
    if (len == 0) {
        i = 0;
    } else {
        i = len - 1;
        pFileEmail->Seek(static_cast<long>(i) * sizeof(mailrec), File::seekBegin);
        pFileEmail->Read(&m1, sizeof(mailrec));
        while ((i > 0) && (m1.tosys == 0) && (m1.touser == 0)) {
            --i;
            pFileEmail->Seek(static_cast<long>(i) * sizeof(mailrec), File::seekBegin);
            int i1 = pFileEmail->Read(&m1, sizeof(mailrec));
            if (i1 == -1) {
                bout << "|#6DIDN'T READ WRITE!\r\n";
            }
        }
        if ((m1.tosys) || (m1.touser)) {
            ++i;
        }
    }
    pFileEmail->Seek(static_cast<long>(i) * sizeof(mailrec), File::seekBegin);
    for (int cv = 0; cv < numu; cv++) {
        if (pnUserNumber[cv] > 0) {
            m.touser = static_cast<unsigned short>(pnUserNumber[cv]);
            pFileEmail->Write(&m, sizeof(mailrec));
        }
    }
    pFileEmail->Close();
}
コード例 #4
0
int oneuser() {
    char s[81], *ss;
    int nUserNumber, nSystemNumber, i;
    WUser user;

    if (mml_s) {
        if (mml_started) {
            ss = strtok(nullptr, "\r\n");
        } else {
            ss = strtok(mml_s, "\r\n");
        }
        mml_started = 1;
        if (ss == nullptr) {
            free(mml_s);
            mml_s = nullptr;
            return -1;
        }
        strcpy(s, ss);
        for (i = 0; s[i] != 0; i++) {
            s[i] = upcase(s[i]);
        }
    } else {
        bout << "|#2>";
        input(s, 40);
    }
    nUserNumber = finduser1(s);
    if (nUserNumber == 65535) {
        return -1;
    }
    if (s[0] == 0) {
        return -1;
    }
    if (nUserNumber <= 0) {
        bout.nl();
        bout << "Unknown user.\r\n\n";
        return 0;
    }
    nSystemNumber = 0;
    if (ForwardMessage(&nUserNumber, &nSystemNumber)) {
        bout.nl();
        bout << "Forwarded.\r\n\n";
        if (nSystemNumber) {
            bout << "Forwarded to another system.\r\n";
            bout << "Can't send multi-mail to another system.\r\n\n";
            return 0;
        }
    }
    if (nUserNumber == 0) {
        bout.nl();
        bout << "Unknown user.\r\n\n";
        return 0;
    }
    application()->users()->ReadUser(&user, nUserNumber);
    if (((user.GetSl() == 255) && (user.GetNumMailWaiting() > (syscfg.maxwaiting * 5))) ||
            ((user.GetSl() != 255) && (user.GetNumMailWaiting() > syscfg.maxwaiting)) ||
            (user.GetNumMailWaiting() > 200)) {
        bout.nl();
        bout << "Mailbox full.\r\n\n";
        return 0;
    }
    if (user.IsUserDeleted()) {
        bout.nl();
        bout << "Deleted user.\r\n\n";
        return 0;
    }
    bout << "     -> " << user.GetUserNameAndNumber(nUserNumber) << wwiv::endl;
    return nUserNumber;
}
コード例 #5
0
ファイル: sysopf.cpp プロジェクト: bhaggerty/wwiv
void valuser(int nUserNumber) {
  char s[81], s1[81], s2[81], s3[81], ar1[20], dar1[20];

  WUser user;
  GetApplication()->GetUserManager()->ReadUser(&user, nUserNumber);
  if (!user.IsUserDeleted()) {
    GetSession()->bout.NewLine();
    GetSession()->bout << "|#9Name: |#2" << user.GetUserNameAndNumber(nUserNumber) << wwiv::endl;
    GetSession()->bout << "|#9RN  : |#2" << user.GetRealName() << wwiv::endl;
    GetSession()->bout << "|#9PH  : |#2" << user.GetVoicePhoneNumber() << wwiv::endl;
    GetSession()->bout << "|#9Age : |#2" << user.GetAge() << " " << user.GetGender() << wwiv::endl;
    GetSession()->bout << "|#9Comp: |#2" << ctypes(user.GetComputerType()) << wwiv::endl;
    if (user.GetNote()[0]) {
      GetSession()->bout << "|#9Note: |#2" << user.GetNote() << wwiv::endl;
    }
    GetSession()->bout << "|#9SL  : |#2" << user.GetSl() << wwiv::endl;
    if (user.GetSl() != 255 && user.GetSl() < GetSession()->GetEffectiveSl()) {
      GetSession()->bout << "|#9New : ";
      input(s, 3, true);
      if (s[0]) {
        int nSl = atoi(s);
        if (!GetApplication()->GetWfcStatus() && nSl >= GetSession()->GetEffectiveSl()) {
          nSl = -2;
        }
        if (nSl >= 0 && nSl < 255) {
          user.SetSl(nSl);
        }
        if (nSl == -1) {
          GetSession()->bout.NewLine();
          GetSession()->bout << "|#9Delete? ";
          if (yesno()) {
            deluser(nUserNumber);
            GetSession()->bout.NewLine();
            GetSession()->bout << "|#6Deleted.\r\n\n";
          } else {
            GetSession()->bout.NewLine();
            GetSession()->bout << "|#3NOT deleted.\r\n";
          }
          return;
        }
      }
    }
    GetSession()->bout.NewLine();
    GetSession()->bout << "|#9DSL : |#2" << user.GetDsl() << wwiv::endl;
    if (user.GetDsl() != 255 && user.GetDsl() < GetSession()->GetCurrentUser()->GetDsl()) {
      GetSession()->bout << "|#9New ? ";
      input(s, 3, true);
      if (s[0]) {
        int nDsl = atoi(s);
        if (!GetApplication()->GetWfcStatus() && nDsl >= GetSession()->GetCurrentUser()->GetDsl()) {
          nDsl = -1;
        }
        if (nDsl >= 0 && nDsl < 255) {
          user.SetDsl(nDsl);
        }
      }
    }
    strcpy(s3, restrict_string);
    int ar2     = 1;
    int dar2    = 1;
    ar1[0]      = RETURN;
    dar1[0]     = RETURN;
    for (int i = 0; i <= 15; i++) {
      if (user.HasArFlag(1 << i)) {
        s[i] = static_cast<char>('A' + i);
      } else {
        s[i] = SPACE;
      }
      if (GetSession()->GetCurrentUser()->HasArFlag(1 << i)) {
        ar1[ar2++] = static_cast<char>('A' + i);
      }
      if (user.HasDarFlag(1 << i)) {
        s1[i] = static_cast<char>('A' + i);
      } else {
        s1[i] = SPACE;
      }
      if (GetSession()->GetCurrentUser()->HasDarFlag(1 << i)) {
        dar1[dar2++] = static_cast<char>('A' + i);
      }
      if (user.HasRestrictionFlag(1 << i)) {
        s2[i] = s3[i];
      } else {
        s2[i] = SPACE;
      }
    }
    s[16]       = '\0';
    s1[16]      = '\0';
    s2[16]      = '\0';
    ar1[ar2]    = '\0';
    dar1[dar2]  = '\0';
    GetSession()->bout.NewLine();
    char ch1 = '\0';
    if (ar2 > 1) {
      do {
        GetSession()->bout << "|#9AR  : |#2" << s << wwiv::endl;
        GetSession()->bout << "|#9Togl? ";
        ch1 = onek(ar1);
        if (ch1 != RETURN) {
          ch1 -= 'A';
          if (s[ch1] == SPACE) {
            s[ch1] = ch1 + 'A';
          } else {
            s[ch1] = SPACE;
          }
          user.ToggleArFlag(1 << ch1);
          ch1 = 0;
        }
      } while (!hangup && ch1 != RETURN);
    }
    GetSession()->bout.NewLine();
    ch1 = 0;
    if (dar2 > 1) {
      do {
        GetSession()->bout << "|#9DAR : |#2" << s1 << wwiv::endl;
        GetSession()->bout << "|#9Togl? ";
        ch1 = onek(dar1);
        if (ch1 != RETURN) {
          ch1 -= 'A';
          if (s1[ch1] == SPACE) {
            s1[ch1] = ch1 + 'A';
          } else {
            s1[ch1] = SPACE;
          }
          user.ToggleDarFlag(1 << ch1);
          ch1 = 0;
        }
      } while (!hangup && ch1 != RETURN);
    }
    GetSession()->bout.NewLine();
    ch1     = 0;
    s[0]    = RETURN;
    s[1]    = '?';
    strcpy(&(s[2]), restrict_string);
    do {
      GetSession()->bout << "      |#2" << s3 << wwiv::endl;
      GetSession()->bout << "|#9Rstr: |#2" << s2 << wwiv::endl;
      GetSession()->bout << "|#9Togl? ";
      ch1 = onek(s);
      if (ch1 != RETURN && ch1 != SPACE && ch1 != '?') {
        int i = -1;
        for (int i1 = 0; i1 < 16; i1++) {
          if (ch1 == s[i1 + 2]) {
            i = i1;
          }
        }
        if (i > -1) {
          user.ToggleRestrictionFlag(1 << i);
          if (s2[i] == SPACE) {
            s2[i] = s3[i];
          } else {
            s2[i] = SPACE;
          }
        }
        ch1 = 0;
      }
      if (ch1 == '?') {
        ch1 = 0;
        printfile(SRESTRCT_NOEXT);
      }
    } while (!hangup && ch1 == 0);
    GetApplication()->GetUserManager()->WriteUser(&user, nUserNumber);
    GetSession()->bout.NewLine();
  } else {
    GetSession()->bout << "\r\n|#6No Such User.\r\n\n";
  }
}
コード例 #6
0
ファイル: bbs.cpp プロジェクト: bhaggerty/wwiv-1
int WApplication::LocalLogon() {
  session()->localIO()->LocalGotoXY(2, 23);
  bout << "|#9Log on to the BBS?";
  double d = timer();
  int lokb = 0;
  while (!session()->localIO()->LocalKeyPressed() && (fabs(timer() - d) < SECONDS_PER_MINUTE_FLOAT))
    ;

  if (session()->localIO()->LocalKeyPressed()) {
    char ch = wwiv::UpperCase<char>(session()->localIO()->LocalGetChar());
    if (ch == 'Y') {
      session()->localIO()->LocalPuts(YesNoString(true));
      bout << wwiv::endl;
      lokb = 1;
    } else if (ch == 0 || static_cast<unsigned char>(ch) == 224) {
      // The ch == 224 is a Win32'ism
      session()->localIO()->LocalGetChar();
    } else {
      bool fast = false;
      if (!AllowLocalSysop()) {
        return lokb;
      }

      if (ch == 'F') {   // 'F' for Fast
        m_unx = 1;
        fast = true;
      } else {
        switch (ch) {
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
          fast = true;
          m_unx = ch - '0';
          break;
        }
      }
      if (!fast || m_unx > GetStatusManager()->GetUserCount()) {
        return lokb;
      }

      WUser tu;
      users()->ReadUserNoCache(&tu, m_unx);
      if (tu.GetSl() != 255 || tu.IsUserDeleted()) {
        return lokb;
      }

      session()->usernum = m_unx;
      int nSavedWFCStatus = GetWfcStatus();
      SetWfcStatus(0);
      session()->ReadCurrentUser();
      read_qscn(session()->usernum, qsc, false);
      SetWfcStatus(nSavedWFCStatus);
      bputch(ch);
      session()->localIO()->LocalPuts("\r\n\r\n\r\n\r\n\r\n\r\n");
      lokb = 2;
      session()->ResetEffectiveSl();
      changedsl();
      if (!set_language(session()->user()->GetLanguage())) {
        session()->user()->SetLanguage(0);
        set_language(0);
      }
      return lokb;
    }
    if (ch == 0 || static_cast<unsigned char>(ch) == 224) {
      // The 224 is a Win32'ism
      session()->localIO()->LocalGetChar();
    }
  }
  if (lokb == 0) {
    session()->localIO()->LocalCls();
  }
  return lokb;
}