[OzzModz] Country Flags by IP Address

[OzzModz] Country Flags by IP Address 2.2.1 Patch Level 3

No permission to download
The data folder must be 0777 chmod completely (and its subdirectories). I would guess that textfile doesn't have 0777 chmod.
SBJ is correct. The data directory and all of it's subdirectories should be world writable.

The owner of the folders and files should be whatever user your PHP installation runs as.

The ONLY time you can get away with permissions other than 777 is when your PHP installation for your site runs as a unique user on your server (note that www-data or some such user is not usually a unique user/group). Such as, on one of my sites the owner is WEB2 and the group is CLIENT0. So I can get away with 755 on the directories and 644 for files.

View attachment 212482
I just looked, and both the data and internal_data folders (and the countryflags sub-folder) are 777. Inside countryflags, the cloudflare-cookie.txt file is 644, GeoLite2-Country.mmdb and index.html files in the countryflags folder are both 666.

Owner of my data folder is root, group is 500eadmin
Owner of my countryflags folder is root, group is www-data
 
Well, anything inside in both folders data and internal_data must be in 0777.
But as you say, those 2 files are not for example. That is the problem. Just do a 0777 on those folders and their subdirectories.

1571687521523.png
 
It's also quite odd that your folders would be owned by root. Root is the super user on your server and usually doesn't own web folders. They should be owned by the user PHP runs as unless there's something really different about your server.

Anyway, the error is fully related to your permissions and isn't a problem with the add-on.
 
A recursive chmod to 777 seems to have fixed the issue, and running the countryflags cron job now confirmed it.

Thanks for the input, guys. Much appreciated and hopefully this could help someone in the future if this comes up.
 
FYI, if you have SSH access to your server and you're just running a plain apache server and not using suexec (which sets a user name and group) you can get the user name and group for PHP with this command...
Code:
more  /etc/apache2/envvars |grep APACHE_RUN_
Your directory and files should have the user and group set as the info for what's returned by that command if you're not running suexec in your site's vhost file. They result should look like this...
group.png
NOTE: APACHE_RUN_USER should NEVER be root

If you are running suexec, your vhost file would give you the proper owner/group info for files in your web folder...
vhost.png
NOTE: Again where it says "web2" is the owner and that should NEVER be root.
 
Last edited:
Hi @Snog
My APACHE_RUN_ user and group are both www-data

I may have misstated and screwed up the columns as I did the ls -l

The first column is permissions, second column is content totals, and third column (I thought is owner?) is "root", fourth column displayed (I thought is group?) is "500eadmin"
 
Hi @Snog
My APACHE_RUN_ user and group are both www-data

I may have misstated and screwed up the columns as I did the ls -l

The first column is permissions, second column is content totals, and third column (I thought is owner?) is "root", fourth column displayed (I thought is group?) is "500eadmin"
Did you recently move servers? If so, it SOUNDS like when you uploaded the files to your server your FTP client may have been running as user "root" and group "500eadmin".

I THINK in your case they should both be www-data because of this.
Owner of my countryflags folder is root, group is www-data
But, not knowing everything about your server and such it's hard to say.

You might want to ask your host for assistance to correct ownership and groups since this isn't something the add-on has control over.
 
I'm self-hosted and I think it is 95% that when I uploaded the files I was using the root FTP account, yes. VPS was set up in March with a scratch XF install.

Thanks for the input/assistance.
 
I Just installed and I can only see my flag and the flag of one other Admin. Is there someone here that can log into my site to see what is up ? I am not able to PM Snog. I followed instructions in the Readme file.
 
I Just installed and I can only see my flag and the flag of one other Admin. Is there someone here that can log into my site to see what is up ? I am not able to PM Snog.
Flags will apear once a user logs in. The addon has no records of "before".
 
so, if the user logs out, then the flag goes away too ? I was hoping for a permanent solution. Once a member registers, then his / her flag will always carry with them on any post past or present.
 
so, if the user logs out, then the flag goes away too ?
No, it stays.
Just when you install the addon for the first time nobody will have a flag displayed. The flags start appearing after users log in, then the addon has a record and can display a flag. The flags stay forever, even if they log out. Unless a) you uninstall/disable the addon or b) the user decides to turn it off in his settings.
 
Was working fine in XF2.
I removed the add-on, then upgraded from XF2 to XF2.1.
Now when I try to install the add-on again, I have this error when I click on "install".
Any ideas?

