Ajout des modules initiaux
darcs-hash:20070124114812-f46e9-171ef12f1e1b89ae005adf4aab6f6535fb9289e6.gz
This commit is contained in:
parent
8713311bc1
commit
ed3ab40ccd
80 changed files with 4852 additions and 5 deletions
249
intranet/modules/mesMachines/main.py
Executable file
249
intranet/modules/mesMachines/main.py
Executable file
|
@ -0,0 +1,249 @@
|
|||
#! /usr/bin/env python
|
||||
# -*- coding: iso-8859-15 -*-
|
||||
# ##################################################################################################### #
|
||||
# Machines
|
||||
# ##################################################################################################### #
|
||||
# Description:
|
||||
# Affiche la liste des machies, les infons sur une machine et permet des modifications
|
||||
# Informations:
|
||||
#
|
||||
# Pages:
|
||||
# index:liste des machines + le reste (AJAX)
|
||||
#
|
||||
# ##################################################################################################### #
|
||||
import cherrypy, sys, os, datetime
|
||||
from time import strftime, localtime, time
|
||||
# libraries crans
|
||||
sys.path.append('/usr/scripts/gestion/')
|
||||
import crans.cp
|
||||
if (cherrypy.config.configMap["global"]["server.environment"] == "development"):
|
||||
from ldap_crans_test import *
|
||||
# print("mesmachines : unsing test ldap : env=" + cherrypy.config.configMap["global"]["server.environment"])
|
||||
else:
|
||||
from ldap_crans import *
|
||||
# print("mesmachines : unsing prod ldap : env=" + cherrypy.config.configMap["global"]["server.environment"])
|
||||
|
||||
from ClassesIntranet.ModuleBase import ModuleBase
|
||||
|
||||
class main(ModuleBase):
|
||||
def title(self):
|
||||
return "Mes Machines"
|
||||
def icon(self):
|
||||
return "machines_icon_fixe.png"
|
||||
|
||||
def AJAXListeMachines(self):
|
||||
adh = cherrypy.session['LDAP'].search('uid=' + cherrypy.session['uid'])['adherent'][0]
|
||||
machines = []
|
||||
for une_machine in adh.machines():
|
||||
machineInfos = {}
|
||||
# nom, mac, mid, ip
|
||||
machineInfos['nom'] = une_machine.nom()
|
||||
machineInfos['nomCourt'] = une_machine.nom().split('.',1)[0]
|
||||
machineInfos['mid'] = une_machine.id()
|
||||
# type
|
||||
if une_machine.objectClass == 'machineFixe':
|
||||
machineInfos['type'] = 'fixe'
|
||||
#machineInfos['type'] = 'Machine fixe'
|
||||
else:
|
||||
machineInfos['type'] = 'wifi'
|
||||
#machineInfos['type'] = 'Machine wifi'
|
||||
# clef ipsec
|
||||
machines.append(machineInfos)
|
||||
|
||||
return {"machines":machines}
|
||||
AJAXListeMachines.exposed = True
|
||||
|
||||
def AJAXMachineInfo(self, mid):
|
||||
try:
|
||||
machine = cherrypy.session['LDAP'].search('mid=' + mid)['machine'][0]
|
||||
if machine.proprietaire().mail() != cherrypy.session['uid']:
|
||||
raise Exception
|
||||
# zamok -> pour tester l'affichage des ports, des alias
|
||||
#machine = cherrypy.session['LDAP'].search('mid=896')['machine'][0]
|
||||
machineInfos = {}
|
||||
# nom, mac, mid, ip
|
||||
machineInfos['nom'] = machine.nom()
|
||||
machineInfos['nomCourt'] = machine.nom().split('.',1)[0]
|
||||
machineInfos['mac'] = machine.mac()
|
||||
machineInfos['mid'] = machine.id()
|
||||
machineInfos['ip'] = machine.ip()
|
||||
# type
|
||||
if machine.objectClass == 'machineFixe':
|
||||
machineInfos['type'] = 'fixe'
|
||||
else:
|
||||
machineInfos['type'] = 'wifi'
|
||||
# clef ipsec
|
||||
try:
|
||||
machineInfos['ipsec'] = machine.ipsec()
|
||||
except:
|
||||
machineInfos['ipsec'] = ''
|
||||
# alias
|
||||
machineInfos['alias'] = machine.alias()
|
||||
# blacklists
|
||||
machineInfos['blacklist'] = []
|
||||
for blacklist_type in machine.blacklist_all()[0].keys():
|
||||
for (begin, end) in machine.blacklist_all()[0][blacklist_type]:
|
||||
blacklist = {}
|
||||
blacklist['begin'] = strftime('%d/%m/%Y %H:%M', localtime(int(begin)))
|
||||
blacklist['end'] = strftime('%d/%m/%Y %H:%M', localtime(int(end)))
|
||||
blacklist['type'] = blacklist_type
|
||||
blacklist['actif'] = 1
|
||||
machineInfos['blacklist'].append(blacklist)
|
||||
for blacklist_type in machine.blacklist_all()[1].keys():
|
||||
for (begin, end) in machine.blacklist_all()[1][blacklist_type]:
|
||||
blacklist = {}
|
||||
blacklist['begin'] = strftime('%d/%m/%Y %H:%M', localtime(int(begin)))
|
||||
blacklist['end'] = strftime('%d/%m/%Y %H:%M', localtime(int(end)))
|
||||
blacklist['type'] = blacklist_type
|
||||
blacklist['actif'] = 0
|
||||
machineInfos['blacklist'].append(blacklist)
|
||||
# ports
|
||||
machineInfos['ports'] = []
|
||||
if machine.portTCPin() != []:
|
||||
machineInfos['ports'].append(
|
||||
{
|
||||
'titre':'Ports TCP ouvert ext->machine',
|
||||
'ports':machine.portTCPin()
|
||||
}
|
||||
)
|
||||
if machine.portTCPout() != []:
|
||||
machineInfos['ports'].append(
|
||||
{
|
||||
'titre':'Ports TCP ouvert machine->ext',
|
||||
'ports':machine.portTCPout()
|
||||
}
|
||||
)
|
||||
if machine.portUDPin() != []:
|
||||
machineInfos['ports'].append(
|
||||
{
|
||||
'titre':'Ports UDP ouvert ext->machine',
|
||||
'ports':machine.portUDPin()
|
||||
}
|
||||
)
|
||||
if machine.portUDPout() != []:
|
||||
machineInfos['ports'].append(
|
||||
{
|
||||
'titre':'Ports TCP ouvert machine->ext',
|
||||
'ports':machine.portUDPout()
|
||||
}
|
||||
)
|
||||
|
||||
return machineInfos
|
||||
except Exception, e:
|
||||
return {"erreur":str(e)}
|
||||
AJAXMachineInfo.exposed = True
|
||||
|
||||
##########################
|
||||
# affichage
|
||||
##########################
|
||||
#
|
||||
# methode qui affiche la template
|
||||
#
|
||||
def index(self):
|
||||
return {
|
||||
'template' :'machines',
|
||||
'values' :{},
|
||||
'stylesheets' :['machines.css'],
|
||||
'scripts':['machines.js'],
|
||||
}
|
||||
index.exposed = True
|
||||
|
||||
|
||||
###########################################################################
|
||||
# methodes pour changer
|
||||
# des valeurs
|
||||
###########################################################################
|
||||
#
|
||||
|
||||
##########################
|
||||
# machine:nom
|
||||
##########################
|
||||
def AJAXChangerNom(self, mid, nouveauNom):
|
||||
try:
|
||||
adh = cherrypy.session['LDAP'].search('uid=' + cherrypy.session['uid'])['adherent'][0]
|
||||
mach = cherrypy.session['LDAP'].search('mid=' + mid, 'w')['machine'][0]
|
||||
# tester si c'est bien la machine de l'adherent
|
||||
if mach.proprietaire().compte() != cherrypy.session['uid']:
|
||||
del adh, mach
|
||||
raise Exception(u"L'uid de l'adherent ne correspond mas au proprietaire de la machine.")
|
||||
anciennom = mach.nom()
|
||||
nouveauNom = mach.nom(nouveauNom)
|
||||
mach.save()
|
||||
del mach
|
||||
except ValueError, e:
|
||||
raise e
|
||||
#return {'error':str(e)}
|
||||
crans.cp.log("Changer nom machine : %s->%s" % (anciennom, nouveauNom), "MESMACHINES")
|
||||
return {'message':u"Modification réussie", 'mid':mid}
|
||||
AJAXChangerNom.exposed = True
|
||||
|
||||
##########################
|
||||
# machine:mac
|
||||
##########################
|
||||
def AJAXchangerMAC(self, mid, nouvelleMAC):
|
||||
try:
|
||||
adh = cherrypy.session['LDAP'].search('uid=' + cherrypy.session['uid'])['adherent'][0]
|
||||
mach = cherrypy.session['LDAP'].search('mid=' + mid, 'w')['machine'][0]
|
||||
# tester si c'est bien la machine de l'adherent
|
||||
if mach.proprietaire().compte() != cherrypy.session['uid']:
|
||||
del adh, mach
|
||||
raise Exception(u"L'uid de l'adherent ne correspond mas au proprietaire de la machine.")
|
||||
anciennemac = mach.mac()
|
||||
nommachine = mach.nom()
|
||||
mach.mac(nouvelleMAC)
|
||||
mach.save()
|
||||
del mach
|
||||
except ValueError, e:
|
||||
return {'error':e.args[0]}
|
||||
crans.cp.log("Change mac machine %s : %s->%s" % (nommachine, anciennemac, nouvelleMAC), "MESMACHINES")
|
||||
return {'message':u"Modification réussie", 'mid':mid}
|
||||
AJAXchangerMAC.exposed = True
|
||||
|
||||
|
||||
|
||||
##########################
|
||||
# machine:suppression
|
||||
##########################
|
||||
def AJAXSupprimerMachine(self, mid):
|
||||
try:
|
||||
adh = cherrypy.session['LDAP'].search('uid=' + cherrypy.session['uid'])['adherent'][0]
|
||||
mach = cherrypy.session['LDAP'].search('mid=' + mid, 'w')['machine'][0]
|
||||
# tester si c'est bien la machine de l'adherent
|
||||
if mach.proprietaire().compte() != cherrypy.session['uid']:
|
||||
del adh, mach
|
||||
raise Exception(u"L'uid de l'adherent ne correspond mas au proprietaire de la machine.")
|
||||
mach.delete()
|
||||
except ValueError, e:
|
||||
return {'error':e.args[0]}
|
||||
crans.cp.log("Machine supprimee", "MACHINES")
|
||||
return {'message':u"Machine supprimée"}
|
||||
AJAXSupprimerMachine.exposed = True
|
||||
|
||||
##########################
|
||||
# machine:creation
|
||||
##########################
|
||||
def AJAXCreerMachine(self, nomNouvelleMachine, MACNouvelleMachine, typeNouvelleMachine):
|
||||
adh = cherrypy.session['LDAP'].search('uid=' + cherrypy.session['uid'])['adherent'][0]
|
||||
if typeNouvelleMachine=='fixe' and adh.droits() == [] and adh.machines_fixes() != []:
|
||||
return {'error':'Vous avez deja une machine fixe. Vous ne pouvez ajouter que des machines WiFi.'}
|
||||
try:
|
||||
if typeNouvelleMachine=='wifi':
|
||||
m = MachineWifi(adh)
|
||||
elif typeNouvelleMachine=='fixe':
|
||||
m = MachineFixe(adh)
|
||||
else:
|
||||
raise Exception, "type de machine inconnu : %s " % typeNouvelleMachine
|
||||
m.nom(nomNouvelleMachine)
|
||||
m.mac(MACNouvelleMachine)
|
||||
m.ip("<automatique>")
|
||||
message = m.save()
|
||||
del m
|
||||
except ValueError, e:
|
||||
del m
|
||||
return {'error':e.args[0].replace("\n","\\n")}
|
||||
crans.cp.log("Nouvelle machine %s" % nomNouvelleMachine, "MACHINES")
|
||||
return {'message':u"Machine enregistrée avec succès"}
|
||||
AJAXCreerMachine.exposed = True
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue