Webcron returns 400 status - cron fails to remove old files

I am running ownCloud 10.0.9 on a hosted server (without SSH access).
The problem I have right now is that the webcron feature is returning an HTTP status code of 400 when invoked by the cron tool of my provider 1&1.

The webcron job logs an error page (created by owncloud) that says “You are accessing the server from an untrusted domain”. If I run the webcron job manually by typing the cron.php URL into my webbrowser, I see a almost empty page with only the text {"status":"success"}

My domain is hosted by 1&1, so I tried adding them to my trusted domains in config.php (by adding 1 => '1und1.de', to the trusted_domains array) but that did not change anything.

Any ideas what I need to do to allow the 1&1 webcron engine to run the cron.php function of my owncloud instance?

Thanks!

I think, this is not sufficient. You have to find out the real name of the server, where your hosting is running on.

Maybe you could explain, what this tool looks like in detail.

I just tried to do that, with minimal PHP knowledge :wink:
I wrote a little PHP file that tries to capture the domain by saving the variables
$_SERVER['HTTP_HOST'], $_SERVER['SERVER_NAME'], $_SERVER['REQUEST_URI'] and $_SERVER['HTTP_REFERER']; to a file, but when I run that as a webcron job, I just get my own domain back…

How would proper PHP code look like that reports the domain that owncloud is considering ‘untrusted’?

It’s a web interface that allows me to type in a URL that will be called at regular intervals. The webcron tool captures the error code and output of each call.

Did you try to select ‘Cron’ instead of ‘Webcron’, in admin settings?

Hey,

i’m not sure if it is really required to use some PHP code for this? From what i understand you need to add the domain your webcron tool is using to connect to your ownCloud installation in that trusted_domains setting.

So if your webcron tool is calling your webcron URL with something like this:

https://mydomain.1und1.de/owncloud/cron.php

you need to enter the following into the trusted_domains setting:

mydomain.1und1.de

Thanks! Not sure I fully follow, though:

Let’s say my domain is
https://www.mydomain.de
and owncloud is located at
https://www.mydomain.de/owncloud

Then the webcron URL provided by owncloud is
https://www.mydomain.de/owncloud/cron.php

That URL is invoked by a tool run by 1&1 - all the tool does is open that URL (and capture the results for error reporting) at regular intervals.

My owncloud config.php already has the domain www.mydomain.de listed as trusted domain (I guess that is part of the installation process?). This is the (anonymized) section of my config.php:
‘trusted_domains’ =>
array (
0 => ‘www.mydomain.de’,
1 => ‘1und1.de’,
),

So I do not really understand why owncloud/webcron is running fine if I manually type the URL into my web browser, but is complaining about an untrusted domaiin when started by the 1&1 webcron tool. Hence I thought I might write a little PHP program to capture the details of the 1&1 webcron call…?

Not yet. Since I do not have SSH access, I would not know how to run a proper cron job on the command line level - that is what the ‘Cron’ option is for, no?

As mentioned earlier, I’m quite sure, the server where your hosting is on, has a different name than the company web-server.

You should give it a try, before any further experiments, no SSH needed.
Just switch to ‘Cron’ in admin settings, enter the relative path to your cron.php script. According your posts, I assume owncloud/cron.php, each 15 minutes. I think, your hoster will run that for you, so you dont have to hassle with untrusted access.

This is the way it works here.

That’s why there is another line in there
‘0 => ‘www.mydomain.de’,’

www.mydomain.de (or rather mydomain.de) is the domain hosted by 1&1 for me.
What am I missing?

I would like to try this but I must be missing some part here. Just clicking on the ‘cron’ option in the admin settings > general section will not allow me to enter some relative path anywhere.
cron_settings
Looking at the documentation it seems to me that I need to set up a bit on the command line:

# crontab -u www-data -e
*  *  *  *  * /usr/bin/php -f /path/to/your/owncloud/cron.php

How would I do this on a purely hosted ownCloud instance?

OK, some more details:

At some point, the cron job seems to have worked (maybe the proper ‘cron’ settings? I will try again); I say this because now I find new entries in my logfile. Here’s an anonymized example:


