Can I run a script on my LOCAL windows machine from PuTTY?
Solution 1
So this probably doesn't work in a lot of cases, but here's what I came up with:
-
Run a service on the host machine that listens for incoming URLs.
I used NodeJS here for no particular reason; I'm sure most popular scripting languages would work.
var http = require('http'), querystring = require('querystring'), cp = require('child_process'), ip = '127.0.0.1', port = 9090, links_opened = 0; //urlopen curl --data "url=%U" 10.0.2.2:9090 %U <- cmd for ttytter http.createServer(function (req, res) { if (req.method == 'POST') { req.on('data', function(chunk) { //get URL var _post = querystring.parse(chunk.toString()), //url has extra quotes for some reason: url_to_open = _post.url.match(/^'(.*)'$/)[1], //these three lines are just for nicely numbered console history (up to 999) link_ind = ++links_opened + ".", ln = link_ind + Array(5 - link_ind.length).join(' ');//pad it console.log( ln + url_to_open); //open tab cp.spawn('c:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe', ['-new-tab', url_to_open]); }); } req.on('end', function() { //respond w/204 (success, no output) res.writeHead(204); res.end(); }); }).listen(port, ip); console.log('Server running at http://' + ip + ":" + port);
-
Send URLs from the host to the guest (I used cURL).
In my
.ttytterrc
, I define the urlopen option thus:urlopen curl --data "url=%U" 10.0.2.2:9090 %U
(%U is expanded to the URL: see urlopen).
I call /url <tweet ID>, it sends a request to my host machine, and the node service opens a new tab in my current browser window. I'm sure there are a host of potential security issues here, but given proper firewall settings, IP checks in the nodeJS script, etc., these are not showstoppers. Anyway, it works for me!
Solution 2
PuTTY doesn't support the launching of local applications unless of course you are connected via SSH to the local machine. One option is to install Cygwin on your Windows box and install TTYtter on there. Essentially TTYtter is a collection of Perl scripts and should work fine on Cygwin assuming you have Perl installed as well.
Yeah
Updated on September 18, 2022Comments
-
Yeah over 1 year
I'm trying to send some emails using PHPMailer and I'd like to attach a pdf file to them. The name of this file has to be selected from the user into a select tag in html. In particular this is the code receiving the input
<select name="Attachment"> <?php $files=scandir("/pathtotherightfolder/"); for($i=0;$i<count($files);$i++) { if(substr($files[$i],-3,3)=="pdf") echo "<option value='".$files[$i]."'>".$files[$i]."</option>"; } ?> <option value="Nessuno">Nessuno</option> </select>
This input is received from another php file which will send the emails and it's working correctly except for the attachment part, I tried all the ways suggested by tutorials, documentation, forums like
1st:
$url="URL of the correct directory in my website".$_POST['Attachment']; $messaggio->AddStringAttachment(file_get_content($url), $_POST['Attachment'], $encoding='base64' , $type='application/pdf');//this one returns FALSE and sends the email with a corrupted attachment, and sends a warning of bad request...adding $_POST['Attachment']=str_replace(" ","%20",$_POST['Attachment']); it still returns false but it doesn't send the email
Also adding
chunk_split(base64_encode(file_get_contents($url)));
2nd:
$url="Samepathofthehtml".$_POST['Attachment'];//this path is correct $messaggio->AddAttachment(realpath($url), $_POST['Attachment'], $encoding='base64' , $type='application/pdf');//this one returns bool(false) and sends the email with no attachments
3rd:
require("fpdf.php"); require("fpdi.php"); $pdf = new FPDI(); $pageCount = $pdf->setSourceFile("Samepathasbefore".$_POST['Attachment']); $tplIdx = $pdf->importPage(1);//just a try with one page $pdf->AddPage(); $pdf->useTemplate($tplIdx, 10, 10, 90); $doc = $pdf->Output('', 'S');//if I try $pdf->Output(); i see the pdf correctly on my browser (so i deduce all the previous instructions are correct) //And in the sending code $messaggio->AddStringAttachment($doc, $_POST['Attachment'], $encoding='base64' , $type='application/pdf');//I obtain the same return value of the 2nd
In the 1st and 3rd case I receive the Attachment but the content is corrupted, in the 2nd I receive the mail without the attachment. Does someone has already tried to do something similar? Any advice?