Tags:
create new tag
, view all tags

Question

I want to write a script to modify an existing TWiki topic. (I'm open to using a shell script with curl, or Python, Ruby or Perl. curl is suggested in HowtoInterfaceDirectlytoTwikiviaAPI.) But we're using template login. From the answer at HowToUseCurlWithTemplateLogin it appears there it can't be done, with curl at least. But if I know the URL of the template login page, can I somehow get a session ID that I can pass to a URL (that uses the save script)?

I note that CrawfordCurrie (who wrote both the above answers) has contributed a WebDAVPlugin. Would I be better off installing it and writing a script using a WebDAV library?

Environment

TWiki version: TWikiRelease04x01x01
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS:  
Web server:  
Perl version:  
Client OS:  
Web Browser:  
Categories: Authentication

-- DarylSpitzer - 19 Apr 2007

Answer

ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.

I don't know about curl. But (I recently have learned) you can write:

/twiki/bin/save/Web/Topic?username=MyName;password=mypasswd;text=BLO
or
/twiki/bin/save/Web/Topic?username=MyName;password=mypasswd;NameFormField=me

-- ArthurClemens - 19 Apr 2007

Depends on what you want to do. WebDAV is useful if you are running Apache 1.3, and you have a lot of users who do a lot of work in - for example - MS Word documents attached to TWiki topics. But it puts a significant load on the server and I don't really recommend it. Arthur is right about the username and password parameters when using template login. See TWikiScripts for details of the other parameters to the TWiki scripts. You can use either wget or curl to invoke these scripts e.g. curl http://myserver.com/twiki/bin/save/Web/Topic?username=user;password=passwd;text=Bibble

-- CrawfordCurrie - 20 Apr 2007

Thanks for such quick responses. I tried:

    curl http://sw-wiki/twiki/bin/save/Main/DarylsTest?username=DarylSpitzer;password=xxxxxx;text=foo

and got no error message, but the page wasn't changed. Here's what I get when I use --verbose:

    curl --verbose http://sw-wiki/twiki/bin/save/Main/DarylsTest?username=DarylSpitzer;password=xxxxxx;text=foo  
    * About to connect() to sw-wiki port 80
    *   Trying 137.57.202.242... * connected
    * Connected to sw-wiki (137.57.202.242) port 80
    > GET /twiki/bin/save/Main/DarylsTest?username=DarylSpitzer HTTP/1.1
    User-Agent: curl/7.13.1 (powerpc-apple-darwin8.0) libcurl/7.13.1 OpenSSL/0.9.7l zlib/1.2.3
    Host: sw-wiki
    Pragma: no-cache
    Accept: */*

    < HTTP/1.1 302 Moved
    < Date: Fri, 20 Apr 2007 15:42:25 GMT
    < Server: Apache/2.0.52 (Red Hat)
    < Set-Cookie: TWIKISID=56ef1ab7012f2381b8c9c56e851603dc; path=/
    < Location: /twiki/bin/login/Main/DarylsTest?username=DarylSpitzer;origurl=%2Ftwiki%2Fbin%2Fsave%2FMain%2FDarylsTest%3Fusername%3DDarylSpitzer
    < Content-Length: 0
    < Content-Type: text/plain; charset=ISO-8859-1
    * Connection #0 to host sw-wiki left intact
    * Closing connection #0

It appears something worked, since there's a TWIKISID in there. Is curl not handling the 302 correctly? Do I need to use a command-line option to have it do so?

-- DarylSpitzer - 20 Apr 2007

TWiki.org uses basic auth, not template login.

-- PeterThoeny - 20 Apr 2007

My problem above is not with TWiki.org. (sw-wiki is an "intranet" domain at my employer.)

-- DarylSpitzer - 22 Apr 2007

It appears the curl command-line option I'm looking for is --location. But the username and/or password are rejected. See UsingCurlWithTemplateLogin.

-- DarylSpitzer - 23 Apr 2007

I have struck the same problem I have a script that runs fine on TWiki 3.x (sep 2004). But it fails on 4.1.2.

Tried to implement Arthurs suggestion above, thinking that I would not have to write anything. But I am unable to get it to work.

I tried and got:

root@jeeves:/home/httpd/twiki412/bin# ./save -web DEMO -topic WebHome -username BramVanOosterhout -password *** -text BLO
Status: 302 Moved
Date: Mon, 24 Mar 2008 11:38:33 GMT
Location: http://bram.van-oosterhout.org/twiki412/bin/view/Main/WebHome
Added other parameters as indicated at TWikiScripts#save but the result is always the same. and the page remains unchanged.

Then decided to write a REST hansler to do the same and did get it to work. But TWikiFuncDotPm#saveTopic_web_topic_meta_text_op cannot set the parent. And I can't find another way to set the parent. Which is pretty useless when uploading dozens of pages.

Any suggestions on how to progress?

-- BramVanOosterhout - 24 Mar 2008

Found out today, by accident, that the ./save -web DEMO... above actually did create WebHome with text BLO. It did that in the Main web.

It's midnight now. I'll investigate further tomorrow.

-- BramVanOosterhout - 25 Mar 2008

I worked out that the following:

root@jeeves:/home/httpd/twiki412/bin# ./save Sandbox.TestTopic1 -username BramVanOosterhout -password * -text BLO

Creates TestTopic1 in Sandbox with text BLO

I also found that my 3.x script works, provided I configure NO authentication. Since I use TemplateLogin, I suspect the answer is the same as in HowToUseCurlWithTemplateLogin.

Well, I learned that I can replace my scripts with curl or lwp-request.pl. And that if I remove Authentication, I can make it work. A kludge, but it will have to do.

-- BramVanOosterhout - 26 Mar 2008

I needed this yesterday to allow a Flash movie to save XML to a TWiki topic. And because the XML may be large, passing the text to the url does not work. I have created a very simple plugin that uses a REST handler to write to a topic: SaveFromRestPlugin.pm. It may be of use to others.

Copy the file to your lib/TWiki/Plugins/ folder. And create a topic in TWiki web SaveFromRestPlugin (just a title as topic text will be fine).

You need to pass these attributes with the form data:

  • username
  • password
  • topic in the syntax Web.Topic
  • text

You call the script with this url: http://mycompany.com/twiki/bin/rest/SaveFromRestPlugin/save

-- ArthurClemens - 09 Apr 2008

See also ScriptedTopicCreation

-- BramVanOosterhout - 13 Apr 2008

Change status to:

Topic attachments
I Attachment History Action Size Date Who Comment
Perl source code filepm SaveFromRestPlugin.pm r1 manage 0.8 K 2008-04-09 - 16:54 ArthurClemens Plugin that uses a REST handler to write to a topic
Edit | Attach | Watch | Print version | History: r12 < r11 < r10 < r9 < r8 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r12 - 2008-04-13 - BramVanOosterhout
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.