Author Archives: slopjong

Linux: rm /*

➜  cache git:(master) ✗ rm /*
rm: cannot remove `/bin': Is a directory
rm: cannot remove `/boot': Is a directory
rm: cannot remove `/dev': Is a directory
rm: cannot remove `/etc': Is a directory
rm: cannot remove `/home': Is a directory
rm: cannot remove `/lib': Is a directory
rm: cannot remove `/lib64': Is a directory
rm: cannot remove `/lost+found': Is a directory
rm: cannot remove `/media': Is a directory
rm: cannot remove `/mnt': Is a directory
rm: cannot remove `/opt': Is a directory
rm: cannot remove `/proc': Is a directory
rm: cannot remove `/root': Is a directory
rm: cannot remove `/run': Is a directory
rm: cannot remove `/sbin': Is a directory
rm: cannot remove `/srv': Is a directory
rm: cannot remove `/sys': Is a directory
rm: cannot remove `/tmp': Is a directory
rm: cannot remove `/usr': Is a directory
rm: cannot remove `/var': Is a directory

Stupid missing dot. Luckily I didn’t specify the option -rf. If I did and was root I would have f****d myself. No further comments.

DeliciousDiggTechnorati FavoritesRedditLinkedInFacebookSpurlTwitterWebnewsYiGGMySpaceYahoo BookmarksFriendFeedGoogle BookmarksLiveJournalShare

cURL: follow locations with safe_mode enabled or open_basedir set

cURL is a tool to connect to a remote server and load data from it while schemes like HTTP, HTTPS, FTP, gopher, telnet, DICT, FILE, LDAP and more are supported for the request URI.

PHP has built-in support by providing its users a layer upon the underlying libcurl library. Here is an example how cURL is used in PHP:

$ch = curl_init("http://example.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);

The option CURLOPT_RETURNTRANSFER advices PHP to return the result after executing curl_exec() on success and FALSE else. If this option is ommitted it would return TRUE instead of the result.

At some point you need to follow a location. This is the case if a server you are connecting to is replying with a location redirect. In a HTTP response the server would reply with a 301 or 302 status code and the HTTP header Location pointing to the new URI. In the code the option CURLOPT_FOLLOWLOCATION needs to be set to allow libcurl to follow the redirect.

$ch = curl_init("http://example.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$data = curl_exec($ch);
curl_close($ch);

However if your web server has safe_mode activated or open_basedir set then CURLOPT_FOLLOWLOCATION won’t have any effect. The below warning will appear and libcurl won’t follow the new location.

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION
cannot be activated when in safe_mode or an open_basedir is set in ...

This blog post shows you a workaround by changing the server configuration and putting the loader script to a directory defined in open_basedir. Unfortunately many websites are hosted on a shared host. Hence most people can’t just alter something in a configuration file but rather need a user-space solution.

One solution is to follow redirects manually by examining the server response and send the request to the new location again. The next sample code does exactly this. The function curl_exec_follow is passed two arguments, one is the cURL handler and the second the maximum amount of allowed redirects. If a server response contains a redirect location the script also checks if it’s a URL or a relative path to the resource.

function curl_exec_follow($ch, &$maxredirect = null) {

  $mr = $maxredirect === null ? 5 : intval($maxredirect);

  if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) {

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $mr > 0);
    curl_setopt($ch, CURLOPT_MAXREDIRS, $mr);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

  } else {

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);

    if ($mr > 0)
    {
      $original_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
      $newurl = $original_url;

      $rch = curl_copy_handle($ch);

      curl_setopt($rch, CURLOPT_HEADER, true);
      curl_setopt($rch, CURLOPT_NOBODY, true);
      curl_setopt($rch, CURLOPT_FORBID_REUSE, false);
      do
      {
        curl_setopt($rch, CURLOPT_URL, $newurl);
        $header = curl_exec($rch);
        if (curl_errno($rch)) {
          $code = 0;
        } else {
          $code = curl_getinfo($rch, CURLINFO_HTTP_CODE);
          if ($code == 301 || $code == 302) {
            preg_match('/Location:(.*?)\n/', $header, $matches);
            $newurl = trim(array_pop($matches));

            // if no scheme is present then the new url is a
            // relative path and thus needs some extra care
            if(!preg_match("/^https?:/i", $newurl)){
              $newurl = $original_url . $newurl;
            }
          } else {
            $code = 0;
          }
        }
      } while ($code && --$mr);

      curl_close($rch);

      if (!$mr)
      {
        if ($maxredirect === null)
        trigger_error('Too many redirects.', E_USER_WARNING);
        else
        $maxredirect = 0;

        return false;
      }
      curl_setopt($ch, CURLOPT_URL, $newurl);
    }
  }
  return curl_exec($ch);
}

This function is used in place of curl_exec() and doesn’t need extra user privileges as you would need to change the server configuration.

$ch = curl_init("http://example.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec_follow($ch);
curl_close($ch);

Hopefully this helped you.

DeliciousDiggTechnorati FavoritesRedditLinkedInFacebookSpurlTwitterWebnewsYiGGMySpaceYahoo BookmarksFriendFeedGoogle BookmarksLiveJournalShare

Star wars

DeliciousDiggTechnorati FavoritesRedditLinkedInFacebookSpurlTwitterWebnewsYiGGMySpaceYahoo BookmarksFriendFeedGoogle BookmarksLiveJournalShare

Arch Linux: failed to load module `zsh/computil’

If you’ve recently updated zsh and used tab auto-complete you’re getting the following error message.

➜  zsh  cd
_tags:36: failed to load module `zsh/computil': /usr/lib/zsh/4.3.15/zsh/computil.so: cannot open shared object file: No such file or directory
_tags:51: failed to load module `zsh/computil': /usr/lib/zsh/4.3.15/zsh/computil.so: cannot open shared object file: No such file or directory
_tags:51: command not found: comptry
_tags:51: command not found: comptry
_tags:55: command not found: comptry
_tags:60: command not found: comptags
_tags:67: command not found: comptags
_tags:36: command not found: comptags
_tags:51: command not found: comptry
_tags:51: command not found: comptry
_tags:51: command not found: comptry
_tags:55: command not found: comptry
_tags:60: command not found: comptags
_tags:67: command not found: comptags
_tags:36: command not found: comptags
_tags:51: command not found: comptry
_tags:51: command not found: comptry
_tags:51: command not found: comptry
_tags:55: command not found: comptry
_tags:60: command not found: comptags
_tags:67: command not found: comptags

This can be an indication for a system intrusion. A hacker cracker might have found a workaround for pacman’s signature system who probably did a man-in-the-middle attack by providing you a modified version of zsh which breaks your entire system and is now under control of this hacker cracker.

!! You definitely must reinstall Arch Linux !!

If you don’t, this hacker cracker can do very evil things by using your IP which identifies you if your computer is connected to the internet. Less evil things could be abuse of your IP for spam purpose. The most evil thing he could do is providing the internet with ch**d p*rn. For government agencies it looks like you provided it and it’s you who will be charged with it.

If you’re sure there was no hacker cracker involved, then the reason might be that the zsh version changed. The library moved from


/usr/lib/zsh/4.3.15/zsh/computil.so

to

/usr/lib/zsh/4.3.16/zsh/computil.so

but your current terminal window thinks it’s still in the old place. This can easily be fixed by opening a new terminal window.

DeliciousDiggTechnorati FavoritesRedditLinkedInFacebookSpurlTwitterWebnewsYiGGMySpaceYahoo BookmarksFriendFeedGoogle BookmarksLiveJournalShare

Firefox add-on for your hackerspace door status

I wrote my first firefox add-on with the source on github, yeah :-)

If you are a member of a hackerspace and are sick of visiting your hackerspace wiki or blog page to see the space status, this add-on is made for you. The following spaces are supported until now:

  • ACKspace
  • Bitlair
  • Fabelier
  • Frack
  • HeatSync Labs
  • Hickerspace
  • Kwartzlab MakerSpace
  • Makers Local 256
  • Milwaukee Makerspace
  • MidsouthMakers
  • Noisebridge
  • Pumping Station: One
  • RaumZeitLabor
  • RevSpace
  • Shackspace
  • syn2cat
  • tetalab
  • TkkrLab
  • TOG
  • Void Warranties

It’s displaying the status of the chosen hackerspace with a green or a red dot in the add-on bar. There’s yet missing an icon to be displayed on the Extensions page (and later also in the menu) in firefox. If you know a good one, let me know or contribute and design one.

Install the add-on

Download openspace@slopjong.de.xpi.zip, extract it and double-click on the xpi file. If firefox doesn’t launch, start it manually and open it from the firefox menu.

If you are installing the add-on please drop a comment here so that I’m able to notify you if an update is available because the current version has no update check included and the much improved version is already on its way. I guess you don’t want to use the initial version forever. Please scroll down and read Outlook to the new version.

Works with firefox 5-10, 11.0b4 and 12.0a2
Not compatible with versions prior 5. If you have firefox 3.6 or 4 you have no luck.

The add-on will be published on mozilla.org after some people tested it and gave me feedback.


Restart firefox


Click on the dot

Activate the add-on bar with the shortcut ctrl+/ or from your menu View > Toolbars > Add-on Bar and click on the dot in the bottom right corner.


Choose your hackerspace and the refresh interval


Report bugs

If the add-on seems to not work correctly, it’s not the add-on, it’s your hackerspace. A couple of spaces deliver incorrect json or don’t implement the specs correctly, amongst others these are:

  • Fabelier (specs error: member open is missing but is mandatory in rel0.11)
  • Kwartzlab MakerSpace (syntax error: (1) invalid comma, expecting } ___ (2) Expecting string, not })
  • syn2cat (specs error: member open is of type string instead of boolean) fixed

Please use OpenSpaceLint to find syntax errors to check your JSON against the specification. Check if you use the correct datatype. "open": "true" is not the same as "open": true. The first returns a string but the latter one a boolean.

If you did check intensively your json and if you are really sure that it’s correct, well then it might be the add-on. Please report bugs as a comment here or as an issue on github.

Outlook to the new version

The new version will load the space directory from the web so an unneeded add-on update is not required to support new spaces in the future that implement the space API. If you’ll be missing your space the new version allows you to add it within the add-on which will use OpenSpaceLint to validate your hackerspace’s space API JSON and finally to insert it in the directory if it hasn’t failed.

DeliciousDiggTechnorati FavoritesRedditLinkedInFacebookSpurlTwitterWebnewsYiGGMySpaceYahoo BookmarksFriendFeedGoogle BookmarksLiveJournalShare