<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
<?xml-stylesheet type="text/css" href="http://linuxevolution.org/styles/feed.css"?>


<title type="html">Filed under: nanoblogger | Linux Evolution dot org and the NSLU2</title>
<subtitle type="html"></subtitle>
<link rel="alternate" type="text/html" href="http://linuxevolution.org"/>
<link rel="self" type="application/atom+xml" href="http://linuxevolution.org/archives/nanoblogger/index-atom.xml"/>
<updated>2010-12-26T18:50:23-05:00</updated>
<author>
<name>orvtech</name>
<uri>http://linuxevolution.org</uri>
</author>
<id>http://linuxevolution.org/</id>
<generator uri="http://nanoblogger.sourceforge.net" version="3.4">
NanoBlogger
</generator>

<entry>
<title type="html">Shell script to backup NanoBlogger to a remote server </title>
<author>
<name>orvtech</name>
</author>
<link rel="alternate" type="text/html" href="http://linuxevolution.org/archives/2010/06/09/shell_script_to_backup_nanoblogger_to_a_remote_server/index.html"/>

<id>http://linuxevolution.org/archives/2010/06/09/shell_script_to_backup_nanoblogger_to_a_remote_server/index.html</id>
<published>2010-06-09T16:23:49-05:00</published>
<updated>2010-06-09T16:23:49-05:00</updated>
<category term="Scripts" />
<category term="Linux" />
<category term="nanoblogger" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>This is a simple script that creates full backups of our NanoBlogger blog by compressing our DocumentRoot directory and upload it to a remote server via SCP.</p>

<p>Lets take a look at it:<br />
<pre>#!/bin/bash
BLOG_PATH="/path/to/the/directory/that/contains/your/blog.conf/"
BLOG_NAME="orvtech.com"
DATE=`date +%d%b%Y-h%Hm%M`
NO_BAKUP="cache/*"
SCP_SERVER="<your_server_here>"
SCP_USER="<your_ssh_login_here>"
SCP_PORT="22"

cd $BLOG_PATH
tar -czpsf ~/$BLOG_NAME-nanoblogger.$DATE.tar.gz --exclude "$NO_BAKUP" *
ls -lah  ~/$BLOG_NAME-nanoblogger.$DATE.tar.gz
scp -P$SCP_PORT ~/$BLOG_NAME-nanoblogger.$DATE.tar.gz $SCP_USER@$SCP_SERVER:~/</pre>
</p>
<br />
<p><i>
<b>Spanish version:</b> <a href="http://orvtech.com/howto/respaldar-nanoblogger/" rel="friend" hreflang="en">Respaldar NanoBlogger.</a>
</i></p>
</div>
</content>

</entry>
<entry>
<title type="html">Web interface for NanoBlogger: Add entries.</title>
<author>
<name>orvtech</name>
</author>
<link rel="alternate" type="text/html" href="http://linuxevolution.org/archives/2010/04/21/web_interface_for_nanoblogger_add_entries/index.html"/>

<id>http://linuxevolution.org/archives/2010/04/21/web_interface_for_nanoblogger_add_entries/index.html</id>
<published>2010-04-21T15:55:50-05:00</published>
<updated>2010-04-21T15:55:50-05:00</updated>
<category term="Scripts" />
<category term="NSLU2" />
<category term="nanoblogger" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>
Please bare in mind that this is a proof of concept (that works) but here it is a web interface that allows you to submit entries to NanoBlogger through a BASH CGI. The script is rather simple, it just takes the fields title, description and body then writes it to a text file, you can latter process it through a cronjob or just leave it there for then you get a chance parse it by nb.
</p>

<p>
For this we will be using 3 code segments, the first would be the HTML form that will allow us to enter the content and pass those values to the CGI besides those two we have a javascript segment that allow us to preview the actual article that we are submitting.

</p>

<p>
<b>The Form.</b><br />
In other to have a bit of eye-candy i decided to use the heather and cascade style sheet from the actual style i am using for NanoBlogger. I found that the easiest way was to create a file by running `nb -b /path/of/the/blog/ make-file nb_send_entry.txt`. This will create a template that we can use to add the form HTML inside the 'BODY' section.
</p>


<textarea  style="height: 140px"  class="bashcode">
<form name="nb_entrada_send" method="post" ACTION="http://orvtech.com/send_nb_entry.cgi"><table border="0" width="600">
<tr>
<td width="100px">Titulo:</td>
<td width="500px"><input type="text" size="60" maxlength="50" id="title" name="entrada_title" value="Enter Title Here"></td>
</tr>
<tr>
<td width="100px">Descripcion:</td>
<td width="500px"><input type="text" size="60" maxlength="100" id="description" name="entrada_description" value="Enter Description Here"></td>
</tr>
<tr>
<td colspan="2">Contenido:<br />
< textarea cols="75" rows="30" id="body" name="entrada_body">
HTML esta permitido.
</ textarea>
</td>
</tr>
<tr>
<td width="600" colspan="2">
<div align="center "style="margin: auto; align: center; width: 600px;">
<input type="button" name="preview" value="Vista Previa" onclick="return openPreview();" />
&nbsp;&nbsp;<input type=submit value="Enviar" />&nbsp;&nbsp;
<input type="reset" value="Cancelar" />
</div>
</td>
</tr>
</table></form></textarea>


<p>
The product of this code is a web page with the same look and feel that the blog has. Here is a sample from our Spanish site:
</p>
<div><img src="http://orvtech.com/images/entry_form_screensho1.png" /></div>
<p>
<b>The JavaScript.</b><br />
If you take a look at above source code we have a 'preview' button; this button calls the function openPreview. The idea of this function is to show how would the HTML that we are codding look using the current style. You can get a good idea on how would this entry look before you submit it. Here is the code:
</p>



<textarea  style="height: 140px"  class="bashcode">
<script language="JavaScript">
function openPreview()
{
features = 'width=800, height=600, toolbar=no, menubar=no, resizable=no, location=no, directories=no, status=no';
var popWin = window.open ('','Preview_Entry', features);

var popTitleText = popWin.document.getElementById("title");
var titleText = document.getElementById("title");
var popBodyText = popWin.document.getElementById("body");
var bodyText = document.getElementById("body");

popWin.document.writeln('<head><title>Submit an Entry | Linux y el NSLU2</title><link rel="stylesheet" href="/styles/nb_default.css" type="text/css" media="all" /><link rel="shortcut icon" href="/favicon.ico" /></head><body> <div class="border"> <div class="container">  <div id="topmenu">  <ul>  <li><a href="/index.html" title="Inicio"><span>Inicio</span></a></li>  <li><a href="/gallery.html" title="Galería"><span>Galería</span></a></li>  <li><a href="/archives/scripts/index.html" title="BASH Scripts"><span>Scripts</span></a></li>  <li><a href="/articles/el_nslu2/" title="El NSLU2"><span>El NSLU2</span></a></li> <li><a href="/archives/scripts/index.html" title="Linux"><span>Linux</span></a></li> <li><a href="http://orvtech.com/index.html" title="orvtech.com in english"><span>In English</span></a></li>  </ul>  </div> <div id="header"></div><div class="container"><div class="archives"><div class="blogbody"> <h3 class="title">' + titleText.value + '</h3>' + bodyText.value + '</div></div></div></div></div></body>');

popTitleText.value = titleText.value;
popWin.document.close();
}
</script></textarea>



<p>
As you can see we are defining a new window and opening it with the content we entered on the form, it uses the nb_default.css. Most of the customizations can be done on in popWin.document.writeln in case you want to adapt it to your blog.
Remember that this is a proof of concept and that it can still be improved, perhaps we can latter make it to read the blog.conf file. Here is a screenshot of how it looks. 
</p>
<div><img src="http://orvtech.com/images/entry_form_screensho1.png" /></div>

<p>
<b>All you need is BASH.</b><br />
A CGI codded in bash to create the new entry for the blog. Here is the source code of send_nb_entry.cgi
</p>



<textarea  style="height: 140px"  class="bashcode">

#!/bin/bash

echo "Content-type: text/html"
echo -e "Status: 200 \n"
echo -e "<html><head><meta http-equiv=\"refresh\" content=\"2;url=http://orvtech.com\"></head><body><p>ENTRY ACCEPTED IN FOR QUEUE</p></body></html>"

DRAFT_ENTRY_DIRECTORY="/tmp"
POST_DATA=$(</dev/stdin)
TEMP_FILE="/tmp/nb_cgi_send_nb_entry.tmp"

nb_entrada_title=`echo $POST_DATA | sed -n 's/^.*entrada_title=\([^&]*\).*$/\1/p' | sed -e 's/%20/ /g'| sed 's/+/ /g'| sed 's/\%0[dD]//g' | awk '/%/{while(match($0,/\%[0-9a-fA-F][0-9a-fA-F]/)) {$0=substr($0,1,RSTART-1)sprintf("%c",0+("0x"substr($0,RSTART+1,2)))substr($0,RSTART+3);}}{print}'`
nb_entrada_description=`echo $POST_DATA | sed -n 's/^.*entrada_description=\([^&]*\).*$/\1/p' | sed -e 's/%20/ /g'| sed 's/+/ /g'| sed 's/\%0[dD]//g' | awk '/%/{while(match($0,/\%[0-9a-fA-F][0-9a-fA-F]/)) {$0=substr($0,1,RSTART-1)sprintf("%c",0+("0x"substr($0,RSTART+1,2)))substr($0,RSTART+3);}}{print}'`
name_entrada_tmp=`date +%Y-%m-%dT%H_%M_%S.tmp`
echo "TITLE: $nb_entrada_title" > $TEMP_FILE
echo "AUTHOR:" >> $TEMP_FILE
echo "DATE:" >> $TEMP_FILE
echo "DESC: $nb_entrada_description" >> $TEMP_FILE
echo "FORMAT: raw" >> $TEMP_FILE
echo "-----" >> $TEMP_FILE
echo "BODY:" >> $TEMP_FILE

