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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
|
#!/usr/bin/perl
#
# Copyright (c) 2011 Dmitry Kolosov <onyx@z-up.ru>
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
use warnings;
no warnings qw( uninitialized );
use strict;
use RPC::XML::Client;
use RPC::XML::Parser;
use Term::ShellUI;
use Cwd;
use Getopt::Long;
use Env qw[$XDG_CONFIG_HOME];
# use non-standart paths
BEGIN {
unshift @INC,
"$XDG_CONFIG_HOME/eiskaltdc++",
"~/.config/eiskaltdc++/",
"/usr/local/share/eiskaltdcpp/cli",
"/usr/share/eiskaltdcpp/cli"
}
# preparing terminal
binmode STDOUT, ':utf8';
# configuration
our %config;
$config{version}=0.2;
require "cli-xmlrpc-config.pl";
my $version,my $help;
GetOptions ('V|version' => \$version, 'h|help' => \$help);
if ($version)
{
print("Command line interface version: $config{version}\n");
exit(1);
}
if ($help)
{
print( "Usage:
\teiskaltdcpp-cli
\teiskaltdcpp-cli <Key>
This is command line interface for eiskaltdcpp-daemon written on perl.
EiskaltDC++ is a cross-platform program that uses the Direct Connect and ADC protocols.
Keys:
\t-h, --help\t Show this message
\t-V, --version\t Show version string\n");
exit(1);
}
print("Configuration:\n");
foreach (keys %config)
{
print("$_: $config{$_}\n");
}
my $P = RPC::XML::Parser->new();
my $cli = RPC::XML::Client->new($config{eiskaltURL}, useragent => ['ssl_opts' => {verify_hostname => 0}]) or die "Can not connect to hub url $config{eiskaltURL}: $_\n";
$cli->credentials("Eiskaltdcpp XML-RPC Management",$config{user},$config{password});
my $term = Term::ShellUI->new(commands => get_commands(), history_file => $config{hist_file}, history_max => $config{hist_max});
$term->prompt("$config{eiskaltHostPort} $config{prompt}");
$term->run();
sub get_commands
{
return
{
# v0.2
"help" =>
{
desc => "Print helpful information",
args => sub { shift->help_args(undef, @_); },
method => sub { shift->help_call(undef, @_); }
},
# v0.2
"hub.add" =>
{
desc => "Add a new hub and connect. Parameters: s/'huburl', s/'encoding'",
minargs => 2,
maxargs => 2,
proc => \&hubadd
},
# v0.2
"hub.del" =>
{
desc => "Disconnect hub and delete from autoconnect. Parameters: s/'huburl'",
# add autocomplete from list of connected hubs
minargs => 1,
maxargs => 1,
proc => \&hubdel
},
# v0.2
"hub.say" =>
{
desc => "Send a public message to hub. Parameters: s/'huburl', s/'message'",
# add autocomplete from list of connected hubs
#args => sub { grep { !/^\.?\.$/ } shift->complete_onlydirs(@_) },
minargs => 2,
maxargs => 2,
proc => \&hubsay
},
# v0.2
"hub.pm" =>
{
desc => "Send a private message to nick on hub. Parameters: s/'huburl', s/'nick', s/'message'",
# add autocomplete from connected hubs and nicks
#args => sub { grep { !/^\.?\.$/ } shift->complete_onlydirs(@_) },
minargs => 3,
maxargs => 3,
proc => \&hubpm
},
# v0.2
"hub.list" =>
{
desc => "Get a list of hubs, configured to connect to. Parameters: s/'separator'",
#args => sub { grep { !/^\.?\.$/ } shift->complete_onlydirs(@_) },
#minargs => 1,
maxargs => 1,
proc => \&hublist
},
"hub.getchat" =>
{
desc => "Get last public chat messages. Parameters: s/'huburl', s/'separator'",
minargs => 1,
maxargs => 2,
proc => \&hubgetchat
},
# v0.2
"daemon.stop" =>
{
desc => "Disconnect from hubs and exit. Parameters: none",
proc => \&daemonstop
},
# v0.2
"magnet.add" =>
{
desc => "Add a magnet to download queue, and fetch it to download directory. Parameters: s/'magnet', s/'download directory'",
args => sub { shift->complete_onlydirs(@_) },
minargs => 2,
maxargs => 2,
proc => \&magnetadd
},
# v0.2
"share.add" =>
{
desc => "Add a directory to share as virtual name. Parameters: s/'directory',s/'virtual name'",
args => sub { shift->complete_onlydirs(@_) },
minargs => 2,
maxargs => 2,
proc => \&shareadd
},
# v0.2
"share.rename" =>
{
desc => "Give a new virtual name to shared directory. Parameters: s/'directory',s/'virtual name'",
args => sub { shift->complete_onlydirs(@_) },
minargs => 2,
maxargs => 2,
proc => \&sharerename
},
# v0.2
"share.del" =>
{
desc => "Unshare directory with virtual name. Parameters: Parameters: s/'virtual name'",
minargs => 1,
maxargs => 1,
proc => \&sharedel
},
# v0.2
"share.list" =>
{
desc => "Get a list of shared directories. Parameters: s/'separator'",
maxargs => 1,
proc => \&sharelist
},
# v0.2
"share.refresh" =>
{
desc => "Refresh a share, hash new files. Parameters: none",
proc => \&sharerefresh
},
# v0.2
"list.download" =>
{
desc => "Download a file list from nick on huburl. Parameters: s/'huburl', s/'nick'",
minargs => 2,
maxargs => 2,
proc => \&listdownload
},
# v0.2
"search.send" =>
{
desc => "Start hub search. Parameters: s/'search string'",
minargs => 1,
maxargs => 1,
proc => \&searchsend
},
# v0.2
"search.getresults" =>
{
desc => "Get search results. Parameters: none",
proc => \&searchgetresults
},
# v0.2
"show.version" =>
{
desc => "Show daemon version. Parameters: none",
proc => \&showversion
},
# v0.2
"show.ratio" =>
{
desc => "Show client ration. Parameters: none",
proc => \&showratio
},
"prompt" =>
{
desc => "Set custom prompt",
minargs => 1,
maxargs =>1,
proc => sub { $term->prompt("$config{eiskaltHostPort} ".shift) }
},
"exec" =>
{
desc => "Execute shell command",
args => sub { shift->complete_files(@_); },
minargs => 1,
proc => sub { system(shift) }
},
"quit" =>
{
desc => "Quit this program",
maxargs => 0,
method => sub { shift->exit_requested(1); }
},
"exit" => { alias => 'quit' },
'' =>
{
proc => "No command here by that name\n",
desc => "No help for unknown commands."
}
}
}
# functions
sub hubadd($$)
{
my $req=RPC::XML::request->new('hub.add', RPC::XML::string->new($_[0]), RPC::XML::string->new($_[1]));
my $resp = $cli->send_request($req) or die "Can not send request to hub url $config{eiskaltURL}: $_\n";
my $res = $P->parse($resp->as_string());
print $$res."\n";
}
sub hubdel($)
{
my $req=RPC::XML::request->new('hub.del', RPC::XML::string->new($_[0]));
my $resp = $cli->send_request($req) or die "Can not send request to hub url $config{eiskaltURL}: $_\n";
my $res = $P->parse($resp->as_string());
print $$res."\n";
}
sub hubsay($$)
{
my $req=RPC::XML::request->new('hub.say', RPC::XML::string->new($_[0]), RPC::XML::string->new($_[1]));
my $resp = $cli->send_request($req) or die "Can not send request to hub url $config{eiskaltURL}: $_\n";
my $res = $P->parse($resp->as_string());
print $$res."\n";
}
sub hubpm($$$)
{
my $req=RPC::XML::request->new('hub.pm', RPC::XML::string->new($_[0]), RPC::XML::string->new($_[1]), RPC::XML::string->new($_[2]));
my $resp = $cli->send_request($req) or die "Can not send request to hub url $config{eiskaltURL}: $_\n";
my $res = $P->parse($resp->as_string());
print $$res."\n";
}
sub hublist($)
{
my $req=RPC::XML::request->new('hub.list', RPC::XML::string->new($_[0] || $config{separator}));
my $resp = $cli->send_request($req) or die "Can not send request to hub url $config{eiskaltURL}: $_\n";
my $res = $P->parse($resp->as_string());
print $$res."\n";
}
sub hubgetchat($$)
{
my $req=RPC::XML::request->new('hub.getchat', RPC::XML::string->new($_[0]), RPC::XML::string->new($_[1] || $config{separator}));
my $resp = $cli->send_request($req) or die "Can not send request to hub url $config{eiskaltURL}: $_\n";
my $res = $P->parse($resp->as_string());
print $$res."\n";
}
sub daemonstop()
{
my $req=RPC::XML::request->new('daemon.stop');
my $resp = $cli->send_request($req) or die "Can not send request to hub url $config{eiskaltURL}: $_\n";
my $res = $P->parse($resp->as_string());
print $$res."\n";
}
sub magnetadd($$)
{
my $req=RPC::XML::request->new('magnet.add', RPC::XML::string->new($_[0]), RPC::XML::string->new($_[1]));
my $resp = $cli->send_request($req) or die "Can not send request to hub url $config{eiskaltURL}: $_\n";
my $res = $P->parse($resp->as_string());
print $$res."\n";
}
sub shareadd($$)
{
my $req=RPC::XML::request->new('share.add', RPC::XML::string->new($_[0]), RPC::XML::string->new($_[1]));
my $resp = $cli->send_request($req) or die "Can not send request to hub url $config{eiskaltURL}: $_\n";
my $res = $P->parse($resp->as_string());
print $$res."\n";
}
sub sharerename($$)
{
my $req=RPC::XML::request->new('share.rename', RPC::XML::string->new($_[0]), RPC::XML::string->new($_[1]));
my $resp = $cli->send_request($req) or die "Can not send request to hub url $config{eiskaltURL}: $_\n";
my $res = $P->parse($resp->as_string());
print $$res."\n";
}
sub sharedel($)
{
my $req=RPC::XML::request->new('share.del', RPC::XML::string->new($_[0]));
my $resp = $cli->send_request($req) or die "Can not send request to hub url $config{eiskaltURL}: $_\n";
my $res = $P->parse($resp->as_string());
print $$res."\n";
}
sub sharelist($)
{
my $req=RPC::XML::request->new('share.list', RPC::XML::string->new($_[0] || $config{separator}));
my $resp = $cli->send_request($req) or die "Can not send request to hub url $config{eiskaltURL}: $_\n";
my $res = $P->parse($resp->as_string());
print $$res."\n";
}
sub sharerefresh()
{
my $req=RPC::XML::request->new('share.refresh');
my $resp = $cli->send_request($req) or die "Can not send request to hub url $config{eiskaltURL}: $_\n";
my $res = $P->parse($resp->as_string());
print $$res."\n";
}
sub listdownload($$)
{
my $req=RPC::XML::request->new('list.download', RPC::XML::string->new($_[0]), RPC::XML::string->new($_[1]));
my $resp = $cli->send_request($req) or die "Can not send request to hub url $config{eiskaltURL}: $_\n";
my $res = $P->parse($resp->as_string());
print $$res."\n";
}
sub searchsend($)
{
my $req=RPC::XML::request->new('search.send', RPC::XML::string->new($_[0]));
my $resp = $cli->send_request($req) or die "Can not send request to hub url $config{eiskaltURL}: $_\n";
my $res = $P->parse($resp->as_string());
print $$res."\n";
}
sub searchgetresults()
{
my $req=RPC::XML::request->new('search.getresults');
my $resp = $cli->send_request($req) or die "Can not send request to hub url $config{eiskaltURL}: $_\n";
my $res = $P->parse($resp->as_string());
foreach (@$res)
{
foreach ($_)
{
my %result=%$_;
foreach (keys %result)
{
print("$_ => ${$result{$_}}\n");
}
}
}
}
sub showversion()
{
my $req=RPC::XML::request->new('show.version');
my $resp = $cli->send_request($req) or die "Can not send request to hub url $config{eiskaltURL}: $_\n";
my $res = $P->parse($resp->as_string());
print $$res."\n";
}
sub showratio()
{
my $req=RPC::XML::request->new('show.ratio');
my $resp = $cli->send_request($req) or die "Can not send request to hub url $config{eiskaltURL}: $_\n";
my $res = $P->parse($resp->as_string());
print $$res."\n";
}
__END__
=pod
xmlrpcRegistry.addMethod("magnet.add", magnetAddMethodP);
xmlrpcRegistry.addMethod("daemon.stop", stopDaemonMethodP);
xmlrpcRegistry.addMethod("hub.add", hubAddMethodP);
xmlrpcRegistry.addMethod("hub.del", hubDelMethodP);
xmlrpcRegistry.addMethod("hub.say", hubSayMethodP);
xmlrpcRegistry.addMethod("hub.pm", hubSayPrivateMethodP);
xmlrpcRegistry.addMethod("hub.list", listHubsMethodP);
xmlrpcRegistry.addMethod("hub.getchat", getChatPubMethodP);
xmlrpcRegistry.addMethod("share.add", addDirInShareMethodP);
xmlrpcRegistry.addMethod("share.rename", renameDirInShareMethodP);
xmlrpcRegistry.addMethod("share.del", delDirFromShareMethodP);
xmlrpcRegistry.addMethod("share.list", listShareMethodP);
xmlrpcRegistry.addMethod("share.refresh", refreshShareMethodP);
xmlrpcRegistry.addMethod("list.download", getFileListMethodP);
xmlrpcRegistry.addMethod("search.send", sendSearchMethodP);
xmlrpcRegistry.addMethod("search.getresults", returnSearchResultsMethodP);
xmlrpcRegistry.addMethod("show.version", showVersionMethodP);
xmlrpcRegistry.addMethod("show.ratio", showRatioMethodP);
=cut
|