The Taiwan earthquake has brought telecommunications in the Taiwan/Hong Kong region to a standstill. I am living in Shenzhen and am unable to read slashdot
directly for several days
gmail and google have privileged bandwidth and local servers. Both gmail and google continue to work perfectly from the region. Could there be some way to use google
or gmail to read slashdot?
A solution was to upload an executable to my webhosting in America that would receive zipped executables by email, execute them, then email me the results.
This works great! Here's some screenshots
Full source-code for email proxy:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using SevenZip;
using System.Diagnostics;
//using System.Net.Mail;
using System.Web.Mail;
namespace base64test
{
class Program
{
static void Main( string[] args )
{
try
{
string message = Console.In.ReadToEnd();
//string output = message + "\n\n";
string output = "";
string[] splitmessage = message.Split( "\n".ToCharArray() );
string subject = "";
string from = "";
string base64string = "";
foreach (string line in splitmessage)
{
if (line.StartsWith( "From: " ))
{
from = line.Substring( "From: ".Length );
}
else if (line.StartsWith( "Subject: " ))
{
subject = line.Substring("Subject: ".Length );
}
}
output += "subject: [" + subject + "]" + "\n";
output += "from: [" + from + "]" + "\n";
if (from.IndexOf( "hughperkins@gmail.com" ) >= 0)
{
if (subject == "mysecretsubject")
{
int i = 0;
bool atcontent = false;
while (i < splitmessage.Length)
{
if (!atcontent)
{
if (splitmessage[i].StartsWith( "X-Attachment-Id:" ))
{
atcontent = true;
i++;
}
}
else
{
if (splitmessage[i].StartsWith( "----" ))
{
atcontent = false;
}
else
{
base64string += splitmessage[i].Trim();
}
}
i++;
}
//output += "base64string: [" + base64string + "]\n";
}
}
byte[] bytes = Convert.FromBase64String( base64string );
FileStream fs = new FileStream( "/home/mdweb/attach.7z", FileMode.Create );
fs.Write( bytes, 0, bytes.Length );
fs.Close();
fs = new FileStream( @"/home/mdweb/attach.7z", FileMode.Open, FileAccess.Read );
ArchiveDatabaseEx archivedatabaseex;
new SzIn().szArchiveOpen( fs, out archivedatabaseex );
for (int i = 0; i < archivedatabaseex.Database.NumFiles; i++)
{
FileItem file = archivedatabaseex.Database.Files[i];
//Console.WriteLine( "file " + i + " " + file + " HasStream? " + file.HasStream );
}
uint blockindex;
byte[] outbuffer;
ulong outbuffersize;
ulong offset = 0;
ulong outsizeprocessed = 0;
new SevenZip.SzExtract().Extract( fs, archivedatabaseex, 0, out blockindex,
out outbuffer, out outbuffersize, ref offset, ref outsizeprocessed );
fs.Close();
//Console.WriteLine( "extracted " + outbuffersize + " bytes" );
FileStream exestream = new FileStream( "/home/mdweb/out.exe", FileMode.Create );
exestream.Write( outbuffer, (int)offset, (int)outsizeprocessed );
exestream.Close();
ProcessStartInfo psi = new ProcessStartInfo( "/home/mdweb/local/bin/mono-1.2.2.1/bin/mono" );
psi.Arguments = "--debug /home/mdweb/out.exe";
//ProcessStartInfo psi = new ProcessStartInfo( "out.exe" );
psi.CreateNoWindow = true;
//psi.RedirectStandardError = true;
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
Process process = new Process();
process.StartInfo = psi;
process.Start();
string commandoutput = process.StandardOutput.ReadToEnd();
//Console.WriteLine( output );
output += "output:\n" + commandoutput + "\n";
MailMessage mailmessage = new MailMessage();
mailmessage.From = "mdweb@manageddreams.com";
mailmessage.To = "hughperkins@gmail.com";
mailmessage.Subject = "test";
mailmessage.Body = output;
//mailmessage.Body = message;
SmtpMail.SmtpServer = "gmail-smtp-in.l.google.com";
SmtpMail.Send( mailmessage );
}
catch (Exception e)
{
Console.WriteLine( e );
}
}
}
}
You'll need a 7zip Archiver for C#, which you can find inside:
http://manageddreams.com/csai/ModReader.7z
Let's say we want to read slashdot, we need an executable to fetch the slashdot page and write out the contents:
Source-code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
namespace Readiht
{
class Program
{
static void ReadPage( string address )
{
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create( address );
HttpWebResponse httpwebresponse = (HttpWebResponse)myReq.GetResponse();
Stream stream = httpwebresponse.GetResponseStream();
StreamReader streamreader = new StreamReader( stream );
string contents = streamreader.ReadToEnd();
streamreader.Close();
stream.Close();
httpwebresponse.Close();
Console.WriteLine( contents );
//Console.WriteLine( "====================================" );
}
static void Main( string[] args )
{
ReadPage( "http://slashdot.org");
//ReadPage("http://science.slashdot.org/science/06/12/30/0743205.shtml" );
}
}
}
Here's the built readslashdot executable:
We zip it using 7zip:
Send an email to our webserver using gmail:
We click send, and 20 seconds later we get our reply:
Save to an html file:
... and open! Finally, after three days of no slashdot :-O
Edits/FAQ
Why not just send the URL?
Increased flexibility. Sending the URL would let me browse the web, but I'd like to be able to do other things, like update my website ;-) and access SVN.
Why not use Google cache/translate/etc?
Cache is censored. Translate times out.
Isnt this bad security?
Well, yes. Being Slashdotted probably didnt enhance it any ;-)