Rebuild your DirectAdmin user cache

In some particular cases I was unable to find my users using the DirectAdmin UI. Since then I use this little script to rebuild the user cache of the “Show All Users” list.

[code]#!/bin/sh

cd /usr/local/directadmin/data/users

for r in `ls */reseller.conf | cut -d/ -f1`; do
{
echo “fixing Reseller $r …”;

echo -n ” > $r/users.list

for u in `grep “^creator=$r$” */user.conf | cut -d/ -f1`; do
{
ISUSER=`grep -c usertype=user $u/user.conf`
if [ “$ISUSER” = “1” ]; then
echo $u >> $r/users.list
fi
};
done;
};
done;[/code]

After using this script all users will be shown again in DirectAdmin.

Nginx configuration for WordPress websites

If you are using the WP Super Cache plugin by Automattic, this configuration can help you settings up your Nginx caching proxy:

[code]proxy_cache_path /data/nginx/cache keys_zone=one:10m inactive=24h max_size=1G;
proxy_cache_key “$host$request_uri$cookie_user”;
proxy_cache one;

server {
server_name ~^(static\.)?(?.+)$;
access_log /var/log/nginx/domains/static.$domain.log;

location ~ ^/(wp-content|wp-includes)/ {
resolver 8.8.8.8;
expires 30d;
add_header Pragma public;
add_header Cache-Control “public”;
proxy_cache_valid 200 10m;
proxy_pass http://www.$domain;
add_header X-Cache-Status $upstream_cache_status;
}
}[/code]

Change the static.domain.com to the hostname the nginx server is listening to. Change domain.com (twice!) to the main domain where the content is pulled from.

Make a DNS record (either cname or a) pointing static.domain.com to the IP the nginx server is running at.

Be sure to chmod the /data/nginx/cache folder to 700 and change the ownership to the same user as nginx is running (default nginx).

Check if the cache is working by using this command:

[code]du -h –max-depth=1 /data/nginx/cache[/code]

Easy as that!

Remove e-mail sent count from e-mailaccount

If you want to reset the e-mail acount of a DirectAdmin account it’s pretty simple, you can just hit the reset button. But there are no such buttons for the e-mail accounts itself. So you can use this little line in SSH to remove the e-mail sent acount of a particular e-mail account:

rm -f /etc/virtual/domain.com/usage/info

Notice this line concerns info@domain.com. So you have to change the domain.com part and the info part.

Adding domain pointer with e-mail and SSL options

If you add a domain pointer to a DirectAdmin domain, you can not set-up the e-mail accounts and SSL certificates by default. Almost all the options are not available.

To fix this you can remove the domain pointer and add the domain as a normal domain to the account. It has to be the same account due to permissions.

Then, remove the private_html folder, symlink it to the public_html and set the correct permissions with this piece of code:

rm -rf /home/user/domains/domain.com/private_html
ln -s /home/user/domains/domain.com/public_html /home/user/domains/domain.com/public_html
chown -h user:user /home/user/domains/domain.com/public_html

Now you have the same effect of the normal Domain Pointer in DirectAdmin, but you are able to use the interface for all other DirectAdmin options!

Blocked from loading by Cross-Origin Resource Sharing policy

Sometimes with a multi-store or a multisite you have missing icons (fonts) or similarities.

If you get this error:

Font from origin ‘http://www.domain.com’ has been blocked from loading by Cross-Origin Resource Sharing policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://sub.domain.com’ is therefore not allowed access.

Add this to .htaccess file from www.domain.com and it will work again.

Header set Access-Control-Allow-Origin "*"

Fix domains list in DirectAdmin

I don’t know why, but at one of my servers the domains.list file gets erased every x weeks. So after some weeks they are missing in the httpd.conf and the domains will not work.

Before I figure out what causes it, this is a little piece of code to fix the list and rewrite httpd:

for d in `ls /home/user/domains`; do echo $d >> /usr/local/directadmin/data/users/user/domains.list; done
/usr/local/directadmin/custombuild/build rewrite_confs

Reset per e-mail account usage limit in DirectAdmin

Since DirectAdmin works with ‘per e-mail account send limits’ some things can work out pretty annoying.

In this case the customer sent 1000 e-mails (not SPAM) and want to send e-mail number 1001. But, changing the limit to 2000 will result in a

Please set a limit between 1 and 1000

Despite the fact of the “Zero is unlimited”, if you enter 0 it will give:

You cannot set an unlimited send limit

So I ended up to search in the files and remove the usage by hand:

rm -f /etc/virtual/domain.com/usage/info

Now the usage is removed and the customer is able to send another 1000 e-mails. Which still is not solved but for now it’s done.

Removing bbPress forum comments

In addition to my previous post about removing WooCommerce products, I just used the same snippet to remove 400k bbPress replies.

With this query you can remove all the replies:

DELETE relations.*, taxes.*, terms.*
FROM wp_term_relationships AS relations
INNER JOIN wp_term_taxonomy AS taxes
ON relations.term_taxonomy_id=taxes.term_taxonomy_id
INNER JOIN wp_terms AS terms
ON taxes.term_id=terms.term_id
WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type='reply');

DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'reply');
DELETE FROM wp_posts WHERE post_type = 'reply';

And use this to empty all bbPress topics:

DELETE relations.*, taxes.*, terms.*
FROM wp_term_relationships AS relations
INNER JOIN wp_term_taxonomy AS taxes
ON relations.term_taxonomy_id=taxes.term_taxonomy_id
INNER JOIN wp_terms AS terms
ON taxes.term_id=terms.term_id
WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type='topic');

DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'topic');
DELETE FROM wp_posts WHERE post_type = 'topic';

Worked like a charm! Now all bbPress topics and replies are deleted.

Removing WooCommerce products in WordPress

I found this handy SQL query to easily remove all the products and related stuff from a WordPress WooCommerce.

DELETE relations.*, taxes.*, terms.*
FROM wp_term_relationships AS relations
INNER JOIN wp_term_taxonomy AS taxes
ON relations.term_taxonomy_id=taxes.term_taxonomy_id
INNER JOIN wp_terms AS terms
ON taxes.term_id=terms.term_id
WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type='product');

DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'product');
DELETE FROM wp_posts WHERE post_type = 'product';

Source