NukeSpamStats()
\n");
//Report table 1
sprintf(query,"SELECT uType,COUNT(*) FROM tMailLog WHERE uType>99 AND uType<200 GROUP BY uType");
mysql_query(&mysql,query);
if(mysql_errno(&mysql))
{
fprintf(stderr,"%s\n",mysql_error(&mysql));
exit(1);
}
res=mysql_store_result(&mysql);
i=mysql_num_rows(res);
if(i)
{
printf("Rejects during last hour");
printf("\n");
printf("| Number | Internal Reject Codes: 100=550, 101=553, 102=554, 103=Other 5XX codes |
\n");
while((field=mysql_fetch_row(res)))
{
printf("| %s | %s |
\n",field[1],field[0]);
}
printf("
\n");
printf("
\n");
}
mysql_free_result(res);
//2nd part of report
sprintf(query,"SELECT uRejectsType,SUM(uCount) FROM tRejects GROUP BY uRejectsType");
mysql_query(&mysql,query);
if(mysql_errno(&mysql))
{
fprintf(stderr,"%s\n",mysql_error(&mysql));
exit(1);
}
res=mysql_store_result(&mysql);
i=mysql_num_rows(res);
if(i)
{
printf("Cummulative rejects\n");
printf("\n");
printf("| Number | Reject Code |
\n");
while((field=mysql_fetch_row(res)))
{
printf("| %s | %s |
\n",field[1],field[0]);
}
printf("
\n");
printf("
\n");
}
mysql_free_result(res);
//3rd part of report
sprintf(query,"SELECT FROM_UNIXTIME(MIN(uFirstCount)),FROM_UNIXTIME(MAX(uLastCount)) FROM tRejects");
mysql_query(&mysql,query);
if(mysql_errno(&mysql))
{
fprintf(stderr,"%s\n",mysql_error(&mysql));
exit(1);
}
res=mysql_store_result(&mysql);
i=mysql_num_rows(res);
if(i)
{
printf("Historical Info\n");
printf("\n");
printf("| Point | Date Time |
\n");
if((field=mysql_fetch_row(res)))
{
printf("| Since | %s |
\n",field[0]);
printf("| Last | %s |
\n",field[1]);
}
printf("
\n");
printf("
\n");
}
mysql_free_result(res);
printf("$Id: mainfunc.h 6 2005-11-24 00:02:59Z ggw $\n");
exit(0);
}//void Stats(void)
#endif
//if defined NUKESPAM
void UpgradeSchema(char *cPasswd)
{
mySQLRootConnect(cPasswd);
sprintf(query,"USE %s",DBNAME);
mysql_query(&mysql,query);
if(mysql_errno(&mysql))
{
fprintf(stderr,"%s\n",mysql_error(&mysql));
exit(1);
}
printf("\nUpgradeSchema() if needed\n");
printf("\ttUser\n");
sprintf(query,"ALTER TABLE tUser CHANGE COLUMN cPasswd cPasswd VARCHAR(64) NOT NULL DEFAULT ''");
mysql_query(&mysql,qstr);
if(mysql_errno(&mysql))
fprintf(stderr,"%s\n",mysql_error(&mysql));
}//void UpgradeSchema(char *cPasswd)
int NewUser(unsigned uUser);
void MigrateUsers(unsigned uDryRun, unsigned uHelp)
{
MYSQL_RES *res;
MYSQL_ROW field;
uid_t uUID=999999;
char cMbox[256]={"var/mail/%s"};
char cImapMail[256]={"INBOX.*"};
time_t luClock;
printf("\nMigrateUsers %s ($Rev: 21 $)\n",RELEASESHORT);
uUID=getuid();
if(uUID)
{
printf("\nOnly root can run this command\n");
exit(1);
}
if(uHelp)
{
printf("\nHelp\n");
printf("1-. mysqldump remote host mysqlsendmail data and pipe into mysql.\n");
printf("2-. rsync mail and user dirs imap mail folders into a /migration dir\n");
printf("\tEx. /migration/home//INBOX.* and /migration/var/mail/\n");
exit(0);
}
else if(uDryRun)
{
printf("\nDryRun: Nothing will be actually done but complete process will be dumped to stdout.\n");
}
printf("\nMigrateUsers Start\n\n");
//Connect to local mySQL
TextConnectDb();
printf("Add or update tUsers from tUser\n");
time(&luClock);
GetConfiguration("cMbox",cMbox,0);
GetConfiguration("cImapMail",cImapMail,0);
sprintf(query,"SELECT cLogin,uUser FROM tUser WHERE uStatus=1 OR uStatus=8");//Active or Modified
mysql_query(&mysql,query);
if(mysql_errno(&mysql))
{
fprintf(stderr,"%s\n",mysql_error(&mysql));
exit(1);
}
res=mysql_store_result(&mysql);
while((field=mysql_fetch_row(res)))
{
unsigned uUser=0;
struct passwd *structPassInfo;
sscanf(field[1],"%u",&uUser);
printf("%s/%u add\n",field[0],uUser);
if(!(structPassInfo=getpwnam(field[0])))
{
printf("%s add",field[0]);
if(!uDryRun)
NewUser(uUser);
else
printf(" dry-run");
printf("\n");
}
else
{
if(uDryRun)
printf("%s dry-run for existing user\n",field[0]);
}
#ifdef MIGRATION_DIR
//install mailbox
char cMboxFmtd[256];
//this is very implementation dependent and should
//come from tConfiguration. Examples:
//char cMbox[256]="var/mail/%s";
//char cMbox[256]="~%s/.maildir";
sprintf(cMboxFmtd,cMbox,field[0]);
sprintf(query,"cp /migration/%s /%s",cMboxFmtd,cMboxFmtd);
if(!uDryRun)
{
if(!system(query))
{
sprintf(query,"chown %s /%s; chgrp mail /%s",
field[0],cMboxFmtd,cMboxFmtd);
if(!system(query))
{
sprintf(query,"chmod 600 /%s",cMboxFmtd);
system(query);
}
}
}
else
{
printf("DryRun: %s\n",query);
}
//this also is very implementation dependent and should
//come from tConfiguration
//copy over users INBOX.* or mail imap dirs if they exist
//this depends on the type of imapd used on the remote server
//char cImapMail[256]="mail";
//char cImapMail[256]="INBOX.*";
//This maybe needed someday: sprintf(cMboxFmtd,cImapMail,field[0]);
sprintf(query,"cp -rp /migration/home/%s/%s ~%s/",field[0],cImapMail,field[0]);
if(!uDryRun)
{
if(!system(query))
{
sprintf(query,"chown -R %s ~%s/%s",field[0],field[0],cImapMail);
system(query);
}
}
else
{
printf("DryRun: %s\n",query);
}
#endif
}
mysql_free_result(res);
printf("\nMigrateUsers Done\n");
mysql_close(&mysql);
exit(0);
}//void MigrateUsers(const char *cRemoteMySQLConnectString, unsigned uDryRun, unsigned uHelp)
//sedall patch1
//sedall patch2