Nix Composable Derivation Options - php

I'm trying to understand what options are available for me in my configuration.nix for particular programs, by searching the pkgs sub-folder of nixpkgs's source tree, picking out the module's definitions to understand the available options. However, I'm running into a troublesome case for PHP - it's a special derivation, a composable derivation. I'm not able to see what options I have available with PHP - something that would be tremendously helpful for enabling special modules like mcrypt, gd, etc. Any help with this would be greatly appreciated!

It took me a while to figure this out but the right way to use composeDerivation for setting the php package build features is this:
# config.nix
{
packageOverrides = pkgs: rec {
php = pkgs.php.merge {
cfg = {
imapSupport = false;
intlSupport = false;
fpmSupport = false;
};
};
};
}
This overrides the default values in cfg specified in php/default.nix (imapSupport, intlSupport and fpmSupport get turned off). You can either place that file in ~/.nixpkgs/config.nix to be active system-wide or use it in another nix file like so to customize the global nixpkgs:
pkgs = import <nixpkgs> { config = (import ./config.nix); };

Try tracking the file interactions from configuration.nix and also try to understand all those flags at first, the PHP file is an "startup engine" of some kind I doesn't seem to have any possible configuration options it is just used as a run switch of some type and read rows 234-236(PHP) it says it needs config
also the http://nixos.org/nixos/manual/sec-configuration-syntax.html#sec-nix-syntax-summary is showing very clearly the possibilities. I say again I'm not into that engine but I think everything further to configure is done with the NixOS admin commands, it will be easier for me to help you if you explain what exactly you need done.

Related

CKFinder 3 upgrade difficulty

I'm following the CKFinder 2 to 3 upgrade guide and it's not making much sense. In CKFinder 2, the PHP code provided could be used to generate the JS snippet with appropriate config and params, like this:
require_once 'ckfinder/core/ckfinder_php5.php';
$finder = new CKFinder() ;
$finder->SelectFunction = 'ShowFileInfo' ;
$finder->DisableThumbnailSelection = true;
$finder->RememberLastFolder = true;
$finder->Id = $name;
$finder->StartupFolderExpanded = true;
$finder->Width = $width;
$finder->Height = $height;
echo $finder->CreateHtml();
This code picks up the config and incorporates it into the generated JS.
In 3 this seems to have disappeared entirely - the upgrade guide describes the changes needed in config.php, but there is no indication of how this is ever used since there is no other PHP involved, and it says
It is no longer possible to enable CKFinder on a page from the PHP level
All that is shown is how to create the JS snippet, which does not contain any config, and so will use incorrect settings. There is no indication of how the config properties set in config.php ever get to the JS code - as far as I can see there is no connection at all and no mention of any other PHP files, even though some are provided but not documented.
This makes no sense - PHP can quite happily generate HTML and JS that is run on the page, which is all the old CreateHTML function did. I don't understand why there is no mention of this mechanism since it was how we were supposed to use CKFinder previously - it's as if the migration guide is for some unrelated package!
If I update the config file and use the default JS widget code as suggested, it breaks the page completely, altering the MIME output type so it does not get rendered as HTML and appends this error:
{"error":{"number":10,"message":"Invalid command."}}
The docs cover various fine details of what PHP config settings mean, but nowhere that I've found says how it's ever loaded, triggered or associated with the JS. How is this supposed to work?
Indeed the CKFinder 3 documentation was lacking some important information. We're gradually adding new articles there. Based on topics you mentioned I just added:
Explanation how PHP code that worked for CKFinder 2 can be refactored to plain JavaScript in CKFinder 3. Should look familiar ;)
A table with Configuration Options Migration - JavaScript Settings which should help you with discovering again options like rememberLastFolder

sending message out of a sandbox to a custom application

