+++ /dev/null
-#!/usr/bin/perl -w
-#
-# System Monitor Scripts
-
-use IO::Socket;
-use Fcntl;
-use strict;
-use POSIX qw(setsid);
-use POSIX qw(strftime);
-
-my (%config, $waitedpid, @pingservers, @webservers, @pwebservers, @cvsservers, @mailservers, @mysqlservers, @pgsqlservers);
-
-#################
-# configuration #
-#################
-$config{'logfile'} = '/home/precision/logfile';
-
-$config{'ipaddr'} = '198.186.203.50';
-$config{'port'} = '10000';
-$config{'username'} = 'nobody';
-
-$SIG{'INT'} = \&exit_nicely;
-$SIG{'TERM'} = \&exit_nicely;
-
-@webservers = (
- 'bush.i',
- 'delerium.i',
- 'garbage.i',
- 'geocrawler.i',
- 'slayer.p',
- 'koil.p',
- 'mail1'
-);
-
-@pwebservers = (
- 'oakenfold.p',
- 'nirvana.p'
-);
-
-@cvsservers = (
- 'slayer.p',
- 'tokyojoe.p',
- 'bluemchen.p'
-);
-
-@mailservers = (
- 'mail1',
- 'toye.p',
- 'geocrawler.i'
-);
-
-@mysqlservers = (
- 'underworld.i'
-);
-
-@pgsqlservers = (
- 'geocrawler.i'
-);
-
-@pingservers = (
- 'mail1',
- 'police.i',
- 'underworld.i',
- 'geocrawler.i',
- 'garbage.i',
- 'bush.i',
- 'delerium.i',
- 'oakenfold.p',
- 'nirvana.p',
- 'koil.p',
- 'offspring.p',
- 'orbital.p',
- 'moby.p',
- 'slayer.p',
- 'poison.p',
- 'tokyojoe.p',
- 'bluemchen.p',
- 'toye'
-);
-
-#########################
-# background the daemon #
-#########################
-sub daemon {
- my ($pid);
- # setup the environment
- chdir "/" || die "Couldn't chdir to /: $!\n";
-
- defined ($pid = fork()) || die "Couldn't fork(): $!\n"; # fork ourselves into the background, duh!
- if ($pid) {
- print "SystemDaemon.pl backgrounded with process: $pid\n";
- if ($config{'logfile'}) { print "Using Logfile $config{'logfile'}\n" }
- exit;
- }
-
- if ($config{'logfile'}) { # open the logfile
- open (Log, ">>$config{'logfile'}") || die "Couldn't Open Logfile: $!\n";
- select (Log);
- $| = 1;
- }
-
- setsid || die "Can't get a new session: $!\n";
- umask 0;
-}
-
-##############################
-# log message to the logfile #
-##############################
-sub logme {
- my $msg = shift (@_);
- my $time = strftime "%Y-%m-%d - %T", localtime;
- print "$time\t$msg\n";
-}
-
-###################
-# exit the server #
-###################
-sub exit_nicely {
- &logme ("----- SystemDaemon.pl Ended -----\n");
- close (Server);
- close (Log);
- exit 0;
-}
-
-##################
-# socket control #
-##################
-sub listen_for_request {
- BEGIN { $ENV{PATH} = '/usr/bin:/usr/games:/bin' }
-
- my ($port, $proto, $EOL, $iaddr, $paddr, $name, $user);
-
- $user = getpwnam($config{'username'});
-
- $SIG{'CHLD'} = \&child_handler;
- $EOL = "\015\012";
-
- $port = $config{'port'};
- $proto = getprotobyname('tcp');
- $port = $1 if $port =~ /(\d+)/; # untaint port number
-
- socket (Server, PF_INET, SOCK_STREAM, $proto) || die "socket(): $!";
- setsockopt (Server, SOL_SOCKET, SO_REUSEADDR, pack ("l", 1)) || die "setsockopt(): $!";
- bind (Server, sockaddr_in ($port, inet_aton("$config{'ipaddr'}"))) || die "bind(): $!";
-
- $> = $user;
-
- listen (Server, SOMAXCONN) || die "listen(): $!";
-
- &logme("----- SystemDaemon.pl Started on Port: $port -----");
-
- $waitedpid = 0;
-
- for ($waitedpid = 0; ($paddr = accept (Client,Server)) || $waitedpid; $waitedpid = 0, close Client) {
- if ($waitedpid && !$paddr) { next; }
- ($port,$iaddr) = sockaddr_in ($paddr);
- $name = gethostbyaddr ($iaddr, AF_INET);
-
- &logme ("Connection From $name [". inet_ntoa($iaddr) ."] at Port $port");
-
- &spawn_new_child;
- }
-
- #################
- # child handler #
- #################
- sub child_handler {
- $waitedpid = wait;
- }
-
- #########################
- # spawn a child process #
- #########################
- sub spawn_new_child {
- my ($pid, $cmd);
- my $tmp;
-
- if (!defined($pid = fork)) {
- &logme("Cannot fork(): $!");
- return;
- } elsif ($pid) {
- return; # I'm the parent
- }
-
- # else I'm the child -- go spawn
- eval {
- local $SIG{'ALRM'} = sub { select (Log); close(Data); die "Timeout\n"; };
- alarm 15;
- open (Data, ">>&Client") || die "Can't read/write to Client: $!\n";
- select (Data);
-
- &check_network;
-
- select (Log);
- close (Data);
- alarm 0;
- };
-
- close (Client);
- exit;
- }
-}
-
-
-
-############################
-# Main Connection Function #
-############################
-sub check_service {
- my ($host, $port, $label_str, $send_str, $search_str) = @_;
-
- my ($bigbuf, $buf, $time);
-
- printf("%-40s", $label_str);
-
- my $sock = IO::Socket::INET->new( PeerAddr => "$host.sourceforge.net",
- PeerPort => $port,
- Proto => 'tcp',
- Timeout => 5,
- Type => SOCK_STREAM() );
-
- if (!$sock) {
- print "[ FAILED ] Could Not Open Socket\n";
- return;
- }
-
- fcntl($sock, F_SETFL(), fcntl($sock, F_GETFL(), 0) | O_NONBLOCK()) || die "Unable to make socket non-blocking: $!";
-
- if ($sock->send($send_str, 0)) {
- $time = time();
-
- while ($time+5 > time()) {
- $sock->recv($buf, 2048, 0);
- $bigbuf .= $buf;
-
- if ($bigbuf =~ $search_str) {
- print "[ OK ]\n";
- $sock->close();
- return;
- }
- }
-
- $sock->close();
- }
- print "[ FAILED ] Could Not Send to Socket\n";
-
- return;
-}
-
-
-####################################
-# check all the different machines #
-####################################
-sub check_network {
- my $output;
-
- print "\n SourceForge Network Checker\n";
-
- # Webservers
- print "\n";
- foreach (@webservers) {
- &check_service($_, 80, "Checking HTTPD on $_ ", "HEAD HTTP/1.1 200 OK\n\n", "Server");
- }
-
- # Project WebServers
- print "\n";
- foreach (@pwebservers) {
- &check_service($_, 80, "Checking HTTPD on $_ ", "GET / HTTP/1.1\nHost: phpsysinfo.sourceforge.net\n\n", "script that displays information");
- }
-
- # CVS
- print "\n";
- foreach $_ (@cvsservers) {
- &check_service($_, 2401, "Checking CVS on $_ ", "hello\n", "cvs");
- }
-
- # Mail
- print "\n";
- foreach (@mailservers) {
- &check_service($_, 25, "Checking Mail on $_ ", "\n", "ESMTP");
- }
-
- # mysql
- print "\n";
- foreach (@mysqlservers) {
- if ($_ eq 'moby.p') {
- &check_service("vhost2.p", 80, "Checking MySQL on moby.p ", "GET /pager.php3\n", "mysql-good");
- } elsif ($_ eq 'underworld.i') {
- &check_service("bush.i", 80, "Checking MySQL on underworld.i ", "GET /pager.php3\n", "mysql-good");
- }
- }
-
- # pgsql
- print "\n";
- foreach (@pgsqlservers) {
- &check_service($_, 80, "Checking PGSQL on $_ ", "GET /testdb.php3\n", "postgres-good");
- }
-
- # Ping Hosts
- print "\n";
- foreach (@pingservers) {
- printf("%-40s", "Checking PING on $_ ");
- $output = `/bin/ping -c 1 $_.sourceforge.net`;
-
- if($output =~ /time=/){
- print "[ OK ]\n";
- } else {
- print "[ FAILED ]\n";
- }
- }
-}
-
-
-################
-# Main Control #
-################
-&daemon;
-&listen_for_request;
+++ /dev/null
-/* graplite - General execution wRAPper LITE!
- * Copyright (C) 1999 Lion Templin <lion@leonine.com>
- * FILE: graplite.c
- * VERSION : 0.1 (991111)
- *
- * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * GOTO FOREVER!
- *
- * Coded on Northwest Airlines Flight 1065, CHI to MSP
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-/* grap is a wrapper designed to verify commands before passing them to system()
- or just reporting the accepted command. grap will report an error if the
- input is invalid. It checks for string lengths (prevent overflows),
- specific sets of options and commands.
-
- grap, in full force, is called as: <grap> <option> "<command> <arguments
- list ... >" Where <grap> is this program, <option> is an optional trap
- for a single option (like "-e" or "-c" used by programs that call shells,
- subject to the approval list below), <command> is the command wished to
- be run (subject to the approval list below), and <arguments list .. > is
- the list of args passed to <command>. All are optional, allowing for
- forms such as:
- graplite -e "foo" graplite "foo bar" graplite -e "foo -c foo -f bar"
- <g ><o ><cmd> <g > <cmd/args> <g ><o> <cmd/ args >
-
- <options> and <command> need to be exact matched to those in the
- acceptance list.
-*/
-
-/* Define the locations of <option> <command> and <arguements list .. >
- on the command line. 0 is this program, begin at 1. Note that
- ARGS_ARGC takes everything FROM that position to the end of the
- arguments.
-
- Undefine any of these to not use them.
-*/
-
-#define OPTION_ARGC 1
-#define ARGS_ARGC 2
-
-#define ARGS_ARE_SINGLE_STRING
-
-/* Define how the <arguements list .. > is checked.
- define ARGS_ALNUMOK for A-Za-z0-9 to be OK
- define any other chars in the string ARGS_CHAROK
-
- Turn both these off to accept everything.
- WARNING, might be able to bad things with
- shell special chars such as & ; , etc.
-*/
-
-#define MAXSTRLEN 256 /* maximum single string length
- (no max on final command) */
-/* Define what strings are acceptable in <option> */
-char *options[] = { "-c", "-e", NULL };
-
-/* Define what strings are acceptable in <command>
- define an optional execution path CMD_PATH if desired */
-char *commands[] = { "cvs", "server", "svnserve", NULL };
-
-#define MAXARGS 256
-
-/* NO USER SERVICEABLE PARTS BELOW --------------------------------- */
-
-
-#define GRAP_TRUE 1
-#define GRAP_FALSE 0
-#define CMD_POS 0
-
-int main(int argc, char *argv[]) {
-
- int i, j, n, argslen, flag;
- char *buf;
- char **args[MAXARGS];
-
-
- if(argc < 3) {
- /* printf("FATAL: %s bailed because not enough options.\n", argv[0]); */
-
- printf("\nWelcome to GForge SCM\n\n");
- printf("This is a restricted Shell Account\n");
- printf("You cannot execute anything here.\n\n");
-
- exit(1);
- }
-
-
- /* process the initial option (see options array) */
-
- i = -1;
- while((options[++i] != NULL) && strncmp(options[i], argv[OPTION_ARGC], MAXSTRLEN));
- if(options[i] == NULL || strlen(argv[OPTION_ARGC]) > MAXSTRLEN) {
- /* printf("FATAL: %s bailed because options didn't qualify.\n", argv[0]); */
-
- printf("\nWelcome to GForge SCM\n\n");
- printf("This is a restricted Shell Account\n");
- printf("You cannot execute anything here.\n\n");
-
- exit(1);
- }
-
- /* break single command and args string into seperate strings
- in a char** for execvp() to use */
-
- i = 0;
- flag = GRAP_TRUE;
- buf = argv[ARGS_ARGC];
-
- j = CMD_POS;
- n = 0;
-
- while(buf[i] != 0 && j < MAXARGS) {
- if(buf[i] == ' ') {
- buf[i] = 0;
- flag = GRAP_TRUE;
- } else
- if(flag) {
- args[j++] = (char **)&buf[i];
- flag = GRAP_FALSE;
- args[j] = NULL;
- n++;
- }
- i++;
- }
-
- /* check the command to insure it's in the acceptance list */
-
- i = -1;
- while((options[++i] != NULL) && strncmp(commands[i], args[CMD_POS], MAXSTRLEN));
- if(options[i] == NULL || strlen((char *)args[CMD_POS]) > MAXSTRLEN) {
-
- /* printf("FATAL: %s bailed because command didn't qualify.\n", args[CMD_POS]); */
-
- printf("\nWelcome to GForge SCM\n\n");
- printf("This is a restricted Shell Account\n");
- printf("You cannot execute anything here.\n\n");
-
- exit(1);
- }
-
-
- /* ok, the command is clear, exec() it */
-
- execvp((char *)args[CMD_POS], (char **)args);
-
-}
-
+++ /dev/null
-
-/*
- sffingerd.c - SourceForge's crazy little fingerd
- do-anything-you-want-with-it-don't-blame-me-for-anything license.
-
- Mukund <muks@users.sourceforge.net>
- 6th July, 2000
-
- #undef LOG_REQUESTS if you don't wanna log any users requests.
-
- gcc -s -I/path/to/mysql/include -o sffingerd sffingerd.c -L/path/to/mysql/lib/mysql -lmysqlclient
- cp -f sffingerd /usr/local/sbin
-
- MUST BE RUN UNDER inetd
- finger stream tcp nowait nobody /usr/local/sbin/sffingerd fingerd
-
-*/
-
-#define LOG_REQUESTS
-
-#define MYSQL_HOST "localhost" // EDIT THIS
-#define MYSQL_DATABASE "sourceforge"
-#define MYSQL_USER "root"
-#define MYSQL_PASSWORD ""
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <syslog.h>
-#include <time.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <mysql.h>
-
-#ifdef LOG_REQUESTS
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#endif
-
-int main(int argc, char *argv[])
-{
-#ifdef LOG_REQUESTS
- struct sockaddr_in name;
- socklen_t length;
- unsigned long int remote;
- char *remote_ip;
- struct hostent *host;
- char remote_machine[1024];
-#endif
- int l, count;
- char user[256];
- MYSQL mysql, *sock;
- MYSQL_RES *user_result, *group_result;
- MYSQL_ROW user_row, group_row;
- char qbuf[4096];
- time_t addtime;
-
- openlog("sffingerd", (LOG_CONS | LOG_PID), LOG_DAEMON);
-
- if (geteuid() == 0)
- {
- syslog(LOG_ERR, "can't run sffingerd as root");
- fprintf(stderr, "can't run sffingerd as root\n");
- return 1;
- }
-
-#ifdef LOG_REQUESTS
-
- length = sizeof(name);
- if (getpeername(0, (struct sockaddr *) &name, &length) == -1)
- {
- perror("getpeername");
- syslog(LOG_ERR, "getpeername: %m");
- closelog();
- return 0;
- }
-
- if (name.sin_family != AF_INET)
- {
- syslog(LOG_ERR, "connection not from INET family");
- fprintf(stderr, "connection not from INET family\n");
- closelog();
- return 0;
- }
-
- remote = ntohl(name.sin_addr.s_addr);
- remote_ip = inet_ntoa(name.sin_addr);
-
- if ((host = gethostbyaddr((char *) &name.sin_addr,
- sizeof(struct in_addr), AF_INET)) != NULL)
- snprintf(remote_machine, 1023, "%.512s [%.15s]", host->h_name, remote_ip);
- else
- snprintf(remote_machine, 1023, "%.15s [%.15s]", remote_ip, remote_ip);
-#endif
-
- // get the query string - i.e., the username
-
- if (fgets(user, 255, stdin) == NULL)
- {
- syslog(LOG_ERR, "fgets failed - no input string?");
- fprintf(stdout, "fgets failed - no input string?\n");
- closelog();
- return 1;
- }
-
- // strip out the \n and \r at the end of the username
- // in the query and terminate the string there
-
- for (l = 0; user[l]; l++)
- {
- if ((user[l] == '\r') || (user[l] == '\n'))
- {
- user[l] = '\0';
- break;
- }
- }
-
-#ifdef LOG_REQUESTS
- syslog(LOG_INFO, "finger request from host %s for user '%s'", remote_machine, user);
-#endif
-
- fprintf(stdout, "\nWelcome to SourceForge's Finger Service!\n"
- "----------------------------------------\n\n");
-
- // check for valid sourceforge username
- // taken from www/include/account.php -> account_namevalid()
-
- if ((strchr(user, ' ') != NULL) ||
- (strspn(user, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_") != strlen(user)) ||
- (strlen(user) < 3) || (strlen(user) > 15))
- {
- fprintf(stdout, "You have supplied a malformed username for a SourceForge developer.\n"
- "Please try again with a legal username. Thank you.\n\n\n");
- closelog();
- return 0;
- }
-
- // hmm. fine. now connect to the mysql database
- // and check if the user exists.
-
- mysql_init(&mysql);
-
- if ((sock = mysql_real_connect(&mysql, MYSQL_HOST,
- MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE, 0, NULL, 0)) == NULL)
- {
- syslog(LOG_ERR, "unable to connect to the MYSQL database");
- fprintf(stderr, "unable to connect to the MYSQL database\n");
- closelog();
- return 1;
- }
-
- snprintf(qbuf, 4095, "SELECT user_id, user_name, realname, people_view_skills, people_resume, add_date FROM users WHERE user_name='%s'", user);
-
- if (mysql_query(sock, qbuf) != 0)
- {
- syslog(LOG_ERR, "MYSQL SELECT FROM user query failed [%s]", mysql_error(sock));
- fprintf(stderr, "MYSQL SELECT FROM user query failed [%s]\n", mysql_error(sock));
- mysql_close(sock);
- closelog();
- return 1;
- }
-
- if ((user_result = mysql_store_result(sock)) == NULL)
- {
- syslog(LOG_ERR, "mysql_store_result() failed [%s]", mysql_error(sock));
- fprintf(stderr, "mysql_store_result() failed [%s]\n", mysql_error(sock));
- mysql_close(sock);
- closelog();
- return 1;
- }
-
- if ((count = mysql_num_rows(user_result)) > 1)
- {
- syslog(LOG_ERR, "mysql_num_rows() for user '%s' returned more than one record!", user);
- fprintf(stderr, "mysql_num_rows() for user '%s' returned more than one record!\n", user);
- mysql_free_result(user_result);
- mysql_close(sock);
- closelog();
- return 1;
- }
-
- if (count <= 0)
- {
-#ifdef LOG_REQUESTS
- syslog(LOG_ERR, "query for user '%s' from host %s didn't happen. user's unknown here.", user, remote_machine);
-#endif
- fprintf(stdout, "\nThe username you supplied is unknown here. That user does not exist.\n");
- }
- else
- {
- user_row = mysql_fetch_row(user_result);
-
- fprintf(stdout, "\nPersonal Information:\n\n");
- fprintf(stdout, "\tUserID : %s\n\tUsername : %s\n", user_row[0], user_row[1]);
- fprintf(stdout, "\tE-mail : %s@users.sourceforge.net\n\tRealname : %s\n", user_row[1], user_row[2]);
-
- addtime = atoi(user_row[5]);
- fprintf(stdout, "\nMember on SourceForge since %s", ctime(&addtime));
-
- snprintf(qbuf, 4095, "SELECT groups.group_name, groups.group_id, groups.unix_group_name "
- "FROM groups, user_group WHERE user_group.user_id = '%s' AND "
- "groups.group_id = user_group.group_id AND "
- "groups.is_public=1", user_row[0]);
-
- if (mysql_query(sock, qbuf) != 0)
- {
- syslog(LOG_ERR, "MYSQL SELECT FROM groups, user_group query failed [%s]", mysql_error(sock));
- fprintf(stderr, "MYSQL SELECT FROM groups, user_group query failed [%s]\n", mysql_error(sock));
- mysql_free_result(user_result);
- mysql_close(sock);
- closelog();
- return 1;
- }
-
- if ((group_result = mysql_store_result(sock)) == NULL)
- {
- syslog(LOG_ERR, "mysql_store_result() failed [%s]", mysql_error(sock));
- fprintf(stderr, "mysql_store_result() failed [%s]\n", mysql_error(sock));
- mysql_free_result(user_result);
- mysql_close(sock);
- closelog();
- return 1;
-
- }
-
- count = mysql_num_rows(group_result);
-
- if (count <= 0)
- {
- fprintf(stdout, "\n\nThe user does not belong in any groups.\n");
- }
- else
- {
- fprintf(stdout, "\n\nMember of the following groups:\n\n");
-
- while ((group_row = mysql_fetch_row(group_result)) != NULL)
- fprintf(stdout, "\to %s (http://sourceforge.net/projects/%s/)\n", group_row[0], group_row[2]);
- }
-
- mysql_free_result(group_result);
-
- if (atoi(user_row[3]) != 1)
- fprintf(stdout, "\n\nThe user has set his/her profile to private.\n");
- else
- {
- fprintf(stdout, "\n\nProfile follows:\n\n");
- fprintf(stdout, "%s\n\n", user_row[4]);
- }
-
- }
-
- mysql_free_result(user_result);
- mysql_close(sock);
-
- fprintf(stdout, "\n\n---------------------------------------------------------------------\n"
- "For FREE hosting, forums, mailing lists, CVS, shell, db, bug tracking,\n"
- "and more for Open Source projects, come to http://sourceforge.net/\n");
-
- fprintf(stdout, "\n");
-
- closelog();
-
- return 0; // darn_compiler();
-}