Manually undeleting a file from ext2, ext3, ext4 or any other filesystem

Yesterday, I worked on a PHP project all day. At the end of the day, I moved it from development to staging. And finally I deleted it from staging. Oops!

I just discovered an hour ago what I did. What to do, what to do...?

Back in the old days, Midnight Commander supported some undelete function, but this option has been removed in the CentOS 6 version I'm running.

Then there's the option to use extundelete, but that would need compiling and a lot of other disk activity before I could use it. Normally, I would compile such a program on another server, then hook up the disk. But since it's a cloud server that I cannot access in any other way but SSH, that's not an option.

And finally there's the option to use ext3undel+foremost+testdisk from rpmforge to undelete information, but somehow I couldn't get all dependencies to install. So there's no usable software to fix this.

Or is there?

Manual recovery

Most filesystems, except for filesystems that do raid/compression/encryption, just write data to blocks on the disk in a structured manner. If you could save and access the blocks, you may be able to do some manual recovery.

Continue Reading…

© GeekLabInfo Manually undeleting a file from ext2, ext3, ext4 or any other filesystem is a post from GeekLab.info. You are free to copy materials from GeekLab.info, but you are required to link back to http://www.geeklab.info

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 4.00 out of 5)
Loading...

WiFi on a HP Elitebook 8570w

There once was a day that I compiled my own kernels and configured all modules manually. It's been quite a while since I've done anything like that, but I remembered some of it.

Today I installed my WiFi drivers. The HP Elitebook 8570w I own has a Centrino Advanced-N 6205 on board that is actually supported by Fedora 17.

$ lspci
00:00.0 Host bridge: Intel Corporation Ivy Bridge DRAM Controller (rev 09)
00:01.0 PCI bridge: Intel Corporation Ivy Bridge PCI Express Root Port (rev 09)
00:14.0 USB Controller: Intel Corporation Panther Point USB xHCI Host Controller (rev 04)
00:16.0 Communication controller: Intel Corporation Panther Point MEI Controller #1 (rev 04)
00:19.0 Ethernet controller: Intel Corporation 82579LM Gigabit Network Connection (rev 04)
00:1a.0 USB Controller: Intel Corporation Panther Point USB Enhanced Host Controller #2 (rev 04)
00:1b.0 Audio device: Intel Corporation Panther Point High Definition Audio Controller (rev 04)
00:1c.0 PCI bridge: Intel Corporation Panther Point PCI Express Root Port 1 (rev c4)
00:1c.1 PCI bridge: Intel Corporation Panther Point PCI Express Root Port 2 (rev c4)
00:1c.2 PCI bridge: Intel Corporation Panther Point PCI Express Root Port 3 (rev c4)
00:1c.3 PCI bridge: Intel Corporation Panther Point PCI Express Root Port 4 (rev c4)
00:1d.0 USB Controller: Intel Corporation Panther Point USB Enhanced Host Controller #1 (rev 04)
00:1f.0 ISA bridge: Intel Corporation Panther Point LPC Controller (rev 04)
00:1f.2 SATA controller: Intel Corporation Panther Point 6 port SATA AHCI Controller (rev 04)
00:1f.3 SMBus: Intel Corporation Panther Point SMBus Controller (rev 04)
01:00.0 VGA compatible controller: nVidia Corporation Device 0ffc (rev a1)
01:00.1 Audio device: nVidia Corporation Device 0e1b (rev a1)
24:00.0 FireWire (IEEE 1394): JMicron Technology Corp. IEEE 1394 Host Controller (rev 30)
24:00.1 System peripheral: JMicron Technology Corp. SD/MMC Host Controller (rev 30)
24:00.2 SD Host controller: JMicron Technology Corp. Standard SD Host Controller (rev 30)
25:00.0 Network controller: Intel Corporation Centrino Advanced-N 6205 (rev 34)

The device at the very bottom is the WiFi device we're looking for. But iwconfig shows it's not available to the system somehow:

$ iwconfig
thuisf    no wireless extensions.
 
vmnet8    no wireless extensions.
 
thuis     no wireless extensions.
 
eth0      no wireless extensions.
 
lo        no wireless extensions.
 
virbr0-nic  no wireless extensions.
 
virbr0    no wireless extensions.
 
noc       no wireless extensions.
 
vmnet1    no wireless extensions.

Continue Reading…

© GeekLabInfo WiFi on a HP Elitebook 8570w is a post from GeekLab.info. You are free to copy materials from GeekLab.info, but you are required to link back to http://www.geeklab.info

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Reusing WordPress components: L10n

Personally, I'm a big fan of WordPress. Although it can be bloated sometimes, it uses smart programming techniques and high quality libraries. (Unlike some of the plugins.)

Today, I sorted out how to use the Localization (l10n) libraries of WordPress in another project. And it was a lot simpler than I could have hoped for.

Step 1: Copy some files

From the WordPress distribution, we're gonna need /wp-includes/l10n.php and the directory /wp-includes/pomo/*.php. Copy l10n and the whole directory pomo to your own includes directory.

Step 2: Compatibility

WordPress extensively uses apply_filters and do_action for filtering data and triggering events. We're not gonna use those now, but unless we want to rewrite half of l10n.php, we better make something for compatibility. I entered these simple statements in a new file named wordpress-compat.php:

Continue Reading…