I got an application which uses flash for it's interfaces, and I want to extract information from this application, and parse/use it in my own application (which processes the data, stores the essentials in a mysqldb and so on).
The .swf files are written in AS2 and can be modded quite easily.
So my goal is to send information (really just information. Being able to send numbers (of a at least decent size) would enable me to implement my own protocol of encoding and partitioning) by any means, I am certainly not picky about the means.
Here is my current approach (not my own idea, credits to koreanrandom.org. I merely use their source to learn):
use DokanLib to mount a virtual filesystem (and implement the getFileInformation-handler)
use LoadVars inside the AS2-Environment with parameters like "../.logger/#encoded_information"
since getFileInformation gets the accessed filename as a parameter, I can decode it, put several ones back together (if they had to be splitted, windows does not seem to like filenames with several hundred characters length) and use the decoded data
However, my application causes bluescreens quite often (dont ask why. i got no clue, the bluescreen messages are always different) and the devs at koreanrandom.org dont like being asked too many questions, so i came to ask here for other means to pass information from a sandboxed flash-environment to a prepared listener.
I started thinking about weird stuff (ok, abusing a virtual filesystem & filenames as a means of transport for information might be weird too - but it is still a great idea imo) like provoking certain windows-functions to be called and work with global hooks, but i didnt grasp a serious plan yet.
The "usual" methods like accessing webservers via methods like this dont appear to work:
var target_mc = createEmptyMovieClip("target_mc", this.getNextHighestDepth());
loadVariables("http://127.0.0.1/Tools/indata.php", "target_mc", "GET");
(indata.php would have created a file, if it was accessed, but it didnt.)
XMLSocket doesnt work either, i tried the following code sample (using netcat -l on port 12345):
Logger.add("begin");
var theSocket:XMLSocket = new XMLSocket();
theSocket.onConnect = function(myStatus) {
if (myStatus) {
Logger.add("XMLSocket sucessfully connected")
} else {
Logger.add("XMLSocket NO CONNECTION");
}
};
theSocket.connect("127.0.0.1", 12345);
var myXML:XML = new XML();
var mySend = myXML.createElement("thenode");
mySend.attributes.myData = "someData";
myXML.appendChild(mySend);
theSocket.send(myXML);
Logger.add("socket sent");
doesnt work at all either, the output of the logger was just begin and socket sent
Annotation: the logger was created by the guys from koreanrandom.org and relies on their dokan implementation, which never caused a bluescreen for me. cant spot my mistake in my implementation though, so i started to look for other means of solving my problem.
EDIT: what the hell is wrong with your "quality messages system"? appearently it didnt like me using the tags "escaping" and/or "information".
hmm, hard to say, try sendAndLoad instead of loadVariables
example:
var result_lv:LoadVars = new LoadVars();
var send_lv:LoadVars = new LoadVars();
send_lv.variable1=value1;
send_lv.variable2=value2;
f=this;//zachytka
result_lv.onLoad = function(success:Boolean) {
if (success) {
trace("ok");
} else {
trace("error");
}
};
send_lv.sendAndLoad("http://127.0.0.1/Tools/indata.php", result_lv, "GET"); //you may also use POST
this should work. the reason it's not working may also be flash security settings. try either moving the stuff to a real server or open up the flash settings manager (there's an alternative online version too) and add the 127.0.0.1 to trusted domains and/or testing file location to the trusted locations (i use C:*)

Flattering a directory structure while renaming all of the files to represent their original paths

