1
2 """Etat du serveur de fichier
3 """
4
5 import os,commands
6 from agent import Agent
7
9 """Etat du serveur de fichier
10 """
12 self.name = "samba"
13 self.description="""Partage de fichier Samba"""
14 Agent.__init__(self)
15 cmd = "net status sessions | grep \"(\" |wc -l"
16 nb = commands.getoutput(cmd).lstrip()
17 virus = self._virus_log()
18
19 self.contenu_xml = self._dump_xml(nb,virus)
20 self.contenu_html= self._dump_html(nb,virus)
21
22 self.write_html()
23 self.write_xml()
24
26 """sortie en xml
27 """
28
29 UPT_DATA = """<variable name="nbconnectes" value="%s"/>
30 <variable name="lastvirus" value="%s"/>
31 """
32
33 return UPT_DATA % (nb,virus)
34
36 """sortie en html
37 """
38 UPT_HTM = """<table><tr><td>
39 Nombres d'utilisateurs connectés : %s
40 </td></tr><tr><td>
41 Dernier virus détecté : %s
42 </td></tr></table>
43 """
44
45 return UPT_HTM % (nb,virus)
46
47
49 """ traitement des virus
50 loggés dans syslog avec samba-vscan
51 """
52 fichier = "/var/log/syslog"
53 try :
54 fp = open(fichier,'r')
55 except:
56 return("Erreur de lecture")
57 lignes = fp.readlines()
58 lignes.reverse()
59 for ligne in lignes:
60 if ligne.find("infected with virus") != -1 :
61
62 date = ligne[4:6]+" "+ligne[0:3]
63 ligne = ligne[ligne.find("'")+1:]
64 next = ligne.find("'")
65
66 fichier = ligne[0:next]
67 ligne = ligne[next+23:]
68 next = ligne.find("'")
69
70 virus = ligne[0:next]
71
72 client = ligne[next+12:-2]
73 return("<font color=red>"+virus+"</font> sur le client"+" "+client+" ("+date+")")
74
75 return("Aucun")
76
77 if __name__ == "__main__":
78 SambaAgent()
79