📄 address.cpp
字号:
#include "webemail.h"#include "delete.h"void address() //displays address book{ FILE *address; FILE *gaddress; char filename[400]; char gfilename[400]; passwd *info; char name[100]; char email[100]; char phone[100]; char fax[100]; char address1[100]; char address2[100]; char notes[100]; char ginfo[400]; char curr; int hasdata=0; int ghasdata = 0; int count = 0; int gcount = 0; info=getpwnam(globaluser); snprintf(filename, 400, "%s/.webmail/book", info->pw_dir); snprintf(gfilename, 400, "%s/.webmail/gbook", info->pw_dir); address = fopen(filename, "r"); if (address == NULL) { cout << "Content-type: text/html" << endl; cout << "Pragma: No-Cache" << endl << endl; cout << "<font size=\"+3\">Error opening file!</font><br>"; cout << "Check the suid settings and user directory.<br>"; cout << "To create user directory and other files use <a href=\"" << EMAILPATH << "?wesetup\" TARGET=_top>"; cout << "wesetup</a>."; return; } if (bothlock(address, 'r')!=0) { fclose(address); error("address():Error locking book for read"); return; } gaddress = fopen(gfilename, "r"); if (gaddress == NULL) { cout << "Content-type: text/html" << endl; cout << "Pragma: No-Cache" << endl << endl; cout << "<font size=\"+3\">Error opening file!</font><br>"; cout << "Check the suid settings and user directory.<br>"; cout << "To create user directory and other files use <a href=\"" << EMAILPATH << "?wesetup\" TARGET=_top>"; cout << "wesetup</a>."; return; } if (bothlock(gaddress, 'r')!=0) { fclose(address); fclose(gaddress); error("address():Error locking gbook for read"); return; } cout << "Content-type: text/HTML" << endl; cout << "Pragma: No-Cache" << endl << endl; cout << "<html>" << endl; cout << "<head>" << endl; cout << "<title>Web E-Mail</title>" << endl; cout << "<META HTTP-EQUIV=\"expires\" content=\"0\">" << endl; cout << "</head>" << endl; cout << "<body text=\"#000000\" bgcolor=\"#FFFFFF\" "; cout << "link=\"#0000EF\" vlink=\"#0000EF\" alink=\"#FF0000\" background=/email/bg1.gif>" << endl; header(WEM_Address_Book); //prints index for (char inc = 'A'; inc <= 'Z'; inc++) { cout << "<a href=\"" << EMAILPATH << "?book#" << inc << "\">" << inc << "</a> "; } cout << "<br><a href=\"" << EMAILPATH << "?addtobook\">" << WEM_Add_Entree << "</a>\n"; cout << " <a href=\"" << EMAILPATH << "?gaddtobook\">" << WEM_Add_Group << "</a><p>\n"; //prints colum for (char inc = 'A'; inc <= 'Z'; inc++) { cout << "<a NAME=\"" << inc << "\"></a><font size=+2>" << inc << "</font><br>"; if (address != NULL) { while(1) //group addresses { if (ghasdata == 0) { while (ghasdata == 0) { if (fgets(ginfo,399,gaddress)==NULL) break; if (ginfo[0] == '-') ghasdata = 1; } if (ghasdata == 0) break; } if (toupper(ginfo[1]) > inc) break; if (toupper(ginfo[1]) < inc) break; if (ghasdata == 1) { ghasdata = 0; gcount++; cout << "<table CELLSPACING=0 CELLPADDING=0 WIDTH=\"100%\" NOSAVE>" << endl; cout << "<tr NOSAVE>" << endl; cout << "<td WIDTH=\"20%\" BGCOLOR=\"#FF6666\" NOSAVE>" << endl; cout << "<a href=\"" << EMAILPATH << "?gaddrsend=" << gcount << "\">\n"; removereturn(ginfo+1); escapeprint(ginfo+1); cout << "</a></td>" << endl; cout << "<td BGCOLOR=\"#FFCCCC\" NOSAVE>" << WEM_Group_List << "</td>" << endl; cout << "<td WIDTH=\"10%\" BGCOLOR=\"#FF6666\" NOSAVE>" << endl; cout << "<center><a href=\"" << EMAILPATH << "?gaddredit=" << gcount << "\">" << WEM_Edit << "</a></center>\n"; cout << "</td><td WIDTH=\"10%\" BGCOLOR=\"#FF6666\" NOSAVE>" << endl; cout << "<center><a href=\"" << EMAILPATH << "?gaddrdelete=" << gcount << "\">" << WEM_Delete << "</a></center>\n"; cout << "</td></tr></table>" << endl; } } while(1) //single addresses { if (hasdata == 0) { if (fgets(name, 99, address)==NULL) break; if (fgets(email, 99, address)==NULL) break; if (fgets(phone, 99, address)==NULL) break; if (fgets(fax, 99, address)==NULL) break; if (fgets(address1, 99, address)==NULL) break; if (fgets(address2, 99, address)==NULL) break; if (fgets(notes, 99, address)==NULL) break; hasdata = 1; curr = toupper(name[0]); } if (toupper(name[0]) > inc) break; if (toupper(name[0]) < inc) break; if (hasdata == 1) { hasdata = 0; count++; cout << "<table CELLSPACING=0 CELLPADDING=0 WIDTH=\"100%\" BGCOLOR=\"#FF6666\" NOSAVE >"; cout << "<tr NOSAVE>" << endl; cout << "<td WIDTH=\"50%\" NOSAVE>"; if (name[0] == '\n') { strcpy(name, " "); cout << name; } else { removereturn(name); escapeprint(name); } cout << "</td>"; cout << "<td><a href=\"" << EMAILPATH << "?addrsend=" << count << "\">"; if (email[0] == '\n') { strcpy(email, " "); cout << email; } else { removereturn(email); escapeprint(email); } cout << "</a></td>"; cout << "</tr></table>" << endl; cout << "<table CELLSPACING=0 CELLPADDING=0 WIDTH=\"100%\" BGCOLOR=\"#FFCCCC\" NOSAVE >"; cout << "<tr NOSAVE>" << endl; cout << "<td WIDTH=\"10%\" BGCOLOR=\"#FFCC33\" NOSAVE>" << endl; cout << "<div align=right>" << WEM_Phone << ":</div>" << endl; cout << "</td>" << endl; cout << "<td WIDTH=\"40%\" BGCOLOR=\"#FFCC99\" NOSAVE>"; if (phone[0] == '\n') { strcpy(phone, " "); cout << phone; } else { removereturn(phone); escapeprint(phone); } cout << "</td>" << endl; cout << "<td WIDTH=\"10%\" BGCOLOR=\"#66FFFF\" NOSAVE>" << endl; cout << "<div align=right>" << WEM_Address << ":</div>"; cout << "</td>" << endl; cout << "<td WIDTH=\"40%\" BGCOLOR=\"#CCFFFF\" NOSAVE>"; if (address1[0] == '\n') { strcpy(address1, " "); cout << address1; } else { removereturn(address1); escapeprint(address1); } cout << "</td>" << endl; cout << "</tr>" << endl; cout << "<tr NOSAVE>" << endl; cout << "<td WIDTH=\"10%\" BGCOLOR=\"#FFCC33\" NOSAVE>" << endl; cout << "<div align=right>" << WEM_Fax << ":</div>" << endl; cout << "</td>" << endl; cout << "<td WIDTH=\"40%\" BGCOLOR=\"#FFCC99\" NOSAVE>"; if (fax[0] == '\n') { strcpy(fax, " "); cout << fax; } else { removereturn(fax); escapeprint(fax); } cout << "</td>" << endl; cout << "<td WIDTH=\"10%\" BGCOLOR=\"#66FFFF\" NOSAVE> </td>" << endl; cout << "<td WIDTH=\"40%\" BGCOLOR=\"#CCFFFF\" NOSAVE>"; if (address2[0] == '\n') { strcpy(address2, " "); cout << address2; } else { removereturn(address2); escapeprint(address2); } cout << "</td>" << endl; cout << "</tr></table>" << endl; cout << "<table CELLSPACING=0 CELLPADDING=0 WIDTH=\"100%\" NOSAVE >" << endl; cout << "<tr NOSAVE>" << endl; cout << "<td WIDTH=\"7%\" BGCOLOR=\"#FF9797\" NOSAVE>" << endl; cout << "<div align=right>" << WEM_Notes << ":</div>"; cout << "</td>" << endl; cout << "<td BGCOLOR=\"#FFCCCC\" NOSAVE>"; if (notes[0] == '\n') { strcpy(notes, " "); cout << notes; } else { removereturn(notes); escapeprint(notes); } cout << "</td>" << endl; cout << "<td WIDTH=\"10%\" BGCOLOR=\"#FF9797\" NOSAVE>" << endl; cout << "<center><a href=\"" << EMAILPATH << "?addredit=" << count << "\">\n"; cout << WEM_Edit <<"</a></center>" << endl; cout << "</td>" << endl; cout << "<td WIDTH=\"10%\" BGCOLOR=\"#FF9797\" NOSAVE>" << endl; cout << "<center><a href=\"" << EMAILPATH << "?addrdelete=" << count << "\">\n"; cout << WEM_Delete << "</a></center>" << endl; cout << "</td></tr></table>" << endl; } } } } cout << "<br>" << endl; //prints index for (char inc = 'A'; inc <= 'Z'; inc++) { cout << "<a href=\"" << EMAILPATH << "?book#" << inc << "\">" << inc << "</a> "; } cout << "<br><a href=\"" << EMAILPATH << "?addtobook\">" << WEM_Add_Entree << "</a>\n"; cout << " <a href=\"" << EMAILPATH << "?gaddtobook\">" << WEM_Add_Group << "</a><p>\n"; cout << "<br>" << endl; tail(); cout << "</body>" << endl; cout << "</html>" << endl; bothunlock(gaddress); fclose(gaddress); bothunlock(address); fclose(address); return;}void addaddress(char *fill, int number) //fill is email to fill space{ FILE *book; char bookname[400]; passwd *info; char name[400]; char email[400]; char phone[400]; char fax[400]; char add1[400]; char add2[400]; char notes[400]; char buf[500]; if (number > 0) //edit one in address book { info=getpwnam(globaluser); snprintf(bookname, 400, "%s/.webmail/book", info->pw_dir); book = fopen(bookname, "r"); if (book == NULL) { error("addaddress():can't open book for read"); return; } if (bothlock(book, 'r')!=0) { fclose(book); error("addaddress():Error locking book for read"); return; } for (int i = 0; i<(number-1)*7; i++) { if(fgets(buf, 499, book)==NULL) { error("addaddress():can't read from book"); return; } } fgets(name, 399, book); fgets(email, 399, book); fgets(phone, 399, book); fgets(fax, 399, book); fgets(add1, 399, book); fgets(add2, 399, book); fgets(notes, 399, book); } cout << "Content-type: text/HTML" << endl; cout << "Pragma: No-Cache" << endl << endl; cout << "<html>" << endl; cout << "<head>" << endl; cout << "<title>Web E-Mail</title>" << endl; cout << "<META HTTP-EQUIV=\"expires\" content=\"0\">" << endl; cout << "</head>" << endl; cout << "<body text=\"#000000\" bgcolor=\"#FFFFFF\" "; cout << "link=\"#0000EF\" vlink=\"#0000EF\" alink=\"#FF0000\" background=/email/bg1.gif>"; cout << "<b></b> "; if (number > 0) header(WEM_Edit_Address_Entree); else header(WEM_Add_Address_Entree); if (number > 0) { cout << "<form method=\"post\" action=\"" << EMAILPATH << "?addreproc=" << number << "\">"; } else { cout << "<form method=\"post\" action=\"" << EMAILPATH << "?addproc\">"; } cout << "<table CELLSPACING=0 CELLPADDING=0 WIDTH=\"100%\" NOSAVE>" << endl; cout << "<tr NOSAVE>" << endl; cout << "<td NOSAVE>" << endl; cout << "<div align=right>" << WEM_Name << ":</div>" << endl; cout << "</td>" << endl; //name: if (number > 0) { removereturn(name); cout << "<td><input type=text name=name size=25 value=\"" << name << "\"></td>"; } else cout << "<td><input type=text name=name size=25></td>"; cout << "<td>" << endl; cout << "<div align=right>" << WEM_E_Mail << ":</div>" << endl; cout << "</td>" << endl; //email: if (number > 0) { removereturn(email); cout << "<td><input type=text name=email size=25 value=\"" << email << "\"></td>"; } else if (number == -2) { quotestospace(fill); commatospace(fill); cout << "<td><input type=text name=email size=25 value=\"" << fill << "\"></td>"; } else cout << "<td><input type=text name=email size=25></td>"; cout << "</tr>" << endl; cout << "<tr NOSAVE>" << endl; cout << "<td>" << endl; cout << "<div align=right>" << WEM_Phone << ": </div>" << endl; cout << "</td>" << endl; //phone: if (number > 0) { removereturn(phone); cout << "<td><input type=text name=phone size=25 value=\"" << phone << "\"></td>"; } else cout << "<td><input type=text name=phone size=25></td>"; cout << "<td>" << endl; cout << "<div align=right>" << WEM_Address_line << " 1:</div>" << endl; cout << "</td>" << endl; //addressline1 if (number > 0) { removereturn(add1); cout << "<td NOSAVE><input type=text name=addressline1 size=25 value=\"" << add1 << "\"></td>"; } else cout << "<td NOSAVE><input type=text name=addressline1 size=25></td>"; cout << "</tr>" << endl; cout << "<tr>" << endl; cout << "<td>" << endl; cout << "<div align=right>" << WEM_Fax << ": </div>" << endl; cout << "</td>" << endl; //fax: if (number > 0) { removereturn(fax); cout << "<td><input type=text name=fax size=25 value=\"" << fax << "\"></td>"; } else cout << "<td><input type=text name=fax size=25></td>"; cout << "<td>" << endl; cout << "<div align=right>" << WEM_Address_line << " 2:</div>" << endl; cout << "</td>" << endl; //address line 2 if (number > 0) { removereturn(add2); cout << "<td><input type=text name=addressline2 size=25 value=\"" << add2 << "\"></td>"; } else cout << "<td><input type=text name=addressline2 size=25></td>"; cout << "</tr>" << endl; cout << "<tr NOSAVE>" << endl; cout << "<td>" << endl; cout << "<div align=right>" << WEM_Notes << ":</div>" << endl; cout << "</td>" << endl; //notes if (number > 0) { removereturn(notes); cout << "<td COLSPAN=\"3\" NOSAVE><input type=text name=notes size=50 value=\"" << notes << "\"></td>"; } else cout << "<td COLSPAN=\"3\" NOSAVE><input type=text name=notes size=50></td>"; cout << "<td></td>" << endl; cout << "<td></td>" << endl; cout << "</tr>" << endl; cout << "</table>" << endl; cout << "<input type=Submit value=\"" << WEM_Add_Entree << "\"><input type=reset value=" << WEM_Reset << "></form>"; cout << "<br>" << endl; tail(); cout << "</body>" << endl; cout << "</html>" << endl; if (number >0) { bothunlock(book); fclose(book); } return;}void addaddressproc() //process data for addressbook{ char data[4000]; char name[100]; char *pname; char fax[100]; char *pfax; char email[100]; char *pemail; char phone[100]; char *pphone; char address1[100]; char *paddress1; char address2[100]; char *paddress2; char notes[200]; char *pnotes; passwd *info; FILE *book; FILE *tmp; char filenametmp[200]; char filename[200]; int inserted = 0; if (fgets(data, 3999, stdin)==NULL) { error("addaddressproc():Post Error"); return; } pname = finddata(data, "name=", name); htmldecode(name); pemail = finddata(data, "email=", email); htmldecode(email); pfax = finddata(data, "fax=", fax); htmldecode(fax); pphone = finddata(data, "phone=", phone); htmldecode(phone); paddress1 = finddata(data, "addressline1=", address1); htmldecode(address1); paddress2 = finddata(data, "addressline2=", address2); htmldecode(address2); pnotes = finddata(data, "notes=", notes); htmldecode(notes); if (isalpha(name[0])==0) { address(); return; } info=getpwnam(globaluser); snprintf(filename, 200, "%s/.webmail/book", info->pw_dir); snprintf(filenametmp, 200, "%s/.webmail/tmp", info->pw_dir); book = fopen(filename, "r"); if (book == NULL) { error("addaddressproc(): error opening addressbook"); return; } if (bothlock(book, 'r')!=0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -