| 1 | #!/usr/bin/perl |
|---|
| 2 | # |
|---|
| 3 | # Web service invocation client |
|---|
| 4 | # Copyright (C) 2005, 2006 Josef Spillner <josef@kstuff.org> |
|---|
| 5 | # Published under 'GNU AGPLv3 or later' conditions |
|---|
| 6 | |
|---|
| 7 | package dxsclient; |
|---|
| 8 | |
|---|
| 9 | use strict; |
|---|
| 10 | use Getopt::Long qw(:config no_auto_abbrev bundling no_ignore_case); |
|---|
| 11 | use XML::DOM; |
|---|
| 12 | use MIME::Base64; |
|---|
| 13 | use SOAP::Lite; #+trace => "debug"; |
|---|
| 14 | use Term::Shell; |
|---|
| 15 | use Data::Dumper; |
|---|
| 16 | use LWP::Simple; |
|---|
| 17 | use base qw(Term::Shell); |
|---|
| 18 | |
|---|
| 19 | my $version = "0.9.3"; |
|---|
| 20 | |
|---|
| 21 | my $default_webservice = "http://localhost/cgi-bin/hotstuff-dxs"; |
|---|
| 22 | |
|---|
| 23 | my ($opt_upload, $opt_provider, $opt_help, $opt_information, $opt_categories, $opt_list); |
|---|
| 24 | my ($opt_version, $opt_webservice); |
|---|
| 25 | |
|---|
| 26 | my %entrycache; |
|---|
| 27 | my %authcache; |
|---|
| 28 | my %categorycache; |
|---|
| 29 | |
|---|
| 30 | $opt_webservice = $default_webservice; |
|---|
| 31 | |
|---|
| 32 | my $options = GetOptions( |
|---|
| 33 | "h|help" => \$opt_help, |
|---|
| 34 | "v|version" => \$opt_version, |
|---|
| 35 | "u|upload=s" => \$opt_upload, |
|---|
| 36 | "p|provider=s" => \$opt_provider, |
|---|
| 37 | "w|webservice=s" => \$opt_webservice, |
|---|
| 38 | "i|information" => \$opt_information, |
|---|
| 39 | "c|categories" => \$opt_categories, |
|---|
| 40 | "l|list=s" => \$opt_list |
|---|
| 41 | ); |
|---|
| 42 | if(!$options){ |
|---|
| 43 | exit 1; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | if($opt_help){ |
|---|
| 47 | print "dxsclient - command line client to the Desktop Exchange Service (DXS)\n"; |
|---|
| 48 | print "Copyright (C) 2005 - 2007 Josef Spillner <josef\@kstuff.org>\n"; |
|---|
| 49 | print "Published under 'GNU AGPLv3 or later' conditions\n"; |
|---|
| 50 | print; |
|---|
| 51 | print "Operations:\n"; |
|---|
| 52 | print "[-u | --upload <file> ] Upload .meta file and associated contents\n"; |
|---|
| 53 | print "[-i | --information ] Display provider information\n"; |
|---|
| 54 | print "[-c | --categories ] List available categories\n"; |
|---|
| 55 | print "[-l | --list <category> ] List all contents of a category\n"; |
|---|
| 56 | print; |
|---|
| 57 | print "Options:\n"; |
|---|
| 58 | print "[-p | --provider <url> ] Select a GHNS provider URL (overrides default webservice)\n"; |
|---|
| 59 | print "[-w | --webservice <url>] Select a webservice URL (if not given, use default: $default_webservice)\n"; |
|---|
| 60 | print "[-v | --version ] Print version information\n"; |
|---|
| 61 | exit; |
|---|
| 62 | } |
|---|
| 63 | if($opt_version){ |
|---|
| 64 | print "$version\n"; |
|---|
| 65 | exit; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | if($opt_provider){ |
|---|
| 69 | print "Loading GHNS provider file from $opt_provider...\n"; |
|---|
| 70 | $opt_webservice = ""; |
|---|
| 71 | |
|---|
| 72 | my $outfile = "/tmp/provider.xml.xxx"; |
|---|
| 73 | mirror($opt_provider, $outfile); |
|---|
| 74 | |
|---|
| 75 | my $parser = new XML::DOM::Parser; |
|---|
| 76 | my $doc = $parser->parsefile($outfile); |
|---|
| 77 | |
|---|
| 78 | my $ghnsproviders = $doc->getDocumentElement(); |
|---|
| 79 | for my $provider($ghnsproviders->getElementsByTagName("provider")){ |
|---|
| 80 | my $webservice = $provider->getAttribute("webservice"); |
|---|
| 81 | if($webservice){ |
|---|
| 82 | my $name; |
|---|
| 83 | for my $title($provider->getElementsByTagName("title")){ |
|---|
| 84 | $name = $title->getFirstChild()->getData; |
|---|
| 85 | } |
|---|
| 86 | print "Provider '$name' offers DXS\n"; |
|---|
| 87 | $opt_webservice = $webservice; |
|---|
| 88 | } |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | if(!$opt_webservice){ |
|---|
| 92 | print "Error: no GHNS provider with DXS found\n"; |
|---|
| 93 | exit 1; |
|---|
| 94 | } |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | if($opt_information){ |
|---|
| 98 | information($opt_webservice); |
|---|
| 99 | exit; |
|---|
| 100 | } |
|---|
| 101 | if($opt_upload){ |
|---|
| 102 | upload($opt_upload, $opt_webservice); |
|---|
| 103 | exit; |
|---|
| 104 | } |
|---|
| 105 | if($opt_categories){ |
|---|
| 106 | categories($opt_webservice); |
|---|
| 107 | exit; |
|---|
| 108 | } |
|---|
| 109 | if(defined $opt_list){ |
|---|
| 110 | list($opt_list, "", $opt_webservice); |
|---|
| 111 | exit; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | interactive(); |
|---|
| 115 | |
|---|
| 116 | sub SOAP::Transport::HTTP::Client::get_basic_credentials{ |
|---|
| 117 | print "This operation needs authentication!\n"; |
|---|
| 118 | |
|---|
| 119 | my $user = $authcache{'user'}; |
|---|
| 120 | my $password = $authcache{'password'}; |
|---|
| 121 | |
|---|
| 122 | if(!($user and $password)){ |
|---|
| 123 | my $shell = dxsclient->new; |
|---|
| 124 | $user = $shell->prompt("Username: ", $user); |
|---|
| 125 | $password = $shell->prompt("Password: ", $password); |
|---|
| 126 | |
|---|
| 127 | $authcache{'user'} = $user; |
|---|
| 128 | $authcache{'password'} = $password; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | return $user => $password; |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | sub upload{ |
|---|
| 135 | my $arg_file = shift(@_); |
|---|
| 136 | my $arg_webservice = shift(@_); |
|---|
| 137 | |
|---|
| 138 | my ($author, $version, $release, $licence, $name, $category, $summary, $payload, $preview); |
|---|
| 139 | my $error = 0; |
|---|
| 140 | my %meta; |
|---|
| 141 | |
|---|
| 142 | print "Preparing web service invocation.\n"; |
|---|
| 143 | |
|---|
| 144 | my $parser = new XML::DOM::Parser; |
|---|
| 145 | my $doc = $parser->parsefile($arg_file); |
|---|
| 146 | |
|---|
| 147 | my $knewstuff = $doc->getDocumentElement(); |
|---|
| 148 | for my $stuff($knewstuff->getElementsByTagName("stuff")){ |
|---|
| 149 | $category = $stuff->getAttribute("category"); |
|---|
| 150 | my @taglist = $stuff->getElementsByTagName("*"); |
|---|
| 151 | for my $tag(@taglist){ |
|---|
| 152 | my $tagname = $tag->getTagName; |
|---|
| 153 | my $tagvalue = ""; |
|---|
| 154 | if($tag->getFirstChild){ |
|---|
| 155 | $tagvalue = $tag->getFirstChild->getData; |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | if($tagname eq "author"){ |
|---|
| 159 | $author = $tagvalue; |
|---|
| 160 | }elsif($tagname eq "version"){ |
|---|
| 161 | $version = $tagvalue; |
|---|
| 162 | }elsif($tagname eq "release"){ |
|---|
| 163 | $release = $tagvalue; |
|---|
| 164 | }elsif($tagname eq "licence"){ |
|---|
| 165 | $licence = $tagvalue; |
|---|
| 166 | }elsif($tagname eq "name"){ |
|---|
| 167 | $name = $tagvalue; |
|---|
| 168 | }elsif($tagname eq "summary"){ |
|---|
| 169 | $summary = $tagvalue; |
|---|
| 170 | }elsif($tagname eq "payload"){ |
|---|
| 171 | $payload = $tagvalue; |
|---|
| 172 | }elsif($tagname eq "preview"){ |
|---|
| 173 | $preview = $tagvalue; |
|---|
| 174 | } |
|---|
| 175 | } |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | local($/) = undef; |
|---|
| 179 | |
|---|
| 180 | open(FILE, $preview); |
|---|
| 181 | my $preview_data = MIME::Base64::encode_base64(<FILE>); |
|---|
| 182 | close(FILE); |
|---|
| 183 | open(FILE, $payload); |
|---|
| 184 | my $payload_data = MIME::Base64::encode_base64(<FILE>); |
|---|
| 185 | close(FILE); |
|---|
| 186 | |
|---|
| 187 | $author = SOAP::Data->name("author" => $author); |
|---|
| 188 | $version = SOAP::Data->name("version" => $version); |
|---|
| 189 | $release = SOAP::Data->name("release" => $release); |
|---|
| 190 | $licence = SOAP::Data->name("licence" => $licence); |
|---|
| 191 | $name = SOAP::Data->name("name" => $name); |
|---|
| 192 | $category = SOAP::Data->name("category" => $category); |
|---|
| 193 | $summary = SOAP::Data->name("summary" => $summary); |
|---|
| 194 | $payload = SOAP::Data->name("payload" => $payload_data); |
|---|
| 195 | $preview = SOAP::Data->name("preview" => $preview_data); |
|---|
| 196 | |
|---|
| 197 | if(!$error){ |
|---|
| 198 | my $ns = "urn:DXS"; |
|---|
| 199 | |
|---|
| 200 | my $ws = SOAP::Lite |
|---|
| 201 | #-> service("file:./ghns.wsdl") |
|---|
| 202 | -> readable(1) |
|---|
| 203 | -> uri($ns) |
|---|
| 204 | -> proxy($arg_webservice); |
|---|
| 205 | |
|---|
| 206 | my $som = $ws->GHNSUpload($author, $version, $release, $licence, $name, $category, $summary, |
|---|
| 207 | $payload, $preview); |
|---|
| 208 | |
|---|
| 209 | if($som->fault){ |
|---|
| 210 | my $string = $som->faultstring; |
|---|
| 211 | chomp $string; |
|---|
| 212 | print "Error: $string\n"; |
|---|
| 213 | }else{ |
|---|
| 214 | print "The response was:\n"; |
|---|
| 215 | print $som->result, "\n"; |
|---|
| 216 | } |
|---|
| 217 | } |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | sub information{ |
|---|
| 221 | my $arg_webservice = shift(@_); |
|---|
| 222 | |
|---|
| 223 | my $ns = "urn:DXS"; |
|---|
| 224 | |
|---|
| 225 | my $ws = SOAP::Lite |
|---|
| 226 | -> readable(1) |
|---|
| 227 | -> uri($ns) |
|---|
| 228 | -> proxy($arg_webservice); |
|---|
| 229 | |
|---|
| 230 | my $som = $ws->GHNSInfo(); |
|---|
| 231 | |
|---|
| 232 | if($som->fault){ |
|---|
| 233 | my $string = $som->faultstring; |
|---|
| 234 | chomp $string; |
|---|
| 235 | print "Error: $string\n"; |
|---|
| 236 | }else{ |
|---|
| 237 | my $server = $som->valueof("//GHNSInfoResponse/server"); |
|---|
| 238 | my $version = $som->valueof("//GHNSInfoResponse/version"); |
|---|
| 239 | my $provider = $som->valueof("//GHNSInfoResponse/provider"); |
|---|
| 240 | my $url = $som->valueof("//GHNSInfoResponse/url"); |
|---|
| 241 | print "Provider: $provider\n"; |
|---|
| 242 | print "Server: $server (Version $version)\n"; |
|---|
| 243 | print "URL: $url\n"; |
|---|
| 244 | } |
|---|
| 245 | } |
|---|
| 246 | |
|---|
| 247 | sub categories{ |
|---|
| 248 | my $arg_webservice = shift(@_); |
|---|
| 249 | |
|---|
| 250 | my $ns = "urn:DXS"; |
|---|
| 251 | |
|---|
| 252 | my $ws = SOAP::Lite |
|---|
| 253 | -> readable(1) |
|---|
| 254 | -> uri($ns) |
|---|
| 255 | -> proxy($arg_webservice); |
|---|
| 256 | |
|---|
| 257 | my $som = $ws->GHNSCategories(); |
|---|
| 258 | |
|---|
| 259 | if($som->fault){ |
|---|
| 260 | my $string = $som->faultstring; |
|---|
| 261 | chomp $string; |
|---|
| 262 | print "Error: $string\n"; |
|---|
| 263 | }else{ |
|---|
| 264 | my $array_hashref = $som->valueof("//GHNSCategoriesResponse"); |
|---|
| 265 | my %array = %{$array_hashref}; |
|---|
| 266 | my @categories; |
|---|
| 267 | if(ref($array{"category"}) eq "ARRAY"){ |
|---|
| 268 | @categories = @{$array{"category"}}; |
|---|
| 269 | }else{ |
|---|
| 270 | @categories = ($array{"category"}); |
|---|
| 271 | } |
|---|
| 272 | for my $category_hashref(@categories){ |
|---|
| 273 | my %category = %{$category_hashref}; |
|---|
| 274 | my $categoryname = $category{"category"}; |
|---|
| 275 | my $icon = $category{"icon"}; |
|---|
| 276 | my $name = $category{"name"}; |
|---|
| 277 | my $description = $category{"description"}; |
|---|
| 278 | print "Category: $categoryname (Icon: $icon/Name: $name/Desc: $description)\n"; |
|---|
| 279 | |
|---|
| 280 | $categorycache{$categoryname} = 1; |
|---|
| 281 | } |
|---|
| 282 | } |
|---|
| 283 | } |
|---|
| 284 | |
|---|
| 285 | sub list{ |
|---|
| 286 | my $arg_category = shift(@_); |
|---|
| 287 | my $arg_feed = shift(@_); |
|---|
| 288 | my $arg_webservice = shift(@_); |
|---|
| 289 | |
|---|
| 290 | my $ns = "urn:DXS"; |
|---|
| 291 | |
|---|
| 292 | my $ws = SOAP::Lite |
|---|
| 293 | -> readable(1) |
|---|
| 294 | -> uri($ns) |
|---|
| 295 | -> proxy($arg_webservice); |
|---|
| 296 | |
|---|
| 297 | my $category = SOAP::Data->name("category" => $arg_category); |
|---|
| 298 | my $feed; |
|---|
| 299 | if($arg_feed){ |
|---|
| 300 | $feed = SOAP::Data->name("feed" => $arg_feed); |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | my $som = $ws->GHNSList($category, $feed); |
|---|
| 304 | |
|---|
| 305 | if($som->fault){ |
|---|
| 306 | my $string = $som->faultstring; |
|---|
| 307 | chomp $string; |
|---|
| 308 | print "Error: $string\n"; |
|---|
| 309 | }else{ |
|---|
| 310 | my @array_ref = $som->valueof("//GHNSListResponse/entries/entry"); |
|---|
| 311 | if(!$#array_ref){ |
|---|
| 312 | print "Warning: no results returned\n"; |
|---|
| 313 | } |
|---|
| 314 | |
|---|
| 315 | for my $entry_hashref(@array_ref){ |
|---|
| 316 | my %entry = %{$entry_hashref}; |
|---|
| 317 | my $id = $entry{"id"}; |
|---|
| 318 | my $author = $entry{"author"}; |
|---|
| 319 | my $name = $entry{"name"}; |
|---|
| 320 | print "Entry: ($id) $name ($author)\n"; |
|---|
| 321 | |
|---|
| 322 | $entrycache{$id} = $entry_hashref; |
|---|
| 323 | } |
|---|
| 324 | |
|---|
| 325 | my $notapproved = $som->dataof("//GHNSListResponse/entries")->attr->{"notapproved"}; |
|---|
| 326 | if($notapproved > 0){ |
|---|
| 327 | print "[... and $notapproved still in the queue...]\n"; |
|---|
| 328 | } |
|---|
| 329 | } |
|---|
| 330 | } |
|---|
| 331 | |
|---|
| 332 | sub history{ |
|---|
| 333 | my $arg_id = shift(@_); |
|---|
| 334 | my $arg_webservice = shift(@_); |
|---|
| 335 | |
|---|
| 336 | my $ns = "urn:DXS"; |
|---|
| 337 | |
|---|
| 338 | my $ws = SOAP::Lite |
|---|
| 339 | -> readable(1) |
|---|
| 340 | -> uri($ns) |
|---|
| 341 | -> proxy($arg_webservice); |
|---|
| 342 | |
|---|
| 343 | my $id = SOAP::Data->name("id" => $arg_id); |
|---|
| 344 | |
|---|
| 345 | my $som = $ws->GHNSHistory($id); |
|---|
| 346 | |
|---|
| 347 | if($som->fault){ |
|---|
| 348 | my $string = $som->faultstring; |
|---|
| 349 | chomp $string; |
|---|
| 350 | print "Error: $string\n"; |
|---|
| 351 | }else{ |
|---|
| 352 | my @entries; |
|---|
| 353 | my $entries_array = $som->valueof("//GHNSHistoryResponse"); |
|---|
| 354 | if($entries_array){ |
|---|
| 355 | @entries = @{$entries_array}; |
|---|
| 356 | } |
|---|
| 357 | for my $entry_hash(@entries){ |
|---|
| 358 | my %entry = %{$entry_hash}; |
|---|
| 359 | my $id = $entry{"id"}; |
|---|
| 360 | my $author = $entry{"author"}; |
|---|
| 361 | my $name = $entry{"name"}; |
|---|
| 362 | print "Entry: ($id) $name ($author)\n"; |
|---|
| 363 | |
|---|
| 364 | $entrycache{$id} = $entry_hash; |
|---|
| 365 | } |
|---|
| 366 | } |
|---|
| 367 | } |
|---|
| 368 | |
|---|
| 369 | sub rating{ |
|---|
| 370 | my $arg_id = shift(@_); |
|---|
| 371 | my $arg_rating = shift(@_); |
|---|
| 372 | my $arg_webservice = shift(@_); |
|---|
| 373 | |
|---|
| 374 | my $ns = "urn:DXS"; |
|---|
| 375 | |
|---|
| 376 | my $ws = SOAP::Lite |
|---|
| 377 | -> readable(1) |
|---|
| 378 | -> uri($ns) |
|---|
| 379 | -> proxy($arg_webservice); |
|---|
| 380 | |
|---|
| 381 | my $id = SOAP::Data->name("id" => $arg_id); |
|---|
| 382 | my $rating = SOAP::Data->name("rating" => $arg_rating); |
|---|
| 383 | |
|---|
| 384 | my $som = $ws->GHNSRating($id, $rating); |
|---|
| 385 | |
|---|
| 386 | if($som->fault){ |
|---|
| 387 | my $string = $som->faultstring; |
|---|
| 388 | chomp $string; |
|---|
| 389 | print "Error: $string\n"; |
|---|
| 390 | }else{ |
|---|
| 391 | print "New collective rating is:\n"; |
|---|
| 392 | print $som->result, "\n"; |
|---|
| 393 | } |
|---|
| 394 | } |
|---|
| 395 | |
|---|
| 396 | sub comment{ |
|---|
| 397 | my $arg_id = shift(@_); |
|---|
| 398 | my $arg_comment = shift(@_); |
|---|
| 399 | my $arg_webservice = shift(@_); |
|---|
| 400 | |
|---|
| 401 | my $ns = "urn:DXS"; |
|---|
| 402 | |
|---|
| 403 | my $ws = SOAP::Lite |
|---|
| 404 | -> readable(1) |
|---|
| 405 | -> uri($ns) |
|---|
| 406 | -> proxy($arg_webservice); |
|---|
| 407 | |
|---|
| 408 | my $id = SOAP::Data->name("id" => $arg_id); |
|---|
| 409 | my $comment = SOAP::Data->name("comment" => $arg_comment); |
|---|
| 410 | |
|---|
| 411 | my $som = $ws->GHNSComment($id, $comment); |
|---|
| 412 | |
|---|
| 413 | if($som->fault){ |
|---|
| 414 | my $string = $som->faultstring; |
|---|
| 415 | chomp $string; |
|---|
| 416 | print "Error: $string\n"; |
|---|
| 417 | }else{ |
|---|
| 418 | print "Comment added.\n"; |
|---|
| 419 | } |
|---|
| 420 | } |
|---|
| 421 | |
|---|
| 422 | sub comments{ |
|---|
| 423 | my $arg_id = shift(@_); |
|---|
| 424 | my $arg_webservice = shift(@_); |
|---|
| 425 | |
|---|
| 426 | my $ns = "urn:DXS"; |
|---|
| 427 | |
|---|
| 428 | my $ws = SOAP::Lite |
|---|
| 429 | -> readable(1) |
|---|
| 430 | -> uri($ns) |
|---|
| 431 | -> proxy($arg_webservice); |
|---|
| 432 | |
|---|
| 433 | my $id = SOAP::Data->name("id" => $arg_id); |
|---|
| 434 | |
|---|
| 435 | my $som = $ws->GHNSComments($id); |
|---|
| 436 | |
|---|
| 437 | if($som->fault){ |
|---|
| 438 | my $string = $som->faultstring; |
|---|
| 439 | chomp $string; |
|---|
| 440 | print "Error: $string\n"; |
|---|
| 441 | }else{ |
|---|
| 442 | print "Comments on this entry:\n"; |
|---|
| 443 | |
|---|
| 444 | my @array_ref = $som->valueof("//GHNSCommentsResponse/comments"); |
|---|
| 445 | |
|---|
| 446 | for my $comment(@array_ref){ |
|---|
| 447 | print "** $comment\n"; |
|---|
| 448 | } |
|---|
| 449 | } |
|---|
| 450 | } |
|---|
| 451 | |
|---|
| 452 | sub removal{ |
|---|
| 453 | my $arg_id = shift(@_); |
|---|
| 454 | my $arg_webservice = shift(@_); |
|---|
| 455 | |
|---|
| 456 | my $ns = "urn:DXS"; |
|---|
| 457 | |
|---|
| 458 | my $ws = SOAP::Lite |
|---|
| 459 | -> readable(1) |
|---|
| 460 | -> uri($ns) |
|---|
| 461 | -> proxy($arg_webservice); |
|---|
| 462 | |
|---|
| 463 | my $id = SOAP::Data->name("id" => $arg_id); |
|---|
| 464 | |
|---|
| 465 | my $som = $ws->GHNSRemoval($id); |
|---|
| 466 | |
|---|
| 467 | if($som->fault){ |
|---|
| 468 | my $string = $som->faultstring; |
|---|
| 469 | chomp $string; |
|---|
| 470 | print "Error: $string\n"; |
|---|
| 471 | }else{ |
|---|
| 472 | print "Removal successfully requested.\n"; |
|---|
| 473 | } |
|---|
| 474 | } |
|---|
| 475 | |
|---|
| 476 | sub interactive{ |
|---|
| 477 | my $shell = dxsclient->new; |
|---|
| 478 | |
|---|
| 479 | run_webservice(undef, $opt_webservice); |
|---|
| 480 | |
|---|
| 481 | $shell->cmdloop(); |
|---|
| 482 | } |
|---|
| 483 | |
|---|
| 484 | sub prompt_str{ |
|---|
| 485 | "dxs> "; |
|---|
| 486 | } |
|---|
| 487 | |
|---|
| 488 | sub smry_info{ |
|---|
| 489 | "Display provider information"; |
|---|
| 490 | } |
|---|
| 491 | |
|---|
| 492 | sub smry_categories{ |
|---|
| 493 | "List available categories"; |
|---|
| 494 | } |
|---|
| 495 | |
|---|
| 496 | sub smry_list{ |
|---|
| 497 | "List all contents of a category"; |
|---|
| 498 | } |
|---|
| 499 | |
|---|
| 500 | sub smry_preview{ |
|---|
| 501 | "Download and view preview"; |
|---|
| 502 | } |
|---|
| 503 | |
|---|
| 504 | sub smry_install{ |
|---|
| 505 | "Download and install payload"; |
|---|
| 506 | } |
|---|
| 507 | |
|---|
| 508 | sub smry_details{ |
|---|
| 509 | "More information about an entry"; |
|---|
| 510 | } |
|---|
| 511 | |
|---|
| 512 | sub smry_history{ |
|---|
| 513 | "List historic information about an entry"; |
|---|
| 514 | } |
|---|
| 515 | |
|---|
| 516 | sub smry_webservice{ |
|---|
| 517 | "Toggle webservice URL"; |
|---|
| 518 | } |
|---|
| 519 | |
|---|
| 520 | sub smry_rating{ |
|---|
| 521 | "Change rating of an entry"; |
|---|
| 522 | } |
|---|
| 523 | |
|---|
| 524 | sub smry_comment{ |
|---|
| 525 | "Append a comment"; |
|---|
| 526 | } |
|---|
| 527 | |
|---|
| 528 | sub smry_comments{ |
|---|
| 529 | "List all comments"; |
|---|
| 530 | } |
|---|
| 531 | |
|---|
| 532 | sub smry_removal{ |
|---|
| 533 | "Request removal of an entry"; |
|---|
| 534 | } |
|---|
| 535 | |
|---|
| 536 | sub comp_list{ |
|---|
| 537 | shift(@_); |
|---|
| 538 | my $word = shift(@_); |
|---|
| 539 | |
|---|
| 540 | my @list = (); |
|---|
| 541 | |
|---|
| 542 | foreach my $key(keys(%categorycache)){ |
|---|
| 543 | if($key =~ /^$word/){ |
|---|
| 544 | @list = (@list, $key); |
|---|
| 545 | } |
|---|
| 546 | } |
|---|
| 547 | |
|---|
| 548 | return @list; |
|---|
| 549 | } |
|---|
| 550 | |
|---|
| 551 | sub run_info{ |
|---|
| 552 | information($opt_webservice); |
|---|
| 553 | } |
|---|
| 554 | |
|---|
| 555 | sub run_categories{ |
|---|
| 556 | categories($opt_webservice); |
|---|
| 557 | } |
|---|
| 558 | |
|---|
| 559 | sub run_list{ |
|---|
| 560 | shift(@_); |
|---|
| 561 | my $opt_category = shift(@_); |
|---|
| 562 | my $opt_feed = shift(@_); |
|---|
| 563 | if(defined $opt_category){ |
|---|
| 564 | list($opt_category, $opt_feed, $opt_webservice); |
|---|
| 565 | }else{ |
|---|
| 566 | print "Syntax: list <category> [<feed>]\n"; |
|---|
| 567 | } |
|---|
| 568 | } |
|---|
| 569 | |
|---|
| 570 | sub run_rating{ |
|---|
| 571 | shift(@_); |
|---|
| 572 | my $opt_id = shift(@_); |
|---|
| 573 | my $opt_rating = shift(@_); |
|---|
| 574 | if($opt_id and $opt_rating){ |
|---|
| 575 | rating($opt_id, $opt_rating, $opt_webservice); |
|---|
| 576 | }else{ |
|---|
| 577 | print "Syntax: rating <id> <rating=0..100>\n"; |
|---|
| 578 | } |
|---|
| 579 | } |
|---|
| 580 | |
|---|
| 581 | sub run_comment{ |
|---|
| 582 | shift(@_); |
|---|
| 583 | my $opt_id = shift(@_); |
|---|
| 584 | my $opt_comment = shift(@_); |
|---|
| 585 | if($opt_id and $opt_comment){ |
|---|
| 586 | comment($opt_id, $opt_comment, $opt_webservice); |
|---|
| 587 | }else{ |
|---|
| 588 | print "Syntax: comment <id> <comment text>\n"; |
|---|
| 589 | } |
|---|
| 590 | } |
|---|
| 591 | |
|---|
| 592 | sub run_comments{ |
|---|
| 593 | shift(@_); |
|---|
| 594 | my $opt_id = shift(@_); |
|---|
| 595 | if($opt_id){ |
|---|
| 596 | comments($opt_id, $opt_webservice); |
|---|
| 597 | }else{ |
|---|
| 598 | print "Syntax: comments <id>\n"; |
|---|
| 599 | } |
|---|
| 600 | } |
|---|
| 601 | |
|---|
| 602 | sub run_removal{ |
|---|
| 603 | shift(@_); |
|---|
| 604 | my $opt_id = shift(@_); |
|---|
| 605 | if($opt_id){ |
|---|
| 606 | removal($opt_id, $opt_webservice); |
|---|
| 607 | }else{ |
|---|
| 608 | print "Syntax: removal <id>\n"; |
|---|
| 609 | } |
|---|
| 610 | } |
|---|
| 611 | |
|---|
| 612 | sub run_preview{ |
|---|
| 613 | shift(@_); |
|---|
| 614 | my $arg_id = shift(@_); |
|---|
| 615 | if($arg_id){ |
|---|
| 616 | entry_preview($arg_id); |
|---|
| 617 | }else{ |
|---|
| 618 | print "Syntax: preview <id>\n"; |
|---|
| 619 | } |
|---|
| 620 | } |
|---|
| 621 | |
|---|
| 622 | sub run_install{ |
|---|
| 623 | shift(@_); |
|---|
| 624 | my $arg_id = shift(@_); |
|---|
| 625 | if($arg_id){ |
|---|
| 626 | entry_install($arg_id); |
|---|
| 627 | }else{ |
|---|
| 628 | print "Syntax: install <id>\n"; |
|---|
| 629 | } |
|---|
| 630 | } |
|---|
| 631 | |
|---|
| 632 | sub run_details{ |
|---|
| 633 | shift(@_); |
|---|
| 634 | my $arg_id = shift(@_); |
|---|
| 635 | if($arg_id){ |
|---|
| 636 | entry_details($arg_id); |
|---|
| 637 | }else{ |
|---|
| 638 | print "Syntax: details <id>\n"; |
|---|
| 639 | } |
|---|
| 640 | } |
|---|
| 641 | |
|---|
| 642 | sub run_history{ |
|---|
| 643 | shift(@_); |
|---|
| 644 | my $arg_id = shift(@_); |
|---|
| 645 | if($arg_id){ |
|---|
| 646 | entry_history($arg_id); |
|---|
| 647 | }else{ |
|---|
| 648 | print "Syntax: history <id>\n"; |
|---|
| 649 | } |
|---|
| 650 | } |
|---|
| 651 | |
|---|
| 652 | sub run_webservice{ |
|---|
| 653 | shift(@_); |
|---|
| 654 | $opt_webservice = shift(@_); |
|---|
| 655 | if($opt_webservice){ |
|---|
| 656 | print "Webservice is set to: $opt_webservice\n"; |
|---|
| 657 | }else{ |
|---|
| 658 | print "Syntax: webservice <url>\n"; |
|---|
| 659 | } |
|---|
| 660 | } |
|---|
| 661 | |
|---|
| 662 | sub run_{ |
|---|
| 663 | } |
|---|
| 664 | |
|---|
| 665 | sub entry_preview{ |
|---|
| 666 | my $arg_id = shift(@_); |
|---|
| 667 | |
|---|
| 668 | my $entry_hash = $entrycache{$arg_id}; |
|---|
| 669 | if(!$entry_hash){ |
|---|
| 670 | print "Error: Unknown id $arg_id\n"; |
|---|
| 671 | return; |
|---|
| 672 | } |
|---|
| 673 | |
|---|
| 674 | my %entry = %{$entry_hash}; |
|---|
| 675 | my $preview = $entry{"preview"}; |
|---|
| 676 | |
|---|
| 677 | my $outfile = "/tmp/dxsclient.out.png"; |
|---|
| 678 | mirror($preview, $outfile); |
|---|
| 679 | system("gqview $outfile"); |
|---|
| 680 | } |
|---|
| 681 | |
|---|
| 682 | sub entry_install{ |
|---|
| 683 | my $arg_id = shift(@_); |
|---|
| 684 | |
|---|
| 685 | my $entry_hash = $entrycache{$arg_id}; |
|---|
| 686 | if(!$entry_hash){ |
|---|
| 687 | print "Error: Unknown id $arg_id\n"; |
|---|
| 688 | return; |
|---|
| 689 | } |
|---|
| 690 | |
|---|
| 691 | my %entry = %{$entry_hash}; |
|---|
| 692 | my $payload = $entry{"payload"}; |
|---|
| 693 | |
|---|
| 694 | my $outfile = "/tmp/dxsclient.out.xxx"; |
|---|
| 695 | mirror($payload, $outfile); |
|---|
| 696 | system("ls -la $outfile"); |
|---|
| 697 | } |
|---|
| 698 | |
|---|
| 699 | sub entry_details{ |
|---|
| 700 | my $arg_id = shift(@_); |
|---|
| 701 | |
|---|
| 702 | my $entry_hash = $entrycache{$arg_id}; |
|---|
| 703 | if(!$entry_hash){ |
|---|
| 704 | print "Error: Unknown id $arg_id\n"; |
|---|
| 705 | return; |
|---|
| 706 | } |
|---|
| 707 | |
|---|
| 708 | my %entry = %{$entry_hash}; |
|---|
| 709 | my $id = $entry{"id"}; |
|---|
| 710 | my $author = $entry{"author"}; |
|---|
| 711 | my $name = $entry{"name"}; |
|---|
| 712 | my $version = $entry{"version"}; |
|---|
| 713 | my $release = $entry{"release"}; |
|---|
| 714 | my $releasedate = $entry{"releasedate"}; |
|---|
| 715 | my $preview = $entry{"preview"}; |
|---|
| 716 | my $payload = $entry{"payload"}; |
|---|
| 717 | my $summary = $entry{"summary "}; |
|---|
| 718 | my $rating = $entry{"rating"}; |
|---|
| 719 | my $downloads = $entry{"downloads"}; |
|---|
| 720 | my $category = $entry{"category"}; |
|---|
| 721 | my $licence = $entry{"licence"}; |
|---|
| 722 | |
|---|
| 723 | print "Name: $name\n"; |
|---|
| 724 | print "Author: $author\n"; |
|---|
| 725 | print "Version: $version\n"; |
|---|
| 726 | print "Release: $release\n"; |
|---|
| 727 | print "Release date: $releasedate\n"; |
|---|
| 728 | print "Preview: $preview\n"; |
|---|
| 729 | print "Payload: $payload\n"; |
|---|
| 730 | print "Summary: $summary\n"; |
|---|
| 731 | print "Rating: $rating\n"; |
|---|
| 732 | print "Downloads: $downloads\n"; |
|---|
| 733 | print "Category: $category\n"; |
|---|
| 734 | print "Licence: $licence\n"; |
|---|
| 735 | } |
|---|
| 736 | |
|---|
| 737 | sub entry_history{ |
|---|
| 738 | my $arg_id = shift(@_); |
|---|
| 739 | |
|---|
| 740 | my $entry_hash = $entrycache{$arg_id}; |
|---|
| 741 | if(!$entry_hash){ |
|---|
| 742 | print "Error: Unknown id $arg_id\n"; |
|---|
| 743 | return; |
|---|
| 744 | } |
|---|
| 745 | |
|---|
| 746 | my %entry = %{$entry_hash}; |
|---|
| 747 | |
|---|
| 748 | history($arg_id, $opt_webservice); |
|---|
| 749 | } |
|---|
| 750 | |
|---|