Google Reader Alternatives

Google Reader stops today. I’m working on a self hosted replacement for quite a while. If you’re interested, please have a look here:

http://www.phppaper.com/

Google Reader Alternatives

Google Reader Alternatives

[WordPress] filter out unneeded menu classes

March 19th, 2013 No comments

Here’s a code snippet for WordPress to filter out unneeded menu classes. Put the following line in your functions.php

// Reduce nav classes, leaving only 'current-menu-item'
function nav_class_filter($var)
{
    return is_array($var) ? array_intersect($var, array(
        'menu',
        'menu-main',
        'menu-primary',
        'menu-item',
        'sub-menu',
        'menu-last-item',
        'menu-first-item',
        'menu-noparent',
        'menu-parent',
        'menu-top',
        'current-menu-item'
    )) : '';
}
add_filter('nav_menu_css_class', 'nav_class_filter', 100, 1);
add_filter('nav_menu_item_id', 'my_css_attributes_filter', 100, 1);
Categories: Uncategorized Tags: ,

[WordPress] set cookie

March 19th, 2013 No comments

Here’s a code snippet for WordPress. Since WordPress doesn’t support any sessions a cookie might be useful. Here’s a code snippet to use for your functions.php

//Set cookie
function set_newuser_cookie() {
	if (!isset($_COOKIE['sitename_newvisitor'])) {
		setcookie('sitename_newvisitor', 1, time()+1209600, COOKIEPATH, COOKIE_DOMAIN, false);
	}
}
add_action( 'init', 'set_newuser_cookie');
Categories: Uncategorized Tags:

[WordPress & Genesis] Add parent and child classses to menu

March 19th, 2013 No comments

Here’s another code snippet for WordPress Genesis Framework.

If you would like to add menu classes to parent and child menu’s, use the code below.
Put this in the functions.php file:


// Function to add parent and child classses to menu
class Arrow_Walker_Nav_Menu extends Walker_Nav_Menu
{
    function display_element($element, &$children_elements, $max_depth, $depth = 0, $args, &$output)
    {
        $id_field = $this->db_fields['id'];
        if (0 == $depth) {
            $element->classes[] = 'menu-top'; //top main menu
            if (empty($children_elements[$element->$id_field])) {
                $element->classes[] = 'menu-noparent'; //no childs
            }
        }
        if (!empty($children_elements[$element->$id_field])) {
            $element->classes[] = 'menu-parent'; //child in menu
        }
        Walker_Nav_Menu::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
    }
}
Categories: Uncategorized Tags: ,

[WordPress & Genesis] Add menu classes to first en last menu items

March 19th, 2013 No comments

Here’s a code snippet for WordPress Genesis Framework.

If you would like to add menu classes to first en last menu items, use the code below. Put this in the functions.php file:

// Function to add menu classes to first en last menu items
function add_first_and_last($items)
{
    $items[1]->classes[]             = 'menu-first-item';
    $items[count($items)]->classes[] = 'menu-last-item';
    return $items;
}
add_filter('wp_nav_menu_objects', 'add_first_and_last');
Categories: Uncategorized Tags: ,

[WordPress & Genesis] custom viewport

March 19th, 2013 No comments

Here’s a code snippet for WordPress Genesis Framework.

If you would like to use a custom viewport for mobile devices, for example, use the code below:

/** Add Viewport meta tag for mobile browsers */
add_action('genesis_meta', 'add_viewport_meta_tag');
function add_viewport_meta_tag()
{
    echo '<meta name="viewport" content="width=1020">';
}
Categories: Uncategorized Tags: ,

[WordPress & Genesis] custom footer or custom header

March 19th, 2013 No comments

Here’s a code snippet for WordPress Genesis. If you would like to use a custom header or custom footer, don’t use any header.php of footer.php. Use the code snippet below:

// Include Header, seperate from functions
include 'custom-header.php';

// Include Footer, seperate from functions
include 'custom-footer.php';
Categories: Uncategorized Tags: ,

[Synology] How to secure photostation with htaccess

March 15th, 2013 No comments

Here’s a short instruction on how to protect your synology photostation by using htaccess:

Create the following file: /volume1/@appstore/PhotoStation/photo/.htaccess

AuthName "Restricted Area"
AuthType Basic
AuthUserFile /volume1/@appstore/PhotoStation/photo/.htpasswd
AuthGroupFile /dev/null
require valid-user

and the following file: /volume1/@appstore/PhotoStation/photo/.passwd

admin:xxxxxxxxxxxxxxxx

Use the passwd htaccess online generate for your own password.

Categories: Uncategorized Tags:

Synology: Monitoring Apache with mod_status

Here another quick manual. If you would like to monitor your apache webserver, you can do that with mod_status. Open the httpd.conf-user file:

pico /usr/syno/apache/conf/httpd.conf-user

Copy paste the following content from below:

<Location /server-status>
   SetHandler server-status
   Order Deny,Allow
   Deny from all
   Allow from all
</Location>

Save the httpd.conf-user file and restart apache with:

/usr/syno/etc/rc.d/S97apache-user.sh restart

You can now obtain the apache server status by querying the following url:

http://diskstation/server-status?auto

This might be useful for people working with cacti.

Categories: Uncategorized Tags: , ,

Synology: Run sabnzbd behind apache

Here’s a quick instruction for those who would like to run sabnzbd behind apache on a synology nas system. Open up a ssh connection, create the following file:

nano /usr/syno/etc/sites-enabled-user/sabnzbd.conf

Copy paste the contents below to this file. Please note that my sabnzbd port is 9090. If you would like to change this, change the config file below.

# Put this after the other LoadModule directives
LoadModule proxy_module /usr/syno/apache/modules/mod_proxy.so
LoadModule proxy_http_module /usr/syno/apache/modules/mod_proxy_http.so

