Composr Tutorial: Commandr
Written by Philip Withnall (ocProducts)Commandr, the Composr Command-Line Environment, is designed for experienced system administrators who find command-lines faster to use than GUI-based alternatives.
Table of contents
Composr Tutorial: Commandr
- PHP code
- SQL queries
- The filesystem
- Running from a normal operating system command prompt
- Example commands
- Commandrchat (advanced)
- Scripts (advanced)
- Bulk actions using Composr
- See also
- PHP code
- SQL database queries
- Commandr-code scripts
- Commandr-code commands, which you can use to fully interact with the Composr Repository
Commandr is accessed from:
Admin Zone > Tools > Commandr
Or, as an overlay using the button in the footer if you have left that enabled (this is very handy).
CommandsAlthough the system is very flexible, there are many commands to use, designed for interaction with the Composr Repository and other systems designed specifically for Commandr. Since UNIX is the grandfather of almost all of the operating systems where command-line use is most prevalent – and administrators comfortable with command-lines will probably be UNIX experts – many of the commands mirror their UNIX counterparts.
The basic format for a command is as follows:
command_name -o -long_option -o2=value -long_option2="value 2" parameter1 "parameter 2" parameter3
- A command name (no spaces)
- followed by a list of options (either in short or long format; this is decided by the command in question) with optional values (quoted if they contain spaces)
- then a list of parameter values (quoted if they contain spaces).
Commandr supports backslashing, so you can escape any quotes in values you're passing:
echo "Grandma said: \"Hello world!\""
For a full list of Commandr commands, simply execute the commands command in Commandr:
You can find help information about any command by simply using the command's -h help flag, or typing help <command>.
:echo "Hello"; echo " World.";
- included code
- included language files
This makes it possible to execute command sequences without having to put them all on one line.
It is implemented using cookies.
Separating multiple queries using semicolons is not supported.
Even though Commandr commands are single-line, pasting multi-line commands in usually works. The only exception would be if the line breaks are a part of strings within the query, in which case they would end up replaced by spaces.
You are allowed to do non-read queries, such as INSERTs and DELETEs, but you'll be told "Error: Your search yielded no results.". Ignore that, it's just a generic messages to tell you explicitly that no results were shown.
The filesystemOne of the main features of Commandr is the fact that various facets of Composr can be manipulated through a virtual filesystem, known as the Composr Repository (aka Commandr-fs). There are many different kinds of directory tied into the filesystem, representing different parts of the Composr system.
It is quite simple to write more as hooks if you know how to program.
To use the repository, simply navigate around using the standard UNIX filesystem commands (cd, pwd, ls, etc.), and modify files in a similar fashion to change the appropriate behind-the-scenes value.
To learn more about the filesystem, which is also used by other parts of Composr, see the The Composr Enterprise Repository tutorial.
Running from a normal operating system command promptCommandr can be loaded up directly from your operating system shell. For example, on Linux you can start it up with this command:
Example commandsIn this section we will show you some of the quick tasks which can be performed efficiently using Commandr.
Quick function searchIt can get quite hectic trying to find a particular function in a big application like Composr, where there are thousands of functions in use, especially if you don't have the code available on your own computer.
Fortunately you can an simply use the find_codes command to help you. For example:
find_codes "function require_code("
In this case it will show sources/global.php.
Open page links on the goYou might often want to quickly test a newly modified page link or just any random page but that'd mean you have to open a new tab window and then manually enter the whole URL.
Commandr comes with a powerful command call which can open up a screen for you on the go, with just a page-link as the only parameter.
Looking up members
This command takes either a username, a member ID, an IP address, or an e-mail address, as the identifying information.
eg: whois 2
Banning membersYou can use the ban_member command to ban a specific member using his/her username or ID.
Giving pointsThe give command is useful to give points to a member. The command takes 3 parameters: Member ID/Username, Number of points, and the reason for the gift points. You can also send points anonymously using the -a flag.
give -a 7334 "Nice User" "I love you"
Changing passwordsThe passwd command works pretty much like the native Linux command of the same name. It will help you change the password of a member using his/her username or Member ID.
passwd -u johnDoe newpassword
Directory and table sizes
It will output a nice formatted list of all the directories for you.
The mysql_table_sizes command will output a tabular list of all the database tables within Composr with their respective size.
These commands are very useful when trying to cut down on disk usage (for example, maybe you are up against a quota limit, or are finding backup files too large).
Clearing cachesCaching is important to maintain performance within Composr; however while testing new changes you might want to clear cached values.
You can use clear_cache command to clear all the caches immediately – or even better, only delete specific caches by passing a comma-separated list of the caches to clear.
Note: If parameters are not given for clear_caches then whole cache will be cleared.
Opening and closing the site
An alternative to the above is:
echo 1 > /etc/site_closed
Accessing system info using Commandr/PHP as a tunnel
This shows info about the server's CPU (Linux servers only, although a Mac-equivalent is shown in a screenshot also):
Please note that the leading : is needed for Commandr to identify that the input's going to be something for PHP.
Commandrchat (advanced)The final feature of Commandr is Commandrchat, which allows users of Commandr to chat with each other across the Internet. It is used via the commandrchat command, taking a website URL and message as parameters (remember to double-quote them if they contain spaces). The system is designed to be resistant to intrusions, as each message is checked before it is displayed.
Commandrchat is designed to allow website administrators to communicate with each other and share tips, tricks and experiences with Composr.
Scripts (advanced)Commands can be put together in scripts and saved for later use in the bin filesystem. These can be executed on the Commandr command-line just by entering the name of the script, or can alternatively be scheduled for execution by the calendar to run at some point in the future (possibly routinely).
Bulk actions using ComposrCommandr is a very effective way to automate tedious maintenance tasks. For example, if you want to delete a set of images and you have their IDs, you could execute this Commandr code:
foreach ($ids as $id) delete_image($id,true);
The code simply interfaces with the standard Composr APIs.
Please rate this tutorial:
Have a suggestion? Report an issue on the tracker.