{"reqId":"W83Ys1KlUo0AAF9JOkwAAAAK","level":3,"time":"2018-10-22T14:03:32+00:00","remoteAddr":"XXX.XXX.XX.XXX","user":"--","app":"no app in context","method":"GET","url":"\/owncloud\/cron.php","message":"Exception: {\"Exception\":\"OCP\\\\Files\\\\NotFoundException\",\"Message\":\"\\\/folder1\\\/folder2\\\/testfile.txt.v1536071029 not found while trying to get owner\",\"Code\":0,\"Trace\":\"#0 \\\/pages\\\/mainfolder\\\/userlogin\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Files\\\/Filesystem.php(960): OC\\\\Files\\\\View->getOwner('\\\/folder1\\\/folder2\\\/testfile...')\\n#1 \\\/pages\\\/mainfolder\\\/userlogin\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Preview.php(1315): OC\\\\Files\\\\Filesystem::getOwner('\\\/folder1\\\/folder2\\\/testfile...')\\n#2 \\\/pages\\\/mainfolder\\\/userlogin\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Preview.php(1303): OC\\\\Preview::post_delete(Array, 'files\\\/')\\n#3 \\\/pages\\\/mainfolder\\\/userlogin\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/legacy\\\/hook.php(105): OC\\\\Preview::post_delete_versions(Array)\\n#4 \\\/pages\\\/mainfolder\\\/userlogin\\\/htdocs\\\/owncloud\\\/apps\\\/files_versions\\\/lib\\\/Storage.php(776): OC_Hook::emit('\\\\\\\\OCP\\\\\\\\Versions', 'delete', Array)\\n#5 \\\/pages\\\/mainfolder\\\/userlogin\\\/htdocs\\\/owncloud\\\/apps\\\/files_versions\\\/lib\\\/Command\\\/Expire.php(61): OCA\\\\Files_Versions\\\\Storage::expire('\\\/folder1\\\/folder2\\\/testfile...', 'folder1')\\n#6 \\\/pages\\\/mainfolder\\\/userlogin\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Command\\\/CommandJob.php(34): OCA\\\\Files_Versions\\\\Command\\\\Expire->handle()\\n#7 \\\/pages\\\/mainfolder\\\/userlogin\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/BackgroundJob\\\/Job.php(57): OC\\\\Command\\\\CommandJob->run('O:33:\\\"OCA\\\\\\\\Files...')\\n#8 \\\/pages\\\/mainfolder\\\/userlogin\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/BackgroundJob\\\/QueuedJob.php(42): OC\\\\BackgroundJob\\\\Job->execute(Object(OC\\\\BackgroundJob\\\\JobList), Object(OC\\\\Log))\\n#9 \\\/pages\\\/mainfolder\\\/userlogin\\\/htdocs\\\/owncloud\\\/cron.php(144): OC\\\\BackgroundJob\\\\QueuedJob->execute(Object(OC\\\\BackgroundJob\\\\JobList), Object(OC\\\\Log))\\n#10 {main}\",\"File\":\"\\\/pages\\\/mainfolder\\\/userlogin\\\/htdocs\\\/owncloud\\\/lib\\\/private\\\/Files\\\/View.php\",\"Line\":1718}"}


So it seems that there also is an issue with clearing up old file versions (in the example above, it’s testfile.txt that causes this problem)?

BTW, my owncloud logfile already has almost 24k lines (> 11 MB) - I guess part of the cronjob would be prune it? Is there a manual way of clearing the log, just to be able to debug this cron problem better?

Hey,

i don’t think that the owncloud logfile is pruned automatically via the cron job. I’m mostly just deleting the content (not the file completely) to clean it.

Just two additional remarks:

  1. I would update to the latest 10.0.10 after the cleaning the logfile to see if this could fix the log entries
  2. Maybe your system has some internal hostname within the 1und1 network and thus the webcron is accessing your ownCloud installation with a different hostname?

@tom42 got the point, there is no such thing. Search for logrotate in the admin manual.

I guess, you have to configure and use your 1&1 Cronjob manager, as you don’t have access to the commandline.

https://help.1and1.com/hosting-c37630/scripts-and-programming-languages-c85099/cron-jobs-c37727/createmanage-cron-jobs-using-the-1and1-cron-job-manager-a793134.html

If this doesn’t fit, use an external service like EasyCron.

https://www.easycron.com/

Thanks, found it. I now added 'log_rotate_size' => 5242880, to config.php. Let’s see what happens.

That is exactly what I have been doing and what did not work. The 1&1 cronjob manager is just opening a user-provided URL at regular intervals. As posted above, doing this results in an ownCloud error related to untrusted domains.

I have not yet tested easycron, but will report back.

Thanks!

I’m just curious, which URL did you use? IMHO this should be:
https://www.mydomain.de/owncloud/cron.php

Yes, exactly. That is what I have been using. And as posted above, if I manually type that URL into a webbrowser, I see a success message. If I use that URL as part of the 1&1 cronjob manager, it fails.
See post 6 in this thread.

Hey,

could this still be valid?

From what i have seen so far in the owncloud.log the domain the webcron is trying to access is logged into it.

Yes, that could still be a problem - hence my attempts to find out what the true server name is, using a clumsy PHP script. Here’s a related question: the config.php allows me to configure trusted domains but what I seem to understand here is that these are full server names, i.e. not ‘mydomain.de’ but rather ‘www.mydomain.de’ - is that right?