📄 mycall.cpp
字号:
#include <time.h>
#include <stdlib.h>
#include "cgic.h"
#include "config.h"
#include "mydblib.h"
int Read_Info_Form()
{
cgiFormString("name",MySoft.Name,sizeof(MySoft.Name));
cgiFormString("ver",MySoft.Ver,sizeof(MySoft.Ver));
cgiFormString("zz",MySoft.ZZ,sizeof(MySoft.ZZ));
cgiFormString("zzlink",MySoft.ZZLink,sizeof(MySoft.ZZLink));
cgiFormString("type",MySoft.Type,sizeof(MySoft.Type));
cgiFormString("system",MySoft.System,sizeof(MySoft.System));
cgiFormInteger("size",&MySoft.Size,1);
cgiFormStringNoNewlines("S1",Soft_Remark,1000);
cgiFormString("down1",MySoft.Down1,sizeof(MySoft.Down1));
cgiFormString("down2",MySoft.Down2,sizeof(MySoft.Down2));
cgiFormString("down3",MySoft.Down3,sizeof(MySoft.Down3));
if(MySoft.Name[0]==0 || MySoft.Type[0]==0 ||
MySoft.System[0]==0 || strlen(Soft_Remark)==0)
{
return 1;
}
return 0;
}
void Print_Html(char **strl)
{
int i=0;
while (stricmp(strl[i],"end_html") !=0) {
fprintf(cgiOut,"%s\n",strl[i++]);
}
}
void Print_Error(char* str)
{
char *html1[]= {
"<html>",
"<head>",
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">",
"<title>消息文本</title>",
"</head>",
"<body bgcolor=\"#99CCCC\">",
"<font face=\"楷体_GB2312\" size=\"5\" color=\"#0000FF\">",
"<p> </p>",
"<p> </p>",
"<p> </p>",
"<p> </p>",
"end_html"
};
// "<p align=\"center\">Str</font></p>",
char *html2[]={
"<p align=\"center\"><a href='javascript:history.back()'>点击此处返回</a></p>",
"</body>",
"</html>",
"End_Html"
};
cgiHeaderContentType("text/html");
Print_Html(html1);
fprintf(cgiOut,"<p align=\"center\">%s</font></p>\n",str);
Print_Html(html2);
}
void Print_Error_NoLink(char* str)
{
char *html1[]={
"<html>",
"<head>",
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">",
"<meta name=\"GENERATOR\" content=\"Microsoft FrontPage 3.0\">",
"<meta name=\"Microsoft Border\" content=\"none\">",
"<base target=\"_self\">",
"<title>消息文本</title>",
"</head>",
"<body bgcolor=\"#99CCCC\">",
"<font face=\"楷体_GB2312\" size=\"5\" color=blue>",
"<p> </p>",
"<p> </p>",
"<p> </p>",
"<p> </p>",
"end_html"
};
// "<p align=\"center\">你的权限不够,无法进行此项操作!</font></p>",
char *html2[]={
"</body>",
"</html>",
"end_html"
};
cgiHeaderContentType("text/html");
Print_Html(html1);
fprintf(cgiOut,"<p align=\"center\">%s</font></p>",str);
Print_Html(html2);
}
void Date2Str(time_t long_time,char *SD)
{
struct tm *newtime;
time( &long_time ); /* Get time as long integer. */
newtime = localtime( &long_time );
sprintf(SD,"%d.%d.%d",newtime->tm_year+1900,newtime->tm_mon+1,newtime->tm_mday);
}
void Set_Cookie(char *key,char *var)
{
fprintf(cgiOut,"Set-Cookie:%s=%s; \n",key,var);
}
void Get_Cookie(char *var,char *key,unsigned int len)
{
int CookieL;
CookieL=strlen(cgiCookie);
if(CookieL==0) {
strcpy(var,"");
return;
}
fprintf(cgiOut,"cgiCookie=%s",cgiCookie);
char *Buffer;
Buffer=(char *)malloc(CookieL+10);
if(Buffer==NULL) return;
strcpy(Buffer,cgiCookie);
strcat(Buffer,"; ");
char key1[800],var1[800];
char ch,ok=0,kv=0;
int pos=0,i,strl;
strl=strlen(Buffer);
for(i=0;i<strl;i++)
{
ch=Buffer[i];
switch(ch)
{
case ';':
var1[pos]=0;
break;
case '=':
key1[pos]=0;
pos=0;
kv=1;
break;
case ' ': //注意这个case要在default上方。
if(Buffer[i-1]==';')
{
if(strcmp(key1,key)==0)
{
strcpy(var,var1);
ok=1;
}
pos=0;
kv=0;
break;
}
default:
if(kv==0)
{
key1[pos++]=ch;
}
else
{
var1[pos++]=ch;
}
}
if(ok==1) break;
}
if(ok==0) {
strcpy(var,"");
}
else
{
strncpy(var,var1,len);
}
free(Buffer);
}
//非法返回0,正确-1,错误1,操作成功设置用户的各值
char Check_Password(char *Name,char *Pass)
{
if(strlen(Name)==0 || strlen(Pass)==0)
{
Print_Error("用户名或密码不能为空!");
return 0;
}
int id=0;
char ok=1;
do {
id=db_next(UserFile,NULL,UserIndex,id,sizeof(User_Info),
&UserInfo.Name,0,NULL);
if(id==0) break;
if(strcmp(UserInfo.Name,Name)==0 &&
strcmp(UserInfo.Password,Pass)==0)
{
User_ID=id;
ok=-1;
break;
}
} while (id !=0);
return ok;
}
//得到Cookie的密码并对权限进行判断
//返回值等于1表示成功,其他值无需处理!
char Get_Check_Pass_Power(int p)
{
char Name[20];
char Pass[20];
char re;
Get_Cookie(Name,"UserName",20);
Get_Cookie(Pass,"Password",20);
if(strlen(Name)==0 || strlen(Pass)==0) {
Print_Error_NoLink("你还未登录!请先进行登录!");
return 0;
}
re=Check_Password(Name,Pass);
if(re==-1)
{
if(p>UserInfo.Power)
{
Print_Error("你的权限不够,无法进行此项操作!");
return 0;
}
}
else
{
Print_Error_NoLink("用户名或密码错误!请进行登录!");
return 0;
}
return 1;
}
void Shell_Pass(char *pa,char w)
{
char xx=33,i,ch;
int plen;
plen=strlen(pa);
for(i=0;i<plen;i++)
{
ch=pa[i];
if(w==1) ch-=28; //解密
pa[i]=ch^xx;
if(w==0) pa[i]+=28; //加密
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -