Commit 52741456 authored by Guillaume Huard's avatar Guillaume Huard
Browse files

Renamed push and reworked set_setting

parent ece9f979
#!/usr/bin/perl
use strict;
use LWP::UserAgent;
use Data::Dumper;
use File::Slurp;
use Getopt::Long qw(:config bundling);
use XML::LibXML;
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;
my $url = 'https://moodle.caseine.org/webservice/rest/server.php';
......@@ -45,8 +43,15 @@ sub set_setting($@) {
my $setting = shift;
failure "Extraneous arguments" unless not scalar(@_);
my ($name, $value) = split /=/, $setting;
failure "Invalid setting" unless not defined($value);
my ($name, $value);
if ($setting =~ m/^\w+=.*$/) {
($name, $value) = split /=/, $setting, 2;
}
if ($setting =~ m/^\w+:.*$/) {
($name, $value) = split /:/, $setting, 2;
($value = read_file($value)) || failure "Cannot read file $value";
}
failure "Invalid setting" unless defined($value);
push @{$content}, "settingname", $name, "settingvalue", $value;
}
......@@ -79,8 +84,10 @@ Pushes data to caseine, where :
- command is one of : @commands and its arguments are :
- filenames for save commands
- a setting name for get_setting
- an assignment of the form name=value for set_setting
- an assignment of the form name=value or name:filename for set_setting
- nothing for the other ones
More informations can be found at : https://moodle.caseine.org/mod/wiki/view.php?pageid=199
END
exit(0);
}
......@@ -119,11 +126,6 @@ my $res = $ua->post( $url,
if (exists($res->{'_content'})) {
my $answer = $res->{'_content'};
print $answer;
# my $parser = XML::LibXML->new();
# my $tree = $parser->parse_string($answer);
# my $root = $tree->getDocumentElement;
# my @values = $root->getElementsByTagName('VALUE');
# print $values[0]->getFirstChild->getData, "\n";
} else {
failure "Invalid answer from server";
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment