I'm trying to analyze the content of an uploaded file (which is supposed to be an image), in order to stop any malicious tampering. So, before processing, I want to detect if the file contains PHP code for instance.
$patern = "/<?php/" ;
$handle = fopen ($_FILES['image']['tmp_name'], "r");
if ($handle)
{
while (($buffer = fgets($handle, 4096)) !== false)
{
if ( preg_match ( $patern , $buffer ) );
{
echo "PHP files are forbidden";
}
}
if (!feof($handle))
{
echo "Error: fgets() failed\n";
}
fclose($handle);
}
After sending an image, the result is "PHP files are forbidden" echoed a 180 times.
Ok normal, it's in the loop, but there is not a single php pattern in mi pic ...
What's the problem ? The patern ? preg_match ? The handel ?
Thanks a lot.
Sorry,
The mistake is : syntax error : semicolon at the end of :
if ( preg_match ( $patern , $buffer ) );
Otherwise it works fine
Related
I'm trying to create a torrent without a tracker. I just want to send some GoPro footage to a friend of mine but I can't get it working.
I've created a torrent with nothing in the tracker field and set the torrent to public, private is unchecked. I sent myself the file to test downloading it on another computer.
I can't get it to work. I've opened my port, when I run the test, it says the port's open on both my laptop and desktop. I've got a static IP on the desktop which is where the torrent was created and is being shared, and I emailed it to myself. I'm running Transmission on both, but one is Windows and one is Mac.
Any ideas why I can't get it to work? DHT is enabled on both.
Transmission is not the best option for that i advice you to use mktorrent faster and more reliable all my time using it it never failed
but if you want to use transmission as a seeder or a uploader client you can use this php script and just edit it to save the torrent files in transmission watch folder or any folder that you want
<?php
define('ROOT_DIR', '/home');
define('SCAN_DIR', ROOT_DIR.'/scan');
define('COMPLETE_DIR', ROOT_DIR.'/complete');
define('TORRENT_DIR', ROOT_DIR.'/torrent');
define('ANNOUNCE_URL', 'YOUR-TRACKER-ANNOUNCE-AND-PASSKEY-HERE');
define('PIECE_SIZE', '21');
function move($source, $dest) {
$cmd = 'mv "'.$source.'" "'.$dest.'"';
exec($cmd, $output, $return_val);
if ($return_val == 0) return 1;
return 0;
}
function make_torrent($file_full, $new_dir, $file) {
$file = pathinfo($file_full, PATHINFO_BASENAME);
$move_file = $new_dir.'/'.$file;
$rez = move($file_full, $move_file);
if (!$rez) die('Cannot move file!');
$info = pathinfo($file);
$output = TORRENT_DIR.'/'.$info['basename'].'.torrent';
if (file_exists($output)) unlink($output);
$cmd = "mktorrent '$move_file' -o '$output'-l".PIECE_SIZE." -a ".ANNOUNCE_URL;
echo $cmd."<br /> <br /> \n \n";
exec($cmd);
if (file_exists($output)) return $output;
else die('Cannot make torrent!');
}
function scan_folder() {
$dir = SCAN_DIR;
$dir_done = COMPLETE_DIR;
if (!is_dir($dir_done))
{
$ok = mkdir($dir_done);
if (!$ok) die('Cannot create destination folder!');
}
$dh = opendir($dir);
while ( $file = readdir($dh) )
{
if ($file == '.' || $file == '..') continue;
$file_full = $dir.'/'.$file;
if ($file_full == COMPLETE_DIR) continue;
make_torrent($file_full, $dir_done, $file);
}
}
scan_folder();
?>
you can ignore the tracker lines or just delete them the script is more or less self explanatory if you need any help please ask away
iCODEiT 0UT
I have the following piece in my config file:
cgi.assign = ( ".sh" => "" )
$HTTP["url"] =~ "^/urlpath/" {
$HTTP["querystring"] =~ "cams=on" {
cgi.assign = ( "" => "/scriptpath/CamsOn" )
}
$HTTP["querystring"] =~ "cams=off" {
cgi.assign = ( "" => "/scriptpath/CamsOff" )
}
url.redirect = ( "^/urlpath/" => "http://somewebsite" )
}
I have the cgi module loaded:
server.modules = (
"mod_redirect",
"mod_access",
"mod_cgi",
"mod_accesslog" )
Now "CamsOn" and "CamsOff" are shebanged shell scripts. To be honest I had done this before and had it working but my server crashed and I lost my configs. For some reason I can't figure for the life of me how to get it working. I do the redirect so I don't have to actually create the "urlpath" page. The redirect works fine inside the $HTTP["url"] piece, and I've even tested the querystring portion by nesting a redirect inside that just takes it to google.com; urlpath/?cams=on sent me to google accordingly.
What am I doing wrong?
Update:
I was to get it to work using
$HTTP["url"] =~ "^/urlpath/" {
$HTTP["querystring"] =~ "cams=on" {
cgi.assign = ( "" => "/scriptpath/CamsOn" )
}
$HTTP["querystring"] =~ "cams=off" {
cgi.assign = ( "" => "/scriptpath/CamsOff" )
}
}
I'm thinking that the redirect was getting parsed first, so when the address changed, it no longer fit the URL and querystring comparisons. Can I change this? The idea is to make the urlpath dynamic and updated in the conf file dynamically. This is why I have the redirect send you to another address. This way I also don't need to do html editing or create additional folders.
What am I doing wrong?
a) did not make backups
b) did not make backups
c) did not make backups
d) did not look in your own stackoverflow post history
See Can't figure out how to receive http requests using lighttpd
If you want to reduce the number of places you edit in your config file, you can assign a value to a variable in lighttpd.conf and use the variable in lighttpd.conf. See var.* in
https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_Configuration
var.camsurlpath = "/urlpath/"
$HTTP["url"] =~ "^" + var.camsurlpath {
...
}
I'd like to know if it's possible to determine using Powershell if a TIFF file has several pages.
And if so, how can I do that?
Thanks.
whit something like this:
[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$a = [System.Drawing.Bitmap]::FromFile( "C:\PS\multipage_tif_example.tif" )
if ($a.GetFrameCount( [System.Drawing.Imaging.FrameDimension]::Page ) -gt 1 )
{ "Tiff is multi pages" }
else
{ "Tiff is single page" }
I did a lot of search for my problem but I did not get anything ..
in codeigniter when I use config files I do that :
my_config.php :
$config['my_title'] = ' My Title Here ' ;
$config['color'] = ' red ' ;
I can retrieve it like this :
$this->load->config('my_config', TRUE );
$data['my_title'] = $this->config->item('my_title', 'my_config');
My question is : How can I get the full array to deal with it ?
I want the $config as an array to do something like this :
foreach($config as $key=>$val){
$data[$key] = $val ;
}
so I do not have to write all my variables that in config file like this :
$data['my_title'] = $this->config->item('my_title', 'my_config');
$data['color'] = $this->config->item('color', 'my_config');
and so on ..
sorry for my broken English !
thanks in advance ;)
While this is undocumented, and might break in future releases, you can access the main config array by:
$config = $this->config->config;
$config=$this->load->config('my_config', TRUE );
$config = $this->config;
$my_config=$config->config['my_config'];
echo"<pre>";print_r($my_config);
It may help you..
If you get multidimentional array from config files in Codeigniter
then
In application/config/config.php
$config['name']='array_name';
In Model or Controller file
$variable = $this->config->item('name');
var_dump($variable);
I have a client who needs a website urgently, but I have no access to information such as the control panel.
PHP Version is 4.4 Which is a pain as I'm used to 5.
The first problem is I keep getting:
Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ')' in D:\hshome\*******\********\includes\functions.php on line 37
This is the function in question:
function read_rss($display=0,$url='') {
$doc = new DOMDocument();
$doc->load($url);
$itemArr = array();
foreach ($doc->getElementsByTagName('item') as $node) {
if ($display == 0) {
break;
}
$itemRSS = array(
'title'=>$node->getElementsByTagName('title')->item(0)->nodeValue,
'description'=>$node->getElementsByTagName('description')->item(0)->nodeValue,
'link'=>$node->getElementsByTagName('link')->item(0)->nodeValue);
array_push($itemArr, $itemRSS);
$display--;
}
return $itemArr;
}
And the line in question:
'title'=>$node->getElementsByTagName('title')->item(0)->nodeValue,
PHP4 does not support object dereferencing. So $obj->something()->something will not work. You need to do $tmp = $obj->something(); $tmp->something...
You can't do that in PHP 4.
Have to do something like
$nodes = $node->getElementsByTagName('title');
$item = $nodes->item(0);
$value = $item->nodeValue,
Try it and it will work.
You can't chain object calls in PHP 4. You're going to have to make each call separately to a variable and store it all.
$titleobj = $node->getElementsByTagName('title');
$itemobj = $titleobj->item(0);
$value = $itemobj->nodeValue;
...
'title'=>$value,
you'll have to do it on all those chained calls
As for .htaccess ... you need to talk to someone who controls the actual server. It sounds like .htaccess isn't allowed to change the setting you're trying to change.
You need to break down that line into individual variables. PHP 4 does not like -> following parentheses. Do this instead:
$title = $node->getElementsByTagName('title');
$title = $title->item(0);
$description = $node->getElementsByTagName('description');
$description = $description->item(0);
$link = $node->getElementsByTagName('link');
$link = $link->item(0);
$itemRSS = array(
'title'=>$title->nodeValue,
'description'=>$description->nodeValue,
'link'=>$link->nodeValue);
The two variable declarations for each may be redundant and condensed, I'm not sure how PHP4 will respond. You can try to condense them if you want.
DOMDocument is php 5 function.You cant use it.
you may need to use DOM XML (PHP 4) Functions