/usr/bin/nopaste-it is in pnopaste-cli 1.6-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | #!/usr/bin/perl
# This file is part of the pnopaste program
# Copyright (C) 2008-2016 Patrick Matthäi <pmatthaei@debian.org>
# Copyright (C) 2010 Philipp Schafft <lion@lion.leolix.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
use warnings;
use strict;
use Getopt::Long;
use LWP::Simple;
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
my $Build = '1.6';
my $NoPaste = 'https://nopaste.linux-dev.org/';
my $Lang = 'Plain';
my $Name = $ENV{'USER'} || undef;
my $Expires = '1w';
my $Version = undef;
my $File = undef;
my $Help = undef;
my $List = undef;
my $Input = '';
my $Quite = undef;
# Get our params.
Getopt::Long::Configure('bundling');
GetOptions (
's|list' => \$List,
'h|help' => \$Help,
'u|url=s' => \$NoPaste,
'n|name=s' => \$Name,
'l|language=s' => \$Lang,
'e|expires=s' => \$Expires,
'f|file=s' => \$File,
'v|version' => \$Version,
'q|quite' => \$Quite,
);
# Show the version.
if($Version){
print <<EOF;
Perl Nopaste Client version: $Build
EOF
exit(0);
}
# Show the usage? :)
if($Help){
print <<EOF;
Usage of nopaste-it:
-h / --help:
Display this help and exit.
-v / --version:
Display version and exit.
-q / --quite:
Be more quite. Only print URL of post.
-u / --url <url>:
Use a different nopaste URL than $NoPaste.
-n / --name:
Use a different author name than your UNIX username (if it is set).
-l / --language <language>:
Set the given code language. Popular ones are for example:
"C", "C++", "Diff", "Perl", "Ruby", etc.
You can get the list of supported languages by using the
"-s/--list" option of this program.
It will be plain unless nothing different is set.
Note: This is case sensitive.
-e / --expires <expire>:
Set the expire option.
At the moment it only accepts: "1d", "1w" and "never".
The default value is "1w".
-f / --file <filename>:
Add the content of the given file to your paste instead of reading
from STDIN.
-s / --list:
Gets supported code languages from remote pnopaste and prints them.
This option could also be mixed with "url".
EOF
exit(0);
}
# Check the given expire time.
if($Expires ne '1d' and $Expires ne '1w' and $Expires ne 'never'){
print STDERR "Invalid expiration code given.\n";
exit(1);
}
### Gets languages and exit.
if($List){
my $Site = get($NoPaste);
die 'Did not found any output.', "\n" if !$Site;
my($Select) = ($Site =~ m!<select[^>]+name="language"[^>]*>(.*?)</select>!s);
my $Values = '';
while($Select =~ s!<option[^>]*>(.*?)</option>!!s){
$Values .= "\t" . $1 . "\n";
}
print 'Supported languages by remote pnopaste:', "\n", $Values;
exit(0);
}
# Read from STDIN or file?
if(!$File){
# We just get our stuff from STDIN.
local $/ = undef;
$Input = <STDIN>;
}
else {
if(!-e $File){
# Epic fail! This file does not exist!
print STDERR 'Error. File ', $File, ' does not exist.', "\n";
exit(1);
}
# Open the file and try to read from it.
open(READ,'<',$File) or die 'Can not read input file: ', $!, "\n";
while(<READ>){
$Input .= $_;
}
close(READ);
}
my $Agent = LWP::UserAgent->new;
# Our name ;)
$Agent->agent('Perl Nopaste Agent ' . $Build);
# Our HTTP request with POST params.
my $Request = POST $NoPaste, [ 'code' => $Input, 'expires' => $Expires, 'name' => $Name, 'language' => $Lang ];
my $Result = $Agent->request($Request);
if($Result->is_success){
# The query itself was successful.
my $Content = $Result->content;
$Content =~ m/<a href=\"(.*)\">/;
my $ID = $1;
if($ID and $ID =~ /\d+/){
# $ID is an integer, so on it has to be right.
if ( !$Quite ) {
print 'You can find your result on: ', "\n";
print "\t", $ID, "\n";
print "\t", $ID, '&download', "\n";
} else {
print $ID, "\n";
}
} else {
# Where the fuck is the fucking integer?
print STDERR 'Seems like there was an error on the server side. The full server output is:', "\n";
print STDERR $Result->content;
}
}
else {
# Epic fail at the query, just fuck up..
print STDERR 'Error: ', $Result->status_line, "\n";
exit(1);
}
|