"Fossies" - the Fresh Open Source Software archive

Member "dbox-2.41/online/antrag.C" of archive dbox-2.41.tgz:


/*

  DBOX Module
  Copyright (C) 1994-2000 Daniel Kroening <kroening@handshake.de>

  Purpose: 

*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <dirent.h>
#include <time.h>

#include <log_serv.h>
#include <dboxpath.h>
#include <oldtools.h>
#include <zconnect.h>
#include <oldui.h>
#include <messageid.h>
#include "gen_from.h"
#include "online.h"
#include "userlog.h"
#include "help.h"
#include "menu.h"
#include "checkuser.h"

static bool wirklichabbrechen()
 {
  omet mes[3];

  online.setattr(3, FALSE);
  online.box(20, 10, 60, 16, BOXFRAMEDBL, NULL, TRUE);

  online.setcursor(29, 12);
  online.printf("Wirklich abbrechen?");

  mes[0].type=omet::COMMANDBUTTON;
  mes[0].x=26;
  mes[0].y=14;
  mes[0].key=Key_C_Ent;
  mes[0].sizex=6;
  mes[0].text="^Ja";

  mes[1].type=omet::COMMANDBUTTON;
  mes[1].x=43;
  mes[1].y=14;
  mes[1].key=0;
  mes[1].sizex=6;
  mes[1].text="^Nein";

  mes[2].type=omet::END_OF_LIST;

  return domenu(&online, mes, 0, TRUE)==0;
 }

static void postantragmail(userpt *up, const char *username)
 {
  FILE *outfile;
  char text[1000];
  char file1[DIRLEN], file2[DIRLEN], abs[TEXTLEN],
       org[TEXTLEN];

  snprintf(file1, DIRLEN, DBOXPORTTEMPDIR "msg.tmp", config.dboxdir, config.port);
  outfile=fopen(file1, "wb");
  if(outfile==NULL)
   {
    log_serv.printf("postantragmail", "Failed to create \"%s\"", file1);
    return;
   }

  snprintf(text, 1000,
    "DBOX Userantrag\r\n"
    "ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\r\n"
    "\r\n"
    "Username: %s\r\n"
    "Realname: %s %s\r\n"
    "Straáe:   %s\r\n"
    "PLZ+Ort:  %s\r\n"
    "Telefon:  %s\r\n"
    "Fax:      %s\r\n",
    username,
    *up|"vorname",
    *up|"nachname",
    *up|"strasse",
    *up|"ort",
    *up|"telefon",
    *up|"fax");

  gen_abs(status, status.username, abs, org, TRUE);

  fprintf(outfile, "ABS:\t%s\r\n", abs);

  fprintf(outfile, "BET:\tUserantrag\r\n");

  fprintf(outfile, "EDA:\t%s\r\n", make_eda_localtime().c_str());

  if(config.antrag_mail[0]==0)
    fprintf(outfile, "EMP:\tSYSOP@%s.%s\r\n",
      config.boxname, config.domain);
  else
    fprintf(outfile, "EMP:\t%s\r\n", config.antrag_mail);

  fprintf(outfile, "LEN:\t%lu\r\n", (dword)(strlen(text)));

  fprintf(outfile, "MAILER:\tDBOX Userantragsmodul\r\n");

  fprintf(outfile, "MID:\t%s\r\n",
    gen_message_id("antrag").c_str());

  if(org[0]!=0)
    fprintf(outfile, "ORG:\t%s\r\n", org);

  fprintf(outfile, "ROT:\r\n");

  fprintf(outfile, "\r\n");

  fwrite(text, 1, strlen(text), outfile);

  fclose(outfile);

  snprintf(file2, DIRLEN, BOXSPOOLINZCMAILDIR "%s.%lu-%lu-%u", config.boxdir,
          status.username, status.midcounter++, time(NULL), config.port);

  rename(file1, file2);
 }

static void showantrag(userpt &up, const char *username, const char *password)
 {
  byte y=2;
  omet mes[2];

  online.setattr(2, FALSE);
  online.box(10, y++, 70, 24, BOXFRAMEDBL, "User-Antrag", TRUE);
  y++;
  online.setattr(2, TRUE);
  online.setcursor(12, y++);
  online.printf("Sie wurden wie folgt in der Mailbox eingetragen:");
  y=6;
  online.setcursor(29, y++); online.printf("%s", username);
  online.setcursor(29, y++); online.printf("%s", password);
  online.setcursor(29, y++); online.printf("%s %s", up|"vorname", up|"nachname");
  online.setcursor(29, y++); online.printf("%s", up|"firma");
  online.setcursor(29, y++); online.printf("%s", up|"strasse");
  online.setcursor(29, y++); online.printf("%s", up|"ort");
  online.setcursor(29, y++); online.printf("%s", up|"telefon");
  online.setcursor(29, y++); online.printf("%s", up|"fax");
  online.setcursor(29, y++); online.printf("%s", up|"sonstiges");
  y+=2;
  online.setcursor(15, y);
  online.printf("%s@%s.%s", username, config.boxname, config.domain);
  online.setattr(2, FALSE);

  y=6;
  online.setcursor(12, y++); online.printf("Username.......: ");
  online.setcursor(12, y++); online.printf("Passwort.......: ");
  online.setcursor(12, y++); online.printf("Voller Name....: ");
  online.setcursor(12, y++); online.printf("Firma..........: ");
  online.setcursor(12, y++); online.printf("Straáe.........: ");
  online.setcursor(12, y++); online.printf("PLZ + Ort......: ");
  online.setcursor(12, y++); online.printf("Telefonnummer..: ");
  online.setcursor(12, y++); online.printf("Fax............: ");
  online.setcursor(12, y++); online.printf("Sonstiges......: ");
  y++;
  online.setcursor(12, y++); online.printf("Ihre E-Mail-Adresse lautet:");
  y+=2;
  online.setcursor(12, y++);
  online.printf("WICHTIG! Sie sollten nie in zwei Mailboxen");
  online.setcursor(12, y++);
  online.printf("         dasselbe Passwort benutzen!");
  y++;

  mes[0].type=omet::COMMANDBUTTON;
  mes[0].x=37;
  mes[0].y=y;
  mes[0].key=Key_C_Ent;
  mes[0].sizex=6;
  mes[0].text="O^k";

  mes[1].type=omet::END_OF_LIST;

  domenu(&online, mes, 0, TRUE);
 }

void doantrag()
 {
  char username[TEXTLEN], password[TEXTLEN];
  bool ende=FALSE;

  userlogprintf1(status, "doantrag", "Userantrag gestartet");

  userpt newprofile("userantrag");
  newprofile.setfilename();

  while(!ende)
   {
    if(status.dologout) return;

    if(doonlinemenu("antrag", &newprofile, FALSE, FALSE, FALSE, "antrag")<0)
     {
      if(status.dologout) return;

      if(wirklichabbrechen())
        ende=TRUE;
     }
    else
     {
      char errormsg[TEXTLEN];

      if(status.dologout) return;

      newprofile.get("_username", username);
      newprofile.get("_password", password);
      dnstring(username);
      username[40]=0;
      password[30]=0;

      if(username[0]==0 || (newprofile|"vorname")[0]==0 ||
         (newprofile|"nachname")[0]==0 || (newprofile|"strasse")[0]==0 ||
         (newprofile|"ort")[0]==0 || (newprofile|"telefon")[0]==0 ||
         strchr(newprofile|"ort", ' ')==NULL)
       {
        errorbox(&online, "Antrag unvollst„ndig!");
        continue;
       }

      if(checkuser(username, errormsg))
       {
        if(status.dologout) return;
        errorbox(&online, errormsg);
        continue;
       }

      userpt tmp_up(username);
      if(!tmp_up.read())
       {
        if(status.dologout) return;
        errorbox(&online, "Username bereits vergeben! W„hlen Sie einen anderen Namen!");
        continue;
       }

      strmaxcpy(newprofile.name, username, TEXTLEN-1);

      if(tmp_up.lock())
       {
        errorbox(&online, "Username bereits vergeben! W„hlen Sie einen anderen Namen!");
        continue;
       }

      tmp_up.copy_from(&newprofile);
      tmp_up.set("eintragsdatum", time(NULL));
      tmp_up.set("gruppe", config.antrag_gruppe);
      tmp_up.set("usecolor", online.usecolor);
      tmp_up.set("charset", status.userprofile|"charset");
      tmp_up.set("_username", "");
      tmp_up.set("_password", "");

       {
        char tempstr[TEXTLEN];
        cryptpassword(password, tempstr);
        tmp_up.set("cryptedpassword", tempstr);
       }
 
      ende=TRUE;

      if(tmp_up.add())
       {
        tmp_up.unlock();
        if(status.dologout) return;
        errorbox(&online, "Eintragsfehler!");
       }
      else
       {
        tmp_up.unlock();
        userlogprintf2(status, username, "doantrag",
          "User %s eingetragen", username);

        postantragmail(&tmp_up, username);
        if(status.dologout) return;
        showantrag(tmp_up, username, password);
       }
     }
   }
 }