<Location /sabnzbd>
order deny,allow
deny from all
allow from all
ProxyPass http://localhost:9090/sabnzbd
ProxyPassReverse http://localhost:9090/sabnzbd
</Location>

Save the file by using control-x. Restart apache with the following command:

/usr/syno/etc/rc.d/S97apache-user.sh restart

Restore / Extract Plesk 9.5.4 backup

December 24th, 2012 No comments

If you want to do a manual restore of your Plesk 9.5.4 backup you should use the following commando:

cat plesk-backup_1205270308.tar* | tar xvf -

The domains, vhosts and databases are found in the clients, domains and resellers folders.

Categories: Plesk Tags: ,

updatedb on Synology

December 19th, 2012 No comments

If you would like to index your Synology file system you should install the mlocate package from optware

Install then the  mlocate package with the following command:

ipkg install mlocate

To update your filesystem use:

updatedb

To then search use the locate command.

Categories: Linux Tags: ,

Useful rc.local script on synology

Here’s a useful rc.local script which restores the optware (ipkg) functionality after an upgrade:

#!/bin/sh

#optware fixes http://forum.synology.com/enu/viewtopic.php?f=189&amp;t=46095
mount -o bind /volume1/@optware /opt

# remount with noatime
mount -o remount,noatime /
mount -o remount,noatime /volume1

# enable debug spindown
syno_hibernate_debug_tool --enable 10

# Optware setup
[ -x /etc/rc.optware ] && /etc/rc.optware start

# configure ssh to run on 443
if ! grep "Port 443" /etc/ssh/sshd_config ; then
sed -i "s/Port 22/#Port 22/g" /etc/ssh/sshd_config
echo 'Port 443' &gt;&gt; /etc/ssh/sshd_config
/usr/syno/etc.defaults/rc.d/S95sshd.sh restart
fi

# restore /opt/bin path
if ! grep "/opt/bin" /root/.profile ; then
sed -i "s/PATH=/PATH=\/opt\/bin:/g" /root/.profile
fi

exit 0
Categories: Uncategorized Tags:

Howto to authenticate with apache against the /etc/passwd file

I used the following files to let apache authenticate against the local /etc/passwd file.

The perl-pass.nl is used to generate a file based on the /etc/passwd and shadow file. You can place this in the crontab for example. Only the lower id’s are used, so root won’t be in the list.

The index.php reads from the passwd.html file generated by the perl script and will redirect the users to welcome.php when a correct password and username are used.

perl-pass.pl

#!/usr/bin/perl
#

open(PASSWD,"/etc/passwd");
open(SHADOW,"/etc/shadow");
open(FLATFILE,">/var/www/passwd.httpd");
while(<SHADOW>){
        chop;
        ($uname,$temppass)=split(/:/);
        $pass{$uname}=$temppass;
}
while(<PASSWD>){
        chop;
        ($uname,$temppass,$uid,$gid,$fn,$homedir,$shell)=split(/:/);
        if ($temppass ne 'x'){ $pass{$uname}=$temppass; }
        if ($uid>=500) {
                print FLATFILE
"$uname:$pass{$uname}:$uid:$gid:$fn:$homedir:$shell\n";
        }
}

close(PASSWD);
close(SHADOW);
close(FLATFILE);
chmod(0644,"/var/www/passwd.httpd");
chown(65534,65534,"/var/www/passwd.httpd");

index.php

<? session_start() ?>

<html>
<body>
<p align="center"><br><br>
<br><br><b>Welcome to Server Manager</b>
</p>
<table align="center" border="0" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
<tr><td>
<form method="POST" action="index.php">
  Username: </td><td>
  <input type="text" name="username" size="19"></td></tr>
  <br>
  <tr><td>Password: &nbsp;</td><td>
  <input type="password" name="password" size="19"></td></tr>
  <tr><td colspan="2" align="center">
    <br><input type="submit" value="Login">
</form>
</td></tr>
</table>

</body>
</html>

<?
// Var
$user = ($_POST['username']);
$pass = ($_POST['password']);
$autharray = file("/var/www/passwd.httpd"); 

// Check passwd
for ($x = 0; $x < count($autharray); $x++)
  {
   if (eregi("^$user:", $autharray[$x])) {
       $passwd = explode(":", $autharray[$x]);
       $salt =  substr($passwd[1],0,11);
       $cryptpw = crypt($pass,$salt);
       if ($cryptpw == $passwd[1]) {
		// Succes
             	echo "<br><p align='center'>Username found on</p>";
		echo "<br><p align='center'>Starting connection: $_SESSION[user]...   Moment Please.....</p>";
		$_SESSION['user'] 		= $user;
		$_SESSION['server'] 		= $servername;
		if ( $_SESSION['user'] == "admin" ) { 
			echo" <META HTTP-EQUIV='Refresh' CONTENT='1; URL=admin_overview.php'> ";
		} else {
			echo" <META HTTP-EQUIV='Refresh' CONTENT='1; URL=welcome.php'> "; 
		}
            } else {
			
		// Error on password
              	echo "<br><p align='center'>Wrong password or username!</p>";
	      }
     	}
}
?>

welcome.php

<? session_start() ?>

<?

if ( $_SESSION[user] == "" ) { 
   echo "No Access!"; 
} else {
   echo "Welcome $_SESSION['user']</b><br><br>";
}

?>
Categories: Uncategorized Tags:

Stop Synology index, thumb and postgresql services

If your synology NAS is slowing down your speed, you might want to give the following commands a try:

/usr/syno/etc/rc.d/S77synomkthumbd.sh stop
/usr/syno/etc/rc.d/S66synoindexd.sh stop
/usr/syno/etc/rc.d/S20pgsql.sh stop
Categories: Uncategorized Tags: , ,