diff --git a/intranet/Root.py b/intranet/Root.py index 556cfe00..b1990bce 100755 --- a/intranet/Root.py +++ b/intranet/Root.py @@ -71,7 +71,7 @@ from plugins.verifdroitsfilter import VerifDroitsFilter class Intranet: __ldap = None def __init__(self): - from pages import monCompte, impression, factures, digicode + from pages import monCompte, impression, factures, digicode, mesmachines self.__ldap = cherrypy.config.configMap["global"]["crans_ldap"] # liste des modules disponibles @@ -81,8 +81,8 @@ class Intranet: self.digicode = digicode.root() # liste des modules en developpement - #if (cherrypy.config.configMap["global"]["server.environment"] == "development"): - + if (cherrypy.config.configMap["global"]["server.environment"] == "development"): + self.mesMachines = mesmachines.root() @@ -92,13 +92,15 @@ class Intranet: return { 'template':'accueil', 'values':{}, + 'stylesheets':['accueil.css'], } index.exposed= True def info(self): return { 'template':'info-diverses', - 'values':{} + 'values':{}, + 'stylesheets':['accueil.css'], } info.exposed = True diff --git a/intranet/conf/dev.cfg b/intranet/conf/dev.cfg index d77ff27a..15026868 100644 --- a/intranet/conf/dev.cfg +++ b/intranet/conf/dev.cfg @@ -21,4 +21,4 @@ paypal.businessAdress = "gdetrez-buisness@crans.org" paypal.useSandbox = True [/static] -staticFilter.dir = "/usr/scripts/intranet/static/" +staticFilter.dir = "/home/gdetrez/crans.usr.scripts/intranet/static/" diff --git a/intranet/pages/mesmachines.py b/intranet/pages/mesmachines.py new file mode 100755 index 00000000..5ebdab7c --- /dev/null +++ b/intranet/pages/mesmachines.py @@ -0,0 +1,237 @@ +#! /usr/bin/env python +# -*- coding: iso-8859-15 -*- + +import cherrypy, sys, os, datetime +from time import strftime, localtime, time +# libraries crans +sys.path.append('/usr/scripts/gestion/') +from config_mail import MailConfig +if (cherrypy.config.configMap["global"]["server.environment"] == "development"): + from ldap_crans_test import * +# print("monCompte : unsing test ldap : env=" + cherrypy.config.configMap["global"]["server.environment"]) +else: + from ldap_crans import * +# print("monCompte : unsing prod ldap : env=" + cherrypy.config.configMap["global"]["server.environment"]) + + + +class root: + __ldap = None + + def __init__(self): + self.__ldap = cherrypy.config.configMap["global"]["crans_ldap"] + + + def AJAXListeMachines(self): + adh = self.__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 = self.__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 = self.__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 = self.__ldap.search('uid=' + cherrypy.session['uid'])['adherent'][0] + mach = self.__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.nom(nouveauNom) + mach.save() + del mach + except ValueError, e: + raise e + #return {'error':str(e)} + cherrypy.log("Changer nom machine : %s" % nouveauNom, "MESMACHINES") + return {'message':u"Modification réussie", 'mid':mid} + AJAXChangerNom.exposed = True + + ########################## + # machine:mac + ########################## + def AJAXchangerMAC(self, mid, nouvelleMAC): + try: + adh = self.__ldap.search('uid=' + cherrypy.session['uid'])['adherent'][0] + mach = self.__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.mac(nouvelleMAC) + mach.save() + del mach + except ValueError, e: + return {'error':e.args[0]} + cherrypy.log("Change mac machine", "MESMACHINES") + return {'message':u"Modification réussie", 'mid':mid} + AJAXchangerMAC.exposed = True + + + + ########################## + # machine:suppression + ########################## + def AJAXSupprimerMachine(self, mid): + try: + adh = self.__ldap.search('uid=' + cherrypy.session['uid'])['adherent'][0] + mach = self.__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]} + cherrypy.log("Machine supprimee", "MACHINES") + return {'message':u"Machine supprimée"} + AJAXSupprimerMachine.exposed = True + + ########################## + # machine:creation + ########################## + def AJAXCreerMachine(self, nomNouvelleMachine, MACNouvelleMachine, typeNouvelleMachine): + adh = self.__ldap.search('uid=' + cherrypy.session['uid'])['adherent'][0] + if typeNouvelleMachine=='wifi' 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("") + message = m.save() + del m + except ValueError, e: + del m + return {'error':e.args[0].replace("\n","\\n")} + cherrypy.log("Nouvelle machine %s" % nomNouvelleMachine, "MACHINES") + return {'message':u"Machine enregistrée avec succès"} + AJAXCreerMachine.exposed = True + + + diff --git a/intranet/static/css/accueil.css b/intranet/static/css/accueil.css new file mode 100644 index 00000000..105f3424 --- /dev/null +++ b/intranet/static/css/accueil.css @@ -0,0 +1,74 @@ +/************************************************************* + .. + .... ............ ........ + . ....... . .... .. + . ... .. .. .. .. ..... . .. + .. .. ....@@@. .. . ........ . + .. . .. ..@.@@..@@. .@@@@@@@ @@@@@@. .... + .@@@@. .@@@@. .@@@@..@@.@@..@@@..@@@..@@@@.... .... + @@@@... .@@@.. @@ @@ .@..@@..@@...@@@. .@@@@@. .. + .@@@.. . @@@. @@.@@..@@.@@..@@@ @@ .@@@@@@.. ..... + ...@@@.... @@@ .@@.......... ........ ..... .. + . ..@@@@.. . .@@@@. .. ....... . ............. + . .. .... .. .. . ... .... +. . .... ............. .. ... +.. .. ... ........ ... ... + ................................ + +============================================================== +mainInterface.css - Intranet Style + + Mise en page de l'accueil + + +Copyright (c) 2006 by www.crans.org + +**************************************************************/ + +div.framed_gray { + border:5px solid #e2e2e2; /* #acc0ff */ + background-color:#f2f2f2; + padding:10px; +} + +div.framed_gray fieldset { + border-width:2px; + border-style:solid none none none; + border-color:#a2a2a2; + padding:10px; + margin:10px 10px; +} + +div.framed_gray fieldset legend { + color:#a2a2a2; +} + +div.framed_gray fieldset ul { + list-style-type:none; + margin:0; + padding:0; +} + +div.framed_gray fieldset ul li { + float:left; + height:70px; + width:100px; + margin:5px; + display:block; + text-align:center; +} + +div.framed_gray fieldset ul li span { + margin-bottom:0; + display:block; +} +div.framed_gray fieldset ul a { + color:black; + text-decoration:none; +} + +div.framed_gray fieldset ul li img { + margin:2px auto; + width:32px; + height:32px; +} diff --git a/intranet/static/css/machines.css b/intranet/static/css/machines.css new file mode 100644 index 00000000..e05bc8ed --- /dev/null +++ b/intranet/static/css/machines.css @@ -0,0 +1,160 @@ +/************************************************************* + .. + .... ............ ........ + . ....... . .... .. + . ... .. .. .. .. ..... . .. + .. .. ....@@@. .. . ........ . + .. . .. ..@.@@..@@. .@@@@@@@ @@@@@@. .... + .@@@@. .@@@@. .@@@@..@@.@@..@@@..@@@..@@@@.... .... + @@@@... .@@@.. @@ @@ .@..@@..@@...@@@. .@@@@@. .. + .@@@.. . @@@. @@.@@..@@.@@..@@@ @@ .@@@@@@.. ..... + ...@@@.... @@@ .@@.......... ........ ..... .. + . ..@@@@.. . .@@@@. .. ....... . ............. + . .. .... .. .. . ... .... +. . .... ............. .. ... +.. .. ... ........ ... ... + ................................ + +============================================================== +macines.css - Intranet Style + +Copyright (c) 2006 by www.crans.org + +**************************************************************/ +#globalDiv { + padding-left : 25%; + margin:0; + position:relative; +} +h2 { + margin: 0 5px .5em 5px;padding:5px; +} + +div.alias { + color:gray; + margin:0; + padding:0 0 0 60px; + display:block; + font-weight:normal; + font-size:0.6em; + +} + +table.blacklist_table, +table.ports_table { + border-top: thin black solid; + border-left: thin black solid; +} + +table.blacklist_table td, +table.blacklist_table th, +table.ports_table td, +table.ports_table th { + border-right: thin black solid; + border-bottom: thin black solid; + padding: 3px; +} + +.actif { + color:red; +} +.inactif { +} + + +#gestion_machines_main_frame { + padding:5px; +} + +dl.basicInfos dt { + float:left; + font-weight:bold; + clear:left; +} + +dl.basicInfos dd { + float:left; + margin:0 1em; +} + +ul#listeMachines { + list-style-type:none; + margin:0; + padding:0; +} + +ul#listeMachines li { + float:left; + height:70px; + width:100px; + margin:5px; + display:block; + text-align:center; +} + +ul#listeMachines li span { + margin-bottom:0; + display:block; +} + +ul#listeMachines li a { +display:block; + color:black; + text-decoration:none; +} + +ul#listeMachines li a:hover { + background:#bbbbff; +} + +ul#listeMachines li a:active { + background:#8888ff; +} + +ul#listeMachines li img { + margin:2px auto; + width:32px; + height:32px; +} + +#menu_actions { +background:#eeeeff; +padding:.3em; +max-width:20%; +float:left; +position:absolute; +top:1em; +left:0; +border: thin black solid; +} + +#menu_actions ul { +list-style-type:none; +padding:0; +margin:.5em; +} +#menu_actions ul li a { +text-decoration:none; +} +#menu_actions ul li a:hover { +text-decoration:underline; +} + +#menu_actions h1 { +font-size:1em; +margin:0; +text-align:center; +border-bottom: thin black solid; +} + +// on change la couleur des messages +.message { + background-color:#000080; + color:white; +} + +label { + width:175px; + display:block; + float:left; +} diff --git a/intranet/static/css/mainInterface.css b/intranet/static/css/mainInterface.css index b9e4e5a0..ff109a0e 100644 --- a/intranet/static/css/mainInterface.css +++ b/intranet/static/css/mainInterface.css @@ -28,8 +28,8 @@ Copyright (c) 2006 by www.crans.org /* STYLE GLOBAL - body - liens - - titres - - images + - messages + - aides - ... */ @@ -60,8 +60,6 @@ div#pageContent { } /**************************************************************************/ - - /* LE HAUT DES PAGES - le logo a gauche - petit menu a droite @@ -126,6 +124,55 @@ ul#main_topContentMenu hr, div#topMenu h1 { margin:5px; } + +/************************************************************************** + * Messages + * (les messages affichĂ©s sur les pages pour indiquer le bon dĂ©roulement + * ou non d'une action) + **************************************************************************/ +#_crans_main_message_place_holder { + height:0; + overflow:visible; + position:absolute; + top:100px; + width:100%; +} + +.messageText { + padding:2px 10px; + display:block; +} + +.message { + padding: 0; + background: #fad163; + width: 300px; + text-align: center; + margin : 1px auto 10px auto; +} +.errorMessage { + display:block; + background:white; + border:2px #cc0000 solid; + padding:5px; + text-align:center; + min-width:230px; + max-width:430px; + font-weight:bold; + margin : 1px auto 10px auto; +} + +#_crans_main_message_chargement { + background:#cc0000; + position:fixed; + top:1px; + right:1px; + z-index:1000; + display:none; + padding:2px 3px; + color:white; +} + /************************************************************************** * DIVERS **************************************************************************/ @@ -142,56 +189,8 @@ ul#main_topContentMenu hr, div#topMenu h1 { display:none; } - div.visualClear {clear:both;} -div.framed_gray { - border:5px solid #e2e2e2; /* #acc0ff */ - background-color:#f2f2f2; - padding:10px; -} - -div.framed_gray fieldset { - border-width:2px; - border-style:solid none none none; - border-color:#a2a2a2; - padding:10px; - margin:10px 10px; -} - -div.framed_gray fieldset legend { - color:#a2a2a2; -} - -div.framed_gray fieldset ul { - list-style-type:none; - margin:0; - padding:0; -} - -div.framed_gray fieldset ul li { - float:left; - height:70px; - width:100px; - margin:5px; - display:block; - text-align:center; -} - -div.framed_gray fieldset ul li span { - margin-bottom:0; - display:block; -} -div.framed_gray fieldset ul a { - color:black; - text-decoration:none; -} - -div.framed_gray fieldset ul li img { - margin:2px auto; - width:32px; - height:32px; -} .aide { font-size:0.8em; diff --git a/intranet/static/scripts/crans.js b/intranet/static/scripts/crans.js index c1b45beb..5f692924 100644 --- a/intranet/static/scripts/crans.js +++ b/intranet/static/scripts/crans.js @@ -1,193 +1,81 @@ -function askForName(oldName) { - var c = ''; - while ( c == '') - c = prompt("Votre nom :",oldName); - if (c == null) - return false; - else - window.location.href= 'changeNomAdherent?nouveauNom=' + c; +/* ************************************************************ + * Crans + ************************************************************ + * Crans.messages : afficher des messages sur les pages + * Crans.loading : afficher l'indicateur de chargement + */ +Crans = {}; + +/***************************** + Crans.Messages + *****************************/ +Crans.messages = {} +Crans.messages.initialized = false; + +Crans.messages.init = function() +{ + if (!Crans.messages.initialized) + { + updateNodeAttributes(document.body, {'onclick':'Crans.messages.setMessage();'}); + appendChildNodes(document.body, DIV({'id':'_crans_main_message_place_holder'})); + Crans.messages.initialized = true; + } } -function askForSurname(oldSurname) { - var c = ''; - while ( c == '') - c = prompt("Votre prĂ©nom :",oldSurname); - if (c == null) - return false; - else - window.location.href= 'changePrenomAdherent?nouveauPrenom=' + c; +Crans.messages.setMessage = function(m, messageClass) +{ + if (!Crans.messages.initialized) + Crans.messages.init(); + if (m == null) { + var messageBox = ''; + } else { + if (messageClass==null) + messageClass='message'; + var textHolder = SPAN({'class':'messageText'},m); + var messageBox = DIV({'class':messageClass},textHolder); + var messagePlace = document.getElementById("_crans_main_message_place_holder"); + } + try + { + var messagePlace = document.getElementById("_crans_main_message_place_holder"); + replaceChildNodes(messagePlace,messageBox); + try {roundElement(messageBox);} catch (error) {} + } + catch (error) + { + logError("élement _crans_main_message_place_holder introuvable") + return + } } -function askForTel(oldTel) { - var c = ''; - while ( c == '') - c = prompt("Votre numĂ©ro de tĂ©lĂ©phone :",oldTel); - if (c == null) - return false; - else - window.location.href= 'changeTelAdherent?nouveauTel=' + c; +/***************************** + Crans.loading + *****************************/ +Crans.loading = {} +Crans.loading.initialized = false; + +Crans.loading.init = function(){ + try { + if (!Crans.loading.initialized) { + appendChildNodes(document.body, DIV({'id':'_crans_main_message_chargement'}, "Chargement...")); + Crans.loading.initialized = true; + } + } catch (error) { + logError(error.description); + } } -function askForMachineMac(oldMac, mid) { - var c = ''; - while ( c == '') - c = prompt("Adresse MAC de la machine :",oldMac); - if (c == null) - return false; - var e = loadJSONDoc('changeMACMachine?nouvelleMAC=' + c + '&mid=' + mid); - e.addCallback(machineModifHandler); - e.addErrback(ajaxErrorHandler); - loading(true); - return false; -} -function askForMachineName(oldName, mid) { - var c = ''; - while ( c == '') - c = prompt("Nom de la machine :",oldName); - if (c == null) - return false; - var e = loadJSONDoc("changeNomMachine?nouveauNom=" + c + "&mid=" + mid); - e.addCallback(machineModifHandler); - e.addErrback(ajaxErrorHandler); - loading(true); - return false; -} - -function askForDeleteMachine(mid, nom) { - if (confirm("Supprimer la machine ?")) { - var e = loadJSONDoc('supprimeMachine?mid=' + mid); - e.addCallback(machineModifHandler); - e.addErrback(ajaxErrorHandler); - loading(true); - return false; - } - return false; -} - -function newAlias() { - var c = ''; - while ( c == '') - c = prompt("Nouvel alias :"); - if (c == null) - return false; - else - window.location.href= 'newAlias?alias=' + c + "#mailTab"; - -} - - - -function newMachineNode(name, shortName, mac, ip, mid, type, ipsec) { - machineName = H3({},shortName); - - var propertiesList = createDOM("DL",{'class':'machineInfos'}); - valuesList = [ - {'label':'Type : ', 'value':type}, - {'label':'Mac : ', 'value':mac}, - {'label':'IP : ', 'value':ip}, - {'label':'ipsec : ', 'value':ipsec}, - ] ; - for (var i=0; i Mon Compte +
  • + icon + Mes Machines +
  • icon Impression diff --git a/intranet/templates/machines.tmpl b/intranet/templates/machines.tmpl new file mode 100644 index 00000000..cbb21a6b --- /dev/null +++ b/intranet/templates/machines.tmpl @@ -0,0 +1,13 @@ +
    + +

    Gestion de mes machines

    +
    +
    + + diff --git a/intranet/templates/monCompte.tmpl b/intranet/templates/monCompte.tmpl index 7d2ac46f..17465f0c 100644 --- a/intranet/templates/monCompte.tmpl +++ b/intranet/templates/monCompte.tmpl @@ -1,24 +1,24 @@ -
    - #if $message != '' - + #end if #if $error != '' - + #end if - -
    - Chargement en cours... -
    - -
    +
    - -
    -

    -
      - #for $machine in $machines -
    • -

      $machine.nomCourt

      -
      -
      Type :
      $machine.type
      -
      MAC :
      $machine.mac
      -
      IP :
      $machine.ip
      - #if $machine.ipsec -
      Clef ipsec :
      $machine.ipsec
      - #end if -
      -
      - - renommer - Changer de MAC - Supprimer - -
      -
    • - #end for -
    -
      -
    • -

      Ajouter une machine

      -
      - -
      - -
      - Comment trouver l'adresse mac ?
      -
      - -
      -

      Note :Pour les non membres actifs, le nombre de machines fixes est limité à 1

      -
    • -
    -
    - -