25.8.15

Wordpress: Convert .htaccess to web.config file

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.

Wordpress has some default rules that writes on Apache .htaccess file.
Something like this below

 # 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  

The web.config equivalent to this is

 <?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>  

In this manner you can avoid all 404 errors caused by rewrite absence.

14.4.15

Installation pgAgent on CentOs

I faced the task to install pgAgent on PostgreSql 9.3 CentOs 6 server.
I serached a lot but I didn't find anything on web very complete.
So why don't write it by myself?
The most explanatory guide I found was this on OrbitPhreak blog

Due to the fact that updating CentOs Epel Repository I met this error

 Loaded plugins: fastestmirror, security  
 Determining fastest mirrors  
 Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again  

I found this useful link to solve also this problem

So let's install this fucking pgAgent.
To install pgAgent we also have to install many packages (wxWidgets) related to graphic libraries used by pgAgent itself.
This is maybe due to the fact that pgAgent was originally a part of the pgAdmin client.
Tha last package of pgAgent in the time I'm writing is 3.4.0, but you find the last package here.
Type in sequence this commands on your CentOs server

 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"  

Now we can install pgAgent.

 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

Ok, now we have installed all, we can create a service called pgagent useful for starting, stopping pgagent whenever we want.

 vim /etc/rc.d/init.d/pgagent  

and we can copy all this text inside the text editor

 #!/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  

Then we set grants on file service and put it starting at boot time.

 chmod 0755 /etc/rc.d/init.d/pgagent  
  /sbin/chkconfig --level 345 pgagent on  
 service pgagent start  

To make pgAgent usable from Postgres we should modify pg_hba.conf in this way

 vim /var/lib/pgsql/9.3/data/pg_hba.conf  

and make the "host" row like this

 host  all       all       127.0.0.1/32      trust  

In this manner the postgres user can trust himself in any way: both with password or woithout it.
For example running this command it should work

 SELECT dblink_connect('user=postgres password=ocpNHosting14 host=127.0.0.1 dbname=postgres');  

Just insert the host definition equal to 127.0.0.1.

That's all!

Now you can create new jobs following this useful guide.

Enjoy!




22.8.14

Proxmox: restore cluster without rebooting

For some reason in these days I faced a problem with proxmox GUI and cluster management.
From one node of the cluster I saw on /var/log/syslog file that
 pveproxy[88540]: WARNING: proxy detected vanished client connection  
and if I try to access to the Web GUI of that node, it says "Login Incorrect".
From other nodes, it seems all right, but it isn't.
The solution is to simulate a reboot of all the machines without rebooting the VM on them: powerful!
So this is the sequence to launch on every node of the cluster, without some particular order
 /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  

Now, it works great.

yum-updatesd occupying memory and bandwith

When you install CentOs, you have to pay attention to this process yum-updatesd.
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.
So, because I am an old style system administrator, I prefer to disable this process and its Micro$oft's style behavior.
To do this, it requires these two commands
 chkconfig --del yum-updatesd  
 kill -9 [pid_of_process]  

Easy but useful.

25.3.14

The Certificate associated with this binding is also assigned to another site's binding.

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).
When I assign the same certificate to two or more websites and after a while I decide to remove, IIS asks the following question:

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?


Well...I think not.

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?

Edit C:\Windows\System32\inetsrv\config\applicationHost.config, search for your application name and manually delete the row with the https binding. 

 <binding protocol="https" bindingInformation<binding protocol="https" bindingInformation="*:443:" />"*:443:" />  

Save file and re-open IIS GUI: the binding should be disappeared.

An IIS bug? Maybe or maybe only Microsoft style ;)





20.3.14

BC30002: Type 'NameClass' not defined

I've struggled a few minutes too long to resolve this problem.
I writed a new class with some type inside, added by a new Namespace.
I added the relative reference on the project.
The solution compiles correctly, but at the site's launch on localhost, I obtained the following error

 BC30002: Type 'NameClass' not defined 

WTF?!

Solution
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.
If not, the solution is to manually add the reference in the following manner
(in my case System.Security)

 <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> 

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.

Enjoy!

22.2.14

How to distribute automatic update on Linux clients

At work with the growth of clients in firm network I need to distribute updates automatically.
To do this I encountered a lot af weird problems due to Linux grants and Bash execution.
So let's have a look to our structure.
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).

Our goal

Download automatically from every client some settings (whatever you want) from server and update automatically the client settings.

Step 1 - SSH automatically to server

On client

First of all I need to ssh automatically to server. So log as root on the client and then type

 ssh-keygen -t rsa  

you need this to create a public and a private key useful to subsitute to the password.

Then send to the server the public key generated on client

 cd /root/  
 cat .ssh/id_rsa.pub | ssh [username]@[servername] -p [port] 'cat >> .ssh/authorized_keys'  


On server

 chmod 700 .ssh
 chmod 640 .ssh/authorized_keys


Adjust grants to permit only to root to manage this file.
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.

Step 2 - Configure the automation 

On client

Now that we managed to login automatically every time we want, let's see how we could automate something.
First I create the file to be automated, something like this, named "script_to_execute.sh"

 #!/bin/bash  
 scp -P [port] -c blowfish -C [username]@[servername]:/source_path/script /destination_path/s 

I define that this file should download at every execution some file from server via SCP.
Once opened SSH, also SCP is opened.

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

 crontab -e  

and then insert this line

 0 9,14 * * * /bin/sh /path/script 2>&1 | tee -a /path/update.log  

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".
You can define every hour or day you prefer, this is only an example.
For a more detailed guide about crontab see this: www.thegeekstuff.com/practical-crontab-examples/

Step 3 - Create an alert

On client

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.
For this reason, on the client I create a script that will send automatically an email every time the log file will be written.

 #!/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  


That's all. This is only a little aspect that could show you the potentiality of this tool.
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.

Thanks all and don't hesitate to ask if you are confused about this.