ApacheMonitor.c revision 69b98a8bfed41fcc362cfe3cb86a423f69de8143
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*
* Portions of this software are based upon public domain software
* originally written at the National Center for Supercomputing Applications,
* University of Illinois, Urbana-Champaign.
*/
/* ====================================================================
* ApacheMonitor.c Simple program to manage and monitor Apache services.
*
* Contributed by Mladen Turk <mturk@mappingsoft.com>
*
* 05 Aug 2001
* ====================================================================
*/
#define _WIN32_WINNT 0x0400
#ifndef STRICT
#define STRICT
#endif
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <stdlib.h>
#include <stdio.h>
#include "ApacheMonitor.h"
#define OS_VERSION_WINNT 1
#define OS_VERSION_WIN9X 2
#define OS_VERSION_WIN2K 3
/* Should be enough */
#define MAX_APACHE_SERVICES 128
#define WM_TIMER_REFRESH 10
#define WM_TIMER_RESCAN 11
#define SERVICE_APACHE_RESTART 128
#define XBITMAP 16
#define YBITMAP 16
#define MAX_LOADSTRING 100
typedef struct _st_APACHE_SERVICE
{
/* Global variables */
void ap_ClearServicesSt()
{
int i;
for (i = 0; i < MAX_APACHE_SERVICES; i++)
{
if (ap_stServices[i].szServiceName)
if (ap_stServices[i].szDisplayName)
if (ap_stServices[i].szDescription)
if (ap_stServices[i].szImagePath)
}
}
{
NULL,
}
{
buffer[0] = 0;
return buffer;
}
{
char szBuff[256];
char szProductType[80];
/*
Try calling GetVersionEx using the OSVERSIONINFOEX structure.
If that fails, try using the OSVERSIONINFO structure.
*/
{
/* If OSVERSIONINFOEX doesn't work, try OSVERSIONINFO. */
return FALSE;
}
switch (osvi.dwPlatformId)
{
case VER_PLATFORM_WIN32_NT:
/* Test for the product. */
{
/* Test for product type.*/
#ifdef VER_VORKSTATION_NT
if (bOsVersionInfoEx)
{
{
#ifdef VER_SUITE_PERSONAL
else
#endif
}
{
else
}
}
else
{
#endif
"SYSTEM\\CurrentControlSet\\Control\\ProductOptions",
0, KEY_QUERY_VALUE, &hKey);
#ifdef VER_VORKSTATION_NT
}
#endif
/* Get version, service pack (if any), and build number. */
{
}
else
{
}
}
{
else
return FALSE;
}
break;
{
{
}
{
}
{
}
}
break;
case VER_PLATFORM_WIN32s:
break;
default:
return FALSE;
break;
}
return TRUE;
}
{
int i = 0, n = 0;
{
if (ap_stServices[i].dwPid != 0)
++n;
++i;
}
if (dwMessage != NIM_DELETE)
{
if (n)
else
}
else
if (n == i)
else if (n)
else
}
{
{
if (fDefault)
}
else
}
{
/* create popup menu */
if (hMenu)
{
GetCursorPos(&pt);
}
}
{
/* Get the Height and Width of the child window */
/* Get the limits of the 'workarea' */
sizeof(RECT),
0);
if (!bResult) {
}
/* Calculate new X and Y position*/
}
{
int nItem;
}
{
{
if (dwReaded > 0)
{
if (ch == '\n')
{
*lpBuf = '\0';
}
else if (ch == '\t')
{
int i, t;
for (i = 0; i < 8 - t; ++i)
*lpBuf++ = ' ';
}
else if (ch != '\r')
}
}
return 0;
}
{
MessageBeep(100);
return 0;
}
{
hProc = GetCurrentProcess();
NULL,
NULL,
TRUE,
NULL,
NULL ,
&stInfo,
if (!bResult)
{
if (nRetValue)
*nRetValue = GetLastError();
return FALSE;
}
return TRUE;
}
{
if (bRedirectConsole)
NULL,
NULL,
TRUE,
NULL,
NULL ,
&stInfo,
&prInfo);
if (!bResult)
{
if (nRetValue)
*nRetValue = GetLastError();
return FALSE;
}
Sleep(2000);
return TRUE;
}
{
int ticks;
if (ap_OSVersion == OS_VERSION_WIN9X)
{
if (sPos)
{
switch (dwCommand)
{
case SERVICE_CONTROL_STOP:
break;
case SERVICE_CONTROL_CONTINUE:
serviceFlag = FALSE;
break;
case SERVICE_APACHE_RESTART:
break;
default:
return FALSE;
}
}
else
return FALSE;
{
return FALSE;
}
else if (!serviceFlag)
{
return TRUE;
}
}
else
{
/* Apache 2.0 uses '-k runservice' as cmdline parameter */
if (!sPos)
{
serviceFlag = FALSE;
}
if (sPos)
else
return FALSE;
NULL,
NULL,
);
if (!schSCManager)
return FALSE;
if (schService != NULL)
{
switch (dwCommand)
{
case SERVICE_CONTROL_STOP:
{
Sleep(1000);
{
Sleep(1000);
else
break;
}
}
{
{
}
}
break;
case SERVICE_CONTROL_CONTINUE:
if (serviceFlag)
else
{
}
{
Sleep(1000);
{
Sleep(1000);
else
break;
}
}
{
{
}
}
/* is this OK to do? */
break;
case SERVICE_APACHE_RESTART:
{
ticks = 60;
{
Sleep(1000);
{
return FALSE;
}
if (!--ticks)
break;
}
}
{
}
break;
}
if (!retValue)
return retValue;
}
else
return FALSE;
}
return FALSE;
}
{
if (ap_OSVersion == OS_VERSION_WIN9X)
{
{
*lpdwPid = 1;
return TRUE;
}
else
return FALSE;
}
else
{
dwPid = 0;
NULL,
NULL,
);
if (!schSCManager)
return FALSE;
if (schService != NULL)
{
{
if (lpdwPid)
*lpdwPid = 1;
}
}
else
return FALSE;
}
return FALSE;
}
{
int i = 0;
{
dwPid = 0;
++i;
}
return rv;
}
{
int i, stPos = 0;
"System\\CurrentControlSet\\Services\\",
if (retCode != ERROR_SUCCESS)
{
return FALSE;
}
{
if (retCode == ERROR_SUCCESS)
{
{
{
{
++stPos;
if (stPos >= MAX_APACHE_SERVICES)
retCode = !ERROR_SUCCESS;
}
}
}
}
}
return TRUE;
}
{
int i;
char szFullPath[256];
char szResult[256];
char szGetName[256];
char szVersion[256];
switch (message) {
case WM_INITDIALOG:
/* Now lets dive in and pull out the version information: */
if (dwVerInfoSize) {
/* Set the title of the dialog: */
(UINT *)&uVersionLen);
/* Notice order of version and string... */
/* Walk through the dialog items that we want to replace: */
for (i = DLG_VERFIRST; i <= DLG_VERLAST; i++) {
uVersionLen = 0;
(UINT *)&uVersionLen);
/* Replace dialog item text with version info */
}
else
{
dwResult = GetLastError();
}
TRUE);
}
}
return (TRUE);
case WM_COMMAND:
return (TRUE);
}
break;
}
return FALSE;
}
{
static HWND hStatusBar;
int i, y;
switch (message)
{
case WM_INITDIALOG:
if (GetApacheServicesStatus())
{
i = 0;
{
++i;
}
}
return TRUE;
break;
case WM_UPDATEMESSAGE:
i = 0;
{
++i;
}
/* Dirty hack to bring the window to the foreground */
return TRUE;
break;
case WM_MEASUREITEM:
return TRUE;
case WM_SETCURSOR:
if (ap_consoleRun)
else
return TRUE;
case WM_DRAWITEM:
{
break;
}
switch (lpdis->itemAction)
{
case ODA_SELECT:
case ODA_DRAWENTIRE:
{
if (hbmpPicture == hbmpStop)
{
}
else if (hbmpPicture == hbmpStart)
{
}
}
else
{
}
XBITMAP + 6,
y,
break;
case ODA_FOCUS:
break;
}
return TRUE;
case WM_COMMAND:
{
case IDL_SERVICES:
{
case LBN_DBLCLK:
/* if started then stop, if stopped the start the service */
{
if (hbmpPicture == hbmpStop)
{
}
else
}
return TRUE;
break;
}
break;
case IDOK:
return TRUE;
break;
case IDC_SSTART:
{
}
return TRUE;
break;
case IDC_SSTOP:
{
}
return TRUE;
break;
case IDC_SRESTART:
{
}
return TRUE;
break;
case IDC_SABOUT:
if (!dlgAboutOn)
{
dlgAboutOn = TRUE;
dlgAboutOn = FALSE;
}
else if (ap_hwndAboutDlg)
return TRUE;
break;
}
break;
case WM_SIZE:
{
case SIZE_MINIMIZED:
return TRUE;
break;
}
break;
case WM_CLOSE:
return TRUE;
case WM_DESTROY:
return TRUE;
default:
return FALSE;
}
return FALSE;
}
{
if (idEvent == WM_TIMER_RESCAN)
{
if (FindRunningServices() || ap_rescanServices)
{
if (ap_hServiceDlg)
}
/* check if services list changed */
++nPrev;
++nNew;
{
if (ap_hServiceDlg)
}
}
else if (idEvent == WM_TIMER_REFRESH)
{
if (ap_rescanServices)
{
if (ap_hServiceDlg)
}
else if (FindRunningServices())
{
if (ap_hServiceDlg)
}
}
}
{
if (message == ap_uiTaskbarCreated)
{
/* restore the tray icon on shell restart */
}
switch (message)
{
case WM_CREATE:
break;
case WM_QUIT:
break;
case WM_TRAYMESSAGE:
switch(lParam)
{
case WM_LBUTTONDBLCLK:
if (!dlgServiceOn)
{
dlgServiceOn = TRUE;
}
else if (ap_hServiceDlg)
{
/* Dirty hack to bring the window to the foreground */
}
break;
case WM_RBUTTONUP:
break;
}
break;
case WM_COMMAND:
{
case IDM_RESTORE:
if (!dlgServiceOn)
{
dlgServiceOn = TRUE;
}
else if (ap_hServiceDlg)
break;
case IDM_ABOUT:
if (!dlgAboutOn)
{
dlgAboutOn = TRUE;
dlgAboutOn = FALSE;
}
else if (ap_hwndAboutDlg)
break;
case IDM_EXIT:
PostQuitMessage(0);
return TRUE;
break;
}
default:
}
return FALSE;
}
/* Create main invisible window */
{
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
if (RegisterClassEx(&wcex))
{
0, 0, 0, 0, 0,
}
return hWnd;
}
int nCmdShow)
{
/* single instance mutex */
{
if (hMutex)
return 0;
}
if (ap_hMainWnd != NULL)
{
{
}
}
return 0;
}