Ci-dessous, les différences entre deux révisions de la page.
serveur_install_party:squirm [2010/06/17 22:28] Fanch Mise a jour lucid1 |
serveur_install_party:squirm [2023/07/18 23:11] |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | Nous utiliserons squid qui permet de réecrire certaines url (celles correspondant aux dépots) grace à un script python. | ||
- | Exemple : | ||
- | - on demande http:// | ||
- | - Squid transmet l'url au script python | ||
- | - le script retranscris en adresse locale : http:// | ||
- | - Si le fichier local existe, le script renvoi l'url locale, sinon renvoi l'url non modifiée | ||
- | |||
- | Voici le script en question / | ||
- | |||
- | |||
- | # | ||
- | | ||
- | # 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 3 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. | ||
- | # GNU General Public License for more details. | ||
- | # | ||
- | # You should have received a copy of the GNU General Public License | ||
- | # along with this program. | ||
- | # | ||
- | # | ||
- | # Author : Fanch317 (fanch@linuxquimper.org) | ||
- | # | ||
- | # Date : 2009-09-27 | ||
- | # Version 0.6 | ||
- | # | ||
- | # Description : Ce script est un redirecteur pour squid. | ||
- | # Il est destinne a faire passer toute requete de depots de | ||
- | # distributions vers des depots locaux plus rapides lors | ||
- | # d' | ||
- | | ||
- | import sys, | ||
- | | ||
- | levels = (logging.DEBUG, | ||
- | LOGLEVEL = logging.INFO | ||
- | | ||
- | # Definition des deots locaux | ||
- | redirectors = {} | ||
- | redirectors[0] = [" | ||
- | redirectors[1] = [" | ||
- | redirectors[2] = [" | ||
- | redirectors[3] = [" | ||
- | redirectors[4] = [" | ||
- | redirectors[5] = [" | ||
- | redirectors[6] = [" | ||
- | | ||
- | # Definition du chemin du fichier log et de sa verbosite | ||
- | LOG_FILENAME = '/ | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | logging.basicConfig(filename=LOG_FILENAME, | ||
- | | ||
- | | ||
- | logging.info(' | ||
- | logging.info(' | ||
- | logging.info(' | ||
- | | ||
- | | ||
- | | ||
- | while True: | ||
- | # URL ip-address/ | ||
- | line_squid = sys.stdin.readline().strip() | ||
- | | ||
- | logging.debug(' | ||
- | | ||
- | # Recuperation de l'URL | ||
- | try: | ||
- | list = line_squid.split(' | ||
- | url_input = list[0] | ||
- | | ||
- | # Recuperation de l' | ||
- | try: | ||
- | client_input = list[1] + rnd | ||
- | except: | ||
- | logging.warning(' | ||
- | client_input = " | ||
- | logging.info(client_input + ' Reception d\'une URL par : ' + url_input) | ||
- | | ||
- | i = 0 | ||
- | while i < len(redirectors): | ||
- | logging.debug(client_input + ' Test sur le depot %d' %(i)) | ||
- | | ||
- | try: | ||
- | # On test sur le depot correpond a ce genre d'URL | ||
- | if re.search(' | ||
- | logging.debug(client_input + ' L\'url correspond au depot' | ||
- | try: | ||
- | url_locale = re.sub(r' | ||
- | logging.debug(client_input + ' Verification de la presence du fichier local : ' + url_locale) | ||
- | urllib2.urlopen(url_locale) | ||
- | url_output = url_locale + ' | ||
- | logging.info(client_input + ' Ce fichier est en cache : ' + url_output) | ||
- | print url_output | ||
- | break | ||
- | except: | ||
- | # Le fichier est introuvable sur le depot | ||
- | logging.debug(client_input + ' Cette URL n\'est telechargeable dans ce depot' | ||
- | except: | ||
- | # L'URL ne correspond pas au depot | ||
- | logging.debug(client_input + ' Ce depot ne correspond pas a l\' | ||
- | i = i + 1 | ||
- | | ||
- | # Tout les depots ont ete testes, aucun ne correspond | ||
- | logging.info(client_input + ' Aucun depot ne contient cette URL') | ||
- | print url_input #+ ' | ||
- | | ||
- | except: | ||
- | logging.error(client_input + ' Impossible de recuperer l\'URL depuis la chaine ' | ||
- | | ||
- | sys.stdout.flush() |