Outils pour utilisateurs

Outils du site


Panneau latéral

Tips

Divers

Projets

Ham Radio

Machines

Research

Privé

Études

projets:mudrublic:misc

Misc

Watchdog

A lancer depuis la fin du /etc/rc.local (watchdog.sh):

#!/usr/local/bin/bash
echo "starting watchdog..."
 
sysctl kern.watchdog.auto=0 > /dev/null
 
while : ; do
        sysctl kern.watchdog.period=10 > /dev/null
        sleep 8
done

Diode d'erreur

On/Off

/*-
 * Copyright (c) 2001 Centaur Technology, Inc.
 * All rights reserved.
 *
 * Eric P Anderson
 *
 * 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 the NetBSD
 *        Foundation, Inc. and its contributors.
 * 4. Neither the name of The NetBSD Foundation nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY CENTAUR TECHNOLOGY, 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 THE REGENTS 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 <stdio.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
 
void usage() {
 
        fprintf(stderr, "Usage: led -[on,off]\n");
 
        exit(-1);
}
 
main(int argc, char **argv) {
 
        int     memfd;
        off_t   offset;
        ssize_t bytes;
        char    data;
 
        /* Need 1 arg */
        if (argc != 2) usage();
 
        /* Check arg */
        if ((!strcmp(argv[1], "-on")) || (!strcmp(argv[1], "-ON"))) {
                offset = 0x000DFC35;
        } else if ((!strcmp(argv[1], "-off")) || (!strcmp(argv[1], "-OFF"))) {  
                offset = 0x000DFC39;
        } else {
                usage();
        }
 
        /* Open memory driver */
        memfd = open("/dev/mem", O_RDWR);
 
        if (memfd == -1) {
                fprintf(stderr, "couldn't open /dev/mem! You need to be root.\n");
                exit(-1);
        }
 
        /* seek to offset */
        offset = lseek(memfd, offset, SEEK_SET); 
 
        if (offset == -1) {
                fprintf(stderr, "lseek to offset %08X failed!\n", offset);
                exit(-1);
        }
 
        /* write data */
        data = 0x02;
        bytes = write(memfd, &data, 1);
 
        if (bytes != 1) {
                fprintf(stderr, "write to offset %08X has failed!\n", offset);
                exit(-1);
        }
 
        /* success */
        exit(0);
 
}

En fonction de l'activité de pf

http://www.pro-bono-publico.de/openbsd/gpio/gpioflicker-0.3.tar.gz

$ lynx -dump http://www.pro-bono-publico.de/openbsd/gpio/gpioflicker-0.3.tar.gz > ~/gpioflicker.tar.gz
$ tar xzvf gpioflicker-0.3.tar.gz
$ cd ~/gpioflicker-0.3
$ make
(...)
$ sudo cp gpioflicker /usr/local/bin

On va faire clignoter en fonction de l'activité sur le WiFi. On rajoute dans /etc/rc.local:

/usr/local/bin/gpioflicker -i rtw0

arpwatch

Pratique pour savoir qui se connecte en passant par le WiFi…

$ sudo pkg_add arpwatch-2.1a13.tgz

et dans le /etc/rc.local:

/usr/local/sbin/arpwatch -i rtw0

pfstat

On veut avoir de jolies tatistiques d'utilisation de l'uplink (set loginterface $EXT_IF dans pf.conf).

$ sudo pkg_add pfstat-1.7.tgz
(...)

Configuration

On veut trois graphes d'entrées/sorties:

  • quotidien
  • mensuel
  • annuel

Dans /etc/pfstat.conf:

image "/var/www/htdocs/admin/pfstat_v4d.jpg" {
        from 24 hours
                width 640 height 240
                left
                graph bytes_v4_in label "incoming" color 0 255 0 filled, 
                graph bytes_v4_out label "outgoing" color 0 0 255
}

image "/var/www/htdocs/admin/pfstat_v4m.jpg" {
        from 30 days
                width 640 height 240
                left
                graph bytes_v4_in label "incoming" color 0 255 0 filled,
                graph bytes_v4_out label "outgoing" color 0 0 255
}

image "/var/www/htdocs/admin/pfstat_v4y.jpg" {
        from 365 days
                width 640 height 240
                left
                graph bytes_v4_in label "incoming" color 0 255 0 filled,
                graph bytes_v4_out label "outgoing" color 0 0 255
}
$ sudo mkdir -p /var/www/htdocs/admin
$ sudo chown www /var/www/htdocs/admin

crontab

$ sudo crontab -e

Ajouter:

# Query pf statistics
*  *  *  *  *  /usr/local/bin/pfstat -q >> /var/log/pfstat
# Truncate logfile
1  1  *  *  1  tail -n 50000 /var/log/pfstat >/tmp/pfstat && mv /tmp/pfstat /var/log/pfstat
$ sudo crontab -e -u www

Ajouter:

# Generate pfstat graphs
*/5  *  *  *  * /usr/local/bin/pfstat -c /etc/pfstat.conf -d /var/log/pfstat >/dev/null

Autoconfiguration du proxy

Dans /var/www/htdocs/proxy.pac:

function FindProxyForURL(url, host)
{
        if (dnsDomainIs(host, ".utc.fr") 
                        || dnsDomainIs(host, ".utc")
                        || dnsDomainIs(host, "195.83.155.56") /* neptune */
           ) {
                return "PROXY proxy.narf.ssji.net:3128";
        } else {
                return "DIRECT";
        }
}

On veut aussi que la détection automatique des paramètres marche:

/var/www/htdocs$ sudo ln -s proxy.pac wpad.dat

Rotation des logs d'Apache

Apache est chroot(8)é. On ne peut donc pas utiliser out-of-the-box des outils comme rotatelogs(8) ou newsyslog(8).

Par contre, cronolog marche bien (dans les packages).

projets/mudrublic/misc.txt · Dernière modification: 2013-11-15 05:06 (modification externe)