⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 servers.cpp

📁 multiplataform real time Linux monitor
💻 CPP
字号:
/* LiMon-Server|  Copyright (C) 2006 Marcelo Busico||  Author:  Marcelo Busico    marcelobusico@gmail.com||  This program is free software which I release under the GNU General Public|  License. You may redistribute and/or modify this program under the terms|  of that 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.  Version 2 is in the|  LICENSE.txt file in the top level directory of this distribution.| |  To get a copy of the GNU General Puplic License, write to the Free Software|  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*//* Implementacion de la libreria que lee el Estado de los Servidores */#include "servers.h"#include "rutas.h"#include <stdio.h>#include <string.h>#include <stdlib.h>//ConstructorEstadoServidores::EstadoServidores(){     FILE *f; //Puntero a archivo    char ejecutable[100]; //Para ejecutar el Script    char buf[2]; //Resultado del Script    //Ruta del script    strcpy(ejecutable,RUTA_SCRIPTS);    //Nombre del script    strcat(ejecutable,"servers.sh");    //Ejecuta el script    system(ejecutable);    // Estado del Servidor Web    //Sale si no puede abrir el archivo    if ((f = fopen("/tmp/limon-server-web", "r")) == NULL)    {		strcpy(cadenaEstadoWeb,"");	strcpy(cadenaEstadoMail,"");	strcpy(cadenaEstadoSSH,"");	strcpy(cadenaEstadoFTP,"");	strcpy(cadenaEstadoSamba,"");	return;    }    if(fgets(buf, sizeof(buf), f)!=NULL)	strcpy(cadenaEstadoWeb,buf);	    else	strcpy(cadenaEstadoWeb,"");    //Cierra el archivo    fclose(f);    // Estado del Servidor de Correo    //Sale si no puede abrir el archivo    if ((f = fopen("/tmp/limon-server-mail", "r")) == NULL)    {		strcpy(cadenaEstadoWeb,"");	strcpy(cadenaEstadoMail,"");	strcpy(cadenaEstadoSSH,"");	strcpy(cadenaEstadoFTP,"");	strcpy(cadenaEstadoSamba,"");	return;    }    if(fgets(buf, sizeof(buf), f)!=NULL)	strcpy(cadenaEstadoMail,buf);	    else	strcpy(cadenaEstadoMail,"");    //Cierra el archivo    fclose(f);    // Estado del Servidor SSH    //Sale si no puede abrir el archivo    if ((f = fopen("/tmp/limon-server-ssh", "r")) == NULL)    {		strcpy(cadenaEstadoWeb,"");	strcpy(cadenaEstadoMail,"");	strcpy(cadenaEstadoSSH,"");	strcpy(cadenaEstadoFTP,"");	strcpy(cadenaEstadoSamba,"");	return;    }    if(fgets(buf, sizeof(buf), f)!=NULL)	strcpy(cadenaEstadoSSH,buf);	    else	strcpy(cadenaEstadoSSH,"");    //Cierra el archivo    fclose(f);    // Estado del Servidor FTP    //Sale si no puede abrir el archivo    if ((f = fopen("/tmp/limon-server-ftp", "r")) == NULL)    {		strcpy(cadenaEstadoWeb,"");	strcpy(cadenaEstadoMail,"");	strcpy(cadenaEstadoSSH,"");	strcpy(cadenaEstadoFTP,"");	strcpy(cadenaEstadoSamba,"");	return;    }    if(fgets(buf, sizeof(buf), f)!=NULL)	strcpy(cadenaEstadoFTP,buf);	    else	strcpy(cadenaEstadoFTP,"");    //Cierra el archivo    fclose(f);    // Estado del Servidor Samba    //Sale si no puede abrir el archivo    if ((f = fopen("/tmp/limon-server-samba", "r")) == NULL)    {		strcpy(cadenaEstadoWeb,"");	strcpy(cadenaEstadoMail,"");	strcpy(cadenaEstadoSSH,"");	strcpy(cadenaEstadoFTP,"");	strcpy(cadenaEstadoSamba,"");	return;    }    if(fgets(buf, sizeof(buf), f)!=NULL)	strcpy(cadenaEstadoSamba,buf);	    else	strcpy(cadenaEstadoSamba,"");    //Cierra el archivo    fclose(f);}//Devuelve el Estado del Servidor Web - Booleanint EstadoServidores::getEstadoWeb(){    int aux=-1; //Almacena el retorno de la funcion    if(strlen(cadenaEstadoWeb)>0)    {	//Encuentra en la cadena del archivo el valor buscado a devolver	sscanf(cadenaEstadoWeb,"%d",&aux);    }    //Retorna valor booleano    return aux;}//Devuelve el Estado del Servidor de Correo - Booleanint EstadoServidores::getEstadoMail(){    int aux=-1; //Almacena el retorno de la funcion    if(strlen(cadenaEstadoMail)>0)    {	//Encuentra en la cadena del archivo el valor buscado a devolver	sscanf(cadenaEstadoMail,"%d",&aux);    }    //Retorna valor booleano    return aux;}//Devuelve el Estado del Servidor SSH - Booleanint EstadoServidores::getEstadoSSH(){    int aux=-1; //Almacena el retorno de la funcion    if(strlen(cadenaEstadoSSH)>0)    {	//Encuentra en la cadena del archivo el valor buscado a devolver	sscanf(cadenaEstadoSSH,"%d",&aux);    }    //Retorna valor booleano    return aux;}//Devuelve el Estado del Servidor FTP - Booleanint EstadoServidores::getEstadoFTP(){    int aux=-1; //Almacena el retorno de la funcion    if(strlen(cadenaEstadoFTP)>0)    {	//Encuentra en la cadena del archivo el valor buscado a devolver	sscanf(cadenaEstadoFTP,"%d",&aux);    }    //Retorna valor booleano    return aux;}//Devuelve el Estado del Servidor Samba - Booleanint EstadoServidores::getEstadoSamba(){    int aux=-1; //Almacena el retorno de la funcion    if(strlen(cadenaEstadoSamba)>0)    {	//Encuentra en la cadena del archivo el valor buscado a devolver	sscanf(cadenaEstadoSamba,"%d",&aux);    }    //Retorna valor booleano    return aux;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -