Hi,
We are testing this in a corporate environment with the ldap plugin. So this script can not work as we have setup that only authenticated users can access the galleries.
We are running on Ubuntu LAMP server.
I though of making a bash bot script and then adding it to cron. Has anyone done this ?
Thanks !
Offline
Just to give you new ideas on how to work around this problem, I have used python and the python library mechanize to create a bot to login and click the right buttons automatically. It is very basic at the moment and has no error checking or real feedback from the website. Here is my python code (note : this is for ldap login using the ldap plugin, the first url link will probably be different if you use other types of login);
import mechanize br = mechanize.Browser() print 'Starting auto synchronizing ...' url = 'https://example.com/identification.php?redirect=%252F' br.open(url) br.select_form('login_form') br.form['username'] = 'username' br.form['password'] = 'password' print 'Logging in ...' response = br.submit() temp = response.read() # the text of the page print "Going to Admin Page ..." url = "https://example.com/admin.php" response = br.open(url) print 'Starting Synchronization ...' br.select_form('QuickSynchro') response = br.submit() temp = response.read() print "Synchronization Finished."
You can then add this as a cron job. Hope this helps some of you.
Last edited by rtevyncke (2014-07-28 08:08:32)
Offline
plg wrote:
[Forum, topic 11924] Automatic synchronization? the user gave no feedback about he did it.
Sorry for the late reply worwan, your topic is very interesting and thanks to my involvement in pLoader and piwigo_remote.pl, I've coded a much cleaner solution, inspired from your wget script. Instead of wget, let's write a small Perl script (oh yes, just like piwigo_remote.pl):Code:
#!/usr/bin/perl # perl remote_sync.pl --base_url=http://localhost/piwigo/dev/branches/2.0 --username=plg --password=plg use strict; use warnings; use LWP::UserAgent; use Getopt::Long; my %opt = (); GetOptions( \%opt, qw/ base_url=s username=s password=s / ); our $ua = LWP::UserAgent->new; $ua->agent('Mozilla/remote_sync.pl'); $ua->cookie_jar({}); $ua->default_headers->authorization_basic( $opt{username}, $opt{password} ); my $form = { method => 'pwg.session.login', username => $opt{username}, password => $opt{password}, }; my $result = $ua->post( $opt{base_url}.'/ws.php?format=json', $form ); # perform the synchronization $form = { 'sync' => 'files', 'display_info' => 1, 'add_to_caddie' => 1, 'privacy_level' => 0, 'sync_meta' => 1, # remove this parameter, turning to 0 is not enough 'simulate' => 0, 'subcats-included' => 1, 'submit' => 1, }; $result = $ua->post( $opt{base_url}.'/admin.php?page=site_update&site=1', $form ); use Data::Dumper; print Dumper($result);With this script you don't need to have HTTP basic authentication (but it also works with it) and you know what? it just works :-) (I've coded it in 30 minutes approximately and I'm quite proud of it)
Copy this code in a file "remote_sync.pl" and then run:Code:
perl remote_sync.pl --base_url=http://localhost/piwigo/dev/branches/2.0 --username=plg --password=plgIf you're using Debian/Ubuntu, you will have to perform:
Code:
sudo apt-get install libwww-perlI think I will add the action "synchronize" in piwigo_remote.pl :-) Please give me your feedback.
any idea how to do this per category ?
Thanks for this script, I know its been a pretty long time and was wonder if some changes might have been made to it or the software that might have changed how this works. It seem to work pretty good, but been seeing some issues. My site is setup with sub sites and some of the sites are doing this odd thing everytime I run the remote script.
If I have one album, It will start of something like this :
http://www.somesite.net/subsite/index.php?/category/1
If I run the script that category /1 changes to category/2
On one of the bigger sites, I saw the first category show up as category/1 after the initial install sync, but after running the script it jumps to 10, then later a higher numbers.
Any idea why this might be happening?
Here is the output of the script 2 runs in a row :
<option value="92">- misc</option>
<option value="93">- home</option>
<option value="94"> - backyard</option>
<option value="95"> - steps</option>
<option value="96"> - shed</option>
<option value="97"> - hvac</option>
<option value="98">- forsale</option>
<option value="99"> - surround</option>
<option value="101">- misc</option>
<option value="102">- home</option>
<option value="103"> - backyard</option>
<option value="104"> - steps</option>
<option value="105"> - shed</option>
<option value="106"> - hvac</option>
<option value="107">- forsale</option>
<option value="108"> - surround</option>
plg wrote:
[Forum, topic 11924] Automatic synchronization? the user gave no feedback about he did it.
Sorry for the late reply worwan, your topic is very interesting and thanks to my involvement in pLoader and piwigo_remote.pl, I've coded a much cleaner solution, inspired from your wget script. Instead of wget, let's write a small Perl script (oh yes, just like piwigo_remote.pl):Code:
#!/usr/bin/perl # perl remote_sync.pl --base_url=http://localhost/piwigo/dev/branches/2.0 --username=plg --password=plg use strict; use warnings; use LWP::UserAgent; use Getopt::Long; my %opt = (); GetOptions( \%opt, qw/ base_url=s username=s password=s / ); our $ua = LWP::UserAgent->new; $ua->agent('Mozilla/remote_sync.pl'); $ua->cookie_jar({}); $ua->default_headers->authorization_basic( $opt{username}, $opt{password} ); my $form = { method => 'pwg.session.login', username => $opt{username}, password => $opt{password}, }; my $result = $ua->post( $opt{base_url}.'/ws.php?format=json', $form ); # perform the synchronization $form = { 'sync' => 'files', 'display_info' => 1, 'add_to_caddie' => 1, 'privacy_level' => 0, 'sync_meta' => 1, # remove this parameter, turning to 0 is not enough 'simulate' => 0, 'subcats-included' => 1, 'submit' => 1, }; $result = $ua->post( $opt{base_url}.'/admin.php?page=site_update&site=1', $form ); use Data::Dumper; print Dumper($result);With this script you don't need to have HTTP basic authentication (but it also works with it) and you know what? it just works :-) (I've coded it in 30 minutes approximately and I'm quite proud of it)
Copy this code in a file "remote_sync.pl" and then run:Code:
perl remote_sync.pl --base_url=http://localhost/piwigo/dev/branches/2.0 --username=plg --password=plgIf you're using Debian/Ubuntu, you will have to perform:
Code:
sudo apt-get install libwww-perlI think I will add the action "synchronize" in piwigo_remote.pl :-) Please give me your feedback.
I was looking for that solution but unable to use Perl. If anyone is looking for a pure PHP solution there is mine using curl, just add that in a .php and trigger that file with cronjob :
$baseurl = 'http://yourpiwigo.com'; $username = 'adminuser'; $password = 'adminpassword'; $url = $baseurl.'/identification.php'; $fields = array( 'username' => $username, 'password' => $password, 'redirect' => '', 'login' => 'on' ); //url-ify the data for the POST foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string, '&'); //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL, $url); curl_setopt($ch,CURLOPT_POST, count($fields)); curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); $cookieJar = 'synchroCookie'; curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookieJar); curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookieJar); curl_exec($ch); curl_close ($ch); unset($ch); $url = $baseurl.'/admin.php?page=site_update&site=1'; $fields = array( 'sync' => urlencode('files'), 'privacy_level' => urlencode('0'), 'subcats-included' => urlencode('1'), 'submit' => urlencode('on') ); //url-ify the data for the POST foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string, '&'); //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL, $url); curl_setopt($ch,CURLOPT_POST, count($fields)); curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookieJar); curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookieJar); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); curl_exec($ch); curl_close ($ch); unset($ch);
Hi,
thanks for the PHP script.
This works like a charm if I execute it from a browser.
As I would like to use the script for a tasked periodic update under Windows I am wondering whether I could execute this directly from the windows shell with php.exe.
Tried this, but did not work.
What would I have to change to make this happen?
Thanks very much
Rgds
Chris
You can wrap the .php Site with static html in an Iframe that refreshes regularly.
This is what I will try. So you can start / stop the "auto Sync" simple by using opening the main page .. like sync_piwigo.html