5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
1 |
# -*- coding: utf-8 -*-
|
3589.30.2
by Jordi Esteve
Added network_extension module: Protocols, services, ... |
2 |
##############################################################################
|
3 |
#
|
|
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
4 |
# network_extension module for OpenERP
|
5 |
# Copyright (C) 2008 Zikzakmedia S.L. (http://zikzakmedia.com)
|
|
6 |
# Jordi Esteve <jesteve@zikzakmedia.com> All Rights Reserved.
|
|
7 |
# Copyright (C) 2009 SYLEAM (http://syleam.fr)
|
|
8 |
# Christophe Chauvet <christophe.chauvet@syleam.fr> All Rights Reserved.
|
|
9 |
#
|
|
10 |
# This file is a part of network_extension
|
|
11 |
#
|
|
12 |
# network_extension is free software: you can redistribute it and/or modify
|
|
3589.30.2
by Jordi Esteve
Added network_extension module: Protocols, services, ... |
13 |
# it under the terms of the GNU General Public License as published by
|
14 |
# the Free Software Foundation, either version 3 of the License, or
|
|
15 |
# (at your option) any later version.
|
|
16 |
#
|
|
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
17 |
# network_extension is distributed in the hope that it will be useful,
|
3589.30.2
by Jordi Esteve
Added network_extension module: Protocols, services, ... |
18 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20 |
# GNU General Public License for more details.
|
|
21 |
#
|
|
22 |
# You should have received a copy of the GNU General Public License
|
|
23 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
24 |
#
|
|
25 |
##############################################################################
|
|
26 |
||
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
27 |
from osv import osv |
28 |
from osv import fields |
|
29 |
from tools.translate import _ |
|
30 |
||
31 |
import base64 |
|
3589.30.2
by Jordi Esteve
Added network_extension module: Protocols, services, ... |
32 |
import time |
33 |
||
34 |
#--------------------------------------------------------------
|
|
35 |
# A network is composed of all kind of networkable materials
|
|
36 |
#--------------------------------------------------------------
|
|
37 |
class network_network(osv.osv): |
|
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
38 |
"""
|
39 |
A network is composed of all kind of networkable materials
|
|
40 |
"""
|
|
3589.30.2
by Jordi Esteve
Added network_extension module: Protocols, services, ... |
41 |
_inherit = "network.network" |
42 |
_columns = { |
|
43 |
'gateway': fields.char('Gateway', size=100), |
|
44 |
'dns': fields.char('DNS', size=100, help="List of DNS servers, separated by commas"), |
|
45 |
'public_ip_address': fields.char('Public IP address', size=100), |
|
46 |
'public_domain': fields.char('Public domain', size=100), |
|
47 |
}
|
|
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
48 |
|
3589.30.2
by Jordi Esteve
Added network_extension module: Protocols, services, ... |
49 |
network_network() |
50 |
||
51 |
||
52 |
#----------------------------------------------------------
|
|
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
53 |
# Materials; computer, printer, switch, ...
|
54 |
#----------------------------------------------------------
|
|
55 |
class network_material(osv.osv): |
|
56 |
_inherit = "network.material" |
|
57 |
_columns = { |
|
58 |
'mac_addr': fields.char('MAC addresss', size=17), |
|
59 |
'partner_id': fields.related('network_id', 'contact_id', type='many2one', relation='res.partner', string='Partner', readonly=True), |
|
60 |
}
|
|
61 |
# TODO: Add On Changeon the mac adress, to check if it correct
|
|
62 |
# regexp: /^([0-9a-f]{2}([:-]|$)){6}$/i
|
|
63 |
||
64 |
network_material() |
|
65 |
||
66 |
||
67 |
#----------------------------------------------------------
|
|
3589.30.2
by Jordi Esteve
Added network_extension module: Protocols, services, ... |
68 |
# A software installed on a material
|
69 |
#----------------------------------------------------------
|
|
70 |
class network_software(osv.osv): |
|
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
71 |
"""
|
72 |
A software installed on a material
|
|
73 |
"""
|
|
3589.30.2
by Jordi Esteve
Added network_extension module: Protocols, services, ... |
74 |
_inherit = "network.software" |
75 |
_columns = { |
|
76 |
'type': fields.many2one('network.software.type', |
|
77 |
'Software Type', required=True, select=1), |
|
78 |
'service_ids': fields.one2many('network.service', 'software_id', string='Service'), |
|
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
79 |
'network_id': fields.related('material_id', 'network_id', type='many2one', relation='network.network', string='Network', readonly=True), |
80 |
'partner_id': fields.related('material_id', 'partner_id', type='many2one', relation='res.partner', string='Partner', readonly=True), |
|
3589.30.2
by Jordi Esteve
Added network_extension module: Protocols, services, ... |
81 |
}
|
82 |
||
83 |
def _default_material(self, cursor, user, context=None): |
|
84 |
if not context.get('material_id', False): |
|
85 |
return False |
|
86 |
value = context['material_id'] |
|
87 |
return value |
|
88 |
||
89 |
_defaults = { |
|
90 |
'material_id': lambda obj, cursor, user, context: obj._default_material(cursor, user, context=context), |
|
91 |
}
|
|
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
92 |
|
3589.30.2
by Jordi Esteve
Added network_extension module: Protocols, services, ... |
93 |
network_software() |
94 |
||
95 |
||
96 |
#------------------------------------------------------------
|
|
97 |
# Couples of login/password
|
|
98 |
#------------------------------------------------------------
|
|
99 |
class network_software_logpass(osv.osv): |
|
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
100 |
"""
|
101 |
Couples of login/password
|
|
102 |
"""
|
|
3589.30.2
by Jordi Esteve
Added network_extension module: Protocols, services, ... |
103 |
_inherit = "network.software.logpass" |
104 |
_columns = { |
|
105 |
'name': fields.char('Name', size=100), |
|
106 |
'note': fields.text('Note'), |
|
3812.1.5
by Jordi Esteve
Change to GPL-3 license in several modules (merged changes from 3914 stable 5.0) |
107 |
'material': fields.related('software_id', 'material_id', type='many2one', relation='network.material', string='Material', readonly=True), |
108 |
'encrypted': fields.boolean('Encrypted'), |
|
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
109 |
'superuser': fields.boolean('Super User'), |
3812.1.5
by Jordi Esteve
Change to GPL-3 license in several modules (merged changes from 3914 stable 5.0) |
110 |
}
|
111 |
||
112 |
_defaults = { |
|
113 |
'encrypted': lambda obj, cursor, user, context: False, |
|
114 |
}
|
|
115 |
||
116 |
def onchange_password(self, cr, uid, ids, encrypted, context={}): |
|
117 |
return {'value':{'encrypted': False}} |
|
118 |
||
119 |
||
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
120 |
def _encrypt_password(self, cr, uid, ids, *args): |
3812.1.5
by Jordi Esteve
Change to GPL-3 license in several modules (merged changes from 3914 stable 5.0) |
121 |
for rec in self.browse(cr, uid, ids): |
122 |
try: |
|
123 |
from Crypto.Cipher import ARC4 |
|
124 |
except ImportError: |
|
125 |
raise osv.except_osv(_('Error !'), _('Package python-crypto no installed.')) |
|
126 |
||
127 |
if not rec.encrypted: |
|
128 |
obj_encrypt_password = self.pool.get('network.encrypt.password') |
|
129 |
encrypt_password_ids = obj_encrypt_password.search(cr, uid, [('create_uid','=',uid),('write_uid','=',uid)]) |
|
130 |
encrypt_password_id = encrypt_password_ids and encrypt_password_ids[0] or False |
|
131 |
if encrypt_password_id: |
|
132 |
passwordkey = obj_encrypt_password.browse(cr, uid, encrypt_password_id).name |
|
133 |
enc = ARC4.new(passwordkey) |
|
134 |
try: |
|
135 |
encripted = base64.b64encode(enc.encrypt(rec.password)) |
|
136 |
except UnicodeEncodeError: |
|
137 |
break
|
|
138 |
self.write(cr, uid, [rec.id], {'password': encripted, 'encrypted': True}) |
|
139 |
else: |
|
140 |
raise osv.except_osv(_('Error !'), _('Not encrypt/decrypt password has given.')) |
|
141 |
return True |
|
142 |
||
143 |
||
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
144 |
def _decrypt_password(self, cr, uid, ids, *args): |
3812.1.5
by Jordi Esteve
Change to GPL-3 license in several modules (merged changes from 3914 stable 5.0) |
145 |
for rec in self.browse(cr, uid, ids): |
146 |
try: |
|
147 |
from Crypto.Cipher import ARC4 |
|
148 |
except ImportError: |
|
149 |
raise osv.except_osv(_('Error !'), _('Package python-crypto no installed.')) |
|
150 |
||
151 |
if rec.encrypted: |
|
152 |
obj_encrypt_password = self.pool.get('network.encrypt.password') |
|
153 |
encrypt_password_ids = obj_encrypt_password.search(cr, uid, [('create_uid','=',uid),('write_uid','=',uid)]) |
|
154 |
encrypt_password_id = encrypt_password_ids and encrypt_password_ids[0] or False |
|
155 |
if encrypt_password_id: |
|
156 |
passwordkey = obj_encrypt_password.browse(cr, uid, encrypt_password_id).name |
|
157 |
dec = ARC4.new(passwordkey) |
|
158 |
try: |
|
159 |
desencripted = dec.decrypt(base64.b64decode(rec.password)) |
|
160 |
unicode(desencripted, 'ascii') |
|
161 |
raise osv.except_osv(rec.login+_(' password:'), desencripted) |
|
162 |
except UnicodeDecodeError: |
|
163 |
raise osv.except_osv(_('Error !'), _('Wrong encrypt/decrypt password.')) |
|
164 |
else: |
|
165 |
raise osv.except_osv(_('Error !'), _('Not encrypt/decrypt password has given.')) |
|
166 |
return True |
|
167 |
||
3589.30.2
by Jordi Esteve
Added network_extension module: Protocols, services, ... |
168 |
network_software_logpass() |
169 |
||
170 |
||
171 |
#----------------------------------------------------------
|
|
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
172 |
# Protocol (ssh, http, smtp, ...)
|
3589.30.2
by Jordi Esteve
Added network_extension module: Protocols, services, ... |
173 |
#----------------------------------------------------------
|
174 |
class network_protocol(osv.osv): |
|
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
175 |
"""
|
176 |
Protocol (ssh, http, smtp, ...)
|
|
177 |
"""
|
|
3589.30.2
by Jordi Esteve
Added network_extension module: Protocols, services, ... |
178 |
_name = "network.protocol" |
179 |
_description = "Protocol" |
|
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
180 |
|
3589.30.2
by Jordi Esteve
Added network_extension module: Protocols, services, ... |
181 |
_columns = { |
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
182 |
'name': fields.char('Name', size=64, required=True, select=1), |
183 |
'description': fields.char('Description', size=256, translate=True), |
|
184 |
'port': fields.integer('Port', help='Default port defined see(http://www.iana.org/assignments/port-numbers)', required=True), |
|
185 |
'protocol': fields.selection([('tcp', 'TCP'),('udp', 'UDP'), ('both', 'Both'), ('other', 'Other')], 'Protocol', required=True), |
|
3589.30.2
by Jordi Esteve
Added network_extension module: Protocols, services, ... |
186 |
}
|
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
187 |
|
3589.30.2
by Jordi Esteve
Added network_extension module: Protocols, services, ... |
188 |
network_protocol() |
189 |
||
190 |
||
191 |
#----------------------------------------------------------
|
|
192 |
# Services
|
|
193 |
#----------------------------------------------------------
|
|
194 |
class network_service(osv.osv): |
|
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
195 |
"""
|
196 |
Services
|
|
197 |
"""
|
|
3589.30.2
by Jordi Esteve
Added network_extension module: Protocols, services, ... |
198 |
_name = "network.service" |
199 |
_description = "Service Network" |
|
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
200 |
|
3589.30.2
by Jordi Esteve
Added network_extension module: Protocols, services, ... |
201 |
_columns = { |
202 |
'name': fields.char('Name', size=64, select=1), |
|
203 |
'software_id': fields.many2one('network.software', 'Software', required=True), |
|
204 |
'material':fields.related('software_id', 'material_id', type='many2one', relation='network.material', string='Material', readonly=True), |
|
205 |
'protocol_id': fields.many2one('network.protocol', 'Protocol', select=1), |
|
206 |
'path': fields.char('Path', size=100), |
|
207 |
'port': fields.integer('Port', required=True, select=2), |
|
208 |
'public_port': fields.integer('Public port', select=2, help="Sometimes public and private ports are different."), |
|
209 |
'private_url': fields.char('Private URL', size=256), |
|
210 |
'public_url': fields.char('Public URL', size=256), |
|
211 |
}
|
|
212 |
||
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
213 |
def _compute_public_url(self, cr, uid, ids, *args): |
3589.30.2
by Jordi Esteve
Added network_extension module: Protocols, services, ... |
214 |
for rec in self.browse(cr, uid, ids): |
215 |
if not rec.protocol_id or not rec.software_id: |
|
216 |
continue
|
|
217 |
protocol = rec.protocol_id.name+"://" |
|
218 |
port = rec.port and ":"+str(rec.port) or "" |
|
219 |
public_port = rec.public_port and ":"+str(rec.public_port) or "" |
|
220 |
path = rec.path and rec.path or "" |
|
221 |
||
222 |
# Compute Private URL from Material IP
|
|
223 |
ip_address = rec.software_id.material_id.ip_addr |
|
224 |
if ip_address: |
|
225 |
service2 = protocol+ip_address+port+path |
|
226 |
self.write(cr, uid, [rec.id], {'private_url' : service2}) |
|
227 |
||
228 |
# Compute Public URL from Network IP
|
|
229 |
if not rec.software_id.material_id.network_id: |
|
230 |
continue
|
|
231 |
public_ip_address = rec.software_id.material_id.network_id.public_ip_address |
|
232 |
public_domain = rec.software_id.material_id.network_id.public_domain |
|
233 |
if public_domain: |
|
234 |
service1 = protocol+public_domain+public_port+path |
|
235 |
self.write(cr, uid, [rec.id], {'public_url' : service1}) |
|
236 |
elif public_ip_address: |
|
237 |
service1 = protocol+public_ip_address+public_port+path |
|
238 |
self.write(cr, uid, [rec.id], {'public_url' : service1}) |
|
239 |
||
240 |
return True |
|
241 |
||
242 |
||
243 |
def onchange_port(self, cr, uid, ids, port, context={}): |
|
244 |
if not port: |
|
245 |
return {} |
|
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
246 |
return {'value': {'public_port': port}} |
3589.30.2
by Jordi Esteve
Added network_extension module: Protocols, services, ... |
247 |
|
248 |
network_service() |
|
3812.1.5
by Jordi Esteve
Change to GPL-3 license in several modules (merged changes from 3914 stable 5.0) |
249 |
|
250 |
||
251 |
class network_encrypt_password(osv.osv_memory): |
|
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
252 |
"""
|
253 |
Password encryption
|
|
254 |
"""
|
|
3812.1.5
by Jordi Esteve
Change to GPL-3 license in several modules (merged changes from 3914 stable 5.0) |
255 |
_name = 'network.encrypt.password' |
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
256 |
_description = 'Password encryption' |
257 |
||
3812.1.5
by Jordi Esteve
Change to GPL-3 license in several modules (merged changes from 3914 stable 5.0) |
258 |
_columns = { |
259 |
'name': fields.char('Encrypt/Decrypt password', size=100), |
|
260 |
}
|
|
261 |
||
262 |
def create(self, cr, uid, vals, context=None): |
|
263 |
encrypt_password_ids = self.search(cr, uid, [('create_uid','=',uid),('write_uid','=',uid)], context=context) |
|
264 |
self.unlink(cr, uid, encrypt_password_ids, context=context) |
|
265 |
return super(osv.osv_memory, self).create(cr, uid, vals, context=context) |
|
266 |
||
267 |
network_encrypt_password() |
|
5228
by Jordi Esteve
[FIX] network and network_extension modules ported form v5 to v6 |
268 |
|
269 |
||
270 |
||
271 |
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|