echo $POST_DATA | sed -n 's/^.*entrada_body=\([^&]*\).*$/\1/p' | sed -e 's/%20/ /g'| sed 's/+/ /g'| sed 's/\%0[dD]//g' |\
   awk '/%/{while(match($0,/\%[0-9a-fA-F][0-9a-fA-F]/))\
       {$0=substr($0,1,RSTART-1)sprintf("%c",0+("0x"substr(\
       	      $0,RSTART+1,2)))substr($0,RSTART+3);}}{print}' >> $TEMP_FILE

	      echo "END-----" >> $TEMP_FILE
	      mv `echo -e $TEMP_FILE` `echo -e $DRAFT_ENTRY_DIRECTORY/$name_entrada_tmp`</textarea>




<p>
We can latter import the file defined by $DRAFT_ENTRY_DIRECTORY/$name_entrada_tmp issuing the command:
</p>


<textarea  style="height: 14px"  class="bashcode">
nb -b /path/to/your/blog import entry /tmp/2010-03-02T15_02_01.tmp</textarea>


<p>
This will add the entry to our blog. I though about automating this in the CGI but at this point i prefer to create a central control panel and keep things separated.
</p>
<br /><br />
<p><i>
<b>Spanish version:</b> <a href="http://orvtech.com/archives/2010/04/06/interfaz_web_para_agregar_entradas_a_nanoblogger/index.html">Interfaz web para agregar entradas a NanoBlogger.</a>
</i></p><br />
</div>
</content>

</entry>
<entry>
<title type="html">A BASH CGI as a workaround to .htaccess files on lighttpd</title>
<author>
<name>orvtech</name>
</author>
<link rel="alternate" type="text/html" href="http://linuxevolution.org/archives/2010/03/26/a_bash_cgi_as_a_workaround_to__htaccess_files_on_lighttpd/index.html"/>

<id>http://linuxevolution.org/archives/2010/03/26/a_bash_cgi_as_a_workaround_to__htaccess_files_on_lighttpd/index.html</id>
<published>2010-03-26T12:49:32-05:00</published>
<updated>2010-03-26T12:49:32-05:00</updated>
<category term="Scripts" />
<category term="NSLU2" />
<category term="Linux" />
<category term="nanoblogger" />
<category term="lighttp" />
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>
As you might remember, in a previous post I explained how to maintain a permanent link which always points 
to the latest submission on your nanoblogger website. Since I decided to migrate from apache to lighttp I 
lost the ability to use .htacees files thus .htacees file based redirects do not work anymore.
</p>
<p>
<br /><b>The workaround.</b><br />

We will keep using the /latest url for the redirects the only thing is that we will use a CGI written in 
BASH to accomplish the redirect. The script will parse our RSS feed (rss.xml) to check which is the latest 
post and redirect to that url. The redirect is accomplished by sending the HTTP headers 'Location' and 
'Status'. Let's take a look at the script:
<br />
<i>latest.cgi</i><br />

<textarea style="height: 80px" class="bashcode">
#!/bin/bash
DocummentRoot="/var/www/linuxevolution.org/htdocs"
Latest=`cat $DocummentRoot/rss.xml | grep link | grep archives | head -n1 | sed -e :a -e 's/<[^>]*>//g;/</N;//ba'`
echo "Status: 302 Moved"
echo -e "Location: $Latest\n"</textarea>
</p>
<p>
Here we are sending the Status header to prevent search engines from associating more than one url to the 
same content (this will give us a lower score in some search engines' systems) and then we send the 
Location header to do the actual redirect.
</p>
<p>
<br /><b>Lighttp and CGIs.</b><br />

In other to execute this CGI we need to make some minor modifications to our VirtualHostost configuration. 
Lets add these two lines to it:
<br />

<textarea style="height: 26px" class="bashcode">
cgi.assign = ( ".cgi" => "/bin/bash" )
url.redirect =( "^/latest/(.*)" => "http://www.linuxevolution.org/latest.cgi")</textarea>


</p>
<p>
In the first line we are telling lighttpd to use /bin/bash to execute any *.cgi file (you can change this 
to anything like *.sh, *.bash). In the second line we redirect all requests to /latest/ to the url 
/latest.cgi. You can either use /latest.cgi or /latest/ for these urls in your signature at the forums; 
personally I like to use /latest/<name of the forum here> to keep track of where is my traffic coming from 
even if I don't get the HTTP referrer.
</p>
<br />
<p><i>
<b>Spanish version:</b> <a href="http://orvtech.com/howto/un-cgi-en-bash-para-mantener-tu-firma-al-dia-en-todos-los-foros-en-que-participas/" rel="friend" hreflang="es">Un CGI en BASH para mantener tu firma al dia en todos los foros en que participas.</a>
</i></p>
</div>
</content>

</entry>

</feed>

