// Copyright © 2010 sss // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "commonheaders.h" extern HINSTANCE hInst; static BOOL CALLBACK DlgProcReplacerOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); static BOOL CheckStateLoadDB(HWND hwndDlg, int idCtrl, const char* szSetting, BYTE bDef) { BOOL state = DBGetContactSettingByte(NULL, szReplacerModuleName, szSetting, bDef); CheckDlgButton(hwndDlg, idCtrl, state); return state; } static BOOL CheckStateStoreDB(HWND hwndDlg, int idCtrl, const char* szSetting) { BOOL state = IsDlgButtonChecked(hwndDlg, idCtrl); DBWriteContactSettingByte(NULL, szReplacerModuleName, szSetting, (BYTE)state); return state; } int ReplacerOptInit(WPARAM wParam,LPARAM lParam) { OPTIONSDIALOGPAGE odp = { 0 }; odp.cbSize = sizeof(odp); odp.hInstance = hInst; odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_REPLACER); odp.pszTitle = szReplacerModuleName; odp.pszGroup = "Message Sessions"; odp.pszTab = "Main"; odp.flags=ODPF_BOLDGROUPS; odp.pfnDlgProc = DlgProcReplacerOpts; CallService(MS_OPT_ADDPAGE,wParam,(LPARAM)&odp); return 0; } map user_data; int item_num = 0; HWND hwndList_p = NULL; HWND hwndCurKey_p = NULL; void ShowLoadPublicKeyDialog(); static BOOL CALLBACK DlgProcReplacerOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { HWND hwndList=GetDlgItem(hwndDlg, IDC_USERLIST); hwndList_p = hwndList; hwndCurKey_p = GetDlgItem(hwndDlg, IDC_CURRENT_KEY); LVCOLUMN col = {0}; LVITEM item = {0}; TCHAR *tmp = NULL; char *tmp2 = NULL; extern bool bIsMiranda09; NMLISTVIEW * hdr = (NMLISTVIEW *) lParam; switch (msg) { case WM_INITDIALOG: { TranslateDialogDefault(hwndDlg); col.pszText = _T("Contact"); col.mask = LVCF_TEXT | LVCF_WIDTH; col.fmt = LVCFMT_LEFT; col.cx = 60; ListView_InsertColumn(hwndList, 0, &col); ZeroMemory(&col,sizeof(col)); col.pszText = _T("Key ID"); col.mask = LVCF_TEXT | LVCF_WIDTH; col.fmt = LVCFMT_LEFT; col.cx = 50; ListView_InsertColumn(hwndList, 1, &col); ZeroMemory(&col,sizeof(col)); col.pszText = _T("Name"); col.mask = LVCF_TEXT | LVCF_WIDTH; col.fmt = LVCFMT_LEFT; col.cx = 50; ListView_InsertColumn(hwndList, 2, &col); ZeroMemory(&col,sizeof(col)); col.pszText = _T("Email"); col.mask = LVCF_TEXT | LVCF_WIDTH; col.fmt = LVCFMT_LEFT; col.cx = 50; ListView_InsertColumn(hwndList, 3, &col); ZeroMemory(&col,sizeof(col)); col.pszText = _T("Protocol"); col.mask = LVCF_TEXT | LVCF_WIDTH; col.fmt = LVCFMT_LEFT; col.cx = 60; ListView_InsertColumn(hwndList, 4, &col); ListView_SetExtendedListViewStyleEx(hwndList, 0, LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT); int i = 1, iRow = 0; /* for(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact != NULL; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) { if(isContactHaveKey(hContact)) { TCHAR *name = (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR); item.mask = LVIF_TEXT; item.iItem = i; item.iSubItem = 0; item.pszText = name; iRow = ListView_InsertItem(hwndList, &item); ListView_SetItemText(hwndList, iRow, 0, name); TCHAR *tmp = mir_a2t((char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0)); ListView_SetItemText(hwndList, iRow, 4, tmp); mir_free(tmp); tmp2 = UniGetContactSettingUtf(hContact, szReplacerModuleName, "KeyID", ""); tmp = mir_a2t(tmp2); mir_free(tmp2); ListView_SetItemText(hwndList, iRow, 1, (_tcslen(tmp) > 1)?tmp:_T("not set")); mir_free(tmp); tmp2 = UniGetContactSettingUtf(hContact, szReplacerModuleName, "KeyMainName", ""); tmp = mir_a2t(tmp2); mir_free(tmp2); ListView_SetItemText(hwndList, iRow, 2, (_tcslen(tmp) > 1)?tmp:_T("not set")); mir_free(tmp); tmp2 = UniGetContactSettingUtf(hContact, szReplacerModuleName, "KeyMainEmail", ""); tmp = mir_a2t(tmp2); mir_free(tmp2); ListView_SetItemText(hwndList, iRow, 3, (_tcslen(tmp) > 1)?tmp:_T("not set")); mir_free(tmp); if(DBGetContactSettingByte(hContact, szReplacerModuleName, "GPGEncryption", 0)) ListView_SetItemState(hwndList, iRow, 0x2000, 0xF000); user_data[i] = hContact; ZeroMemory(&item,sizeof(item)); ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE);// not sure about this ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE); ListView_SetColumnWidth(hwndList, 2, LVSCW_AUTOSIZE); ListView_SetColumnWidth(hwndList, 3, LVSCW_AUTOSIZE); ListView_SetColumnWidth(hwndList, 4, LVSCW_AUTOSIZE); i++; } }*/ tmp = UniGetContactSettingUtf(NULL, szReplacerModuleName, "szLogFilePath", _T("")); SetDlgItemText(hwndDlg, IDC_LOG_FILE_EDIT, (_tcslen(tmp) > 1)?tmp:_T("c:\\GPGdebug.log")); mir_free(tmp); CheckStateLoadDB(hwndDlg, IDC_DEBUG_LOG, "bDebugLog", 0); EnableWindow(GetDlgItem(hwndDlg, IDC_JABBER_API), bIsMiranda09); { string keyinfo = "Current private key id: "; char *keyid = UniGetContactSettingUtf(NULL, szReplacerModuleName, "KeyID", ""); keyinfo += (strlen(keyid) > 0)?keyid:"not set"; mir_free(keyid); SetDlgItemTextA(hwndDlg, IDC_CURRENT_KEY, keyinfo.c_str()); } if(bIsMiranda09) CheckStateLoadDB(hwndDlg, IDC_JABBER_API, "bJabberAPI", 1); CheckStateLoadDB(hwndDlg, IDC_FILE_TRANSFERS, "bFileTransfers", 1); return TRUE; } case WM_COMMAND: { switch (LOWORD(wParam)) { case IDC_DELETE_KEY_BUTTON: /* { //gpg execute block TCHAR tmp2[MAX_PATH] = {0}; TCHAR *ptmp; char *tmp; bool keep = false; bool ismetacontact = false; HANDLE meta = NULL; HANDLE hContact = user_data[item_num+1]; if(isProtoMetaContacts(hContact)) { meta = hContact; hContact = metaGetMostOnline(hContact); ismetacontact = true; } else if((meta = metaGetContact(user_data[item_num+1])) != NULL) { hContact = metaGetMostOnline(meta); ismetacontact = true; } tmp = UniGetContactSettingUtf(hContact, szReplacerModuleName, "KeyID", ""); for(HANDLE hcnttmp = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hcnttmp != NULL; hcnttmp = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hcnttmp, 0)) { if(hcnttmp != hContact) { char *tmp2 = UniGetContactSettingUtf(hcnttmp, szReplacerModuleName, "KeyID", ""); if(!strcmp(tmp, tmp2)) { mir_free(tmp2); keep = true; break; } mir_free(tmp2); } } if(!keep) if(MessageBox(0, _T("This key not used by any contact, do you want to remove it from publick keyring ?"), _T("Key info"), MB_YESNO) == IDYES) { wstring cmd; string output; DWORD exitcode; cmd += _T(" --batch --yes --delete-key "); ptmp = mir_a2t(tmp); cmd += ptmp; mir_free(ptmp); gpg_execution_params params; pxResult result; params.cmd = &cmd; params.useless = ""; params.out = &output; params.code = &exitcode; params.result = &result; HANDLE gpg_thread = mir_forkthread(pxEexcute_thread, (void*)¶ms); if(WaitForSingleObject(gpg_thread, 10000) == WAIT_TIMEOUT) { TerminateThread(gpg_thread, 0); MessageBox(0, _T("GPG execution timed out, aborted"), _T(""), MB_OK); } if(result == pxNotFound) { MessageBox(0, _T("Set path to gpg.exe first!"), _T("Warning"), MB_OK); mir_free(tmp); break; } if(output.find("--delete-secret-keys") != string::npos) MessageBoxA(0, "we have secret key for this public key, do not removing from GPG keyring", "info", MB_OK); else MessageBoxA(0, "Key removed from GPG keyring", "info", MB_OK); } mir_free(tmp); if(ismetacontact) { if(MessageBox(0, _T("Do you want to remove key from entire metacontact (all subcontacts) ?"), _T("Metacontact detected"), MB_YESNO) == IDYES) { HANDLE hcnt = NULL; int count = metaGetContactsNum(meta); for(int i = 0; i < count; i++) { hcnt = metaGetSubcontact(meta, i); if(hcnt) { DBDeleteContactSetting(hcnt, szReplacerModuleName, "KeyID"); DBDeleteContactSetting(hcnt, szReplacerModuleName, "GPGPubKey"); DBDeleteContactSetting(hcnt, szReplacerModuleName, "KeyMainName"); DBDeleteContactSetting(hcnt, szReplacerModuleName, "KeyType"); DBDeleteContactSetting(hcnt, szReplacerModuleName, "KeyMainEmail"); DBDeleteContactSetting(hcnt, szReplacerModuleName, "KeyComment"); setClistIcon(hcnt); setSrmmIcon(hcnt); } } } else { DBDeleteContactSetting(hContact, szReplacerModuleName, "KeyID"); DBDeleteContactSetting(hContact, szReplacerModuleName, "GPGPubKey"); DBDeleteContactSetting(hContact, szReplacerModuleName, "KeyMainName"); DBDeleteContactSetting(hContact, szReplacerModuleName, "KeyType"); DBDeleteContactSetting(hContact, szReplacerModuleName, "KeyMainEmail"); DBDeleteContactSetting(hContact, szReplacerModuleName, "KeyComment"); setClistIcon(hContact); setSrmmIcon(hContact); } } else { DBDeleteContactSetting(user_data[item_num+1], szReplacerModuleName, "KeyID"); DBDeleteContactSetting(user_data[item_num+1], szReplacerModuleName, "GPGPubKey"); DBDeleteContactSetting(user_data[item_num+1], szReplacerModuleName, "KeyMainName"); DBDeleteContactSetting(user_data[item_num+1], szReplacerModuleName, "KeyType"); DBDeleteContactSetting(user_data[item_num+1], szReplacerModuleName, "KeyMainEmail"); DBDeleteContactSetting(user_data[item_num+1], szReplacerModuleName, "KeyComment"); setClistIcon(user_data[item_num+1]); setSrmmIcon(user_data[item_num+1]); } } ListView_SetItemText(hwndList, item_num, 3, _T("not set")); ListView_SetItemText(hwndList, item_num, 2, _T("not set")); ListView_SetItemText(hwndList, item_num, 1, _T("not set")); */ break; case IDC_SAVE_KEY_BUTTON: /* { tmp = GetFilePath(_T("Export public key"), _T("*"), _T(".asc pubkey file"), true); if(!tmp) { break; } wstring str; { TCHAR *tmp = UniGetContactSettingUtf(user_data[item_num+1], szReplacerModuleName, "GPGPubKey", _T("")); str.append(tmp); mir_free(tmp); } wstring::size_type s = 0; while((s = str.find(_T("\r"), s)) != wstring::npos) { str.erase(s, 1); } wfstream f(tmp, std::ios::out); delete [] tmp; f<hdr.hwndFrom) && hdr->iItem != (-1)) { if(hdr->hdr.code == LVN_ITEMCHANGED) { int i = hdr->iItem; if(ListView_GetItemState(hwndList, i, 0xF000) == 0x2000) DBWriteContactSettingByte(user_data[i+1], szReplacerModuleName, "GPGEncryption", 1); else DBWriteContactSettingByte(user_data[i+1], szReplacerModuleName, "GPGEncryption", 0); item_num = i; } } switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: { extern bool bDebugLog, bJabberAPI, bFileTransfers; bJabberAPI = CheckStateStoreDB(hwndDlg, IDC_JABBER_API, "bJabberAPI"); return TRUE; } } } break; } return FALSE; }