<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>In the box &#187; Jamie</title>
	<atom:link href="http://inthebox.webmin.com/author/jamie/feed" rel="self" type="application/rss+xml" />
	<link>http://inthebox.webmin.com</link>
	<description>Automating the data center</description>
	<lastBuildDate>Sat, 24 Oct 2009 23:16:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Creating an iPhone UI for&#160;Virtualmin</title>
		<link>http://inthebox.webmin.com/creating-an-iphone-ui-for-virtualmin-part-1</link>
		<comments>http://inthebox.webmin.com/creating-an-iphone-ui-for-virtualmin-part-1#comments</comments>
		<pubDate>Fri, 22 Aug 2008 20:15:59 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Features]]></category>
		<category><![CDATA[virtualmin webmin iphone iui mobile]]></category>

		<guid isPermaLink="false">http://inthebox.webmin.com/?p=33</guid>
		<description><![CDATA[Introduction and History Around the start of the year, I created a theme for Webmin designed to make it easier to access from mobile devices like smartphones and cellphones with simple built-in browsers. At the time I had a Treo 650, which had a very basic browser &#8211; certainly not powerful enough to render the [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction and History</h2>
<p>Around the start of the year, I created a theme for Webmin designed to make it easier to access from mobile devices like smartphones and cellphones with simple built-in browsers. At the time I had a Treo 650, which had a very basic browser &#8211; certainly not powerful enough to render the standard Virtualmin or Webmin framed themes.</p>
<p>By using Webmin&#8217;s theming features, I was able to create a UI that used multiple levels of menus to access global and domain-level settings, instead of frames. The theme also changed the layouts of forms to be more vertical than horizontal, use fewer tables, and remove all use of Javascript and CSS for hiding sections.</p>
<p>This was released in the virtual-server-mobile theme package version 1.6, and all was good in the world. Anyone using it could now access all the features of Virtualmin from a very basic browser, and read mail in Usermin without having to rely on the awful IMAP implementations in most smartphones.</p>
<p>This shows what Virtualmin looked like on a Treo :</p>
<p><img class="alignnone" title="Virtualmin domain links" src="http://www.webmin.com/images/treo_edit.png" alt="" width="322" height="323" /></p>
<p>Then I bought an iPhone.</p>
<p>It has a <strong>much</strong> more capable browser, technically the equal of any desktop browser like Firefox or IE. The regular Webmin themes actually worked fine, although a fair bit of zooming is needed to use them. The mobile theme looked like crap, as it didn&#8217;t use any of the browser features like CSS and Javascript that the iPhone supports. Plus the layout rendered poorly due to the use of long lines of text that didn&#8217;t get wrapped at the browser&#8217;s screen width.</p>
<p>On the iPhone, the Create Alias page in mobile theme looked like this :</p>
<p><a href="http://inthebox.webmin.com/wp-content/uploads/2008/08/iphone_mobile.jpg"><img class="alignnone size-full wp-image-42" title="Old mobile theme on iPhone" src="http://inthebox.webmin.com/wp-content/uploads/2008/08/iphone_mobile.jpg" alt="" width="320" height="480" /></a></p>
<p>And in the regular Virtualmin theme, the Create Alias page looked like :</p>
<p><a href="http://inthebox.webmin.com/wp-content/uploads/2008/08/iphone_framed.jpg"><img class="alignnone size-full wp-image-43" title="Framed theme on iPhone" src="http://inthebox.webmin.com/wp-content/uploads/2008/08/iphone_framed.jpg" alt="" width="320" height="480" /></a></p>
<p>I mentioned this to Joe, and he pointed me at <a href="http://code.google.com/p/iui/">iUI</a>, an awesome library of CSS and Javascript that allows developers to create websites that mimic the look of native iPhone applications. After trying out the demos and looking at their source code, it was clear that iUI would be perfect for creating an iPhone-specific theme.</p>
<p>It wasn&#8217;t quite as simple as I first thought, but after some hacking on both the theme code and iUI itself I was able to come up with a pretty good layout, as you can see in this screenshot of the Create Alias page :</p>
<p><img class="alignnone" title="Virtualmin alias form on iPhone" src="http://www.webmin.com/images/mobile_alias.png" alt="" width="320" height="480" /></p>
<h2>Menu Implementation</h2>
<p>Actually getting IUI to play nicely with the Webmin theming system was slightly more complex than I originally expected though. For example, an iPhone-style multi-level menu that slides to the left is implemented in IUI with HTML like :</p>
<pre>&lt;ul id='main' title='My Menu' selected='true'&gt;
&lt;li&gt;&lt;a href='#menu1'&gt;Submenu One&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href='#menu2'&gt;Submenu Two&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul id='menu1' title='Submenu One'&gt;
&lt;li&gt;&lt;a href='foo.cgi'&gt;Foo&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href='bar.cgi'&gt;Bar&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul id='menu2' title='Submenu Two'&gt;
&lt;li&gt;&lt;a href='quux.cgi'&gt;Quux&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href='#page'&gt;Some page&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div id='page' class='panel' title='Some page'&gt;
Any HTML can go here.
&lt;/div&gt;</pre>
<p>As you might guess, CSS and Javascript are used to show only one menu or div at a time, even though they are all in the same HTML file. This is quite different to the way menus are usually created in Webmin.</p>
<p>To get this kind of HTML from the theme, I created an index.cgi that generates a large set of &lt;ul&gt; lists and &lt;div&gt; blocks containing all the Virtualmin domains, global settings, Webmin categories and modules. This is loaded by the iPhone when a user logs in, and allows quick navigation to without any additional page loads. For example, these screenshots show the path down to the Users and Groups module. Only the last requires an extra page load :</p>
<p><a href="http://inthebox.webmin.com/wp-content/uploads/2008/08/menu1.jpg"><img class="alignnone size-medium wp-image-48" title="Top Level Menu" src="http://inthebox.webmin.com/wp-content/uploads/2008/08/menu1-200x300.jpg" alt="" width="200" height="300" /></a><a href="http://inthebox.webmin.com/wp-content/uploads/2008/08/menu2.jpg"><img class="alignnone size-medium wp-image-49" title="Webmin Categories Menu" src="http://inthebox.webmin.com/wp-content/uploads/2008/08/menu2-200x300.jpg" alt="" width="200" height="300" /></a><a href="http://inthebox.webmin.com/wp-content/uploads/2008/08/menu3.jpg"><img class="alignnone size-medium wp-image-50" title="Webmin Modules" src="http://inthebox.webmin.com/wp-content/uploads/2008/08/menu3-200x300.jpg" alt="" width="200" height="300" /></a><a href="http://inthebox.webmin.com/wp-content/uploads/2008/08/menu4.jpg"><img class="alignnone size-medium wp-image-51" title="Users and Groups" src="http://inthebox.webmin.com/wp-content/uploads/2008/08/menu4-200x300.jpg" alt="" width="200" height="300" /></a></p>
<p>The index.cgi script is able to fetch all Webmin modules and categories with the functions <strong>get_visible_module_infos</strong> and <strong>list_categories</strong>, which are part of the core API. It also fetches Virtualmin domains with <strong>virtual_server::list_domains</strong> and global actions with <strong>virtual_server::get_all_global_links</strong>.</p>
<p>For example, the code that generates the menus of modules and categories looks roughly like :</p>

<div class="wp_syntax"><div class="code"><pre class="perl perl" style="font-family:monospace;"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@modules</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>get_visible_module_infos<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">%cats</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>list_categories<span style="color: #009900;">&#40;</span>\<span style="color: #0000ff;">@modules</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;&lt;ul id='modules' title='Webmin Modules'&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
<span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$c</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">sort</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">$b</span> <span style="color: #b1b100;">cmp</span> <span style="color: #0000ff;">$a</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">keys</span> <span style="color: #0000ff;">%cats</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;&lt;li&gt;&lt;a href='#cat_$c'&gt;$cats{$c}&lt;/a&gt;&lt;/li&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$c</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">sort</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">$b</span> <span style="color: #b1b100;">cmp</span> <span style="color: #0000ff;">$a</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">keys</span> <span style="color: #0000ff;">%cats</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@incat</span> <span style="color: #339933;">=</span> <span style="color: #000066;">grep</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">$_</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="">'category'</span><span style="color: #009900;">&#125;</span> eq <span style="color: #0000ff;">$c</span> <span style="color: #009900;">&#125;</span> <span style="color: #0000ff;">@modules</span>;
    <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;&lt;ul id='cat_$c' title='$cats{$c}'&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
    <span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$m</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">sort</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066;">lc</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$a</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="">'desc'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">cmp</span> <span style="color: #000066;">lc</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$b</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="">'desc'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span> <span style="color: #0000ff;">@incat</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;&lt;li&gt;&lt;a href='$m-&gt;{'dir'}/' target=_self&gt;$m-&gt;{'desc'}&lt;/a&gt;&lt;/li&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
        <span style="color: #009900;">&#125;</span>
    <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;&lt;/ul&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;&lt;/ul&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;</pre></div></div>

<p>The actual IUI styling and menu navigation comes from CSS and Javascript files which are referenced on every page in the &lt;head&gt; section, generated by the theme&#8217;s <strong>theme_header</strong> function which overrides the Webmin <strong>header</strong> call.</p>
<h2>Other Pages</h2>
<p>Other pages within Webmin are generated using the regular CGI scripts, but with their HTML modified by the theme. This is done by overriding many of the <strong>ui_</strong> family of functions, in particular those that generate forms with labels and input fields. Because the iPhone screen is relatively narrow, it is more suited to a layout in which all labels and inputs are arranged vertically, rather than the Webmin default that uses multiple columns.</p>
<p>For example, the <strong>theme_ui_table_row</strong> override function contains code like :</p>

<div class="wp_syntax"><div class="code"><pre class="perl perl" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$label</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">/\S/</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #0000ff;">$rv</span> .<span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;&lt;div class='webminTableName'&gt;$label&lt;/div&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #0000ff;">$rv</span> .<span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;&lt;div class='webminTableValue'&gt;$value&lt;/div&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;</pre></div></div>

<p>The label and value variables are the field label and input HTML respectively. The actual styling is done using CSS classes that were added to IUI for the theme. The same thing is done in functions that render multi-column tabs, tabs and other input elements generated with <strong>ui_</strong> family functions.</p>
<p>The only downside to this approach is that not all Webmin modules have yet been converted to use the functions in <strong>ui-lib.pl</strong>, and so do not get the iPhone-style theming. However, I am working on a long-term project to convert all modules from manually generated HTML to the using the UI library functions.</p>
<h2>Headers and Footers</h2>
<p>In most Webmin themes, there are links at the bottom of each page back to previous pages in the heirarchy &#8211; for example, when editing a Unix group there is a link back to the list of all groups.</p>
<p>However, IUI puts the back link at the top of the page next to the title, as in native iPhone applications. Fortunately, CSS absolute positioning allows the theme to place this link at the top, even though it is only generated at the end of the HTML. The generated HTML for this looks like :</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div class='toolbar'&gt;
&lt;h1 id='pageTitle'&gt;&lt;/h1&gt;
&lt;a class='button indexButton' href='/useradmin/index.cgi?mode=groups' target=_self&gt;Back&lt;/a&gt;
&lt;a class='button' href='/help.cgi/useradmin/edit_group'&gt;Help&lt;/a&gt;
&lt;/div&gt;</pre></div></div>

<p>The <strong>toolbar</strong> CSS class contains the magic attributes needed to position it at the top of the page, even though the theme outputs it last.</p>
]]></content:encoded>
			<wfw:commentRss>http://inthebox.webmin.com/creating-an-iphone-ui-for-virtualmin-part-1/feed</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Extending Virtualmin with&#160;plugins</title>
		<link>http://inthebox.webmin.com/extending-virtualmin-with-plugins</link>
		<comments>http://inthebox.webmin.com/extending-virtualmin-with-plugins#comments</comments>
		<pubDate>Mon, 03 Mar 2008 23:51:22 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Snippets]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[virtualmin]]></category>

		<guid isPermaLink="false">http://inthebox.webmin.com/extending-virtualmin-with-plugins</guid>
		<description><![CDATA[Not many people know that Virtualmin&#8217;s already extensive list of built-in features can be extended by writing plugins, which are basically Webmin modules that export a special API. Why would you want to do this, you may ask? Let&#8217;s say their is a mailing list application, log analyzer, database or source code control system that [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/images/Runner-for-37500-HP-turbine.jpeg" alt="Plugins can be big" width="496" height="519" /></p>
<p>Not many people know that Virtualmin&#8217;s already extensive list of built-in features can be extended by writing plugins, which are basically Webmin modules that export a special API. Why would you want to do this, you may ask? Let&#8217;s say their is a mailing list application, log analyzer, database or source code control system that you want to make available on a per-domain basis .. if so, a plugin is the way to do it.</p>
<p>A plugin is typically used to a new <strong>feature </strong>to Virtualmin. In it&#8217;s parlance, a feature is something that is enabled on a per-domain basis, such as a website, DNS domain or MySQL database. Let&#8217;s say you have discovered an awesome new log analysis program that you want run on each domain&#8217;s log files &#8211; a plugin would be the way to implement it.</p>
<p>A plugin can also add options to mailbox users. The most common use of this is to grant access on a per-user basis to some resource, such as statistics, an application or database. Plugins can also create new database types, add links to the left menu in the Virtualmin framed theme, and add sections to it&#8217;s system information page.</p>
<p>Some of the existing plugins give you an idea of what&#8217;s possible :</p>
<ol>
<li>The <strong>DAV </strong>plugin adds a feature which makes a virtual server&#8217;s web pages editable from applications that support the protocol, such as Windows and OSX. It also lets you enable DAV logins for each mailbox in the domain.</li>
<li>The <strong>Bootup Actions</strong> plugin allows domain owners to have their long-running server processes started when the system boots.</li>
<li>The <strong>Mail Relay</strong> plugin lets you forward email for a domain to another server, which can be configured by the domain owner.</li>
<li>The <strong>Admin Notes</strong> feature adds a new section to the right-hand frame for entering comments about the system, for sharing status between master admins.</li>
</ol>
<p>To see a full list of plugins that exist, check out the <a href="http://www.webmin.com/cgi-bin/search_third.cgi?category=Virtualmin">third-party modules database</a>.</p>
<p>If you know Perl, have written a regular Webmin module, and want to write your own plugin, check out the <a href="http://www.virtualmin.com/documentation/id,writing_virtualmin_plugins/">extensive documentation</a> on the API.</p>
]]></content:encoded>
			<wfw:commentRss>http://inthebox.webmin.com/extending-virtualmin-with-plugins/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

