⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webctl.cpp

📁 web应用控件,主要是实现的web开发中文件的加密和解密.该控件b/s架构的应用系统 中有比较好的用途
💻 CPP
📖 第 1 页 / 共 2 页
字号:
					iAds->Release();
					iContainer->Release();
					iContainer->Release();
					return false;
				}
			}
			else
			{
				iAds->Release();
				iContainer->Release();
				return false;
			}
		}
		else
		{
			iAds->Release();
			return false;
		}
		iContainer->Release();
	}
	return false;
}
//////////////删除考生目录及及目录下所有文件与子目录/////////////
BOOL CWebCtrl::DeleteKSDirectory(LPCTSTR ksDir) 
{
	// TODO: Add your dispatch handler code here
	CFileFind tempFind;
	char tempFileFind[200];
	sprintf(tempFileFind,"%s\\*.*",ksDir);
	BOOL IsFinded=(BOOL)tempFind.FindFile(tempFileFind);
	while(IsFinded)
		{
			IsFinded=(BOOL)tempFind.FindNextFile();
			if(!tempFind.IsDots())
				{
					char foundFileName[200];
					strcpy(foundFileName,tempFind.GetFileName().GetBuffer(200));
					if(tempFind.IsDirectory())
						{
							char tempDir[200];
							sprintf(tempDir,"%s\\%s",ksDir,foundFileName);
							DeleteKSDirectory(tempDir);
						}
						else
						{
							char tempFileName[200];
							sprintf(tempFileName,"%s\\%s",ksDir,foundFileName);
							SetFileAttributes(tempFileName,FILE_ATTRIBUTE_ARCHIVE);
							DeleteFile(tempFileName);
						}
				}
		}
	tempFind.Close();
	if(!RemoveDirectory(ksDir))
	{
		return false;
 	}
	return TRUE;
}



////////////////Ftp上传文件////////////////////

BOOL CWebCtrl::UpFile(LPCTSTR ipAddress, LPCTSTR localFilePath, LPCTSTR remoteFilePath) 
{

//TODO: Add your dispatch handler code here
 CString strResult;
 CInternetSession *pInetSession;
 CFtpConnection *pFtpConnection=NULL;
 CString templocal=(CString)localFilePath;
 CString logPath=templocal.Mid(0,templocal.ReverseFind('/'));
 pInetSession=new CInternetSession(AfxGetAppName(),1, PRE_CONFIG_INTERNET_ACCESS); 
		 try 
		{ 
			pFtpConnection=pInetSession->GetFtpConnection(ipAddress); 
		} 
		catch(CInternetException *pEx)
		{ 
			 pEx->Delete(); 
			 pFtpConnection=NULL;
			 pInetSession->Close();
			 strResult="连接ftp://"+(CString)ipAddress+"失败!";
			 WriteLog(strResult,logPath);
			return false;
		}

		CString filename=templocal.Mid(templocal.ReverseFind('/')+1);
		pFtpConnection->Remove(remoteFilePath);
        ecfile(localFilePath);
		if(!pFtpConnection->PutFile(localFilePath,remoteFilePath))
		{
			 pInetSession->Close();
			 pFtpConnection->Close();
 			 strResult="上传"+filename+"文件失败!";
			 WriteLog(strResult,logPath);
			 dcfile(localFilePath);
			 return false;
 		}
     pInetSession->Close();
     pFtpConnection->Close();
 	 strResult="上传"+filename+"文件成功!";
	 WriteLog(strResult,logPath);
	 dcfile(localFilePath);
 	 return TRUE;
}
/////////////////////////下载文件////////////////////
BOOL CWebCtrl::DownFile(LPCTSTR ipAddress, LPCTSTR remoteFilePath, LPCTSTR localFilePath) 
{
	// TODO: Add your dispatch handler code here
CString strResult;
CInternetSession *pInetSession;
CFtpConnection *pFtpConnection=NULL; 
CString templocal=(CString)localFilePath;
CString logPath=templocal.Mid(0,templocal.ReverseFind('/'));
pInetSession=new CInternetSession(AfxGetAppName(),1, PRE_CONFIG_INTERNET_ACCESS); 
		try 
		{ 
			pFtpConnection=pInetSession->GetFtpConnection(ipAddress); 
		} 
		catch(CInternetException *pEx) 
		{ 
			pEx->Delete(); 
			pFtpConnection=NULL;
			pInetSession->Close();
			strResult="连接ftp://"+(CString)ipAddress+"失败!";
			WriteLog(strResult,logPath);
			return false;
		}

CString filename=templocal.Mid(templocal.ReverseFind('/')+1);		  				 
if(!pFtpConnection->GetFile(remoteFilePath,localFilePath,false,FILE_ATTRIBUTE_ARCHIVE))
		{
			pInetSession->Close();
			pFtpConnection->Close();
			strResult="下载"+filename+"文件失败!";
			WriteLog(strResult,logPath);
			return false;
		}
pInetSession->Close();
pFtpConnection->Close();
strResult="下载"+filename+"文件成功!";
WriteLog(strResult,logPath);
dcfile(localFilePath);
return TRUE;
}

