tag:blogger.com,1999:blog-27262749969989792772024-03-06T00:39:11.857+01:00WundercodeBecause everything is made of code and for doing everything you need code.cyberfidohttp://www.blogger.com/profile/11212966372629742529noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-2726274996998979277.post-44077211018768529312015-08-25T15:16:00.002+02:002015-08-25T15:16:34.424+02:00Wordpress: Convert .htaccess to web.config file<div dir="ltr" style="text-align: left;" trbidi="on">
Everywhere you will find step-by-step guides to migrate from Linux hosting to Windows hosting (or viceversa), but something very useful to know is how to convert .htaccess file to web.config file.<br />
<br />
Wordpress has some default rules that writes on Apache .htaccess file.<br />
Something like this below<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ft0qZYuP7iwls7qrDwZPozx62VStbLhM0_t_AfiZub0YbwPnBYOJF8dDi9-DTvGFC-uKwC1Mv5SD9wCRnDtM2o9VWVutQLysEdO23PeiU6ww5y-DR1wHaYEn7MsLgVaeoGZmYLkXLiIY/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> # BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
</code></pre>
<br />
The web.config equivalent to this is<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ft0qZYuP7iwls7qrDwZPozx62VStbLhM0_t_AfiZub0YbwPnBYOJF8dDi9-DTvGFC-uKwC1Mv5SD9wCRnDtM2o9VWVutQLysEdO23PeiU6ww5y-DR1wHaYEn7MsLgVaeoGZmYLkXLiIY/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
</code></pre>
<br />
In this manner you can avoid all 404 errors caused by rewrite absence.<br />
<br /></div>
cyberfidohttp://www.blogger.com/profile/11212966372629742529noreply@blogger.com0tag:blogger.com,1999:blog-2726274996998979277.post-81876256163163540282015-04-14T12:06:00.001+02:002015-04-14T12:07:44.202+02:00Installation pgAgent on CentOs<div dir="ltr" style="text-align: left;" trbidi="on">
I faced the task to install pgAgent on PostgreSql 9.3 CentOs 6 server.<br />
I serached a lot but I didn't find anything on web very complete.<br />
So why don't write it by myself?<br />
The most explanatory guide I found was this on <a href="http://orbitphreak.blogspot.it/2013/04/installing-pgagent-33-on-centos-5x-x8664.html">OrbitPhreak blog</a><br />
<br />
Due to the fact that updating CentOs Epel Repository I met this error<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ft0qZYuP7iwls7qrDwZPozx62VStbLhM0_t_AfiZub0YbwPnBYOJF8dDi9-DTvGFC-uKwC1Mv5SD9wCRnDtM2o9VWVutQLysEdO23PeiU6ww5y-DR1wHaYEn7MsLgVaeoGZmYLkXLiIY/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> Loaded plugins: fastestmirror, security
Determining fastest mirrors
Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again
</code></pre>
<br />
I found <a href="https://community.hpcloud.com/article/centos-63-instance-giving-cannot-retrieve-metalink-repository-epel-error">this useful link</a> to solve also this problem<br />
<br />
So let's install this fucking pgAgent.<br />
To install pgAgent we also have to install many packages (wxWidgets) related to graphic libraries used by pgAgent itself.<br />
This is maybe due to the fact that pgAgent was originally a part of the pgAdmin client.<br />
Tha last package of pgAgent in the time I'm writing is 3.4.0, but you find the last package <a href="http://www.postgresql.org/ftp/pgadmin3/release/pgagent/">here</a>.<br />
Type in sequence this commands on your CentOs server<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ft0qZYuP7iwls7qrDwZPozx62VStbLhM0_t_AfiZub0YbwPnBYOJF8dDi9-DTvGFC-uKwC1Mv5SD9wCRnDtM2o9VWVutQLysEdO23PeiU6ww5y-DR1wHaYEn7MsLgVaeoGZmYLkXLiIY/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> yum install wxGTK.x86_64 wxGTK-devel.x86_64 cmake
yum install gcc
yum install gcc-c++
yum install postgresql-devel
yum install wget
wget http://ftp.postgresql.org/pub/pgadmin3/release/pgagent/pgAgent-3.4.0-Source.tar.gz
tar -zxvf pgAgent-3.4.0-Source.tar.gz
wget http://sourceforge.net/projects/wxwindows/files/2.8.12/wxWidgets-2.8.12.tar.gz
tar -zxvf wxWidgets-2.8.12.tar.gz
cd wxWidgets*
./configure --with-gtk --enable-gtk2 --enable-unicode
make
su -c "make install; /sbin/ldconfig"
cd contrib
make
su -c "make install"
</code></pre>
<br />
Now we can install pgAgent.<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ft0qZYuP7iwls7qrDwZPozx62VStbLhM0_t_AfiZub0YbwPnBYOJF8dDi9-DTvGFC-uKwC1Mv5SD9wCRnDtM2o9VWVutQLysEdO23PeiU6ww5y-DR1wHaYEn7MsLgVaeoGZmYLkXLiIY/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> cd pgAgent*
cmake -D PG_CONFIG_PATH:FILEPATH=/usr/pgsql-9.3/bin/pg_config -D STATIC_BUILD:BOOL=OFF .
make
su -c "make install"
cp sql/pgagent.sql /var/lib/pgsql/9.3
su postgres
psql -U postgres -d postgres -f pgagent.sql
exit
echo '/usr/pgsql-9.3/lib' >> /etc/ld.so.conf.d/postgres.conf
</code></pre>
<br />
Ok, now we have installed all, we can create a service called pgagent useful for starting, stopping pgagent whenever we want.<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ft0qZYuP7iwls7qrDwZPozx62VStbLhM0_t_AfiZub0YbwPnBYOJF8dDi9-DTvGFC-uKwC1Mv5SD9wCRnDtM2o9VWVutQLysEdO23PeiU6ww5y-DR1wHaYEn7MsLgVaeoGZmYLkXLiIY/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> vim /etc/rc.d/init.d/pgagent
</code></pre>
<br />
and we can copy all this text inside the text editor<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ft0qZYuP7iwls7qrDwZPozx62VStbLhM0_t_AfiZub0YbwPnBYOJF8dDi9-DTvGFC-uKwC1Mv5SD9wCRnDtM2o9VWVutQLysEdO23PeiU6ww5y-DR1wHaYEn7MsLgVaeoGZmYLkXLiIY/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> #!/bin/bash
#
# /etc/rc.d/init.d/pgagent
#
# Manages the pgagent daemon
#
# chkconfig: - 65 35
# description: PgAgent PostgreSQL Job Service
# processname: pgagent
. /etc/init.d/functions
RETVAL=0
prog="PgAgent"
start() {
echo -n $"Starting $prog: "
daemon "/usr/local/bin/pgagent hostaddr=127.0.0.1 dbname=postgres user=postgres password=??????"
RETVAL=$?
echo
}
stop() {
echo -n $"Stopping $prog: "
killproc /usr/local/bin/pgagent
RETVAL=$?
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload|restart)
stop
start
RETVAL=$?
;;
status)
status /usr/local/bin/pgagent
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit $RETVAL
</code></pre>
<br />
Then we set grants on file service and put it starting at boot time.<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ft0qZYuP7iwls7qrDwZPozx62VStbLhM0_t_AfiZub0YbwPnBYOJF8dDi9-DTvGFC-uKwC1Mv5SD9wCRnDtM2o9VWVutQLysEdO23PeiU6ww5y-DR1wHaYEn7MsLgVaeoGZmYLkXLiIY/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> chmod 0755 /etc/rc.d/init.d/pgagent
/sbin/chkconfig --level 345 pgagent on
service pgagent start
</code></pre>
<br />
To make pgAgent usable from Postgres we should modify pg_hba.conf in this way<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ft0qZYuP7iwls7qrDwZPozx62VStbLhM0_t_AfiZub0YbwPnBYOJF8dDi9-DTvGFC-uKwC1Mv5SD9wCRnDtM2o9VWVutQLysEdO23PeiU6ww5y-DR1wHaYEn7MsLgVaeoGZmYLkXLiIY/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> vim /var/lib/pgsql/9.3/data/pg_hba.conf
</code></pre>
<br />
and make the "host" row like this<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ft0qZYuP7iwls7qrDwZPozx62VStbLhM0_t_AfiZub0YbwPnBYOJF8dDi9-DTvGFC-uKwC1Mv5SD9wCRnDtM2o9VWVutQLysEdO23PeiU6ww5y-DR1wHaYEn7MsLgVaeoGZmYLkXLiIY/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> host all all 127.0.0.1/32 trust
</code></pre>
<br />
In this manner the postgres user can trust himself in any way: both with password or woithout it.<br />
For example running this command it should work<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ft0qZYuP7iwls7qrDwZPozx62VStbLhM0_t_AfiZub0YbwPnBYOJF8dDi9-DTvGFC-uKwC1Mv5SD9wCRnDtM2o9VWVutQLysEdO23PeiU6ww5y-DR1wHaYEn7MsLgVaeoGZmYLkXLiIY/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> SELECT dblink_connect('user=postgres password=ocpNHosting14 host=127.0.0.1 dbname=postgres');
</code></pre>
<br />
Just insert the host definition equal to 127.0.0.1.<br />
<br />
That's all!<br />
<br />
Now you can create new jobs following <a href="http://www.pgadmin.org/docs/1.6/pgagent.html">this useful guide</a>.<br />
<br />
Enjoy!<br />
<br />
<br />
<br />
<br /></div>
cyberfidohttp://www.blogger.com/profile/11212966372629742529noreply@blogger.com6tag:blogger.com,1999:blog-2726274996998979277.post-78389446484936581482014-08-22T14:41:00.003+02:002015-08-25T15:19:50.415+02:00Proxmox: restore cluster without rebooting<div dir="ltr" style="text-align: left;" trbidi="on">
For some reason in these days I faced a problem with proxmox GUI and cluster management.<br />
From one node of the cluster I saw on /var/log/syslog file that<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ft0qZYuP7iwls7qrDwZPozx62VStbLhM0_t_AfiZub0YbwPnBYOJF8dDi9-DTvGFC-uKwC1Mv5SD9wCRnDtM2o9VWVutQLysEdO23PeiU6ww5y-DR1wHaYEn7MsLgVaeoGZmYLkXLiIY/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> pveproxy[88540]: WARNING: proxy detected vanished client connection
</code></pre>
and if I try to access to the Web GUI of that node, it says "Login Incorrect".<br />
From other nodes, it seems all right, but it isn't.<br />
The solution is to simulate a reboot of all the machines without rebooting the VM on them: powerful!<br />
So this is the sequence to launch on every node of the cluster, without some particular order<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ft0qZYuP7iwls7qrDwZPozx62VStbLhM0_t_AfiZub0YbwPnBYOJF8dDi9-DTvGFC-uKwC1Mv5SD9wCRnDtM2o9VWVutQLysEdO23PeiU6ww5y-DR1wHaYEn7MsLgVaeoGZmYLkXLiIY/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> /etc/init.d/cman restart
/etc/init.d/pvedaemon restart
/etc/init.d/pvestatd restart
/etc/init.d/pve-manager restart
/etc/init.d/pve-cluster restart
</code></pre>
<br />
Now, it works great.</div>
cyberfidohttp://www.blogger.com/profile/11212966372629742529noreply@blogger.com2tag:blogger.com,1999:blog-2726274996998979277.post-35207211423894921512014-08-22T13:08:00.001+02:002014-09-15T11:36:40.129+02:00yum-updatesd occupying memory and bandwith<div dir="ltr" style="text-align: left;" trbidi="on">
When you install CentOs, you have to pay attention to this process yum-updatesd.<br />
It manages updates od OS autonomously, but due to a bug not fixed, it could occupy memory, cpu and bandwith depending of the operations it is doing.<br />
So, because I am an old style system administrator, I prefer to disable this process and its Micro$oft's style behavior.<br />
To do this, it requires these two commands<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ft0qZYuP7iwls7qrDwZPozx62VStbLhM0_t_AfiZub0YbwPnBYOJF8dDi9-DTvGFC-uKwC1Mv5SD9wCRnDtM2o9VWVutQLysEdO23PeiU6ww5y-DR1wHaYEn7MsLgVaeoGZmYLkXLiIY/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> chkconfig --del yum-updatesd
kill -9 [pid_of_process]
</code></pre>
<br />
Easy but useful.</div>
cyberfidohttp://www.blogger.com/profile/11212966372629742529noreply@blogger.com0tag:blogger.com,1999:blog-2726274996998979277.post-31232542823172019992014-03-25T10:23:00.002+01:002015-08-25T15:22:51.382+02:00The Certificate associated with this binding is also assigned to another site's binding.<div dir="ltr" style="text-align: left;" trbidi="on">
I faced this problem twice, so I decide to write down some notes to help me and you in case we'll face this problem again (or for the first time).<br />
When I assign the same certificate to two or more websites and after a while I decide to remove, IIS asks the following question:<br />
<br />
<div style="text-align: left;">
<span style="font-weight: normal;"><span name="subject">The Certificate associated with this binding is
also assigned to another site's binding. Deleting this binding will
cause the HTTPS binding of the other site to be unusable. Do you still
want to continue?</span></span></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<span style="font-weight: normal;"><span name="subject">Well...I think not. </span></span></div>
<div style="text-align: left;">
<span style="font-weight: normal;"><span name="subject"><br /></span></span></div>
<div style="text-align: left;">
<span style="font-weight: normal;"><span name="subject">The consequence of this action is the stop of all others applications using that certificate, not quite good for a production environment. So what to do?</span></span></div>
<div style="text-align: left;">
<span style="font-weight: normal;"><span name="subject"><br /></span></span></div>
<div style="text-align: left;">
<span style="font-weight: normal;"><span name="subject">Edit C:\Windows\System32\inetsrv\config\</span></span><span style="font-weight: normal;"><span name="subject">applicationHost.config, search for your application name and manually delete the row with the https binding. </span></span></div>
<div style="text-align: left;">
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ft0qZYuP7iwls7qrDwZPozx62VStbLhM0_t_AfiZub0YbwPnBYOJF8dDi9-DTvGFC-uKwC1Mv5SD9wCRnDtM2o9VWVutQLysEdO23PeiU6ww5y-DR1wHaYEn7MsLgVaeoGZmYLkXLiIY/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> <binding protocol="https" bindingInformation<binding protocol="https" bindingInformation="*:443:" />"*:443:" />
</code></pre>
<br />
<span style="font-weight: normal;"><span name="subject">Save file and re-open IIS GUI: the binding should be disappeared.</span></span></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<span style="font-weight: normal;"><span name="subject">An IIS bug? Maybe or maybe only Microsoft style ;) </span></span></div>
<div style="text-align: left;">
<span style="font-weight: normal;"><span name="subject"><br /></span></span></div>
<div style="text-align: left;">
<span style="font-weight: normal;"><span name="subject"><br /></span></span></div>
<div style="text-align: left;">
<span style="font-weight: normal;"><span name="subject"><br /></span></span></div>
<div style="text-align: left;">
<span style="font-weight: normal;"><span name="subject"><br /></span></span></div>
<div style="text-align: left;">
<span style="font-weight: normal;"><span name="subject"><br /></span></span></div>
</div>
cyberfidohttp://www.blogger.com/profile/11212966372629742529noreply@blogger.com7tag:blogger.com,1999:blog-2726274996998979277.post-55266975255689216442014-03-20T11:48:00.002+01:002014-03-25T14:17:12.928+01:00BC30002: Type 'NameClass' not defined<div dir="ltr" style="text-align: left;" trbidi="on">
I've struggled a few minutes too long to resolve this problem.<br />
I writed a new class with some type inside, added by a new Namespace.<br />
I added the relative reference on the project.<br />
The solution compiles correctly, but at the site's launch on localhost, I obtained the following error<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ft0qZYuP7iwls7qrDwZPozx62VStbLhM0_t_AfiZub0YbwPnBYOJF8dDi9-DTvGFC-uKwC1Mv5SD9wCRnDtM2o9VWVutQLysEdO23PeiU6ww5y-DR1wHaYEn7MsLgVaeoGZmYLkXLiIY/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> BC30002: Type 'NameClass' not defined
</code></pre>
<br />
WTF?!<br />
<br />
Solution<br />
Check if has been added the dll relative to the reference added and/or in the web.config has been added the relative assembly reference.<br />
If not, the solution is to manually add the reference in the following manner<br />
(in my case System.Security) <br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ft0qZYuP7iwls7qrDwZPozx62VStbLhM0_t_AfiZub0YbwPnBYOJF8dDi9-DTvGFC-uKwC1Mv5SD9wCRnDtM2o9VWVutQLysEdO23PeiU6ww5y-DR1wHaYEn7MsLgVaeoGZmYLkXLiIY/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> <compilation debug="true" strict="false" explicit="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
</assemblies>
</compilation>
</code></pre>
<br />
To find the exact string to write in the web.config, search in the machine.config that shows all packages already installed on your PC.<br />
<br />
Enjoy! </div>
cyberfidohttp://www.blogger.com/profile/11212966372629742529noreply@blogger.com0tag:blogger.com,1999:blog-2726274996998979277.post-58123550243021229612014-02-22T14:49:00.002+01:002014-02-22T14:49:03.775+01:00How to distribute automatic update on Linux clients<div dir="ltr" style="text-align: left;" trbidi="on">
At work with the growth of clients in firm network I need to distribute updates automatically.<br />
To do this I encountered a lot af weird problems due to Linux grants and Bash execution.<br />
So let's have a look to our structure.<br />
We have one server (a CentOS 6.5 in this case, but it's not significant) and many Ubuntu 12.04 LTS clients (also this is not very signficant).<br />
<br />
<h3 style="text-align: left;">
Our goal</h3>
Download automatically from every client some settings (whatever you want) from server and update automatically the client settings.<br />
<br />
<h3 style="text-align: left;">
Step 1 - SSH automatically to server</h3>
<h4 style="text-align: left;">
On client</h4>
First of all I need to ssh automatically to server. So log as root on the client and then type<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ft0qZYuP7iwls7qrDwZPozx62VStbLhM0_t_AfiZub0YbwPnBYOJF8dDi9-DTvGFC-uKwC1Mv5SD9wCRnDtM2o9VWVutQLysEdO23PeiU6ww5y-DR1wHaYEn7MsLgVaeoGZmYLkXLiIY/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> ssh-keygen -t rsa
</code></pre>
<br />
you need this to create a public and a private key useful to subsitute to the password.<br />
<br />
Then send to the server the public key generated on client<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ft0qZYuP7iwls7qrDwZPozx62VStbLhM0_t_AfiZub0YbwPnBYOJF8dDi9-DTvGFC-uKwC1Mv5SD9wCRnDtM2o9VWVutQLysEdO23PeiU6ww5y-DR1wHaYEn7MsLgVaeoGZmYLkXLiIY/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> cd /root/
cat .ssh/id_rsa.pub | ssh [username]@[servername] -p [port] 'cat >> .ssh/authorized_keys'
</code>
</pre>
<br />
<h4 style="text-align: left;">
On server</h4>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ft0qZYuP7iwls7qrDwZPozx62VStbLhM0_t_AfiZub0YbwPnBYOJF8dDi9-DTvGFC-uKwC1Mv5SD9wCRnDtM2o9VWVutQLysEdO23PeiU6ww5y-DR1wHaYEn7MsLgVaeoGZmYLkXLiIY/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> chmod 700 .ssh
chmod 640 .ssh/authorized_keys
</code></pre>
<div style="text-align: left;">
<br />
<br />
Adjust grants to permit only to root to manage this file.<br />
The authorized_keys is the file where every client will store its public key, so at every login, server will check this file to recognize the key sent from the client.<br />
<br />
<h3 style="text-align: left;">
Step 2 - Configure the automation </h3>
<h4 style="text-align: left;">
On client </h4>
<div style="text-align: left;">
Now that we managed to login automatically every time we want, let's see how we could automate something.</div>
<div style="text-align: left;">
First I create the file to be automated, something like this, named "script_to_execute.sh"</div>
<div style="text-align: left;">
<br /></div>
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ft0qZYuP7iwls7qrDwZPozx62VStbLhM0_t_AfiZub0YbwPnBYOJF8dDi9-DTvGFC-uKwC1Mv5SD9wCRnDtM2o9VWVutQLysEdO23PeiU6ww5y-DR1wHaYEn7MsLgVaeoGZmYLkXLiIY/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> #!/bin/bash
scp -P [port] -c blowfish -C [username]@[servername]:/source_path/script /destination_path/s </code></pre>
<br />
I define that this file should download at every execution some file from server via SCP.<br />
Once opened SSH, also SCP is opened.<br />
<br />
The next step is to define when this script should be called. I decided to define this directly on crontab. Due to user grants, the simplest way to do this is to log in as root on the client and access to root's crontab. So type<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ft0qZYuP7iwls7qrDwZPozx62VStbLhM0_t_AfiZub0YbwPnBYOJF8dDi9-DTvGFC-uKwC1Mv5SD9wCRnDtM2o9VWVutQLysEdO23PeiU6ww5y-DR1wHaYEn7MsLgVaeoGZmYLkXLiIY/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> crontab -e
</code></pre>
<br />
and then insert this line<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ft0qZYuP7iwls7qrDwZPozx62VStbLhM0_t_AfiZub0YbwPnBYOJF8dDi9-DTvGFC-uKwC1Mv5SD9wCRnDtM2o9VWVutQLysEdO23PeiU6ww5y-DR1wHaYEn7MsLgVaeoGZmYLkXLiIY/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> 0 9,14 * * * /bin/sh /path/script 2>&1 | tee -a /path/update.log
</code></pre>
<br />
In this manner I define that twice a day, at 9 A.M. and 2 P.M. this script will be executed and both STDOUT and STDERR will redirect to the file "update.log".<br />
You can define every hour or day you prefer, this is only an example.<br />
For a more detailed guide about crontab see this: <a href="http://www.thegeekstuff.com/2009/06/15-practical-crontab-examples/">www.thegeekstuff.com/practical-crontab-examples/</a> <br />
<br />
<h3 style="text-align: left;">
Step 3 - Create an alert</h3>
<h4 style="text-align: left;">
On client </h4>
In the past two steps we've seen how to log on automatically and how to automate the execution of a script. Now we need to know if our automatic updates are working or not.<br />
For this reason, on the client I create a script that will send automatically an email every time the log file will be written.<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1ft0qZYuP7iwls7qrDwZPozx62VStbLhM0_t_AfiZub0YbwPnBYOJF8dDi9-DTvGFC-uKwC1Mv5SD9wCRnDtM2o9VWVutQLysEdO23PeiU6ww5y-DR1wHaYEn7MsLgVaeoGZmYLkXLiIY/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> #!/bin/bash
# sendemail.sh
subject="Log update PC "
pcname=`cat /etc/hostname`
subject=$subject$pcname
email="recipient@foo.com"
# copy the content of update.log to emailmessage variable
emailmessage=`cat /path/update.log`
logfile="/path/update.log"
actualsize=$(du -b "$logfile" | cut -f 1)
# check if update.log file contains something
if [ $actualsize -gt 0 ]; then
sendEmail -f sender@foo.com -t "$email" -u "$subject" -m "$emailmessage" -s [smtp_name]:[smtp_port] -xu [smtp_username] -xp [smtp_password]
fi
# delete update.log
rm /path/update.log
</code></pre>
<br />
<br />That's all. This is only a little aspect that could show you the potentiality of this tool.<br />
For example I use this to update blacklists and whitelists on clients Dansguardian or to update an https proxy that I've made and that I accurately dscrive on this pages soon or later.<br />
<br />
Thanks all and don't hesitate to ask if you are confused about this.<br />
<br />
<br />
<br />
<br /></div>
</div>
cyberfidohttp://www.blogger.com/profile/11212966372629742529noreply@blogger.com0tag:blogger.com,1999:blog-2726274996998979277.post-13046076523680519812014-02-16T08:54:00.003+01:002014-02-16T08:54:36.519+01:00Day 1<div dir="ltr" style="text-align: left;" trbidi="on">
Hi all!<br />
I am a programmer and a system administrator and everyday I struggle with things that I haven't studied, I don't know and I really never heard before.<br />
So the best thing to do for me if I don't know even what I'm facing is to try new solutions and search on the Internet.<br />
In many cases I fail, but sometimes I manage to discover a new function, a new way to do a thing and resolve a problem.<br />
So why don't tell others what I've done? I think it could be useful for all to have a simple solution available.<br />
I've always read guides made for dummies, but now I want to announce what dummies can do for all.<br />
So here it is, good read. </div>
cyberfidohttp://www.blogger.com/profile/11212966372629742529noreply@blogger.com0