Don’t Leave Your emlog Admin URL Sitting in Plain Sight

Published:

Exposing the backend address of a website is a risky habit. The web is messy enough as it is, and anyone running a site should at least avoid handing out obvious clues to the admin entrance.

In emlog, the default admin directory is simply admin. That may be convenient, but it also reveals exactly where the management panel lives. Changing this default path is a small defensive step, though it comes with a few side effects that need to be cleaned up afterward.

The basic change can be done in three steps.

First, open the admin directory and find globals.php. Use EditPlus or another proper editor if you have one. Notepad may work, but if it causes trouble, that is on you.

Next, rename the admin folder to whatever name you want, for example xxxx.

Then open the file that used to be admin/globals.php. After renaming the directory, it should now be something like xxxx/globals.php.

Find the code on line 9:

define('TEMPLATE_PATH', EMLOG_ROOT.'/admin/views/');

Change admin to the new folder name, such as xxxx:

define('TEMPLATE_PATH', EMLOG_ROOT.'/xxxx/views/');

After that, refresh the admin login page. In the navigation settings, hide the “Login” item. Otherwise, clicking it will just throw a 404 error, which is annoying for no good reason.

Cleaning up the leftovers

Renaming the backend directory is not always the end of the story. Some paths in emlog still point to admin, so a few broken links or missing images may appear.

1. Emoticon images in micro-posts stop showing

Open include/lib/function.base.php and find:

$t = str_replace($data,'<img title="'.$data.'" src="'.BLOG_URL.'admin/editor/plugins/emoticons/images/'.$emos[$data].'"/>',$t);

Replace admin with xxxx:

$t = str_replace($data,'<img title="'.$data.'" src="'.BLOG_URL.'xxxx/editor/plugins/emoticons/images/'.$emos[$data].'"/>',$t);

2. Default micro-post avatars fail to display

If no new avatar has been uploaded in the backend personal settings, the default avatar used by micro-posts may not appear on the frontend.

Open t/index.php and find:

$avatar = empty($user_cache[UID]['avatar']) ? '../admin/views/images/avatar.jpg' : '../' . $user_cache[UID]['avatar'];

Change admin to xxxx:

$avatar = empty($user_cache[UID]['avatar']) ? '../xxxx/views/images/avatar.jpg' : '../' . $user_cache[UID]['avatar'];

Then open the template file t.php, usually located at content/templates/template-name/t.php, and find:

BLOG_URL . 'admin/views/images/avatar.jpg' :

Replace it with:

BLOG_URL . 'xxxx/views/images/avatar.jpg' :

3. The “click to return” link breaks when a template is damaged

When the current template has been deleted or corrupted, emlog may show a message with a return link. By default, that link still points to admin, so it will fail after the directory has been renamed.

Open include/lib/view.php and find:

emMsg('当前使用的模板已被删除或损坏,请登录后台更换其他模板。', BLOG_URL . 'admin/template.php');

Change it to:

emMsg('当前使用的模板已被删除或损坏,请登录后台更换其他模板。', BLOG_URL . 'xxxx/template.php');

4. The edit link on the article list points to the old backend path

Open the template’s module.php file and find:

$editflg = ROLE == ROLE_ADMIN || $author == UID ? '<a href="'.BLOG_URL.'admin/write_log.php?action=edit&gid='.$logid.'" target="_blank">编辑</a>' : '';

Replace admin with xxxx:

$editflg = ROLE == ROLE_ADMIN || $author == UID ? '<a href="'.BLOG_URL.'xxxx/write_log.php?action=edit&gid='.$logid.'" target="_blank">编辑</a>' : '';

That covers the main places where the old backend path tends to remain hardcoded. It does not mean these are the only leftovers. Depending on the template and setup, there may be more references to admin hiding elsewhere.

Renaming the backend path is simple in theory, but chasing these aftereffects can be painfully tedious. If the site breaks while testing, restoring and clearing things again and again gets old very quickly.