/////////////////写日志///////////////

void CWebCtrl::WriteLog(CString strResult, CString logPath)
{
 	CFile file(logPath+"/log.log",CFile::modeCreate | CFile::modeNoTruncate | CFile::modeWrite);
 	file.SeekToEnd();
 	file.Write(strResult+"\r\n",strlen(strResult+"\r\n"));
	file.Close();
}

void CWebCtrl::OpenFrontPage(LPCTSTR filePath) 
{
	// TODO: Add your dispatch handler code here
STARTUPINFO si;
 PROCESS_INFORMATION pi;
 ZeroMemory( &si, sizeof(si) ); 
 si.cb=sizeof(si);
 si.wShowWindow=SW_SHOW;
 si.dwFlags=STARTF_USESHOWWINDOW;
if(GetFrontPagePath()=="")
{
MessageBox("请安装FrontPage 2003!");
return;
}
CString fullpath=GetFrontPagePath()+"\\FRONTPG.EXE "+(CString)filePath;
 
LPTSTR cmd =(LPTSTR)(LPCTSTR)fullpath;
     if (!CreateProcess(
					 NULL,
					 cmd,
 					 NULL,
					 NULL,
					 false,
 					 NULL,
					 NULL,
					 NULL,
					 &si,
					 &pi))
	  {
 		  
 		 MessageBox("打开FrontPage 2003失败!");  
	 }
}

CString CWebCtrl::GetFrontPagePath()
{
	HKEY m_hKey=NULL;
	CString	Value="";
	if (ERROR_SUCCESS==::RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Office\\11.0\\FrontPage\\InstallRoot",NULL,KEY_ALL_ACCESS,&m_hKey))
	{
	DWORD dwSize=255,dwType=REG_SZ;
	char String[256];
	
	if (ERROR_SUCCESS==::RegQueryValueEx(m_hKey,"Path",0,&dwType,(BYTE *)String,&dwSize))
	{	
    Value=String;
	
	}
	return Value;
}
	return Value;

}

BOOL CWebCtrl::dcfile(LPCTSTR fpath)
{
	char *data;
	CFile *file;
	DWORD flen;
	char love[5];

	file = new CFile;
	if( !file->Open(fpath, CFile::shareDenyNone|CFile::modeReadWrite))
	{
		return FALSE;
	}

	flen = file->GetLength();
	data = new char[(int)flen];

	//检验密码是不是正确
	file->Seek(-5, CFile::end);
	file->Read(&love, 5);

	m_password = epass();

	for(int i=0; i<5; i++)
	{
		love[i] ^= m_password;
	}

	if(strcmp(love, "love")!=0)
	{
		return FALSE;
	}

	//解密
	file->SeekToBegin();
	file->Read(data, flen);

	for(int j=0; j<(int)flen; j++)
	{
		data[j] ^= m_password;
		data[j] ^= (flen-5);
	}
	file->SeekToBegin();
	file->Write(data, flen);
	file->SetLength(flen-5);
	file->Close();

	delete[] data;
	delete file;
	return TRUE;

}

BOOL CWebCtrl::ecfile(LPCTSTR fpath)
{
	char *data;
	CFile *file;
	DWORD flen;

	m_password = epass();

	file = new CFile;
	if ( !file->Open(fpath, CFile::shareDenyNone|CFile::modeReadWrite))
	{
		return FALSE;
	}

	flen = file->GetLength();
	data = new char[(int)flen];

	file->SeekToBegin();
	file->Read(data, flen);

	for(int i=0; i<(int)flen; i++)
	{
		data[i] ^= m_password;
		data[i] ^= flen;
	}

	file->SeekToBegin();
	file->Write(data, flen);
	delete[] data;

	//添加密码验证信息
	char cpass[5] = "love";
	for(int j=0; j<5; j++)
	{
		cpass[j] ^= m_password;
	}
	file->SeekToEnd();
	file->Write(&cpass, 5);
	file->Close();
	delete file;

	return TRUE;
}
__int64 CWebCtrl::epass()
{
	DWORD plen;
	char *ppass;
	
	__int64 mc= 8757735233305;
	m_pass="webks2006";
	ppass = m_pass.GetBuffer(0);

	plen = strlen(ppass);

	for(int i=0; i<(int)plen; i++)
	{
		mc ^= ppass[i]|128;
	}
	return mc;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -