ocPortal Tutorial: OcCLE
Written by Philip Withnall, ocProducts
A new feature in ocPortal 3 is OcCLE: the ocPortal Command-Line Environment. It is designed for experienced system administrators who find command-lines faster to use than GUI-based alternatives. The idea when designing OcCLE was not to duplicate effort and code hundreds of commands for every aspect of the system, but to make OcCLE as flexible as possible. To this end, the interface will take PHP code, SQL database queries, scripts, commands, and fully interact with a meta-filesystem created specifically for this module.Table of contents
Commands
Although the system is very flexible, there are many commands to use, designed for interaction with the meta-filesystem and other systems designed specifically for OcCLE. 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:
Code
command_name -o -long_option -o2=value -long_option2="value 2" parameter1 "parameter 2" parameter3
To reiterate: the command name and option names cannot contain spaces, and option values and parameter values can only contain them if they're quoted. OcCLE supports backslashing, so you can escape any quotes in values you're passing:
Code
echo "Grandma said: \"Hello world!\""
Scripts
Using the bin meta-filesystem, commands can be put together in scripts and saved for later use in the bin filesystem. These can be executed on the OcCLE command-line just by entering the name of the script, or can alternatively be scheduled for execution by the calendar at some point in the future.PHP code
PHP can be entered and executed by OcCLE, simply by prefixing the code to be executed with a colon (":"). The returned data will be displayed as best as possible (its type will be determined and outputted as appropriate). Multiple PHP commands may be executed, and ocPortal will attempt to store variables and included files between them (in a cookie) to make it possible to execute multiple commands which are dependent on each other.SQL queries
SQL queries can also be executed by OcCLE, simply by prefixing the query to be executed with a semi-colon (";"). As with PHP commands, the output will be returned as best as possible.Meta-filesystems
One of the main features of OcCLE is the fact that various facets of ocPortal can be manipulated through meta-filesystems. There are several included by default, but it is quite simple to write more as hooks if you know how to program. There are several different meta-filesystems for accessing the real file structure of the ocPortal installation, one for manipulating members (if you have OCF installed), one for manipulating the database, and a couple of others. To use these meta-filesystems, 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.Each of the default meta-filesystems is mapped to a subdirectory of the OcCLE meta-root directory, with obvious mappings sometimes inspired by UNIX. These mappings are stored in an array in sources/occle.php, and if you know how to program you can easily change and customise the mappings to personalise your OcCLE installation.
The default meta-filesystems are as follows, and are all subdirectories of the root directory:
- bin: A place to store all your OcCLE scripts
- database: Access to the raw SQL database
- etc: Access to ocPortal configuration options
- home: Access to the filedump
- members: A listing of every member registered on the system, with their preferences and groups
- raw: A raw listing of the actual ocPortal installation directory
- root: A listing of the ocPortal installation directory, taking source code overrides into account
OcCLEchat
The final feature of OcCLE is OcCLEchat, which allows users of OcCLE to chat with each other across the internet. It is used via the occlechat 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's validity is checked before it is displayed.OcCLEchat will hopefully be useful in allowing website administrators to communicate with each other and share tips, tricks and experiences with ocPortal.



