I am trying to create an automated documentation feature for our servers by using a Mediawiki and its API and feeding scripts on each server, but failed so far. The idea is to collect several vital data about a server by a script, create a wiki page and feed this into a central Mediawiki instance using wget
as a means of transfer.
I set up a test-Wiki using Mediawiki 1.21.2 using a simple XAMPP stack on SLES11 (i intend to work on the software integration part later) and set up a user account with all rights (bureaucrat, administrator) to avoid any authentication issues for the test.
I finally wrote the following script on a test server to try creation of a wiki page:
#! /bin/ksh93
typeset WGET=$(which wget)
typeset chWikiInst="my_wiki"
typeset chWikiURL="http://<wikiserver>/wiki/api.php"
typeset fTgt=/tmp/wikitest
typeset fOut="$fTgt/outfile"
typeset chUser="wikiroot"
typeset chPwd="<password>"
typeset chToken=""
typeset chEditToken=""
rm outfile*
rm wikitest.login
rm wikitest.session*
# ----------------------- login --------------------
$WGET --post-data "action=login&lgname=${chUser}&lgpassword=${chPwd}&format=xml" \
--save-cookies="$fTgt/wikitest.login" \
--output-document="$fOut" \
--keep-session-cookies \
"$chWikiURL"
# extract info
chToken="$(sed 's/.*\ token="\([^"]*\)".*/\1/' "$fOut")"
$WGET --post-data "action=login&lgname=${chUser}&lgpassword=${chPwd}&lgtoken=${chToken}&format=xml" \
--load-cookies="$fTgt/wikitest.login" \
--save-cookies="$fTgt/wikitest.session" \
--output-document="$fOut".1 \
"$chWikiURL"
# ----------------------- get edit token -----------
wget --post-data "action=query&prop=info|revisions&intoken=edit&titles=Mypage&format=xml" \
--load-cookies="$fTgt/wikitest.session" \
--save-cookies="$fTgt/wikitest.sessionedit" \
--output-document="$fOut".2 \
"$chWikiURL"
chEditToken="$(sed -n 's/.*\ edittoken="\([^"]*\)".*/\1/p' "${fOut}.2")"
print - "------------------------------------------------"
print - "chEditToken=${chEditToken}"
print - "------------------------------------------------"
# ----------------------- edit page ----------------
wget --post-data "action=edit&title=Mypage&summary=wikitest%20summary&text=wikitest%20Text&token=${chEditToken}" \
--load-cookies="$fTgt/wikitest.sessionedit" \
--save-cookies="$fTgt/wikitest.sessionedit" \
--output-document="$fOut".3 \
"$chWikiURL"
# ----------------------- logout -------------------
$WGET --post-data "action=logout&format=xml" \
--load-cookies="$fTgt/wikitest.session" \
--save-cookies="$fTgt/wikitest.sessionend" \
--output-document="$fOut".4 \
"$chWikiURL"
exit 0
What worked was the login- the query- and the logout-part. I get the correct answers back, the cookies/tokens are set correctly and all works correctly. Somehow, though, when i try to use the edit-token to create the new page (it doesn't exist yet) i get back the API-documentation, which indicates an error.
I checked if the API is allowed to be used at all in LocalSettings.php
and include/DefaultSettings.php
, but everything seems to be as it should be.
wget
and OS version is as follows:
# wget --version
GNU Wget 1.14 built on aix5.1.0.0.
Locale: /opt/freeware/share/locale
Compile: xlc_r -D_LARGE_FILES -DHAVE_CONFIG_H
-DSYSTEM_WGETRC="/opt/freeware/etc/wgetrc"
-DLOCALEDIR="/opt/freeware/share/locale" -I. -I../lib -I../lib
-D_THREAD_SAFE -I/opt/freeware/include -I/opt/freeware/include
-qmaxmem=16384 -DSYSV -D_AIX -D_AIX32 -D_AIX41 -D_AIX43 -D_AIX51
-D_ALL_SOURCE -DFUNCPROTO=15 -O -I/opt/freeware/include
Link: xlc_r -D_LARGE_FILES -qmaxmem=16384 -DSYSV -D_AIX -D_AIX32 -D_AIX41
-D_AIX43 -D_AIX51 -D_ALL_SOURCE -DFUNCPROTO=15 -O
-I/opt/freeware/include -L/opt/freeware/lib
-Wl,-bmaxdata:0x80000000 -L/opt/freeware/lib
/opt/freeware/lib/libiconv.a /opt/freeware/lib/libintl.a
/opt/freeware/lib/libiconv.a /opt/freeware/lib/libssl.so
/opt/freeware/lib/libcrypto.so /opt/freeware/lib/libz.a -ldl -lz
-lz -lidn -lpcre ftp-opie.o openssl.o http-ntlm.o ../lib/libgnu.a
-liconv
# oslevel -s
5300-10-01-0921
# uname -a
AIX myTestHost 3 5 <####>
Can someone explain to me what i am doing wrong?
bakunin