KK Multicopter Flash Tool Uncaught exception in main method: java.lang.UnsatisfiedLinkError: /Library/Java/Extensions/librxtxSerial.jnilib:

kkmulticopter logoIf you just downloaded the KKMulticopter Flash Tool on Mac OsX, like me and once launched you get: Uncaught exception in main method: java.lang.UnsatisfiedLinkError: /Library/Java/Extensions/librxtxSerial.jnilib: no suitable image found. Did find: /Library/Java/Extensions/librxtxSerial.jnilib: no matching architecture in universal wrapper

Your Solution is: Continue reading “KK Multicopter Flash Tool Uncaught exception in main method: java.lang.UnsatisfiedLinkError: /Library/Java/Extensions/librxtxSerial.jnilib:”

Multiwii MWC, Chinese 10DOF (codename GY-80) and Arduino Nano V.3: hooking and testing

 

This image shows how to connect the pro-mini to the gy-80Well, i just received my i2c sensors breakout board

Here it is what the Multiwii software configuration calls GY_80 or GY-80.
There is no brand, no model, no serial.
We know something just about single main components/chip: Continue reading “Multiwii MWC, Chinese 10DOF (codename GY-80) and Arduino Nano V.3: hooking and testing”

Moodle and WordPress Single Sign On in 20 minutes – Part 1

It’s time to make WordPress authentication work on Moodle too.

For moodle 3.0, please see the comment from Carlos below, it takes a few changes in order to work on this new version of moodle.

Scenario:

WordPress installation and Moodle installation.
We are going to use the WordPress database in order to authenticate Moodle users. This way, we can sell courses using some wordpress ecommerce plugin and have instant access from customers.

The two sites are on the very same machine but on different domains (actually WordPress is in the “www.domain.tld” and “*.domain.tld” subdomains and Moodle is on another subdomain (courses.domain.tld) so we need to authenticate users in both sites using the very same database table.

The Problem:

The Moodle external autentication plugin does not work with WordPress authentication out of the box. To make it work, it will need a couple of modification very easy to make, don’t worry, even for a non php skilled person.
We will come back on this later on this post.

Let’s start our 20 minutes modification!

Shop list:

  • WordPress Version 3.4.2
  • WordPress database informations
  • Moodle Version 2.0
  • Moodle External Database Authentication Plugin (already in the Moodle default installation)
  • Some coding so, all stuff for ftp things/sftp/ssh things and a decent text editor with some failsafe feature (save a copy before modify etc)

That’s enough to start working on.

Once installed the two systems, you will have to properly configure the external database authentication plugin on Moodle platform. To do this you have to authenticate yourself as site administrator, then on the menubar choose and click on “Site Administration” -> “Plugin” -> “Authentication” -> “Manage Authentication”.

You can use the provided image on the left to quickly find out the links path needed to get there.

 

 

 

Once there you will see a list of all authentication plugin, their status (active or inactive) their priority order and the link to their “settings”. As you can see in the image below, you have to enable and prioritize the plugin in order to make it work. You probably want to disable the self-registration (see picture in bottom part) feature in order to prevent user to signup using moodle platform because, otherwise, all users created within Moodle will not be able to authenticate against WordPress.

This is the list of the moodle authentication plugins. It shows if a plugin is enabled or not, and it exposes a link for each plugin to be configured.

Once you have done, let’s click on the “Setting” link and let’s try to configure this plugin the best we can.

We have to enter all info used by Moodle to read the WordPress database.
Fields are:

  • Host, in my case i will use “localhost” and probably you too unless your db is hosted on a different machine, in that case you have to use the Hostname or ip address of that machine
  • Database, in my case “mysqli” (Please, notice the trailer “i” – mysqli and not mysql).
  • Use sybase quotes, we do not need this to be on so we will leave it on “NO
  • Db name, the name of your wordpress database (get it from wp-config.php)
  • Db User, mysql user that can access WordPress db tables
  • Db Password, mysql password for mysql user
  • Table, the name of the table where username/passwords are stored. The most of the time is “wp_users” unless you changed your table prefix
  • Username Field, the field containing the username, for WordPress: “user_login”
  • Password Field the field containing the password for username for WordPress: “user_pass”.
  • Password Format, we should choose “wordpressformat but there is no such option in this drop down, so what? we will solve this later, don’t worry
  • External db encoding, i use “UTF-8″
  • SQL setup command, you can leave it blank
  • Debug ADOdb, choose “NO
  • Password-change URL, we use the wordpress password recovery page link

These are the needed field to make this thing work, if you want more integration, you can configure the part named “cron syncronization script” and sync information such as first name, surname, user preferences and so.

But now we have to stay focused on the missing dropdown item and find a way to get it out of there.

We need to modify the file in /auth/db/config.html and change this (at line 190)

$passtype = array();
$passtype["plaintext"] = get_string("plaintext", "auth");
$passtype["md5"] = get_string("md5", "auth");
$passtype["sha1"] = get_string("sha1", "auth");
$passtype["internal"] = get_string("internal", "auth");
echo html_writer::select($passtype, "passtype", $config->passtype, false);

to this

$passtype = array();
$passtype["plaintext"] = get_string("plaintext", "auth");
$passtype["md5"] = get_string("md5", "auth");
$passtype["sha1"] = get_string("sha1", "auth");
$passtype["internal"] = get_string("internal", "auth");
$passtype["wordpress"] = "wordpress";
echo html_writer::select($passtype, "passtype", $config->passtype, false);

This modification will make “WordPress” authentication drop down item available, but still not working.
We need to process the password with this class: class-phpass.php [Phpass Website].
This class, can actually process passwords the same way wordpress does, so this is the missing link to make sso work.
Just copy the file class-phpass.php in your /moodle/lib folder
And then add this line right after other requires at the beginning of wp-login.php to moodle/auth/db/auth.php:

require_once($CFG->libdir."/class-phpass.php");

.
To make our modifications work we need to add a few lines of code to the file /auth/db/auth.php, it’s easy. Open the file and go about line 90, you should see something like this:

if ($this->config->;passtype === 'md5') {   // Re-format password accordingly

$extpassword = md5($extpassword);

} else if ($this->config->;passtype === 'sha1') {
$extpassword = sha1($extpassword);
}

Now, let’s do our final modification and right after the lines here, add this code:

else if ($this->config->passtype === 'wordpress') {
$hash =new PasswordHash(8, false);
$rs = $authdb->Execute("SELECT * FROM {$this->config->table}
WHERE {$this->config->fielduser} = '".$this->ext_addslashes($extusername)."'");
$check = $hash->CheckPassword( $extpassword, $rs->fields["user_pass"]);
return $check;
}

If you are as lazy, you can download a copy of both file here, but i strongly suggest you to make modification by hand because time goes by and releases change.

Moodle auth with wordpress

Now, finally we can come back to the settings page and add “WordPress” as “Password format“.

All you have to do to try if this works, is to logout from wordpress, signup into wordpress as new user, and then go and authenticate with the same credentials against Moodle. If all work you will be redirected to the user profile page on moodle where you can complete your profile with your informations.

WordPress and “ALERT – script tried to increase memory_limit to 268435456 bytes” issue

untitledSometimes you can find the following line appearing in your webserver error logs:

[Tue Mar 13 10:48:03 2012] [error] [client 23.19.25.190] ALERT - script tried to increase memory_limit to 268435456 bytes which is above the allowed value (attacker '23.xx.25.190', file '/var/www/xxxxx/xxxxxx/xxxxxx/web/wp-admin/admin.php', line 109), referer: http://website.com/wp-admin/edit.php

There is a quick solution and it can be found in a file called:

wp-includes/default-constants.php

[20121223 – UPDATED]: Please, see the Andreas comment below.
It seems to be better to move the “define(‘WP_MAX_MEMORY_LIMIT’, ’64M’);” in wp-config.php rather than default-constants.php. Anyway this stopped after the wordpress update
Thank you Andreas!

you can easily change (around line 96) the var value from 256 megs to the memory size that best suits your server needs.

Do not hesitate to comment for help.

WordPress and “ALERT – configured POST variable limit exceeded – dropped variable” issue

ICustom Grunge WordPress Logot may happen in several hosting environments to discover this line in your webserver error log:

ALERT - configured POST variable limit exceeded - dropped variable 'name_of_dropped_variable' (attacker '20.2.26.212', file '/several dirs..../wp-admin/post.php'), referer: http://sitename.tld/wp-admin/post.php?post=181&action=edit

Well i discovered and solved this situation:

Cause: It is caused by PHP suhosin

you can “locate” it on your disk it using the “locate” command as follows

(if it is first time you use locate) type:

# updatedb

then type:

# locate suhosin

for my machine (debian) it is located within /etc/php5/conf.d/suhosin.ini

so you can edit it by typing:

#nano /etc/php5/conf.d/suhosin.ini

Now, look into your suhosin.ini fìle until you see the followings vars:

suhosin.post.max_vars

suhosin.request.max_vars

You want to remove the comment symbol “;” from the very beginning of these two lines and the increase the default value (it should be 200) to at least 500 in order to make complex wordpress themes working properly.

Remember to kick apache2 typing

#/etc/init.d/apache2 restart

Debian, Apache2, PHP5 AND GEOIP Logging

geolocalization apache ipHelo there! In these last days one client of mine asked me how to prevent non-italian visitors from seeing national ADS when they visit one or more websites.
The solution comes alog with builtin geoip functions in the php5-geoip package to be installed as usual using apt-get
After installed this package typing:
apt-get install php5-geoip

Now, what you have is a countries database, and if you want to be much more precise (as me for example) you can download a detailed Cities database typing the following set of commands:

cd /tmp
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
gunzip GeoLiteCity.dat.gz
sudo mv -v GeoLiteCity.dat /usr/share/GeoIP/GeoIPCity.dat

Now you own the entire planet cities database! 🙂

Let’s try it within a PHP web page: create a new file (or edit an existent one) and type:

print_r(geoip_record_by_name('php.net'));

It should return something like this:

Array
(
[country_code] => US
[country_code3] => USA
[country_name] => United States
[region] => CA
[city] => Sunnyvale
[postal_code] => 94089
[latitude] => 37.4249000549
[longitude] => -122.007400513
[dma_code] => 807
[area_code] => 408
)

Comments or questions are welcome, Also if you neew to setup a geo based service, now you know who could do it for you!

Cheers

VPS: Debian squeeze apt-get update returned an error code (1)

Also known as “E: Sub-process /usr/bin/dpkg returned an error code (1)“.
Well you are trying to run apt-get upgrade on a virtual private server running Debian squeeze (it can happen on Lenny too) hosted on several Xen based platforms.
It happens because grub cannot find your disk in order to rewrite your initrd image.

Since Xen kernel management is transparent to your machine itself, and it is all you need in order to boot your machine, you can remove grub with no fear, typing:

root@apple.com:~#apt-get remove grub-legacy grub-common

And yes, finally you will go to the end of your apt-get upgrade process.

Hope this can help out there!

 

Output of my machine follows:

Setting up linux-image-2.6.32-5-amd64 (2.6.32-39squeeze1) ...
Running depmod.
Running update-initramfs.
update-initramfs: Generating /boot/initrd.img-2.6.32-5-amd64
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 2.6.32-5-amd64 /boot/vmlinuz-2.6.32-5-amd64
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 2.6.32-5-amd64 /boot/vmlinuz-2.6.32-5-amd64
Searching for GRUB installation directory ... found: /boot/grub
warning: grub-probe can't find drive for /dev/xvda1.
grub-probe: error: cannot find a GRUB drive for /dev/xvda1.  Check your device.map.
run-parts: /etc/kernel/postinst.d/zz-update-grub exited with return code 1
Failed to process /etc/kernel/postinst.d at /var/lib/dpkg/info/linux-image-2.6.32-5-amd64.postinst line 799.
dpkg: error processing linux-image-2.6.32-5-amd64 (--configure):
subprocess installed post-installation script returned error exit status 2
Setting up linux-image-2.6.32-5-xen-amd64 (2.6.32-39squeeze1) ...
configured to not write apport reports
Running depmod.
Running update-initramfs.
update-initramfs: Generating /boot/initrd.img-2.6.32-5-xen-amd64
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 2.6.32-5-xen-amd64 /boot/vmlinuz-2.6.32-5-xen-amd64
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 2.6.32-5-xen-amd64 /boot/vmlinuz-2.6.32-5-xen-amd64
Searching for GRUB installation directory ... found: /boot/grub
warning: grub-probe can't find drive for /dev/xvda1.
grub-probe: error: cannot find a GRUB drive for /dev/xvda1.  Check your device.map.
run-parts: /etc/kernel/postinst.d/zz-update-grub exited with return code 1
Failed to process /etc/kernel/postinst.d at /var/lib/dpkg/info/linux-image-2.6.32-5-xen-amd64.postinst line 799.
dpkg: error processing linux-image-2.6.32-5-xen-amd64 (--configure):
subprocess installed post-installation script returned error exit status 2
configured to not write apport reports
Errors were encountered while processing:
linux-image-2.6.32-5-amd64
linux-image-2.6.32-5-xen-amd64
E: Sub-process /usr/bin/dpkg returned an error code (1)

After the cure, finally:

root@apple.com:~# apt-get remove grub-legacy grub-common
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
gettext-base libfreetype6 ucf os-prober
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
grub-common grub-legacy
0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
2 not fully installed or removed.
After this operation, 5,931 kB disk space will be freed.
Do you want to continue [Y/n]? Y
(Reading database ... 17063 files and directories currently installed.)
Removing grub-legacy ...
Removing grub-common ...
Processing triggers for man-db ...
Processing triggers for install-info ...
Setting up linux-image-2.6.32-5-amd64 (2.6.32-39squeeze1) ...
Running depmod.
Running update-initramfs.
update-initramfs: Generating /boot/initrd.img-2.6.32-5-amd64
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 2.6.32-5-amd64 /boot/vmlinuz-2.6.32-5-amd64
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 2.6.32-5-amd64 /boot/vmlinuz-2.6.32-5-amd64
Setting up linux-image-2.6.32-5-xen-amd64 (2.6.32-39squeeze1) ...
Running depmod.
Running update-initramfs.
update-initramfs: Generating /boot/initrd.img-2.6.32-5-xen-amd64
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 2.6.32-5-xen-amd64 /boot/vmlinuz-2.6.32-5-xen-amd64
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 2.6.32-5-xen-amd64 /boot/vmlinuz-2.6.32-5-xen-amd64

et voilà

And now

Some music