I'm looking into storing Zend Framework on Microsoft Azures Blob Storage. Azure Blob storage has a flat file system where as Zend Framework has a deeply nested structure.
I want to create a folder containing all Zend Framework files using the following naming convention / method.
eg: The Zend_Log_Writter class is stored at:
library/Zend/Log/Writer.php
In the new flat output folder the file would be named:
Zend.Log.Writter.php
I'll use any tool that will accomplish the job linux or windows. I could write a PHP script that would do this but I'm guessing there is a piece of Linux Foo out there that could accomplish what I'm after with a few linked commands.
If I'm reading this question correctly, it sounds like you're trying to map a file system to individual blobs in Windows Azure Storage. You'd need some type of in-between tier to map requested files to individual blobs (and php has a very robust SDK you can use for accessing blobs). One correction about blobs: it's not exactly flat: The URI would be https://mystorageaccount/containername/blobname. You have one native directory (container), and you can then simulate further levels with the technique Pekka provided a link to.
However: To me, this mapping sounds like it may have performance implications, as well as transaction implications.
As an alternative, why not mount an NTFS-formatted Cloud Drive in a Windows Azure page blob? Your drive can be up to 1TB, accessible via drive-letter. It's durable (meaning triple-replicated within the data center), and would let you then install pretty much anything to it (such as the file directory structure for Zend). Pretty easy to set up - maybe a dozen lines of code.
The one caveat to Cloud Drives: only one writer. You'd have to keep that in mind when scaling your web app to multiple instances. There are workarounds (such as having one Cloud Drive per instance), and taking advantage of caching (such as the new AppFabric Cache which recently went into production).
EDIT: Here's a great Cloud Drive sample by Maarten Balliauw, demonstrating the steps needed for creating/allocating/mounting a Cloud Drive.
I know how to do this in python. Here is an example. Test it on some dummy directory first just to make sure you're using it right.
import os
import shutil
directory = '/path/to/your/directory/'
for root, folder, files in os.walk(directory):
for file in files:
print(directory+'renamed/'+root.replace('/', '.')[1:]+'.'+file)
shutil.copy(root+'/'+file, directory+'renamed/'+root.replace('/', '.')[1:]+'.'+file)
Edit as to why I used python: I did try using the find command and the -exec option in Linux initially....but much cleaner and easier to understand this way. I'm guessing you could go with one uber awesome line at the bash shell. However not sure the extra time needed to try and figure that out is worth it being as this is basically only 4 lines of relevant code.
Try this code. It makes use of StorageClient library from Microsoft.
namespace RenameBlobs
{
class Program
{
static void Main(string[] args)
{
CloudStorageAccount csa = CloudStorageAccount.DevelopmentStorageAccount;
string blobContainerName = "png1";
string oldDelimiter = "/";
string newDelimiter = ".";
CloudBlobClient blobClient = csa.CreateCloudBlobClient();
var blobContainer = blobClient.GetContainerReference(blobContainerName);
string blobContainerUriString = blobContainer.Uri.AbsoluteUri;
BlobRequestOptions blobRequestOptions = new BlobRequestOptions()
{
UseFlatBlobListing = true,
};
var blobsList = blobContainer.ListBlobs(blobRequestOptions);
foreach (var blob in blobsList)
{
var blockBlob = (CloudBlockBlob) blob;
var abc = blockBlob.Metadata;
blockBlob.FetchAttributes();
string blobName = blockBlob.Uri.AbsoluteUri;
blobName = blobName.Replace(blobContainerUriString, string.Empty);
if (blobName.StartsWith(oldDelimiter))
{
blobName = blobName.Substring(1);
}
if (blobName.Contains(oldDelimiter))
{
blobName = blobName.Replace(oldDelimiter, newDelimiter);
string newBlobUriString = string.Format("{0}/{1}", blobContainerUriString, blobName);
var cloudBlob = blobContainer.GetBlobReference(newBlobUriString);
cloudBlob.CopyFromBlob(blockBlob);
}
}
}
}
}
Let me know if you have any questions about this code.
Hope this helps.
Thanks

Count number of file requests triggered

