Could unlink(__FILE__) delete multiple files and folders? - php

There is a line of code in a plugin I've constructed that contains these lines:
if (time() > 1459382400) {
unlink(__DIR__ . '/specific-subfolder-name/specific-file.class.php');
unlink(__FILE__);
}
Is there any way either one of these commands could delete multiple files and folders?
If so, how would it happen?
Potentially relevant details:
1. I do not know the OS or web server (Windows, Linux, Mac, Apache, IIS, ???)
2. That timestamp is March 31, 2016 (this question is posted / the code ran March 25, 2016)
3. This code is not in any loop, recursion, or other mechanism that would have caused it to run multiple times.
4. This code lives in /wp-plugins/plugin-name/plugin-file.php. Files in root, as well as /wp-content/* and /wp-admin/* allegedly got vaped.

Related

require of a file with return value fails silently.

I have two simple files (+those generated and downloaded by composer)
I have a simple php file:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
require __DIR__ . '/vendor/composer/autoload_classmap.php';
echo 'OK';
where autoload_classmap.php is generated based on this composer.json:
{
"require-dev": {
"symplify/easy-coding-standard": "5.3.*"
},
"config": {
"optimize-autoloader": true
}
}
But php script fails on the line with require. There's no error, no data are returned. Browser shows only ERR_CONNECTION_RESET.
(specific package in composer is probably irrelevant, I picked it because it has quite a lot of dependencies)
The problem is in the size of the required file (maybe not in the absolute size of the file but number of rows in array that's being returned definitively plays a role), if I delete number of rows down to around 1600 (I wasn't able to determine exact number - length of individual rows probably factors in).
I think this problem isn't really connected to composer itself though when I tried to replace array of classes with much larger array of random long text it worked fine.
The problem is (most probably) platform dependent: I tried it on my server and it worked fine but when I run it locally on a machine using Windows + WAMPServer (tested on two different machines) through web browser it fails with aforementioned disconnect error. It fails both in Chrome and Edge.
I run Windows 10, PHP 7.2.12 (but tested with 7.3 as well), Apache 2.4.37
On the other hand, when running through CLI it again works fine - so I don't think there's problem with some specific setting in php. But again - probably, what do I know? :)
I tried to find reasons why require may silently fail but I wasn't able to find anything. And I'm out of ideas hot to get it working. Framework I use in my real app relies on requiring this file and for that reason I need to keep optimize-autoloader on false (simply because that way it'll generate much smaller file and require works)
Any ideas?
Thanks
Turns out apache logged this notice:
[mpm_winnt:notice] [pid 6696:tid 672] AH00428: Parent: child process 14924 exited with status 3221225725 -- Restarting.
which directed me to this solution: https://www.codexpedia.com/apache-server/parent-child-process-exited-with-status-3221225725-restarting-on-xamp-apache/
All I needed to do was to add this:
<IfModule mpm_winnt_module>
ThreadStackSize 8888888
</IfModule>
in the httpd.conf file.

Syntax difference between MAMP and Ubuntu Server

I have the following function to account for Sundays in business day calculations. It works on my test server which is MAMP running on a Mac. When I move the code to an Ubuntu server running LAMP, it stops working (manifested as the page not loading anything).
I can't work out why, and have tried all different combinations of single quotes and double quotes.
The function is:-
// function to account for Sundays, and public holidays. Add holiday dates in $holidayDays variable
function get_next_business_date($from, $days) {
$workingDays = [1, 2, 3, 4, 5, 6]; # date format = N (1 = Monday, ...)
$holidayDays = ["*-12-25","*-12-26", "*-01-01", "2014-12-24"]; # variable and fixed holidays
$from = new DateTime($from);
while ($days) {
$from->modify("+1 day");
if (!in_array($from->format('N'), $workingDays)) continue;
if (in_array($from->format('Y-m-d'), $holidayDays)) continue;
if (in_array($from->format('*-m-d'), $holidayDays)) continue;
$days--;
}
return $from->format("Y-m-d"); # or just return DateTime object
}
$today = date("Y-m-d", strtotime("today"));
$tomorrow = get_next_business_date("today", 1);
$twodays = get_next_business_date("today", 2);
$yesterday = date("Y-m-d", strtotime("yesterday"));
I'm lost as to why this could be.
you may have version changes between the machines.
on ubuntu, you can check the file /var/log/apache2/error.log
tail -f /var/log/apache2/error.log
to see what error was thrown.
To check for the current PHP version on your machine, you could use
php -v
from the command line (requires php5-cli module installed)
another way is to put a PHP file with:
<?php
phpinfo();
?>
in your web dir, and open it with your browser.
As per the responses in the various comments, this was a server version issue. The version of PHP on my test box was more recent than the version on the live.
If it's of any use, I am using MAMP on a Mac Mini as my test environment which had 5.5.3, and LAMP on an UBUNTU 12.04 server box which had 5.3. I didn't want to upgrade the Ubuntu version, just the PHP version and did so as per this http://phpave.com/upgrade-php-5-3-php-5-5-ubuntu-12-04-lts/
Things to be aware of (if you don't know) are that the default directory for your php code will change from /var/www to /var/www/html. You can either move your PHP to the /var/www/html folder or change the default folder as per the link above. I suspect that changing the default may have repercussions to future versions as they will be expecting code to reside in /var/www/html.
There will also be some permissions issues for that folder that you may wish to be aware of if you are copying into and creating sub folders.
Hope this is of use to someone.

PHP command line error : Timezone database is corrupt

My date.php is -
<?php
echo date('Y');
When I execute php -f date.php on my staging machine, I get error -
PHP Fatal error: date(): Timezone database is corrupt - this should *never* happen!
in /home/staging/test/date.php on line 2
But when I execute the same on my local / dev machine it works. Although on both staging and local machines, permissions on /etc/localtime and /usr/share/zoneinfo/ are the same.
But output of file /etc/localtime vary on both machines.
Local (php5.3.5) :
/etc/localtime: timezone data, version 2, 4 gmt time flags, 4 std time flags, no leap seconds, 4 transition times, 4 abbreviation chars
Staging (php5.3.10) :
/etc/localtime: timezone data, version 2, 1 gmt time flag, 1 std time flag, no leap seconds, no transition times, 1 abbreviation char
While trying to find what the issue is I found this link from SO. I am confused over the accepted answer. My apache user is not executing the script.
What seems to be the problem? How do I resolve this issue?
For various reasons, PHP ships with its own timezone database - it is possible to use the system TZDB by configuring the software differently at compile time.
The PHP timezonedb is implemented as C code (lots of defines) - hence you need to recompile PHP to get it working.
If your PHP interpreter is not explicitly configured to use the OS timezoneDB, then you really need to investigate why the executable is corrupt.
Please check permission of your timezone files.It might have changed when you have install some rpms.
change the permission to 655
Also check following files:
/usr
/lib
/share
/etc
My problem was that I was running php-fpm in chroot mode. I changed it to run without a chroot, and then the error went away.

running tex from php script

I've installed mactex on my macbook and configured apache + php + mysql.
So when I'm running texi2pdf from bash it works fine. But when I'm trying to run it from php script the next error occurs
Font T2A/cmr/m/n/10=larm1000 at 10.0pt not loadable: Metric (TFM) file not found.
The function is called as
exec("texi2pdf .... ")
$PATH var is OK.
I guess the problem with access to some files but I've set permission to all necessary files (including ~/Library/texlive) and all of them are successfully read with
exec("ls ... ")
or
exec("cat ...")
The problem is not with cyrillic fonts, all necessary packages are installed and as I've already said texi2pdf works fine from bash.
MacOSX 10.7
Apache/2.2.19 (Unix) DAV/2 PHP/5.3.6
TeX 3.1415926 (TeX Live 2011)
Problem solved.
As PHP script uses current directory (or DocumentRoot) to load and generate necessary tex fonts the home directory should be change to user home
putenv('HOME=/Users/username');
Are you tried to allow exec? It may be blocked as default.

Temp-Files in Symfony-Cache folder

I'm using Windows on some production machines (IIS with FastCGI-PHP). Since the update of one SF-Project to 1.3.x I notice some strange problems. The Server is "collecting" Temp-Files in the config-cache folder of the applications. They are named like con1718.tmp and always containing the autoload-config-cache. The tmp-files are not generated for every request but I have 1 or 2 new files every half an hour or so. If the application is running some days/months there are a lot of these Temp-Files (Megabytes of them).
Machine-Details: - Windows Server 2008 - IIS 7 - ZendServer? with PHP 5.2.11
Project with SF 1.3.3
Any ideas what the problem can be?
I checked out symfony 1.4 and saw this in the code:
// Hack from Agavi (http://trac.agavi.org/changeset/3979)
// With php < 5.2.6 on win32, renaming to an already existing file doesn't work, but copy does,
// so we simply assume that when rename() fails that we are on win32 and try to use copy()
if (!#rename($tmpFile, $cache))
{
if (copy($tmpFile, $cache))
{
unlink($tmpFile);
}
}
This piece of code should be in sfConfigCache.php on line 354, could you check you have this lines? If not, consider updating, or patching, and if yes, you could log $tmpFile before unlinking it, just to see if there is an attempt to unlink these files or not.
To add more information log, you should try this code instead:
if (!#rename($tmpFile, $cache))
{
sfContext::getInstance()->getLogger()->info('attempt to renaming ' . $tmpFile . ' failed, trying copy');
if (copy($tmpFile, $cache))
{
sfContext::getInstance()->getLogger()->info('copy successful, now unlinking ' . $tmpFile);
unlink($tmpFile);
}
else
{
sfContext::getInstance()->getLogger()->err('probem with copy for file '.$tmpFile);
}
}
'con1718.tmp' looks like a temporary file name generated with tempnam PHP function:
tempnam('c:/tmp', 'con'); // produces something like c:\\tmp\con1234.tmp
I used grep on symfony sources to find such calls but didn't find any tempnam() usage with 'con'. Maybe it's one of the plugins you're using?
Any chance you're running the Windows Cache Extension for PHP (Windows Cache Extension 1.1 for PHP 5.2 in Web Platform Installer 2.0)? I've noticed that while this package tries to ape the behaviour of APC PHP Accelerator that is widely used, it does consume a lot of resources and do some odd things, especially file writes in odd places. I've yet to mash symfony and it together, but will be doing so in the next few weeks. Otherwise, my specs match yours quite closely.
Not a full answer maybe, but if it is installed, how about disabling it and retrying?

Categories