file: access_view.xml
<record model="ir.ui.view" id="it_access_form">
<field name="name">it.access.form</field>
<field name="model">it.access</field>
<field name="arch" type="xml">
<form string="Access">
<sheet>
<div class="oe_title">
<div class="oe_edit_only">
<label for="name"/>
</div>
<h1>
<field name="name"/>
</h1>
<div class="oe_edit_only">
<label for="equipment_id"/>
</div>
<h1>
<field name="equipment_id"/>
</h1>
<div class="oe_edit_only">
<label for="partner_id"/>
</div>
<h1>
<field name="partner_id"/>
</h1>
</div>
<group>
<!--fields-->
</group>
<field colspan="4" name="note" nolabel="1" placeholder="Write a note.."/>
<notebook>
<page string="Information">
<group col="4">
<field name="user"/>
<field name="application"/>
<field name="port"/>
<field name="description"/>
<field name="link" widget="url" />
</group>
<newline/>
<group col="5">
<field name="password" on_change="onchange_password(encrypted)"/>
<button name="get_random_password" string="Generate" type="object" groups="it.group_it_mod"
confirm="Are you sure?" colspan="1" icon="gtk-convert"/>
<button name="encrypt_password" type="object" string="Encrypt" confirm="Are you sure?"
icon="gtk-execute" colspan="1" attrs="{'invisible': [('encrypted', '=', True)]}"/>
<button name="decrypt_password" type="object" string="Decrypt" icon="gtk-print"
colspan="1" attrs="{'invisible': [('encrypted', '=', False)]}"/>
<newline/>
<field name="encrypted" readonly="True"/>
</group>
</page>
<page string="SSL">
<group label="SSL">
<field name="ssl_csr" filename="ssl_csr_filename"/>
<field name="ssl_csr_filename" invisible="1"/>
<field name="ssl_cert" filename="ssl_cert_filename"/>
<field name="ssl_cert_filename" invisible="1"/>
<field name="ssl_publickey" filename="ssl_publickey_filename"/>
<field name="ssl_publickey_filename" invisible="1"/>
<field name="ssl_privatekey" filename="ssl_privatekey_filename"/>
<field name="ssl_privatekey_filename" invisible="1"/>
</group>
</page>
<page string="Audit Data" groups="it.group_it_mod">
<group>
<group>
<field name="user_id"/>
<field name="creation_date" />
</group>
</group>
</page>
<page string="Configuration" groups="it.group_it_mod">
<group>
<group>
<field name="active" />
<field name="company_id" string="Company" groups="base.group_multi_company"/>
</group>
</group>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
file: access.py
def get_random_password(self, cr, uid, ids, context=None):
logging.info("......1")
for access in self.browse(cr, uid, ids, context=context):
longitud = 16
valores = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<=>@#%&+"
p = ""
p = p.join([choice(valores) for i in range(longitud)])
# self.write(cr, uid, ids, {'password': p, 'encrypted': False })
return True
def onchange_password(self, cr, uid, ids, encrypted, context={}):
return {'value':{'encrypted': False}}
def encrypt_password(self, cr, uid, ids, *args):
logging.info('.........')
try:
from Crypto.Cipher import ARC4
except ImportError:
raise osv.except_osv(_('Error !'), _('Package python-crypto no installed.'))
val = self.pool.get('ir.config_parameter').get_param(cr, uid, 'it_passkey')
if not val:
raise osv.except_osv(_('Error !'), _('For Encryptation you must set a system parameter with key "it_passkey" and fill in value a passkey'))
for rec in self.browse(cr, uid, ids):
if not rec.encrypted:
enc = ARC4.new(val)
try:
encripted = base64.b64encode(enc.encrypt(rec.password))
except UnicodeEncodeError:
break
self.write(cr, uid, [rec.id], {'password': encripted, 'encrypted': True})
else:
raise osv.except_osv(_('Error !'), _('Password already encrypted'))
return True
def decrypt_password(self, cr, uid, ids, *args):
try:
from Crypto.Cipher import ARC4
except ImportError:
raise osv.except_osv(_('Error !'), _('Package python-crypto no installed.'))
val = self.pool.get('ir.config_parameter').get_param(cr, uid, 'it_passkey')
if not val:
raise osv.except_osv(_('Error !'), _('For Encryptation you must set a system parameter with key "it_passkey" and fill in value a passkey'))
for rec in self.browse(cr, uid, ids):
dec = ARC4.new(val)
try:
desencripted = dec.decrypt(base64.b64decode(rec.password))
unicode(desencripted, 'ascii')
raise osv.except_osv(_('Decrypt password:'), desencripted)
except UnicodeDecodeError:
raise osv.except_osv(_('Error !'), _('Wrong encrypt/decrypt password.'))
return True