Is it possible with PHP(5) or other Linux tools on an apache debian webserver to get the file requests a single http request made?
for performance reasons i would like to compare them with the cached "version" of my cake app.
non-cached that might be over 100 in some views.
cached only up to 10 (hopefully).
afaik there are 3 main file functions:
file_get_contents(), file() and the manual fopen() etc
but i cannot override them so i cannot place a logRequest() function in them.
is there any other way? attaching callbacks to functions? intercepting the file requests?
This suggestion does not seems intuitive, but you can take look on xdebug - function trace
Once you have xdebug installed and enabled, you can using all sort of configuration to save the profiling into a disk file and you can retrieve it later. Such as profiling results for different URL save into different disk file.
To monitoring file system related functions, you can do a parse of the text file(profiling results) and do a count of matchable functions (programmable or manually)
The way I would do it would be to create a custom function that wraps around the one you need.
function custom_file_get_contents($filename) {
$GLOBALS['file_get_contents_count']++;
return file_get_contents($filename);
}
And just replace all of your calls to file_get_contents with custom_file_get_contents. This is just a rudimentary example, but you get the idea.
Side note, if you want to count how many files your script has included (or required), see get_included_files()
You can use Xdebug to log all function calls
Those so-called "function traces" can be a help for when you are new to an application or when you are trying to figure out what exactly is going on when your application is running. The function traces can optionally also show the values of variables passed to the functions and methods, and also return values. In the default traces those two elements are not available.
http://www.xdebug.org/docs/execution_trace
Interesting question. I'd start with the stream_wrapper ... try to replace them with custom classes.
There is a pecl extention called ADB (Advanced PHP Debugger) that has tow functions that would be very useful for a cse like this - override_function() and rename_function(). You could do something like this:
rename_function('file_get_contents', 'file_get_contents_orig');
function file_get_contents($filename) {
logRequest();
return file_get_contents_orig($filename);
}
It looks like ADB is pretty easy to install, too.
See http://www.php.net/manual/en/book.apd.php

Use DLL in PHP?

I'm not going to lie. I'm not all the familiar with Windows and COM objects. That's why i'm here. First of all is it possible to access a DLL from within a PHP script running out of Apache? In my journey around the internets i believe that i have 2 options:
compile the dll as an extension for PHP. (i didn't make this dll)
access the DLL as a COM object which is sort of what it's designed for anyways.
So i'm taking the COM approach.
try{
$com = new COM('WHAT_GOES_HERE');
} catch(Exception $e){
echo 'error: ' . $e->getMessage(), "\n";
}
How do i go about finding out what would go into the initialization string? is there a com viewer type program i could/should be using to find this out? the documentation associated with this DLL doesn't seem to specify what strings i should be using to initialize but gets very in-depth into what streams are available, and all sorts of fun stuff. just gotta past this initial hump. Please help!
WHAT_GOES_HERE is the ProgID, Class ID or Moniker registered on the Operating System.
Each of these can change for the same DLL registered on different machines. There are several ways to find what's the ProgID/CLSID/Moniker of a registered dll. You can search the web for "dll debugger", "dll export", "dll inspect" and you'll see several solutions, and also ways to show what functions the dll export so you can use them.
The easiest way, you can just register the dll with Regsvr32.exe and search Window's register with regedit.exe for the dll's name, you might need to search several times until you find the key under \HKEY_CLASSES_ROOT\, which is the ProgID.
The command dcomcnfg.exe shows a lot of information about COM objects.
If you have Visual Studio, the OLE/COM Object Viewer (oleview.exe) might be useful.
You can run dll functions (from dlls which are not php extensions) with winbinder.
http://winbinder.org/
Using it is simple. You have to download php_winbinder.dll and include it in php.ini as an extension.
In the php script you have to use something similar:
function callDll($func, $param = "")
{
static $dll = null;
static $funcAddr = null;
if ($dll === null)
{
$dll = wb_load_library(<DLL PATH AND FILENAME>);
}
$funcAddr = wb_get_function_address($func, $dll);
if ($param != "")
{
return wb_call_function($funcAddr,array(mb_convert_encoding($param,"UTF-16LE")));
}
else
{
return wb_call_function($funcAddr);
}
}
You can simply develop a wrapper around your main dll and use this wrapper as an extension in your PHP. Some free tools like SWIG can generate this wrapper for you automatically by getting the header of your dll functions. I myself use this approach and it was easy and reliable.
With PHP>=7.4.0's new FFI/Foreign Function Interface (which didn't exist yet when this question was posted), this is now easier than ever before! For example, to call the GetCurrentProcessId(); function from kernel32.dll:
<?php
declare(strict_types=1);
$ffi = FFI::cdef(
'unsigned long GetCurrentProcessId(void);',
"C:\\windows\\system32\\kernel32.dll"
);
var_dump($ffi->GetCurrentProcessId());
outputs
C:\PHP>php test.php
int(24200)
:)

Categories