© GeekLabInfo Reusing WordPress components: L10n is a post from GeekLab.info. You are free to copy materials from GeekLab.info, but you are required to link back to http://www.geeklab.info

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

My l10n makefile

To easily gather .pot files, combine them with existing .po files and converting them to .mo files, I created this makefile for use with automake:

.PHONY: _site.pot backup
POFILES:=$(wildcard *.po)
NOW=$(shell date +%s)
 
all:    backup
        make $(POFILES:.po=.mo)
 
%.mo:   %.po
        echo Generating $@
        msgfmt -o $@ $< || echo -e "\033[33;1m $@ is wrong \033[0m"
 
%.po:   _site.pot
        if [ -e $@ ]; then \
        mv $@ $(@:.po=.potmp) ; msgmerge --no-fuzzy-matching $(@:.po=.potmp) _site.pot > $@ ; \
        rm $(@:.po=.potmp) ; \
        else \
        echo Creating new file ; cp _site.pot $@ ; \
        fi
 
_site.pot: 
        find /var/www/html -iname "*.php" | grep -v wpcode > my-php-files
        xgettext --from-code=utf-8 -d site -f my-php-files --keyword=_e --keyword=__ -o - | sed "s/CHARSET/UTF-8/" > _site.pot
        rm my-php-files
 
backup:
        mkdir -f .backup
        tar zcf .backup/backup-$(NOW).tgz *.po Makefile

Continue Reading…

© GeekLabInfo My l10n makefile is a post from GeekLab.info. You are free to copy materials from GeekLab.info, but you are required to link back to http://www.geeklab.info

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

X11 forwarding request failed on channel 0

Since upgrading to Fedora 17, I've been getting this message "X11 forwarding request failed on channel 0". I haven't done anything to fix it for a while, but today I got so annoyed with this message, that I decided to fix it.

First I google'd around a bit. What does this message mean? I read a lot of reactions that suggest to fix something on ssh_config on the client side or in sshd_config on the server side. These suggestions did not work for me.

So, how do we debug this?

On the server side, open the firewall on a non-standard port. I used port 222:
iptables -I INPUT -s [client-ip] -p tcp --dport 222 -j ACCEPT
Then I ran sshd in non-forking debug mode on this port:
/usr/sbin/sshd -d -p 222
Then we login from the client, using verbose mode:
ssh -vvv [server]

This generates a lot of logs on both sides. The log on the client side contains:
debug3: Ignored env GTK_IM_MODULE
debug3: Ignored env XAUTHORITY
debug3: Ignored env CCACHE_HASHDIR
debug3: Ignored env _
debug2: channel 0: request shell confirm 1
debug2: callback done
debug2: channel 0: open confirm rwindow 0 rmax 32768
debug1: Remote: No xauth program; cannot forward with spoofing.
debug2: channel_input_status_confirm: type 100 id 0
X11 forwarding request failed on channel 0

So, what's the problem? The server has no xauth program. The old versions of the ssh client silently failed when the server had no xauth, this new version is just a little more verbose.

Continue Reading…

© GeekLabInfo X11 forwarding request failed on channel 0 is a post from GeekLab.info. You are free to copy materials from GeekLab.info, but you are required to link back to http://www.geeklab.info

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...

MySQL – How to get Top N rows for each group

We have the following table and data:

CREATE TEMPORARY TABLE girls(
name text,
haircolor text,
score INT
);
 
INSERT INTO girls VALUES ('Megan','brunette',9);
INSERT INTO girls VALUES ('Tiffany','brunette',5);
INSERT INTO girls VALUES ('Kimberly','brunette',7);
INSERT INTO girls VALUES ('Hester','blonde',10);
INSERT INTO girls VALUES ('Caroline','blonde',5);
 
SELECT * from girls;
+----------+-----------+-------+
| name     | haircolor | score |
+----------+-----------+-------+
| Megan    | brunette  |     9 | 
| Tiffany  | brunette  |     5 | 
| Kimberly | brunette  |     7 | 
| Hester   | blonde    |    10 | 
| Caroline | blonde    |     5 | 
+----------+-----------+-------+
5 rows in set (0.00 sec)

Session Variables

MySQL, at least on the versions I've checked, does not support ROW_NUMBER() function that can assign a sequence number within a group, the MySQL session variables can be used to build a workaround. Session variables do not need to be declared first and can be used to do calculations and perform actions based on them. They appear to require initialization. For instance:

Continue Reading…

© GeekLabInfo MySQL - How to get Top N rows for each group is a post from GeekLab.info. You are free to copy materials from GeekLab.info, but you are required to link back to http://www.geeklab.info

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 1.00 out of 5)
Loading...

Making broken link checker work with Woocommerce external products

I'm working on a new project to bring together all high quality WordPress themes on one website. Today I tried to make broken link checker work with Woocommerce external products.

When you configure the broken link checker to look for urls in the custom field named _product_url, BLC would find all these links. Unfortunately, this only works for posts and pages, but Woocommerce stores its products as product.

So, in order to make these plugins work together, you should add the post_type 'product' to both line 441 and 478 of broken-link-checker/modules/containers/custom_field.php

Guess it would be better if the plugin asked you which post_types should be included.

© GeekLabInfo Making broken link checker work with Woocommerce external products is a post from GeekLab.info. You are free to copy materials from GeekLab.info, but you are required to link back to http://www.geeklab.info

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...