Code:
ErrorException: [E_WARNING] file_put_contents(/usr/local/lsws/sites/xxxxxx/public_html/data/countryflags/cloudflare_cookie.txt): failed to open stream: No such file or directory in src/vendor/guzzlehttp/guzzle/src/Cookie/FileCookieJar.php at line 59
[LIST=1]
[*]XF::handlePhpError()
[*]file_put_contents() in src/vendor/guzzlehttp/guzzle/src/Cookie/FileCookieJar.php at line 59
[*]GuzzleHttp\Cookie\FileCookieJar->save() in src/vendor/guzzlehttp/guzzle/src/Cookie/FileCookieJar.php at line 39
[*]GuzzleHttp\Cookie\FileCookieJar->__destruct() in src/addons/Snog/Flags/Setup.php at line 95
[*]Snog\Flags\Setup->checkRequirements() in src/XF/AddOn/AddOn.php at line 444
[*]XF\AddOn\AddOn->checkRequirements() in src/XF/Admin/Controller/AddOn.php at line 771
[*]XF\Admin\Controller\AddOn->getAddOnWarningsAndErrors() in src/XF/Admin/Controller/AddOn.php at line 366
[*]XF\Admin\Controller\AddOn->actionInstall() in src/XF/Mvc/Dispatcher.php at line 321
[*]XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 248
[*]XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 100
[*]XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 50
[*]XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2177
[*]XF\App->run() in src/XF.php at line 390
[*]XF::runApp() in admin.php at line 13
[/LIST]
 
I tried making these changes but it didn't change the problem.


Setup.php
Code:
$dataDir = FILE::canonicalizePath(\XF::app()->config('externalDataPath') . '/countryflags');
Changed to this:
Code:
$dataDir = FILE::canonicalizePath(\XF::app()->config('externalDataPath') . DIRECTORY_SEPARATOR . 'countryflags');

Maxmind.php
Code:
$cookiefile = $dataDir . '/cloudflare_cookie.txt';
Changed to this:
Code:
$cookiefile = $dataDir . '/cloudflare_cookie.txt';$cookiefile = $dataDir . DIRECTORY_SEPARATOR . 'cloudflare_cookie.txt';
 
What's in src/vendor/guzzlehttp/guzzle/src/Cookie/FileCookieJar.php at line 59?

Paste the line here.
 
Was working fine in XF2.
I removed the add-on, then upgraded from XF2 to XF2.1.
Now when I try to install the add-on again, I have this error when I click on "install".
Any ideas?

Code:
ErrorException: [E_WARNING] file_put_contents(/usr/local/lsws/sites/xxxxxx/public_html/data/countryflags/cloudflare_cookie.txt): failed to open stream: No such file or directory in src/vendor/guzzlehttp/guzzle/src/Cookie/FileCookieJar.php at line 59
[LIST=1]
[*]XF::handlePhpError()
[*]file_put_contents() in src/vendor/guzzlehttp/guzzle/src/Cookie/FileCookieJar.php at line 59
[*]GuzzleHttp\Cookie\FileCookieJar->save() in src/vendor/guzzlehttp/guzzle/src/Cookie/FileCookieJar.php at line 39
[*]GuzzleHttp\Cookie\FileCookieJar->__destruct() in src/addons/Snog/Flags/Setup.php at line 95
[*]Snog\Flags\Setup->checkRequirements() in src/XF/AddOn/AddOn.php at line 444
[*]XF\AddOn\AddOn->checkRequirements() in src/XF/Admin/Controller/AddOn.php at line 771
[*]XF\Admin\Controller\AddOn->getAddOnWarningsAndErrors() in src/XF/Admin/Controller/AddOn.php at line 366
[*]XF\Admin\Controller\AddOn->actionInstall() in src/XF/Mvc/Dispatcher.php at line 321
[*]XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line 248
[*]XF\Mvc\Dispatcher->dispatchFromMatch() in src/XF/Mvc/Dispatcher.php at line 100
[*]XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line 50
[*]XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2177
[*]XF\App->run() in src/XF.php at line 390
[*]XF::runApp() in admin.php at line 13
[/LIST]
That is implying that the system is unable to write the file to it's proper folder. There's no reason that error should happen on a Linux system. Unless something is preventing the file from being written, or is preventing the system from accessing MaxMind.

If you changed servers before you upgraded, try deleting the data/countryflags folder. It may be owned by a different user than what your PHP is running as now.

Or, if the data/countryflags folder doesn't exist, try creating it and giving world write permissions (777) to it.

And FYI, there was no reason to remove the add-on before upgrading XenForo. You lost all of the flag data for users by doing so. ;)
I tried making these changes but it didn't change the problem.


Setup.php
Code:
$dataDir = FILE::canonicalizePath(\XF::app()->config('externalDataPath') . '/countryflags');
Changed to this:
Code:
$dataDir = FILE::canonicalizePath(\XF::app()->config('externalDataPath') . DIRECTORY_SEPARATOR . 'countryflags');

Maxmind.php
Code:
$cookiefile = $dataDir . '/cloudflare_cookie.txt';
Changed to this:
Code:
$cookiefile = $dataDir . '/cloudflare_cookie.txt';$cookiefile = $dataDir . DIRECTORY_SEPARATOR . 'cloudflare_cookie.txt';
That fix affects Windows servers only. It isn't needed on Linux servers (it would have no effect, and wouldn't change anything).
What's in src/vendor/guzzlehttp/guzzle/src/Cookie/FileCookieJar.php at line 59?

Paste the line here.
That line is a call to PHP's file_put_contents (the same as using fopen(), fwrite() and fclose() in sequence). It's not the cause or root of the problem.
 
Last edited:
Top Bottom