📄 modifypassword.cpp
字号:
#include <iostream.h>
#include "ModifyPassword.h"
#include <math.h>
#include<stdlib.h>
#ifndef WIN32
#include <sys/types.h>
#include <unistd.h>
#include "DomainManageCommonDefine.h"
#include "cmysql.h"#include "cdname.h"
#include "crrpcli.h"
#endif
const int PRESSCOUNT = 1000;
char* ModifyPassword::pDomainEx[] =
{
".com",
".cn",
".net",
".org",
};
ModifyPassword::ModifyPassword()
:prrpServer(NULL)
{
srand(time(NULL));
memset(szModifying_,0,sizeof(szModifying_));
}
ModifyPassword::~ModifyPassword()
{
Domainiterator it = Domainlist_.begin();
for(; it != Domainlist_.end(); it ++)
{
ModifyState* pState = * it;
delete pState;
}
Domainlist_.clear();
}
RESULT ModifyPassword::DoJob(void *pPara,FILE* pFile)
{
ModifyState * pState = reinterpret_cast<ModifyState*>(pPara);
RESULT& iRet = pState->Result;
#ifndef WIN32
CDomainName *pDomain = NULL;
pid_t pid = getpid();
#ifdef _DEBUG
char szBuf[128] = {0};
time_t t = time(NULL);
struct tm *dest = localtime(&t);
fprintf(pFile,"process id = %5u %04d-%02d-%02d %02d:%02d:%02d processing:%32s\n",pid,dest->tm_year + 1900,dest->tm_mon + 1,dest->tm_mday,dest->tm_hour,dest->tm_min,dest->tm_sec,pState->DomainName.c_str());
fflush(pFile);
#endif
CDomainName Domain((char*)pState->DomainName.c_str());
pDomain = &Domain;
char szPassword[32] = {0};
if(prrpServer->StatusDomain(pDomain) > 0)
{
bool hold_flag = false;
bool update_flag = false;
bool delete_flag = false;
int status_num = 0;
status_num = prrpServer->RRPGetPropertyValueSize(pDomain->prop,"status");
for ( int i = 0; i < status_num ; i ++ )
{
char *lock = prrpServer->GetPropertyValue(pDomain->prop,"status",i);
if(strstr(lock,"pendingDelete")!=NULL)
{
delete_flag = true;
break;
}
/* if ( strstr(lock,"clientHold")!=NULL ) //clientUpdateProhibited
{
hold_flag = true;
}
//*/
if ( strstr(lock,"clientUpdateProhibited")!=NULL )
{
update_flag = true;
}
}
if(delete_flag)
{
iRet = pendingdelete;
char szBuf[64] = {0};
fprintf(pFile,"pending delete\n");
fflush(pFile);
pState->Processtime = time(NULL);
return iRet;
}
if(update_flag)
{
pDomain->Add("Status","clientUpdateProhibited");
pDomain->Add("Cmd","");
prrpServer->ModifyDomain(pDomain);
}
/*
if ( hold_flag )
{
pDomain->Add("Status","clientHold");
pDomain->Add("Cmd","");
prrpServer->ModifyDomain(pDomain);
}
//*/
if(update_flag)//hold_flag ||
{
pDomain->Add("Status","");
pDomain->Add("Cmd","");
}
char szPassword[32] = {0};
NewPassword(szPassword);
pDomain->Add("Password",szPassword);
if(prrpServer->ModifyDomain(pDomain) > 0)
{
char szBuf[128] = {0};
time_t t = time(NULL);
struct tm *dest = localtime(&t);
fprintf(pFile,"process id = %5u %04d-%02d-%02d %02d:%02d:%02d processing:%32s modify success\n",pid,dest->tm_year + 1900,dest->tm_mon + 1,dest->tm_mday,dest->tm_hour,dest->tm_min,dest->tm_sec,pState->DomainName.c_str());
fflush(pFile);
iRet = Success;
pState->Processtime = time(NULL);
}
else
{
iRet = MoifyFaild;
char szBuf[128] = {0};
time_t t = time(NULL);
struct tm *dest = localtime(&t);
fprintf(pFile,"process id = %5u %04d-%02d-%02d %02d:%02d:%02d processing:%32s modify faild\n",pid,dest->tm_year + 1900,dest->tm_mon + 1,dest->tm_mday,dest->tm_hour,dest->tm_min,dest->tm_sec,pState->DomainName.c_str());
fflush(pFile);
pState->Processtime = time(NULL);
}
/* if(hold_flag)
{
pDomain->Add("Status","");
pDomain->Add("Cmd","clientHold");
prrpServer->ModifyDomain(pDomain);
}
//*/
if(update_flag)
{
pDomain->Add("Status","");
pDomain->Add("Cmd","clientUpdateProhibited");
prrpServer->ModifyDomain(pDomain);
}
if(update_flag)//hold_flag ||
{
pDomain->Add("Status","");
pDomain->Add("Cmd","");
}
}
else
{
pState->Processtime = time(NULL);
switch( pDomain->retCode)
{
case 200:
{
}
break;
case 2201:
case 2001:
{
#ifdef _DEBUG
char szBuf[128] = {0};
time_t t = time(NULL);
struct tm *dest = localtime(&t);
fprintf(pFile,"process id = %5u %04d-%02d-%02d %02d:%02d:%02d processing:%32s Organise error\n",pid,dest->tm_year + 1900,dest->tm_mon + 1,dest->tm_mday,dest->tm_hour,dest->tm_min,dest->tm_sec,pState->DomainName.c_str());
fflush(pFile);
#endif
iRet = OrganiseErr;
}
break;
case 2303:
{
#ifdef _DEBUG
char szBuf[128] = {0};
time_t t = time(NULL);
struct tm *dest = localtime(&t);
fprintf(pFile,"process id = %5u %04d-%02d-%02d %02d:%02d:%02d processing:%32s unexist\n",pid,dest->tm_year + 1900,dest->tm_mon + 1,dest->tm_mday,dest->tm_hour,dest->tm_min,dest->tm_sec,pState->DomainName.c_str());
fflush(pFile);
#endif
iRet = UnExist;
}
break;
case 421:
case 0:
{
#ifdef _DEBUG
char szBuf[128] = {0};
time_t t = time(NULL);
struct tm *dest = localtime(&t);
fprintf(pFile,"process id = %5u %04d-%02d-%02d %02d:%02d:%02d processing:%32s connect error\n",pid,dest->tm_year + 1900,dest->tm_mon + 1,dest->tm_mday,dest->tm_hour,dest->tm_min,dest->tm_sec,pState->DomainName.c_str());
fflush(pFile);
#endif
iRet = ConnectErr;
}
break;
case 2005:
{
iRet = Paramerror;
}
break;
default:
{
}
break;
}
#ifdef _DEBUG
char szBuf[128] = {0};
time_t t = time(NULL);
struct tm *dest = localtime(&t);
fprintf(pFile,"process id = %5u %04d-%02d-%02d %02d:%02d:%02d processing:%32s process result %d\n",pid,dest->tm_year + 1900,dest->tm_mon + 1,dest->tm_mday,dest->tm_hour,dest->tm_min,dest->tm_sec,pState->DomainName.c_str(),pDomain->retCode);
fflush(pFile);
#endif
}
//delete pDomain;
pDomain = NULL;
#endif
return iRet;
}
char* ModifyPassword::NewPassword(char* pPwd)
{
char *p = pPwd;
const int DEFLEN = 8;
int i;
for(i = 0; i < DEFLEN; i += 2)
{
*(p + i) = 'a' + abs(rand()) % 26;
}
for(i = 1; i < DEFLEN; i += 2)
{
*(p + i) = '0' + abs(rand()) % 10;
}
return pPwd;
}
char* ModifyPassword::TimeToA(char* pszTime,time_t t)
{
struct tm *pcurtime;
pcurtime = localtime(&t);
sprintf(pszTime,"%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d",
pcurtime->tm_year+1900,pcurtime->tm_mon+1,pcurtime->tm_mday,
pcurtime->tm_hour,pcurtime->tm_min,pcurtime->tm_sec);
return pszTime;
}
int ModifyPassword::ReadDBProcess(int nReadCount)
{
#ifndef WIN32
CDatabase db("202.10.67.46","temp");
int iResult = db.Open("temp","temp0987E");
if( iResult < 1 )
{
return false;
}
CRecordset Set(&db);
char szSQL[1024] = {0};
sprintf(szSQL, "select domain,flag from mpDomain where mpDomain.domain like '%c.%s' ORDER BY domain LIMIT 0, %d;",'%', szDomainType,nReadCount );
int iRet ;
iRet = Set.Open(szSQL);
if (iRet < 1)
{
return false;
}
int nCount = Set.GetRecordCount();
int i;
char *pDomainName;
char *pFlag;
for(i = 0;i < nCount ; i++)
{
ModifyState* pState = new ModifyState;
pDomainName = Set("domain");
pFlag = Set("flag");
if(pDomainName != NULL && pFlag != NULL)
{
pState->DomainName = pDomainName;
pState->falg = pFlag;
pState->Result = Unknown;
Domainlist_.push_back(pState);
}
Set.MoveNext();
}
Set.Close();
memset(szSQL,0,sizeof(szSQL));
sprintf(szSQL, "delete from mpDomain where domain like '%c.%s' ORDER BY domain LIMIT %d;",'%', szDomainType,nReadCount );
db.ExecSql(szSQL);
return true;
#else
return false;
#endif
}
void ModifyPassword::ModifyProcess()
{
#ifndef WIN32
prrpServer = new CRrpCli;
#endif
Domainiterator it = Domainlist_.begin();
if(prrpServer == NULL)
{
return;
}
FILE * pFile = fopen("./log/processing.log","a");
if(pFile != NULL)
{
for(;it != Domainlist_.end() ; it ++)
{
ModifyState* pState = * it;
DoJob(pState,pFile);
}
fclose(pFile);
pFile = NULL;
}
#ifndef WIN32
if(prrpServer != NULL)
{
delete prrpServer;
prrpServer = NULL;
}
#else
#endif
}
void ModifyPassword::UpdateDate()
{
#ifndef WIN32
CDatabase db("202.10.67.46","temp");
int iResult = db.Open("temp","temp0987E");
if( iResult < 1 )
{
return ;
}
#endif
char szSQL[1024] = {0};
Domainiterator it = Domainlist_.begin();
for(; it != Domainlist_.end(); it ++ )
{
ModifyState* pState = * it;
switch(pState->Result)
{
case Success:
{
sprintf(szSQL,"insert into modifyed (domain,flag) VALUES ('%s','success')",(char*)pState->DomainName.c_str());
}
break;
case UnExist:
case OrganiseErr:
{
sprintf(szSQL,"insert into modifyed (domain,flag) VALUES ('%s','UnExist')",(char*)pState->DomainName.c_str());
}
break;
case pendingdelete:
case Paramerror:
{
sprintf(szSQL,"insert into modifyed (domain,flag) VALUES ('%s','deleted')",(char*)pState->DomainName.c_str());
}
break;
case MoifyFaild:
case logMoify:
case ConnectErr:
case Abort:
{
if(strcmp(pState->falg.c_str(),"uncheck") == 0)
{
sprintf(szSQL,"insert into mpDomain (domain,flag) VALUES ('%s','Error1st')",(char*)pState->DomainName.c_str());
}
else
if(strcmp(pState->falg.c_str(),"Error1st") == 0)
{
sprintf(szSQL,"insert into mpDomain (domain,flag) VALUES ('%s','Error2nd')",(char*)pState->DomainName.c_str());
}
else
if(strcmp(pState->falg.c_str(),"Error2nd") == 0 || strcmp(pState->falg.c_str(),"delete") == 0)
{
sprintf(szSQL,"insert into modifyed (domain,flag) VALUES ('%s','UnExist')",(char*)pState->DomainName.c_str());
}
}
break;
default:
{
sprintf(szSQL,"insert into mpDomain (domain,flag) VALUES ('%s','uncheck')",(char*)pState->DomainName.c_str());
}
break;
}
#ifndef WIN32
db.ExecSql(szSQL);
#endif
}
}
bool ModifyPassword:: Init(void* pVoid)
{
char*pszDomainType = reinterpret_cast<char*>(pVoid);
strcpy(szDomainType,pszDomainType);
return true;
}
int ModifyPassword::input(int nCount)
{
return ReadDBProcess(nCount);
}
bool ModifyPassword::output()
{
ModifyProcess();
UpdateDate();
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -