ups/0040755000175000017500000000000007566666510011014 5ustar titustitusups/README0100644000175000017500000000426107362522371011662 0ustar titustitus# Licence # 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 the # documentation and/or other materials provided with the distribution. # 3. All advertising materials mentioning features or use of this software # must display the following acknowledgement: # This product includes software developed by Eastern Digital Inc. # 4. Neither the name of the author nor the names of any co-contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY Eastern Digital Inc AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS 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 Eastern Digital Inc OR 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 package provides a daemon that monitors BANATTIKA ups-es. It can sense when power is lost/restored and when battery is low. It can execute a script of your choice on each of these events. It should compile and work without problems on Linux FreeBSD, OpenBSD, NetBSD and other unices. The package provides two binaries : bupsd : the ups monitoring daemon smbbbcast: program to send winpopup messages to workgroup The programs are documented in their manpages bupsd.8 and smbbcast.8 ups/LICENSE0100644000175000017500000000326707362522371012014 0ustar titustitus# Licence # 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 the # documentation and/or other materials provided with the distribution. # 3. All advertising materials mentioning features or use of this software # must display the following acknowledgement: # This product includes software developed by Eastern Digital Inc. # 4. Neither the name of the author nor the names of any co-contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY Eastern Digital Inc AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS 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 Eastern Digital Inc OR 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. # # ups/bupsd_msg.c0100644000175000017500000000343507504401523013124 0ustar titustitus#include char *translate(char *XXX) { if(!strcmp(XXX,"opening config file")) return "Eroare la deschiderea fisierului de configurare"; if(!strcmp(XXX,"Warning : parse error in line %d file %s\n")) return "Atentie: eroare de sintaxa in linia %d, fisierul %s\n"; if(!strcmp(XXX,"\t-d device = serial port|host:port which ups connects to\n")) return "\t-d device = portul serial la care e conectat UPS-ul\n"; if(!strcmp(XXX,"\t-m minutes = minutes to shutdown if power not restored\n")) return "\t-m minutes = timp maxim de functionare pe baterie\n"; if(!strcmp(XXX,"\t-s script = run this script to shutdown (must be +x)\n")) return "\t-s script = executa acest script pentru shutdown\n"; if(!strcmp(XXX,"\t-a script = run this script to warn power down (must be +x)\n")) return "\t-a script = executa acest script cand cade tensiunea\n"; if(!strcmp(XXX,"\t-r script = run this script to warn power restore (must be +x)\n")) return "\t-r script = executa ascest script cand tensiunea revine\n"; if(!strcmp(XXX,"\t-n = dont become a daemon\n")) return "\t-n programul va rula in foreground\n"; if(!strcmp(XXX,"\t-l port = listen on port for remote clients\n")) return "\t-l port = accepta clienti TCP pe portul \n"; if(!strcmp(XXX,"Executing shutdown script")) return "Execut comanda de shutdown"; if(!strcmp(XXX,"Config file")) return "Fisierul de configurare"; if(!strcmp(XXX,"Must specify serial device")) return "Trebuie specifcat dispozitivul serial"; if(!strcmp(XXX,"Device open")) return "Deschidere dispozitiv serial"; if(!strcmp(XXX,"Mains restored")) return "tensiunea a revenit"; if(!strcmp(XXX,"Mains failed, MAX %d minutes remaining")) return "Tensiunea a cazut, au ramas maxim %d minute"; if(!strcmp(XXX,"Mains failed")) return "Tensiunea a cazut"; return XXX; } ups/INSTALL0100644000175000017500000000073007362522371012030 0ustar titustitusThis package provides a daemon that monitors BANATTIKA ups-es It can sense when power is lost/restored and when battery is low It can execute a script of your choice on each of these events Unpack the archive in a directory of your choice Edit the Makefile (you may need to change TARGETDIR, MANDIR and EXAMPLESDIR ) make all install look at the samples in the samples/ directory for usage examples startup scripts are not provided beacuse they are too OS dependend ups/samples/0040755000175000017500000000000007362522372012447 5ustar titustitusups/samples/power-restored.sh0100755000175000017500000000062507362522372015767 0ustar titustitus#!/bin/sh MAIL=/usr/bin/mail SMBBCAST=/usr/local/sbin/smbbcast MY_IP=10.1.1.10 MY_NAME=SERVER WORKGROUP=EDC BROADCAST_ADDR=10.1.1.255 DATE=`/bin/date` HOSTNAME=`/bin/hostname` MESSAGE="$DATE : Power restored on ${HOSTNAME}" SUBJECT="Notice !!!" RECIPIENTS="root titus" echo "$MESSAGE" | $MAIL -s "$SUBJECT" "${RECIPIENTS}" $SMBBCAST -s $MY_IP -S "$MY_NAME" -W "$WORKGROUP" -b $BROADCAST_ADDR "$MESSAGE" ups/samples/upsd.conf0100644000175000017500000000034207362522372014265 0ustar titustitus# sample config file for banattika ups daemon Device = /dev/cuaa1 Shutdown = /usr/local/etc/bupsd/go-down.sh PowerLost = /usr/local/etc/bupsd/power-lost.sh PowerRestored = /usr/local/etc/bupsd/power-restored.sh # timeout = 5 ups/samples/go-down.sh0100755000175000017500000000011607362522372014353 0ustar titustitus#!/bin/sh # No more messages, batteries will fail soon /sbin/shutdown -h now ups/samples/power-lost.sh0100755000175000017500000000062207362522372015116 0ustar titustitus#!/bin/sh MAIL=/usr/bin/mail SMBBCAST=/usr/local/sbin/smbbcast MY_IP=10.1.1.10 MY_NAME=SERVER WORKGROUP=EDC BROADCAST_ADDR=10.1.1.255 DATE=`/bin/date` HOSTNAME=`/bin/hostname` MESSAGE="$DATE : Power failed on ${HOSTNAME}" SUBJECT="Alert !!!" RECIPIENTS="root titus" echo "$MESSAGE" | $MAIL -s "$SUBJECT" "${RECIPIENTS}" $SMBBCAST -s $MY_IP -S "$MY_NAME" -W "$WORKGROUP" -b $BROADCAST_ADDR "$MESSAGE" ups/samples/README0100644000175000017500000000020007362522372013314 0ustar titustitusnotice that on Linux based systems the serial device is /dev/cuaX not /dev/cuaaX, also it is /bin/mail not /usr/bin/mail ups/bupsd.c0100644000175000017500000003057607566666456012316 0ustar titustitus/* Licence 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 the documentation and/or other materials provided with the distribution. 3. All advertising materials mentioning features or use of this software must display the following acknowledgement: This product includes software developed by Eastern Digital Inc. 4. Neither the name of the author nor the names of any co-contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY Eastern Digital Inc AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 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 Eastern Digital Inc OR 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. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define ENG 1 #ifndef LANG #define LANG 1 #endif #if LANG == 1 #define _(X) X #else #include "bupsd_msg.c" #define _(X) translate(X) #endif #define UPS_NORMALOP (TIOCM_CAR | TIOCM_CTS) #define UPS_BATTERYOP (TIOCM_CAR) #define UPS_BATTERYLOW 0 #define UPS_MASK (TIOCM_CAR | TIOCM_CTS) char device[MAXPATHLEN + 1]; int minutes = -1; char script[MAXPATHLEN + 1] = ""; char ascript[MAXPATHLEN + 1] = ""; char rscript[MAXPATHLEN + 1] = ""; char conffile[MAXPATHLEN + 1]; int nodaemon = 0, test = 0, use_tcp = 0; u_short lport = 0, rport = 12223; int i_lport; u_int32_t raddr; int lsock, listening = 0; char *valid_options[] = { "device", "shutdown", "powerlost", "powerrestored", "timeout", "listen" }; int init_listener(void) { struct sockaddr_in sin; int i = 0; if (!lport) { #ifdef DEBUG fprintf(stderr, _("lport invalid")); #endif return -1; } lsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (lsock == -1 ) { #ifdef DEBUG perror(_("ioctl socket")); #endif return -1; } memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_port = htons(lport); sin.sin_addr.s_addr = htonl(INADDR_ANY); if (bind(lsock, (struct sockaddr *)&sin, sizeof(sin))) { #ifdef DEBUG perror(_("bind socket")); #endif close(lsock); return -1; } if (listen(lsock, 32)) { #ifdef DEBUG perror(_("listen socket")); #endif close(lsock); return -1; } if (ioctl(lsock, FIONBIO, &i) < 0) { #ifdef DEBUG perror(_("ioctl listening socket")); #endif close(lsock); return -1; } listening = 1; return 0; } int check_client(int curr_state) { int sock; struct sockaddr_in sacc; int i = 0, cst = 0; fd_set fdsock; struct timeval tv; char buff[32]; tv.tv_sec = 2; tv.tv_usec = 0; switch (curr_state) { case UPS_NORMALOP: cst = 0;break; case UPS_BATTERYOP: cst = 1;break; case UPS_BATTERYLOW: cst = 2;break; default: cst = 0; } FD_ZERO(&fdsock); FD_SET(lsock, &fdsock); if (select(lsock + 1, &fdsock, NULL, NULL, &tv) < 1 ) { #ifdef DEBUG perror(_("select socket accept")); #endif return -1; } if ((sock = accept(lsock, (struct sockaddr *)&sacc ,&i)) == -1 ) { #ifdef DEBUG perror(_(" socket accept")); #endif return -1; } i = fork(); if (i < 0) { close(sock); return -1; } if (i > 0) { close(sock); return 0; } if (i == 0 ) { sprintf(buff,"%d", cst); send(sock, buff, 1, 0); sleep(1); exit(0); } return 0; } int check_host(char *host_port) { char host[256]; char *p; struct hostent *h; unsigned port; if (strlen(host_port) > 256 ) return -1; if ((p = strchr(host_port, ':')) == NULL ) return -2; *p = ' '; if ( 2 != sscanf(host_port, "%s %d", host, &port)) return -1; if (port > 65535 || port < 1) return -3; rport = port; if((raddr = inet_addr(host)) != INADDR_NONE) return 0; h = gethostbyname(host); if(!h) return -4; raddr = ((struct in_addr *)h->h_addr)->s_addr; return 0; } int get_remote_stat(int prevstate) { int sock; struct sockaddr_in sin; int i = 0; fd_set fdsock; struct timeval tv; char buff[30] = ""; tv.tv_sec = 3; tv.tv_usec = 0; sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (sock == -1) { #ifdef DEBUG perror(_("socket")); #endif return prevstate; } if(ioctl(sock,FIONBIO,&i) == -1) { #ifdef DEBUG perror(_("ioctl socket")); #endif close(sock); return prevstate; } memset(&sin, 0, sizeof(sin)); sin.sin_port = htons(rport); sin.sin_family = AF_INET; sin.sin_addr.s_addr = raddr; FD_ZERO(&fdsock); FD_SET(sock, &fdsock); i = connect(sock, (struct sockaddr *)&sin , sizeof(sin)); if (select(sock + 1, NULL, &fdsock, NULL, &tv) < 1 ) { #ifdef DEBUG perror(_("select socket connect")); #endif close(sock); return prevstate; } FD_ZERO(&fdsock); FD_SET(sock, &fdsock); if (select(sock + 1, &fdsock, NULL, NULL, &tv) < 1 ) { #ifdef DEBUG perror(_("select socket read")); #endif close(sock); return prevstate; } i = recv(sock,buff,1,0); close(sock); if (i < 1) { #ifdef DEBUG perror(_("recv")); #endif return prevstate; } switch (buff[0]) { case '0': return UPS_NORMALOP; case '1': return UPS_BATTERYOP; case '2': return UPS_BATTERYLOW; default: return prevstate; } } int parseconf(char *conffile) { FILE *fconf; char line[256], *eq, option[256], value[256]; int i, linenr = 0; fconf = fopen(conffile, _("r")); if (!fconf) { perror(_("opening config file")); return -1; } while (fgets(line, 255, fconf)) { linenr++; if (line[0] == '#' || line[0] == '\n' || line[0] == '\r') continue; eq = strchr(line, '='); if (!eq) { fprintf(stderr, _("Warning : parse error in line %d file %s\n"), linenr, conffile); continue; } *eq = 0; eq++; sscanf(line, _("%s"), option); while (isspace(*eq) && (*eq)) eq++; strcpy(value, eq); eq = strchr(value, '\n'); if (eq) *eq = 0; for (i = 0; i < strlen(option); i++) option[i] = tolower(option[i]); for (i = 0; i < sizeof(valid_options) / sizeof(char *); i++) { if (!strcmp(valid_options[i], option)) { #ifdef DEBUG printf(_("#%s#%s\n"), option, value); #endif switch (i) { case 0: if(strlen(device)) break; strcpy(device, value); break; case 1: if(strlen(script)) break; strcpy(script, value); break; case 2: if(strlen(ascript)) break; strcpy(ascript, value); break; case 3: if(strlen(rscript)) break; strcpy(rscript, value); break; case 4: if (minutes != -1) break; sscanf(value, _("%d"), &minutes); break; case 5: if (lport != 0) break; sscanf(value, _("%d"), &i_lport); lport = (u_short)i_lport; break; } /* switch */ } } /* for i */ } fclose(fconf); return 0; } int fatal(char *s) { fputs(s, stderr); exit(-1); } int usage(char *s) { fprintf(stderr, "%s [-f conffile] [-t] [-n] -d [-m minutes] [-s script] \ [-r script] [-a script ] [-l port]\n", s); fprintf(stderr, _("\t-d device = serial port|host:port which ups connects to\n")); fprintf(stderr, _("\t-m minutes = minutes to shutdown if power not restored\n")); fprintf(stderr, _("\t-s script = run this script to shutdown (must be +x)\n")); fprintf(stderr, _("\t-a script = run this script to warn power down (must be +x)\n")); fprintf(stderr, _("\t-r script = run this script to warn power restore (must be +x)\n")); fprintf(stderr, _("\t-n = dont become a daemon\n")); fprintf(stderr, _("\t-l port = listen on port for remote clients\n")); fprintf(stderr, _("\t-t = test\n")); exit(1); } void sigalarm(int param) { syslog(LOG_ALERT, _("Executing shutdown script")); system(script); } int main(int argc, char **argv) { int fd, iorv, comstat, prevstate = UPS_NORMALOP, tmp; int ch; char *pname = argv[0]; sigset_t sigset; struct sigaction sa_old, sa_new; if (argc < 2) usage(pname); openlog(pname, LOG_PID, LOG_DAEMON); while ((ch = getopt(argc, argv, _("tnd:f:m:s:a:r:l:"))) != -1) { switch (ch) { case 't': test = 1; case 'n': nodaemon = 1; break; case 'd': strncpy(device, optarg, sizeof(device) - 1); break; case 's': strncpy(script, optarg, sizeof(script) - 1); break; case 'a': strncpy(ascript, optarg, sizeof(ascript) - 1); break; case 'r': strncpy(rscript, optarg, sizeof(rscript) - 1); break; case 'm': minutes = atoi(optarg); break; case 'l': lport = atoi(optarg); break; case 'f': strncpy(conffile, optarg, sizeof(conffile) - 1); break; default: usage(pname); break; } } if(strlen(conffile)) if (parseconf(conffile)) { perror(_("Config file")); exit(1); } if (!strlen(device)) fatal(_("Must specify serial device")); if (access(ascript,R_OK|X_OK)) { fprintf(stderr,_("Error reading power-lost script %s\n%s\n"), ascript,strerror(errno)); exit(1); } if (access(rscript,R_OK|X_OK)) { fprintf(stderr,_("Error reading power-restored script %s\n%s\n"), rscript,strerror(errno)); exit(1); } if (access(script,R_OK|X_OK)) { fprintf(stderr,_("Error reading shutdown script %s\n%s\n"), script,strerror(errno)); exit(1); } /* printf("%d \n",minutes);exit(1); */ if (device[0] == '/') { fd = open(device, O_RDONLY); if (fd == -1) { perror(_("Device open")); exit(1); } } else { if (check_host(device) < 0) { fprintf(stderr,_("Invalid host:port specification")); exit(1); } #ifdef DEBUG { struct in_addr ina; ina.s_addr = raddr; printf("%s %d\n", inet_ntoa(ina), rport); } #endif use_tcp = 1; } if (!nodaemon) { ioctl(0, TIOCNOTTY); if (fork()) exit(1); } if (nodaemon) openlog(pname, LOG_PERROR | LOG_PID, LOG_DAEMON); else openlog(pname, LOG_PID, LOG_DAEMON); sigemptyset( &sigset ); sa_new.sa_mask = sigset; sa_new.sa_flags = 0; sa_new.sa_handler = sigalarm; sigaction(SIGALRM, &sa_new,&sa_old); if (lport) init_listener(); while (1) { if (!use_tcp) { iorv = ioctl(fd, TIOCMGET, &comstat); if (iorv == -1) { fprintf(stderr, _("ioctl")); exit(1); } } if (test) { printf(_("%08x\n"), comstat); fflush(stdout); test++; if (test > 300000) exit(1); } comstat &= UPS_MASK; if( use_tcp ) comstat = get_remote_stat(prevstate); if (listening) check_client(comstat); sleep(5); if (test || comstat == prevstate) continue; switch (comstat) { case UPS_NORMALOP: syslog(LOG_ALERT, _("Mains restored")); alarm(0); system(rscript); break; case UPS_BATTERYOP: if (prevstate == UPS_NORMALOP) { system(ascript); if (minutes > 0) { alarm(minutes * 60); tmp = alarm(1000); syslog(LOG_ALERT, _("Mains failed, MAX %d minutes remaining"), tmp / 60); alarm(tmp); } else syslog(LOG_ALERT, _("Mains failed")); } break; case UPS_BATTERYLOW: sigalarm(0); } prevstate = comstat; } return 0; } ups/smbbcast.c0100644000175000017500000001424207362522372012745 0ustar titustitus/* Licence 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 the documentation and/or other materials provided with the distribution. 3. All advertising materials mentioning features or use of this software must display the following acknowledgement: This product includes software developed by Eastern Digital Inc. 4. Neither the name of the author nor the names of any co-contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY Eastern Digital Inc AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 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 Eastern Digital Inc OR 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. */ #include #include #include #include #include #include #include #include #include #include #include #define ENG 1 #ifndef LANG #define LANG 1 #endif #if LANG == 1 #define _(X) X #else #include "smbbcast_msg.c" #define _(X) translate(X) #endif char * make_nmb_name(const char *in, char *out) { int i; int c; char buf[15]; char *p = out; (void) memset(buf, 0x20, 15); if (strcmp(in, "*") == 0) { (void) memset(buf, 0, 15); buf[0] = '*'; } else { memcpy(buf, in, strlen(in)); buf[15] = '\0'; } p[0] = 32; p++; for (i = 0; i < 16; i++) { c = toupper(buf[i]); p[i * 2] = ((c >> 4) & 0x000F) + 'A'; p[(i * 2) + 1] = (c & 0x000F) + 'A'; } p += 32; p[0] = '\0'; return out; } int bcast_msg(char *dest_name, char *dest_ip, char *src_name, char *src_ip, char *msg) { int total_len = 173 + strlen(msg) + strlen(src_name) + strlen(dest_name); char pop[total_len], nmb1[35], nmb2[35]; char *p = pop; u_int32_t my_ip, his_ip; int checksum, checksum2; int sock, opt = 1; struct sockaddr_in sin, sin_to; memset(pop, 0, total_len); my_ip = inet_addr(src_ip); his_ip = inet_addr(dest_ip); p[0] = 0x11; p[1] = 02; p[3] = 0x56; p += 4; p[0] = my_ip; p[1] = (my_ip >> 8); p[2] = (my_ip >> 16); p[3] = (my_ip >> 24); p[5] = 0x8a; //port 138 p += 6; checksum = total_len - 14; p[1] = checksum; if (checksum > 255) p[0] = (checksum >> 8); p += 4; memcpy(&p[0], make_nmb_name(src_name, nmb1), 33); memcpy(pop + 48, make_nmb_name(dest_name, nmb2), 33); p += 68; p[0] = 0xff; p[1] = 0x53; p[2] = 0x4d; p[3] = 0x42; p[4] = 0x25; p[24] = 0xff; p[25] = 0xff; p[28] = 0xff; p[29] = 0xff; p[32] = 0x11; checksum2 = strlen(src_name) + strlen(dest_name) + strlen(msg) + 3; p[35] = checksum2; if (checksum2 > 255) p[36] = (checksum2 >> 8); p[43] = 0x02; p[53] = 0x58; p[55] = checksum2; if (checksum2 > 255) p[56] = (checksum2 >> 8); p[57] = 0x58; p[59] = 0x03; p[61] = 0x01; p[65] = 0x02; checksum2 += 19; p[67] = checksum2; if (checksum2 > 255) p[68] = (checksum >> 8); memcpy(&p[69], "\\MAILSLOT\\MESSNGR", 17); memcpy(&p[88], src_name, strlen(src_name)); memcpy(&p[89 + strlen(src_name)], dest_name, strlen(dest_name)); memcpy(&p[90 + strlen(src_name) + strlen(dest_name)], msg, strlen(msg)); sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); memset(&sin, 0, sizeof(sin)); memset(&sin_to, 0, sizeof(sin_to)); sin.sin_family = AF_INET; sin.sin_port = htons(138); sin.sin_addr.s_addr = my_ip; sin_to.sin_family = AF_INET; sin_to.sin_port = htons(138); sin_to.sin_addr.s_addr = his_ip; setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &opt, sizeof(opt)); if (bind(sock, (struct sockaddr *) & sin, sizeof(sin)) < 0) { if (errno != EADDRINUSE) { perror("Bind"); return -1; } } if (sendto(sock, pop, sizeof(pop), 0, (struct sockaddr *) & sin_to, sizeof(sin_to)) < 0) { perror("sendto"); return -1; } return 0; } int usage(char *s) { fprintf(stderr, _("%s -s -S -b brodcast addr -W workgroup message\n"), s); fprintf(stderr, _("\t-s IP addr = local ethernet ip \n")); fprintf(stderr, _("\t-S = local NETBIOS name \n")); fprintf(stderr, _("\t-b broadcast addr = broadcast address for the IP specified with -s\n")); fprintf(stderr, _("\t-W workgroup = workgroup to send message to\n")); fprintf(stderr, _("\t message = Message to send\n")); exit(1); } int main(int argc, char **argv) { char *pname = argv[0]; char my_ip[32],my_name[256],wgrp[16],bcast[32]; int ch; if (argc < 4) usage(pname); memset(my_ip, 0, sizeof(my_ip)); memset(my_name, 0, sizeof(my_name)); memset(wgrp, 0, sizeof(wgrp)); memset(bcast, 0, sizeof(bcast)); while ((ch = getopt(argc, argv, "s:S:b:W:")) != -1) { switch (ch) { case 's': strncpy(my_ip, optarg, sizeof(my_ip) - 1); break; case 'S': strncpy(my_name, optarg, sizeof(my_name) - 1); break; case 'W': strncpy(wgrp, optarg, sizeof(wgrp) - 1); break; case 'b': strncpy(bcast, optarg, sizeof(bcast) - 1); break; default: usage(pname); break; } } if ( !strlen(my_ip) || !strlen(my_name) || !strlen(wgrp) || !strlen(bcast) || optind != argc -1) usage(pname); return bcast_msg(wgrp,bcast,my_name,my_ip,argv[optind]); } ups/README.rom0100644000175000017500000000105207362522372012452 0ustar titustitusPentru a compila programul cu mesaje si help in limba romana make XLANG=RO all install Acest program este un serviciu de monitorizare pt UPS-urile produse de BANATTIKA srl. Programul monitorizeaza portul serial specificat si executa un script corespunzator evenimentelor detectate. Programul ar trebui sa se compileze si sa functioneze pe *BSD si Linux. Pachetul contine doua programe : bupsd: servicul de monitorizare al UPS smbbcast: program de transmis mesaje la statiile windows Cele doua programe sunt documentate in bupsd(8) si smbbcast(8). ups/bupsd.po0100644000175000017500000000737507504400773012467 0ustar titustitus#: bupsd.c:92 msgid "device" msgstr "" #: bupsd.c:92 msgid "shutdown" msgstr "" #: bupsd.c:92 msgid "powerlost" msgstr "" #: bupsd.c:93 msgid "powerrestored" msgstr "" #: bupsd.c:93 msgid "timeout" msgstr "" #: bupsd.c:93 msgid "listen" msgstr "" #: bupsd.c:105 msgid "lport invalid" msgstr "" #: bupsd.c:113 bupsd.c:252 msgid "ioctl socket" msgstr "" #: bupsd.c:124 msgid "bind socket" msgstr "" #: bupsd.c:131 msgid "listen socket" msgstr "" #: bupsd.c:139 msgid "ioctl listening socket" msgstr "" #: bupsd.c:176 msgid "select socket accept" msgstr "" #: bupsd.c:182 msgid " socket accept" msgstr "" #: bupsd.c:197 bupsd.c:360 #, c-format msgid "%d" msgstr "" #: bupsd.c:218 #, c-format msgid "%s %d" msgstr "" #: bupsd.c:246 msgid "socket" msgstr "" #: bupsd.c:266 msgid "select socket connect" msgstr "" #: bupsd.c:275 msgid "select socket read" msgstr "" #: bupsd.c:285 msgid "recv" msgstr "" #: bupsd.c:308 msgid "r" msgstr "" #: bupsd.c:310 msgid "opening config file" msgstr "Eroare la deschiderea fisierului de configurare" #: bupsd.c:319 #, c-format msgid "Warning : parse error in line %d file %s\n" msgstr "Atentie: eroare de sintaxa in linia %d, fisierul %s\n" #: bupsd.c:325 #, c-format msgid "%s" msgstr "" #: bupsd.c:338 #, c-format msgid "#%s#%s\n" msgstr "" #: bupsd.c:380 #, c-format msgid "" "%s [-f conffile] [-t] [-n] -d [-m minutes] [-s script] \t[-r " "script] [-a script ] [-l port]\n" msgstr "" #: bupsd.c:382 #, fuzzy msgid "\t-d device = serial port|host:port which ups connects to\n" msgstr "\t-d device = portul serial la care e conectat UPS-ul\n" #: bupsd.c:383 msgid "\t-m minutes = minutes to shutdown if power not restored\n" msgstr "\t-m minutes = timp maxim de functionare pe baterie\n" #: bupsd.c:384 msgid "\t-s script = run this script to shutdown (must be +x)\n" msgstr "\t-s script = executa acest script pentru shutdown\n" #: bupsd.c:385 msgid "\t-a script = run this script to warn power down (must be +x)\n" msgstr "\t-a script = executa acest script cand cade tensiunea\n" #: bupsd.c:386 msgid "\t-r script = run this script to warn power restore (must be +x)\n" msgstr "\t-r script = executa ascest script cand tensiunea revine\n" #: bupsd.c:387 #, fuzzy msgid "\t-n = dont become a daemon\n" msgstr "\t-n programul va rula in foreground\n" #: bupsd.c:388 msgid "\t-l port = listen on port for remote clients\n" msgstr "\t-l port = accepta clienti TCP pe portul \n" #: bupsd.c:389 msgid "\t-t = test\n" msgstr "" #: bupsd.c:396 msgid "Executing shutdown script" msgstr "Execut comanda de shutdown" #: bupsd.c:412 msgid "tnd:f:m:s:a:r:l:" msgstr "" #: bupsd.c:447 msgid "Config file" msgstr "Fisierul de configurare" #: bupsd.c:451 msgid "Must specify serial device" msgstr "Trebuie specifcat dispozitivul serial" #: bupsd.c:454 #, c-format msgid "" "Error reading power-lost script %s\n" "%s\n" msgstr "" "Nu pot citi scriptul pt pierderea tensiunii %s\n" "%s\n" #: bupsd.c:460 #, c-format msgid "" "Error reading power-restored script %s\n" "%s\n" msgstr "" "Nu pot citi scriptul pt revenirea tensiunii %s\n" "%s\n" #: bupsd.c:466 #, c-format msgid "" "Error reading shutdown script %s\n" "%s\n" msgstr "" "Nu pot citi scriptul de shutdown %s\n" "%s\n" #: bupsd.c:474 msgid "Device open" msgstr "Deschidere dispozitiv serial" #: bupsd.c:479 msgid "Invalid host:port specification" msgstr "" #: bupsd.c:486 #, c-format msgid "%s %d\n" msgstr "" #: bupsd.c:512 msgid "ioctl" msgstr "" #: bupsd.c:517 #, c-format msgid "%08x\n" msgstr "" #: bupsd.c:534 msgid "Mains restored" msgstr "tensiunea a revenit" #: bupsd.c:544 #, c-format msgid "Mains failed, MAX %d minutes remaining" msgstr "Tensiunea a cazut, au ramas maxim %d minute" #: bupsd.c:547 msgid "Mains failed" msgstr "Tensiunea a cazut" ups/makeh.awk0100644000175000017500000000077707362522373012605 0ustar titustitusBEGIN { print "#include \n" print "char *translate(char *XXX) {\n" } { if ( $1 == "msgid" ) { str = substr($0,7); do { getline if ( $1 == "msgstr") break; str = str "\n" $0 } while (1) if ( $1 == "msgstr") { newstr = substr($0,8); if ( length(newstr) < 3) next; while ( 1 ) { x = getline if ( substr($0,1,1)!= "\"" ) break; if ( !x ) break; newstr = newstr "\n" $0 } print "if(!strcmp(XXX," str ")) return " newstr ";"; } } } END { print "return XXX;\n}\n" }ups/Makefile0100644000175000017500000000540307504401522012431 0ustar titustitus# Licence # 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 the # documentation and/or other materials provided with the distribution. # 3. All advertising materials mentioning features or use of this software # must display the following acknowledgement: # This product includes software developed by Eastern Digital Inc. # 4. Neither the name of the author nor the names of any co-contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY Eastern Digital Inc AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS 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 Eastern Digital Inc OR 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. # # CC = cc CFLAGS = -Wall -DDEBUG TARGETDIR = /usr/local/sbin MANDIR = /usr/local/man/man8 MANPAGES = bupsd.8.gz smbbcast.8.gz BINARIES = smbbcast bupsd EXAMPLESDIR = /usr/local/share/examples/bupsd XLANG?=ENG all: $(BINARIES) $(MANPAGES) smbbcast:smbbcast.c smbbcast_msg.c cc $(CFLAGS) -DLANG=$(XLANG) -o smbbcast smbbcast.c bupsd:bupsd.c bupsd_msg.c cc $(CFLAGS) -DLANG=$(XLANG) -o bupsd bupsd.c bupsd.8.gz:$(XLANG)/bupsd.8 gzip -c $(XLANG)/bupsd.8 >bupsd.8.gz smbbcast.8.gz:$(XLANG)/smbbcast.8 gzip -c $(XLANG)/smbbcast.8 >smbbcast.8.gz clean: rm -f bupsd smbbcast *.core *.o *.8.gz a.out install:all install -c -m 755 -g 0 -o root bupsd $(TARGETDIR) install -c -m 755 -g 0 -o root smbbcast $(TARGETDIR) install -c -m 644 -g 0 -o root bupsd.8.gz $(MANDIR) install -c -m 644 -g 0 -o root smbbcast.8.gz $(MANDIR) install -d -m 755 -o root -g 0 $(EXAMPLESDIR) install -c -m 644 -g 0 -o root samples/* $(EXAMPLESDIR) chmod +x $(EXAMPLESDIR)/*.sh bupsd_msg.c:bupsd.po awk -f makeh.awk < bupsd.po > bupsd_msg.c smbbcast_msg.c: awk -f makeh.awk < smbbcast.po > smbbcast_msg.c ups/RO/0040755000175000017500000000000007504544523011323 5ustar titustitusups/RO/smbbcast.80100644000175000017500000000613107362522373013211 0ustar titustitus.\" Copyright (c) [2001] [Eastern Digital Inc] .\" 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 the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS 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 AUTHOR OR 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. .\" .\" $FreeBSD: src/share/examples/mdoc/example.1,v 1.10.2.1 1999/12/12 17:41:56 mpp Exp $ .\" Note: All FreeBSD man pages should have a FreeBSD revision .\" control id to make it easier for translation teams to track .\" changes. .\" .\" Note: The date here should be updated whenever a non-trivial .\" change is made to the manual page. .Dd August 14, 2001 .Dt smbbcast 8 .\" Note: Only specify the operating system when the command .\" is FreeBSD specific, otherwise use the .Os macro with no .\" arguments. .Os Unix .Sh NAME .Nm smbbcast .Nd smbbcast manual page .Sh SYNOPSIS .Nm smbbcast .Fl s Ar my_ip .Fl S Ar my_netbios_name .Fl b Ar broadcast_address .Fl W Ar workgroup .Ar message .Sh DESCRIPTION .Nm este un program insotitor pentru bupsd(8). Scopul lui este de a transmite mesaje stil "Winpopup" la statiile de lucru care ruleaza Windows(tm) si sunt conectate la serverul UNIX. .Pp Optiunile sunt urmatoarele: .Bl -tag -width Fl .It Fl s Ar my_ip Specifica adresa IP sursa a mesajelor. Aceasta adresa trebuie sa fie adresa IP a uneia dintre placile de retea a calculatorului pe care .Nm ruleaza. .It Fl S Ar my_netbios_name Specifica numele NETBIOS al calculatorului. Destinatarii mesajului vor vedea acest nume la adresa expeditorului. .It Fl b Ar broadcast_address Adresa de broadcast a subretelei pe care adresa IP specificata cu -s se afla. .It Fl W Ar workgroup Numele "workgroup"-ului destinatar .It Ar message Mesajul care va fi trimis. .El Exemplu de folosire: .Pp smbbcast -s 10.1.1.1 -S SERVER -W WORKGROUP -b 10.1.1.255 \\ "Power failed. Please save your work." .Pp .Nm trebuie sa ruleze ca "root" deoarece portul sursa al mesajelor trebuie sa fie 138 ( < 1024). .Sh AUTHORS Aceasta pagina a fost scrisa de .An Titus Manea Aq titus@2edc.com . ups/RO/bupsd.80100644000175000017500000001356407566666256012557 0ustar titustitus.\" Copyright (c) [2001] [Eastern Digital Inc] .\" 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 the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS 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 AUTHOR OR 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. .\" .\" $FreeBSD: src/share/examples/mdoc/example.1,v 1.10.2.1 1999/12/12 17:41:56 mpp Exp $ .\" Note: All FreeBSD man pages should have a FreeBSD revision .\" control id to make it easier for translation teams to track .\" changes. .\" .\" Note: The date here should be updated whenever a non-trivial .\" change is made to the manual page. .Dd Iunie 21, 2002 .Dt bupsd 8 .\" Note: Only specify the operating system when the command .\" is FreeBSD specific, otherwise use the .Os macro with no .\" arguments. .Os Unix .Sh NAME .Nm bupsd .Nd bupsd manual page .Sh SYNOPSIS .Nm bupsd .Op Fl n .Op Fl t .Op Fl d Ar device .Op Fl l Ar port .Op Fl f Ar config file .Op Fl a Ar ascript .Op Fl r Ar rscript .Op Fl s Ar sscript .Op Fl m Ar timeout .Sh DESCRIPTION .Nm este un program de monitorizare a UPS-urilor BANATTIKA(tm) . Programul citeste starea portului serial specificat si ruleaza diferite comenzi pentru urmatoarele evenimente. - caderea tensiune - revenirea tensiunii - descarcarea bateriei .Pp Optiunile sunt urmatoarele: .Bl -tag -width Fl .It Fl n .Nm nu se va detasa de terminalul sau si va rula in foreground. .It Fl t .Nm va rula in mod test si nu va executa nici un script. Folosit pentru debug. .It Fl d Ar device Specifica portul serial sau adresa calculatorului la care este conectat UPS-ul.Acest parametru trebuie sa fie prezent in linia de comanda sau in fisierul de configurare. Daca portul este specificat in format /dev/DEVICE sau incepe cu '/' va fii interpretat ca un port serial. Daca este speificat in formatul host:port atunci va fii considerat ca adresa IP a unui calculator pe care se afla UPS si ruleaza acest program. .It Fl l Ar port .Nm va asculta si va raspunde clientilor TCP pe acest port. .It Fl a Ar ascript Specifica numele unei comenzi externe care se va executa cand tensiunea de la retea cade. Comanda trebuie sa fie executabila prin system(3) si va rula cu aceleasi drepturi cu care ruleaza si bupsd. .Nm nu va porni daca acest fisier nu e citibil si executabil de userul care a executat bupsd. Acest parametru trebuie specificat in linia de comanda sau in fisierul de configuare .It Fl r Ar rscript Specifica numele unei comenzi externe care se va executa cand tensiunea de la retea revine dupa o cadere. Comanda trebuie sa fie executabila prin system(3) si va rula cu aceleasi drepturi cu care ruleaza si bupsd. .Nm nu va porni daca acest fisier nu e citibil si executabil de userul care a executat bupsd. Acest parametru trebuie specificat in linia de comanda sau in fisierul de configuare .It Fl s Ar sscript Specifica numele unei comenzi externe care se va executa cand UPS semnalizeaza ca bateria e descarcata sau timpul maxim de lucru pe baterie a expirat. Comanda trebuie sa fie executabila prin system(3) si va rula cu aceleasi drepturi cu care ruleaza si bupsd. .Nm nu va porni daca acest fisier nu e citibil si executabil de userul care a executat bupsd. Acest parametru trebuie specificat in linia de comanda sau in fisierul de configuare .It Fl m Ar timeout Scriptul specificat cu -s va rula dupa "timeout" minute de functionare pe baterie chiar daca UPS nu a semnalizat ca bateria este descarcata. Acest parametru este optional. In mod normal scriptul pentru oprirea sistemului se va executa doar cand UPS va semnala descarcarea bateriei. .It Fl f Ar config_file .Nm Se vor folosi datele din fisierul de configurare specificat. Aceste valori sunt suprascrise de valorile din linia de comanda daca parametrul respectiv e specificat in ambele locuri. Formatul fisierului este parametru = valoare Liniile goale sau care incep cu diez `#' sunt ignorate. Parametrii recunoscuti sunt urmatorii: .It Ar Device : acelasi lucru cu -d device in linia de comanda .It Ar Shutdown : acelasi cu -s script in linia de comanda .It Ar PowerLost : same as -a command line option .It Ar PowerRestored : acelasi lucru cu -r in linia de comanda .It Ar Timeout :acelasi lucru cu -m in linia de comanda .It Ar Listen :acelasi lucru cu -l in linia de comanda .El Exemplu de folosire .Nm command: .Pp bupsd -d /dev/cuaa0 -a /usr/local/etc/power-lost.sh -r /usr/local/etc/power-restored.sh -s /usr/local/etc/down.sh bupsd -f /usr/local/etc/bupsd.conf Exemplu de fisier de configurare: .Pp device = /dev/cuaa1 shutdown = /etc/bupsd/shutdown.sh powerlost = /etc/bupsd/power-lost.sh powerrestored = /etc/bupsd/power-restored.sh #timeout = 5 .Sh DIAGNOSTICS Programul va scrie cate un mesaj in logul sistemului pt fiecare eveniment, dupa care va executa scriptul aferent. .Sh AUTHORS Aceast pagina a fost scrisa de .An Titus Manea Aq titus@2edc.com . ups/smbbcast.po0100644000175000017500000000160007362522373013134 0ustar titustitus #: smbbcast.c:173 msgid "Bind" msgstr "" #: smbbcast.c:178 msgid "sendto" msgstr "" #: smbbcast.c:187 #, c-format msgid "" "%s -s -S -b brodcast addr -W workgroup message\n" msgstr "" #: smbbcast.c:188 msgid "\t-s IP addr = local ethernet ip \n" msgstr "\t-s IP addr = Adresa IP al cartelei de retea \n" #: smbbcast.c:189 msgid "\t-S = local NETBIOS name \n" msgstr "\t-S = Numele NETBIOS al calculatorului \n" #: smbbcast.c:190 msgid "\t-b broadcast addr = broadcast address for the IP specified with -s\n" msgstr "\t-b broadcast addr = Adresa de broadcast pentru IP specificat cu -s\n" #: smbbcast.c:191 msgid "\t-W workgroup = workgroup to send message to\n" msgstr "\t-W workgroup = workgroup destinatie\n" #: smbbcast.c:192 msgid "\t message = Message to send\n" msgstr "\t message = Mesajul de transmis\n" #: smbbcast.c:211 msgid "s:S:b:W:" msgstr "" ups/ENG/0040755000175000017500000000000007504544517011417 5ustar titustitusups/ENG/bupsd.80100644000175000017500000001321307566666304012631 0ustar titustitus.\" Copyright (c) [2001] [Eastern Digital Inc] .\" 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 the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS 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 AUTHOR OR 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. .\" .\" $FreeBSD: src/share/examples/mdoc/example.1,v 1.10.2.1 1999/12/12 17:41:56 mpp Exp $ .\" Note: All FreeBSD man pages should have a FreeBSD revision .\" control id to make it easier for translation teams to track .\" changes. .\" .\" Note: The date here should be updated whenever a non-trivial .\" change is made to the manual page. .Dd June 21, 2002 .Dt bupsd 8 .\" Note: Only specify the operating system when the command .\" is FreeBSD specific, otherwise use the .Os macro with no .\" arguments. .Os Unix .Sh NAME .Nm bupsd .Nd bupsd manual page .Sh SYNOPSIS .Nm bupsd .Op Fl n .Op Fl t .Op Fl d Ar device .Op Fl l Ar port .Op Fl f Ar config file .Op Fl a Ar ascript .Op Fl r Ar rscript .Op Fl s Ar sscript .Op Fl m Ar timeout .Sh DESCRIPTION .Nm is the BANATTIKA(tm) UPS monitoring daemon. It monitors the specified serial line and it runs a specified script for the folowing actions - power failed - power restored - battery low .Pp The options are as follows: .Bl -tag -width Fl .It Fl n The software will not detach from its controlling tty and will run in foreground. .It Fl t Run in test mode, dont execute any scripts (intended for debugging). .It Fl d Ar device Specifies the serial port device or remote host which the ups is connected to. This parameter must be present either on command line or the config file. If the parameter is specified as /dev/DEVICE or starts with a slash '/' it will be considered as a serial device. A remote host should be specified as host:port. .It Fl l Ar port .Nm will listen for remote clients on the specified port. It will bind on all available interfaces. Remote clients can connect and read the ups status from this machine. .It Fl a Ar ascript Specifies the command the daemon should execute when the power fails. The command should be executable by system(3) and will run as the same user as bupsd is ran. This parameter must be present either on command line or the config file. .Nm will fail to start if the file specified by this option is not readable and executable by the user under which the daemon runs. .It Fl r Ar rscript Specifies the command the daemon should execute when the power is restored. The command should be executable by system(3) and will run as the same user as bupsd is ran. This parameter must be present either on command line or the config file. .Nm will fail to start if the file specified by this option is not readable and executable by the user under which the daemon runs. .It Fl s Ar sscript Specifies the command the daemon should execute when battery is low or a specified period of time has elapsed since power failed. The command should be executable by system(3) and will run as the same user bupsd is ran. This parameter must be present either on command line or the config file. .Nm will fail to start if the file specified by this option is not readable and executable by the user under which the daemon runs. .It Fl m Ar timeout Invoke shutdown script after Ar minutes since the power failed. The shutdown script will run either when battery low is signaled or after Ar minutes have elapsed, which event happens first. .It Fl f Ar config_file .Nm will use values in the specified config file. Values in the .Ar config file are overriden by command line parameters. The config file format is as follows parameter = value. Lines that begin with a pound `#' or are empty will be ignored. The recognized parameters are: .It Ar Device : same as -d command line option .It Ar Shutdown : same as -s command line option .It Ar PowerLost : same as -a command line option .It Ar PowerRestored : same as -r command line option .It Ar Timeout :same as -m command line option .It Ar Listen :same as -l command line option .El The following is an example of a typical usage of the .Nm command: .Pp bupsd -d /dev/cuaa0 -a /usr/local/etc/power-lost.sh -r /usr/local/etc/power-restored.sh -s /usr/local/etc/down.sh bupsd -f /usr/local/etc/bupsd.conf Config file example: .Pp device = /dev/cuaa1 shutdown = /etc/bupsd/shutdown.sh powerlost = /etc/bupsd/power-lost.sh powerrestored = /etc/bupsd/power-restored.sh #timeout = 5 .Sh DIAGNOSTICS The default action is taken for all signals. bupsd will write a message to system log on each event before any script is executed. .Sh AUTHORS This manual page was written by .An Titus Manea Aq titus@2edc.com . ups/ENG/smbbcast.80100644000175000017500000000633107362522374013305 0ustar titustitus.\" Copyright (c) [2001] [Eastern Digital Inc] .\" 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 the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS 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 AUTHOR OR 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. .\" .\" $FreeBSD: src/share/examples/mdoc/example.1,v 1.10.2.1 1999/12/12 17:41:56 mpp Exp $ .\" Note: All FreeBSD man pages should have a FreeBSD revision .\" control id to make it easier for translation teams to track .\" changes. .\" .\" Note: The date here should be updated whenever a non-trivial .\" change is made to the manual page. .Dd August 14, 2001 .Dt smbbcast 8 .\" Note: Only specify the operating system when the command .\" is FreeBSD specific, otherwise use the .Os macro with no .\" arguments. .Os Unix .Sh NAME .Nm smbbcast .Nd smbbcast manual page .Sh SYNOPSIS .Nm smbbcast .Fl s Ar my_ip .Fl S Ar my_netbios_name .Fl b Ar broadcast_address .Fl W Ar workgroup .Ar message .Sh DESCRIPTION .Nm is a companion program for bupsd(8). Its purpose is to send Winpopup style messages to Windows(tm) workstations. In order to make it more portable user has to specify the local ip address and the subnet broadcast address. .Pp The options are as follows: .Bl -tag -width Fl .It Fl s Ar my_ip Specifies the source ip address of the messages to be sent. The ip should be in decimal dotted notation and must be a local address of the host. .It Fl S Ar my_netbios_name Species the netbios name of the host. The recipients will see this name as the sender of the message. .It Fl b Ar broadcast_address Specifies the broadcast address for the subnet on which the ip specified with -s resides. .It Fl W Ar workgroup Specifies the windows networking workgroup to receive the message. .It Ar message The message to be sent. .El The following is an example of a typical usage of the .Nm command: .Pp smbbcast -s 10.1.1.1 -S SERVER -W WORKGROUP -b 10.1.1.255 \\ "Power failed. Please save your work." .Pp .Nm should run as root because it needs to bind to 138 port in order to send winpopup broadcast messages. .Sh AUTHORS This manual page was written by .An Titus Manea Aq titus@2edc.com . ups/INSTALL.rom0100644000175000017500000000072107362522374012627 0ustar titustitusPentru a compila programul cu mesaje si help in limba romana make XLANG=RO all install Despachetati arhiva intr-un director la alegere. Editati fiserul Makefile ( schimbati daca doriti varaibilele TARGETDIR, MANDIR si EXAMPLESDIR ) make XLANG=RO all install cateva exemple de scripturi si fisier de configurare sunt in directorul samples. Pentru a porni automat serviciul de UPS la boot-are consultati manualul sistemului de operare pe care il folositi. ups/smbbcast_msg.c0100644000175000017500000000123507362522374013613 0ustar titustitus#include char *translate(char *XXX) { if(!strcmp(XXX,"\t-s IP addr = local ethernet ip \n")) return "\t-s IP addr = Adresa IP al cartelei de retea \n"; if(!strcmp(XXX,"\t-S = local NETBIOS name \n")) return "\t-S = Numele NETBIOS al calculatorului \n"; if(!strcmp(XXX,"\t-b broadcast addr = broadcast address for the IP specified with -s\n")) return "\t-b broadcast addr = Adresa de broadcast pentru IP specificat cu -s\n"; if(!strcmp(XXX,"\t-W workgroup = workgroup to send message to\n")) return "\t-W workgroup = workgroup destinatie\n"; if(!strcmp(XXX,"\t message = Message to send\n")) return "\t message = Mesajul de transmis\n"; return XXX; } ups/upd-po.sh0100644000175000017500000000014607504400611012526 0ustar titustitusxgettext -o aaa.po -a -C bupsd.c msgmerge -o xxxx.po bupsd.po aaa.po rm aaa.po mv -f xxxx.po bupsd.po