Mailing List Archive

Upload Addressbook to Davical via Command Line?
Dear Davical Users,

it is very convenient to upload an addressbook file (replacing the
existing one) to a collection using a browser on the davical
administion frontend.

But how could one do automated that via command line (e.g. by using
curl or such)?

I see the URL and tried to upload the file via curl POST. The server
replies the HTML-Code of the admin page but does not accecpt the file
content. Do I miss some hidden entries? Has anyone a working example?


Thanks and best regards


Torsten



--
------------------------------------------------------------------------
Torsten Finke
fi@igh.de
------------------------------------------------------------------------


_______________________________________________
Davical-general mailing list
Davical-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/davical-general
Re: Upload Addressbook to Davical via Command Line? [ In reply to ]
Hello,

Agreed: pushing a file to DAViCal is very convenient. But AFAIK there is
now way or API to programmatically do it.
The following is a sample of a Python script I use to upload a .vcf file
to a DAViCal collection. This comes from a "quick and dirty" work of
reverse engineering the source HTML form.

import requests
# Authenticate to DAViCal
davicalWebSession = requests.Session()
result = davicalWebSession.post(DAVICAL_LOGIN_URL, data={"username":
DAVICAL_USER, "password": DAVICAL_PWD})

# Getting CSRF token from DAViCal
result = davicalWebSession.get(DAVICAL_COLLECTION_URL +
DAVICAL_COLLECTION_ID)
search = re.search('<input type="hidden" name="csrf_token"
value="(.*)">', result.text)
csrf = search.group(1)

# Send a VCF file to DAViCal
postData = {"mode": "off", "submit": "", "csrf_token": csrf,
"_editor_action[editor_1]": "update", "collection_id":
DAVICAL_COLLECTION_ID}
filesData = {'ics_file': open(VCF_FILE ,'r')}
result = davicalWebSession.post(DAVICAL_COLLECTION_URL +
DAVICAL_COLLECTION_ID, data=postData, files=filesData)


If interested, I previously made a similar implementation using Bash.

Regards,
Julien

Le 29/11/2023 à 18:46, fi@igh.de a écrit :
> Dear Davical Users,
>
> it is very convenient to upload an addressbook file (replacing the
> existing one) to a collection using a browser on the davical
> administion frontend.
>
> But how could one do automated that via command line (e.g. by using
> curl or such)?
>
> I see the URL and tried to upload the file via curl POST. The server
> replies the HTML-Code of the admin page but does not accecpt the file
> content. Do I miss some hidden entries? Has anyone a working example?
>
>
> Thanks and best regards
>
>
> Torsten
>
>
>


_______________________________________________
Davical-general mailing list
Davical-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/davical-general
Re: Upload Addressbook to Davical via Command Line? [ In reply to ]
Hello Julien,

On Thu, Nov 30, 2023 at 10:49:45PM +0100, Julien Métairie wrote:
> Hello,
>
> Agreed: pushing a file to DAViCal is very convenient. But AFAIK there is now
> way or API to programmatically do it.
>
> The following is a sample of a Python script I use to upload a .vcf file to
> a DAViCal collection. This comes from a "quick and dirty" work of reverse
> engineering the source HTML form.

"Mechanizing" seems to be the last resort in this case also.

> import requests
> # Authenticate to DAViCal
> davicalWebSession = requests.Session()
> result = davicalWebSession.post(DAVICAL_LOGIN_URL, data={"username":
> DAVICAL_USER, "password": DAVICAL_PWD})
>
> # Getting CSRF token from DAViCal
> result = davicalWebSession.get(DAVICAL_COLLECTION_URL +
> DAVICAL_COLLECTION_ID)
> search = re.search('<input type="hidden" name="csrf_token" value="(.*)">',
> result.text)
> csrf = search.group(1)
>
> # Send a VCF file to DAViCal
> postData = {"mode": "off", "submit": "", "csrf_token": csrf,
> "_editor_action[editor_1]": "update", "collection_id":
> DAVICAL_COLLECTION_ID}
> filesData = {'ics_file': open(VCF_FILE ,'r')}
> result = davicalWebSession.post(DAVICAL_COLLECTION_URL +
> DAVICAL_COLLECTION_ID, data=postData, files=filesData)

Great! That is very useful. Thanks a lot!

> If interested, I previously made a similar implementation using Bash.

of course that would be interesting. I would appretiate seeing that
solution very much.




Best Regards

Torsten


> Le 29/11/2023 à 18:46, fi@igh.de a écrit :
> > Dear Davical Users,
> >
> > it is very convenient to upload an addressbook file (replacing the
> > existing one) to a collection using a browser on the davical
> > administion frontend.
> >
> > But how could one do automated that via command line (e.g. by using
> > curl or such)?
> >
> > I see the URL and tried to upload the file via curl POST. The server
> > replies the HTML-Code of the admin page but does not accecpt the file
> > content. Do I miss some hidden entries? Has anyone a working example?
> >
> >
> > Thanks and best regards
> >
> >
> > Torsten
> >
> >
> >

--
------------------------------------------------------------------------
Torsten Finke
fi@igh.de
------------------------------------------------------------------------

_______________________________________________
Davical-general mailing list
Davical-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/davical-general
Re: Upload Addressbook to Davical via Command Line [ In reply to ]
Torsten,

It looks like the following. Please don't blame for this terrible thing! :X

# Authentication
curl --silent --show-error --output /dev/null --request POST --form "username=$DAVICAL_USER" --form "password=$DAVICAL_PWD" --cookie-jar $DAVICAL_COOKIE_FILE 'https://davserver.domain/index.php'

# Get CSRF token from DAViCal
CSRF=$(curl --silent --show-error --cookie $DAVICAL_COOKIE_FILE --cookie-jar $DAVICAL_COOKIE_FILE "https://davserver.domain/admin.php?action=edit&t=collection&id=${DAVICAL_COLLECTION_
ID}" | grep '<input type="hidden" name="csrf_token"' | head -1 | sed --regexp-extended 's/<input type="hidden" name="csrf_token" value="(.*)">/\1/')

# Send VCF file to DAViCal
curl --silent --show-error --output /dev/null -X POST -F "ics_file=@${VCF_FILE}" -F "collection_id=${DAVICAL_COLLECTION_ID}" -F 'mode=off' -F 'submit=' -F "csrf_token=$CSRF" -F '_editor_action[editor_1]=update' --cookie $DAVICAL_COOKIE_FILE "https://davserver.domain/admin.php?action=edit&t=collection"

# Remove cookie
rm $DAVICAL_COOKIE_FILE

Regards,
Julien

December 1, 2023 at 12:57 AM, fi@igh.de wrote:



>
> Hello Julien,
>
> On Thu, Nov 30, 2023 at 10:49:45PM +0100, Julien Métairie wrote:
>
> >
> > Hello,
> >
> > Agreed: pushing a file to DAViCal is very convenient. But AFAIK there is now
> > way or API to programmatically do it.
> >
> > The following is a sample of a Python script I use to upload a .vcf file to
> > a DAViCal collection. This comes from a "quick and dirty" work of reverse
> > engineering the source HTML form.
> >
>
> "Mechanizing" seems to be the last resort in this case also.
>
> >
> > import requests
> > # Authenticate to DAViCal
> > davicalWebSession = requests.Session()
> > result = davicalWebSession.post(DAVICAL_LOGIN_URL, data={"username":
> > DAVICAL_USER, "password": DAVICAL_PWD})
> >
> > # Getting CSRF token from DAViCal
> > result = davicalWebSession.get(DAVICAL_COLLECTION_URL +
> > DAVICAL_COLLECTION_ID)
> > search = re.search('<input type="hidden" name="csrf_token" value="(.*)">',
> > result.text)
> > csrf = search.group(1)
> >
> > # Send a VCF file to DAViCal
> > postData = {"mode": "off", "submit": "", "csrf_token": csrf,
> > "_editor_action[editor_1]": "update", "collection_id":
> > DAVICAL_COLLECTION_ID}
> > filesData = {'ics_file': open(VCF_FILE ,'r')}
> > result = davicalWebSession.post(DAVICAL_COLLECTION_URL +
> > DAVICAL_COLLECTION_ID, data=postData, files=filesData)
> >
>
> Great! That is very useful. Thanks a lot!
>
> >
> > If interested, I previously made a similar implementation using Bash.
> >
>
> of course that would be interesting. I would appretiate seeing that
> solution very much.
>
> Best Regards
>
> Torsten
>
> >
> > Le 29/11/2023 à 18:46, fi@igh.de a écrit :
> > Dear Davical Users,
> >
> > it is very convenient to upload an addressbook file (replacing the
> > existing one) to a collection using a browser on the davical
> > administion frontend.
> >
> > But how could one do automated that via command line (e.g. by using
> > curl or such)?
> >
> > I see the URL and tried to upload the file via curl POST. The server
> > replies the HTML-Code of the admin page but does not accecpt the file
> > content. Do I miss some hidden entries? Has anyone a working example?
> >
> >
> > Thanks and best regards
> >
> >
> > Torsten
> >
>
> --
> ------------------------------------------------------------------------
> Torsten Finke
> fi@igh.de
> ------------------------------------------------------------------------
>


_______________________________________________
Davical-general mailing list
Davical-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/davical-general