A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.
Jump to
Showing posts with label server. Show all posts
Showing posts with label server. Show all posts
POD servers for Perl
You want to browse Perl embedded documentation (POD)
You have some software that was designed for browsing information: a web browser
You need a server to turn the POD into web pages and serve it to the browser.
You try one of these modules:
- https://metacpan.org/pod/Pod::Browser
- Uses Catalyst
- https://metacpan.org/pod/Pod::Server
- ?
- https://metacpan.org/pod/Pod::Webserver
- Very basic
- Parsing much better than Pod::POM::Web, but still fails in places.
- Contains all the Perl built-in modules, which I don't want to see.
- How to run: podwebserver
- https://metacpan.org/pod/Pod::POM::Web
- Advanced design
- Fails to parse nested tags
- Contains all the Perl built-in modules, which I don't want to see.
- How to run: perl -I $DOC_PATH -I $POD_POM_WEB_PATH -MPod::POM::Web -e server
Questions:
- What is the reference implementation of a POD interpreter? `perldoc` just removes links and it is plain text only. So in what viewer do the links actually link to something?
Many different ways to resolve an IP to a hostname in Perl
Some different ways to look up hostnames.
Notes:
Notes:
- getnameinfo() gets a hostname and a service name, so it's not exactly the same as gethostbyaddr()
- although the docs imply you need to enter a port, that's just to get the local service name. If you set it as undef then you can ignore any service
# 1, old deprecated way
use Socket; # gethostbyaddr, inet_aton, AF_INET
sub ip_address_to_host {
my ( $self, $ip_address ) = @_;
my ($hostname) = gethostbyaddr(
inet_aton($ip_address),
AF_INET,
);
return $hostname;
}
# 2, newer better way
use Socket qw(AF_INET inet_pton getnameinfo sockaddr_in);
sub ip_address_to_host {
my ( $self, $ip_address ) = @_;
my $port = undef;
my $socket_address = sockaddr_in($port, inet_pton(AF_INET, $ip_address));
my $flags = 0;
my $xflags = 0;
my ($error, $hostname, $servicename) = getnameinfo($socket_address, $flags, $xflags);
return $hostname;
}
# 3, best way - that only uses DNS and not /etc/hosts first
use Net::DNS;
sub ip_address_to_host {
my ( $self, $ip_address ) = @_;
my $res = Net::DNS::Resolver->new;
my $target_ip = join('.', reverse split(/\./, $ip_address)).".in-addr.arpa";
my $query = $res->query("$target_ip", "PTR") // return;
my $answer = ($query->answer)[0] // return;
my $hostname = $answer->rdatastr;
return $hostname;
}
# 4, the code golf way (no validation) - by Mark B
perl -le 'use Net::DNS::Resolver; print ((Net::DNS::Resolver->new()->query("10.232.32.158","PTR")->answer)[0]->ptrdname);'
SSH warning: authenticity of host can't be established
Problem
The authenticity of host 'example.com (1.2.3.4)' can't be established.
RSA key fingerprint is ab:cd:ef:12:34:56:78:90:ab:cd:ef:12:34:56:78:90
Are you sure you want to continue connecting (yes/no)?
Solution
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
Make sure you understand the security implications of doing this (Hint: they're not good).
(source)
The authenticity of host 'example.com (1.2.3.4)' can't be established.
RSA key fingerprint is ab:cd:ef:12:34:56:78:90:ab:cd:ef:12:34:56:78:90
Are you sure you want to continue connecting (yes/no)?
Solution
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
Make sure you understand the security implications of doing this (Hint: they're not good).
(source)
POD servers
You know, POD.
- Pod::Simple::HTMLBatch - The best one. Properly marked up HTML, so fully customisable with CSS. Split into top-level directories. Doesn't do .t files, but can use a subclass of Pod::Simple::Search rigged to recognise .t files. Submitted patch.
- Pod::Server - Basic default output, one single list. Docs lacking. What about CSS?
- Pod::Webserver - Lots of dependencies, Catalyst, etc. GUI looks great. Couldn't get it to read from local dirs though.
- Pod::POM::Web - Untested
Simple small Perl webservers
Quick start, if it's just a proof-of-concept and won't be running for long:
- HTTP::Daemon - can't get simpler than this. It even picks a port for you
- HTTP::Server::Simple - it works
More complicated to set up, but much more robust:
- PSGI/Plack - the future
- lighttpd - it's pronounced lighty
How to sync over FTP
Don't re-invent the wheel.
1) Install rsync instead, which is designed with syncing in mind.
2) ftpsync was written a decade ago. Perhaps it has been updated since.
3) lftp syncs over FTP and is being actively maintained.
4) Perl package turbo-ftp-sync may also fit the bill.
1) Install rsync instead, which is designed with syncing in mind.
2) ftpsync was written a decade ago. Perhaps it has been updated since.
3) lftp syncs over FTP and is being actively maintained.
4) Perl package turbo-ftp-sync may also fit the bill.
Developing over FTP
Using Eclipse and RSE plugin:
- Logs in okay
- But seems to always be closing directory sub-trees I've opened in 'Remote Systems' panel
- It wants to do an 'ls' on every parent directory in the hierarchy, every time I change files. Very slow.
Using CurlFtpFS:
- Install in Ubuntu from the software centre
- to mount: curlftpfs -v username:password@server.example.com local_dir/
- to unmount: fusermount -u local_dir/
- Performance is unusably slow... Eclipse wants to know about every single file on the remote server, not just the ones I'm editing.
- Saving the file through Eclipse using CurlFtpFS takes even longer than it would to upload it separately.
Using FileZilla and gedit:
- Browsing is fast
- Editing is fast
- But you have to navigate to every file manually each session, it doesn't remember what you had open
- The system of holding temp files locally is not ideal, but FileZilla detects changes in them very nicely
- You still can't grep over the files as they're all held remotely, and it's a bit fiddly to navigate to a specific file
Editing locally with Eclipse, and uploading after changes are made:
- Write an Ant script to upload any modified files?
- ...to investigate
Log into a server using secure keys instead of typing a password
On the client:
See also this and this.
(Upon error "Agent admitted failure to sign using the key", log out of the client and log back in again to fix).
- ssh-keygen -t rsa
- accept the default filename
- press enter for a blank password
- a private (id_rsa) and public key (id_rsa.pub) will be created
- copy the public key to the server
- cat id_rsa.pub >> ~/.ssh/authorized_keys
- chmod 700 ~/.ssh
- chmod 644 ~/.ssh/authorized_keys
See also this and this.
(Upon error "Agent admitted failure to sign using the key", log out of the client and log back in again to fix).
Edit text files on remote linux servers
UNTESTED:
> I've never managed to figure out how to rig up editors to edit
> files on remote servers.
On the server, put this in smb.conf
[homes]
comment = Home Directories
hide dot files = yes
read only = No
browseable = yes
Then in the finder/windows explorer connect to 'smb://hostname/' . Then make an alias to it on your desktop.
Alternatively, TextWrangler on the Mac has an ftp/sftp browser.
http://www.barebones.com/products/TextWrangler/
> I've never managed to figure out how to rig up editors to edit
> files on remote servers.
On the server, put this in smb.conf
[homes]
comment = Home Directories
hide dot files = yes
read only = No
browseable = yes
Then in the finder/windows explorer connect to 'smb://hostname/' . Then make an alias to it on your desktop.
Alternatively, TextWrangler on the Mac has an ftp/sftp browser.
http://www.barebones.com/products/TextWrangler/
Labels:
ftp,
linux,
mac,
networking,
samba,
server,
text editor,
untested,
windows
Subscribe to:
Posts (Atom)