void vncMenu::SendTrayMsg(DWORD msg, BOOL flash) { // Create the tray icon message m_nid.hWnd = m_hwnd; m_nid.cbSize = sizeof(m_nid); m_nid.uID = ID_WINVNC; // never changes after construction m_nid.hIcon = flash ? m_flash_icon : m_winvnc_icon; m_nid.uFlags = NIF_ICON | NIF_MESSAGE; m_nid.uCallbackMessage = WM_TRAYNOTIFY; //vnclog.Print(LL_INTINFO, VNCLOG("SendTRaymesg\n")); // Use resource string as tip if there is one if (LoadString(hAppInstance, ID_WINVNC, m_nid.szTip, sizeof(m_nid.szTip))) { m_nid.uFlags |= NIF_TIP; } // Try to add the server's IP addresses to the tip string, if possible if (m_nid.uFlags & NIF_TIP) { strncat(m_nid.szTip, " - ", (sizeof(m_nid.szTip)-1)-strlen(m_nid.szTip)); if (m_server->SockConnected()) { unsigned long tiplen = strlen(m_nid.szTip); char *tipptr = ((char *)&m_nid.szTip) + tiplen; GetIPAddrString(tipptr, sizeof(m_nid.szTip) - tiplen); } else { strncat(m_nid.szTip, " listening", (sizeof(m_nid.szTip)-1)-strlen(m_nid.szTip)); } } if (strcmp(Balloon1Title,"")!=NULL)if (nport!=0 && (connect_counter%5==0 || connect_counter==1)) { char all[450]; strcpy(all,Balloon1A); strcat(all,"\n"); strcat(all,Balloon1B); strcat(all,"\n"); strcat(all,Balloon1C); m_nid.uFlags |= NIF_INFO; strncpy(m_nid.szInfo,all, sizeof(all)); strncpy(m_nid.szInfoTitle,Balloon1Title,sizeof(Balloon1Title)); m_nid.uTimeout=10000; m_nid.dwInfoFlags=NIIF_INFO; } if (strcmp(Balloon2Title,"")!=NULL)if (connected==1 && connect_counter%10==0) { connect_counter++; char all[450]; strcpy(all,Balloon2A); strcat(all,"\n"); strcat(all,Balloon2B); strcat(all,"\n"); strcat(all,Balloon2C); m_nid.uFlags |= NIF_INFO; strncpy(m_nid.szInfo,all, sizeof(all)); strncpy(m_nid.szInfoTitle,Balloon2Title,sizeof(Balloon2Title)); m_nid.uTimeout=10000; m_nid.dwInfoFlags=NIIF_INFO; } // Send the message if (Shell_NotifyIcon(msg, &m_nid)) { // Set the enabled/disabled state of the menu items // vnclog.Print(LL_INTINFO, VNCLOG("tray icon added ok\n")); EnableMenuItem(m_hmenu, ID_CLOSE, m_properties.AllowShutdown() ? MF_ENABLED : MF_GRAYED); } else { if (!vncService::RunningAsService()) { if (msg == NIM_ADD) { // The tray icon couldn't be created, so use the Properties dialog // as the main program window /* vnclog.Print(LL_INTINFO, VNCLOG("opening dialog box\n")); m_properties.ShowAdmin(TRUE, TRUE); PostQuitMessage(0);*/ } } } }
long NetCollector::CollectFallback(NVDataItem *DataItems) { USES_CONVERSION; DWORD Status; DWORD NumIfEntries; Status = GetNumberOfInterfaces( &NumIfEntries); if (Status != NO_ERROR) return ERROR_SUCCESS; PMIB_IFTABLE IfTable = NULL; PMIB_IPADDRTABLE IPAddrTable = NULL; unsigned long IfLen = 0; unsigned long IpLen = 0; Status = GetIfTable(IfTable, &IfLen, TRUE); if (Status != ERROR_INSUFFICIENT_BUFFER) return ERROR_SUCCESS; Status = GetIpAddrTable(IPAddrTable, &IpLen, FALSE); if (Status != ERROR_INSUFFICIENT_BUFFER) return ERROR_SUCCESS; IfTable = (PMIB_IFTABLE) new char[IfLen]; memset(IfTable, 0 , IfLen); IPAddrTable = (PMIB_IPADDRTABLE) new char[IpLen]; memset(IPAddrTable, 0 , IpLen); Status = GetIfTable(IfTable, &IfLen, TRUE); if (Status != NO_ERROR) { delete IfTable; delete IPAddrTable; return ERROR_SUCCESS; } Status = GetIpAddrTable(IPAddrTable, &IpLen, FALSE); if (Status != NO_ERROR) { delete IfTable; delete IPAddrTable; return ERROR_SUCCESS; } DWORD CurrIf; char TransString[64]; char IPString[64]; PMIB_IFROW CurrEntry = NULL; for (CurrIf = 0, CurrEntry = IfTable->table; CurrIf < IfTable->dwNumEntries; CurrIf ++, CurrEntry ++) { auto_ptr<NVDataItem> SubItem (new NVDataItem(NCI_TAG)); TransString[0] = '\0'; if (Status != NO_ERROR) { delete IfTable; return ERROR_SUCCESS; } #if 0 if (CurrEntry.dwPhysAddrLen < 1) continue; #endif char * IfTypeName; switch (CurrEntry->dwType) { case MIB_IF_TYPE_ETHERNET: IfTypeName = "Ethernet 802.3"; break; case MIB_IF_TYPE_TOKENRING: IfTypeName = "Token Ring 802.5"; break; case MIB_IF_TYPE_FDDI: IfTypeName = "Fiber Distributed Data Interface (FDDI)"; break; case MIB_IF_TYPE_PPP: IfTypeName = "PPP"; break; case MIB_IF_TYPE_SLIP: IfTypeName = "SLIP"; break; default: IfTypeName = "Unknown"; // continue; } SubItem->AddNVItem("InterfaceType", IfTypeName); //if (wcslen(IfTable->Adapter[CurrIf].Name) > 0) { // SubItem->AddNVItem("SysName", W2A(IfTable->Adapter[CurrIf].Name)); //} if (CurrEntry->wszName != NULL && wcslen(CurrEntry->wszName) > 0) { SubItem->AddNVItem("Description", CurrEntry->wszName); } else if (strlen((const char *) CurrEntry->bDescr) > 0) { SubItem->AddNVItem("Description", (const char *) CurrEntry->bDescr); } //_ASSERT (CurrIfTableEntry.dwPhysAddrLen == 6); if (CurrEntry->bPhysAddr[0] == 0 && CurrEntry->bPhysAddr[1] == 0 && CurrEntry->bPhysAddr[2] == 0 && CurrEntry->bPhysAddr[3] == 0 && CurrEntry->bPhysAddr[4] == 0 && CurrEntry->bPhysAddr[5] == 0) { continue; } sprintf (TransString,"%02X:%02X:%02X:%02X:%02X:%02X", CurrEntry->bPhysAddr[0], CurrEntry->bPhysAddr[1], CurrEntry->bPhysAddr[2], CurrEntry->bPhysAddr[3], CurrEntry->bPhysAddr[4], CurrEntry->bPhysAddr[5]); SubItem->AddNVItem("MACAddress", TransString); string IPAddrList; long CurrIPIndex; MIB_IPADDRROW * CurrIPAddrInfo; long FoundIP = 0; for (CurrIPIndex = 0, CurrIPAddrInfo = IPAddrTable->table; CurrIPIndex < IPAddrTable->dwNumEntries; CurrIPIndex ++, CurrIPAddrInfo ++) { if (IPAddrTable->table[CurrIPIndex].dwIndex == CurrEntry->dwIndex) { FoundIP ++; if (FoundIP > 1) IPAddrList.append(","); else { GetIPAddrString (CurrIPAddrInfo->dwMask, IPString); SubItem->AddNVItem("IPSubNet", IPString); } GetIPAddrString(CurrIPAddrInfo->dwAddr, IPString); IPAddrList.append(IPString); } } SubItem->AddNVItem("IPAddress", IPAddrList.c_str()); DataItems->AddSubItem(SubItem.release()); } delete IfTable; delete IPAddrTable; // WinSetupEnumerateDevClass((GUID) GUID_DEVCLASS_NET, NCI_TAG, DataItems, NULL); return ERROR_SUCCESS; }
void vncMenu::SendTrayMsg(DWORD msg, BOOL flash) { // adzm 2009-07-05 omni_mutex_lock sync(m_mutexTrayIcon); // Create the tray icon message m_nid.hWnd = m_hwnd; m_nid.cbSize = sizeof(m_nid); m_nid.uID = IDI_WINVNC; // never changes after construction m_nid.hIcon = flash ? m_flash_icon : m_winvnc_icon; m_nid.uFlags = NIF_ICON | NIF_MESSAGE |NIF_STATE; m_nid.uCallbackMessage = WM_TRAYNOTIFY; if (m_server->GetDisableTrayIcon()) { m_nid.dwState = NIS_HIDDEN; m_nid.dwStateMask = NIS_HIDDEN; } else { m_nid.dwState = 0; m_nid.dwStateMask = NIS_HIDDEN; } // adzm 2009-07-05 - Tray icon balloon tips if (m_BalloonInfo && (strlen(m_BalloonInfo) > 0)) { m_nid.uFlags |= NIF_INFO; strncpy(m_nid.szInfo, m_BalloonInfo, 255); m_nid.szInfo[255] = '\0'; if (m_BalloonTitle && (strlen(m_BalloonTitle) > 0)) { strncpy(m_nid.szInfoTitle, m_BalloonTitle, 63); m_nid.szInfoTitle[63] = '\0'; } else { strcpy(m_nid.szInfoTitle, "Remote Connection"); } m_nid.uTimeout=10000; // minimum m_nid.dwInfoFlags=NIIF_INFO; } if (m_BalloonInfo) { free(m_BalloonInfo); m_BalloonInfo = NULL; } if (m_BalloonTitle) { free(m_BalloonTitle); m_BalloonTitle = NULL; } //vnclog.Print(LL_INTINFO, VNCLOG("SendTRaymesg\n")); // Use resource string as tip if there is one // [v1.0.2-jp1 fix] //if (LoadString(hAppInstance, IDI_WINVNC, m_nid.szTip, sizeof(m_nid.szTip))) if (LoadString(hInstResDLL, IDI_WINVNC, m_nid.szTip, sizeof(m_nid.szTip))) { m_nid.uFlags |= NIF_TIP; } // Try to add the server's IP addresses to the tip string, if possible if (m_nid.uFlags & NIF_TIP) { strncat(m_nid.szTip, " - ", (sizeof(m_nid.szTip)-1)-strlen(m_nid.szTip)); if (m_server->SockConnected()) { unsigned long tiplen = strlen(m_nid.szTip); char *tipptr = ((char *)&m_nid.szTip) + tiplen; GetIPAddrString(tipptr, sizeof(m_nid.szTip) - tiplen); } else { strncat(m_nid.szTip, "Not listening", (sizeof(m_nid.szTip)-1)-strlen(m_nid.szTip)); } } // vnclog.Print(LL_INTERR, VNCLOG("########### vncMenu::SendTrayMsg - Shell_NotifyIcon call\n")); // Send the message if ((msg == NIM_MODIFY) && (IsIconSet == FALSE)) return; //no icon to modify if ((msg ==NIM_ADD) && (IsIconSet != FALSE)) return; //no icon to set if (msg == NIM_DELETE) { IsIconSet=false; IconFaultCounter=0; } if (Shell_NotifyIcon(msg, &m_nid)) { // vnclog.Print(LL_INTERR, VNCLOG("########### vncMenu::SendTrayMsg - Shell_NotifyIcon call SUCCESS\n")); // Set the enabled/disabled state of the menu items // vnclog.Print(LL_INTINFO, VNCLOG("tray icon added ok\n")); EnableMenuItem(m_hmenu, ID_ADMIN_PROPERTIES, m_properties.AllowProperties() ? MF_ENABLED : MF_GRAYED); EnableMenuItem(m_hmenu, ID_PROPERTIES, m_properties.AllowProperties() ? MF_ENABLED : MF_GRAYED); EnableMenuItem(m_hmenu, ID_CLOSE, m_properties.AllowShutdown() ? MF_ENABLED : MF_GRAYED); EnableMenuItem(m_hmenu, ID_KILLCLIENTS, m_properties.AllowEditClients() ? MF_ENABLED : MF_GRAYED); EnableMenuItem(m_hmenu, ID_OUTGOING_CONN, m_properties.AllowEditClients() ? MF_ENABLED : MF_GRAYED); EnableMenuItem(m_hmenu, ID_CLOSE_SERVICE,(vncService::RunningAsService()&&m_properties.AllowShutdown()) ? MF_ENABLED : MF_GRAYED); EnableMenuItem(m_hmenu, ID_START_SERVICE,(vncService::IsInstalled() && !vncService::RunningAsService() && m_properties.AllowShutdown()) ? MF_ENABLED : MF_GRAYED); EnableMenuItem(m_hmenu, ID_RUNASSERVICE,(!vncService::IsInstalled() &&!vncService::RunningAsService() && m_properties.AllowShutdown()) ? MF_ENABLED : MF_GRAYED); EnableMenuItem(m_hmenu, ID_UNINSTALL_SERVICE,(vncService::IsInstalled()&&m_properties.AllowShutdown()) ? MF_ENABLED : MF_GRAYED); // adzm 2009-07-05 if (SPECIAL_SC_PROMPT) { RemoveMenu(m_hmenu, ID_ADMIN_PROPERTIES, MF_BYCOMMAND); RemoveMenu(m_hmenu, ID_CLOSE_SERVICE, MF_BYCOMMAND); RemoveMenu(m_hmenu, ID_START_SERVICE, MF_BYCOMMAND); RemoveMenu(m_hmenu, ID_RUNASSERVICE, MF_BYCOMMAND); RemoveMenu(m_hmenu, ID_UNINSTALL_SERVICE, MF_BYCOMMAND); } if (msg == NIM_ADD) { IsIconSet=true; IconFaultCounter=0; vnclog.Print(LL_INTINFO, VNCLOG("IsIconSet \n")); } } else { // vnclog.Print(LL_INTERR, VNCLOG("########### vncMenu::SendTrayMsg - Shell_NotifyIcon call FAILED ( %u ) \n"), 0); if (!vncService::RunningAsService()) { // //vnclog.Print(LL_INTERR, VNCLOG("########### vncMenu::SendTrayMsg - Shell_NotifyIcon call FAILED NOT runasservice\n")); if (msg == NIM_ADD) { // The tray icon couldn't be created, so use the Properties dialog // as the main program window if (!m_server->RunningFromExternalService()) // sf@2007 - Do not display Properties pages when running in Application0 mode { // vnclog.Print(LL_INTERR, VNCLOG("########### vncMenu::SendTrayMsg - Shell_NotifyIcon call FAILED NOT runfromexternalservice\n")); //vnclog.Print(LL_INTINFO, VNCLOG("opening dialog box\n")); m_properties.ShowAdmin(TRUE, TRUE); PostQuitMessage(0); } } } else { if (msg == NIM_ADD) { IsIconSet=false; IconFaultCounter++; m_server->TriggerUpdate(); vnclog.Print(LL_INTINFO, VNCLOG("Failed IsIconSet \n")); } } } }