Welcome Guest, Not a member yet? Register   Sign In
Verifier Library - 0.3
#1

[eluser]Pygon[/eluser]
In response to this thread: http://ellislab.com/forums/viewthread/74377/

I've created the following Verifier class.

Current version is 0.3

Changelog:
Version 0.3
-Fixed dependancies
-Added more accurate verification for Image_lib (actually checks that the library’s extension option (gd,gd2,imagemagik,netpbm is loaded)

Version 0.2
-Added extension checks ( check_has_extension() )
-Added extension dependancy ( check_dependancy(), check_all_dependancies() )
-Added get array of extensions=>versions ( get_extensions() )
-Fixed check_writeable()

Comments and suggestions are appreciated.

http://pastebin.com/f5f216e40
#2

[eluser]Pygon[/eluser]
TODO:

CI Library Dependancy Checker (library to check)
>> true | Missing Dependancies

Image Support Checker (gd,gd2,imagemagik)
>> specific type to check ? true | false
-or-
>> Array( extensions => array(name => version), types => array( image_types ) ) | false
Problem: Image types not available for imagemagik
#3

[eluser]Derek Allard[/eluser]
rock ON Pygon. Nice, thanks. When this gets finished up, I promise you we'll look at how we can best use this in CI.
#4

[eluser]wiredesignz[/eluser]
Just a note Pygon, you should remove your email address from your code or obfuscate it somehow, Google loves this forum and spammers love to use Google to find addy's.

Oops too late, its already been indexed. :lol:
#5

[eluser]Pygon[/eluser]
Derek:

Thanks, hopefully I'll get it built up relatively quickly.

wired:

I'm not terribly worried since it's mostly a junk box for CI forum replies, but thanks -- removed.
#6

[eluser]Seppo[/eluser]
Pygon: I like this project.

One bug, in the check_writeable method you forgot the $this-> =)
I'm gonna check for some CI required versions requirements and I'll post it.
#7

[eluser]Seppo[/eluser]
This is as much as I could do...
I have to use many native PHP functions instead of the library, because some loaded extensions, after phpversion() return FALSE... for example phpversion('xml') returns false (at least on my enviroment) so I had to use extension_loaded when I just needed to know that the extension is loaded, and didn't care about the version.

Code:
$this->load->library('verifier');
        $log_path = $this->config->item('log_path');
        if ($log_path == '')
        {
            $log_path = BASEPATH . 'logs/';
        }
        $cache_path = $this->config->item('cache_path');
        if ($cache_path == '')
        {
            $cache_path = BASEPATH . 'cache/';
        }
        echo '<pre>';
        echo 'Log messages: ' , $this->verifier->check_writable($log_path) ? 'Yes': 'No' , "\n";
        echo 'Cache: ' , $this->verifier->check_writable($cache_path) ? 'Yes': 'No' , "\n";
        echo "\n";
        echo 'Extend Loader class: ' , strtolower(get_parent_class('ci_base')) != 'ci_loader' ? 'Yes': 'No' , "\n";
        echo "\n";
        echo 'FTP: ' , extension_loaded('ftp') ? 'Yes': 'No' , "\n";
        echo 'FTP::chmod: ' , function_exists('ftp_chmod') ? 'Yes': 'No' , "\n";
        echo 'XML-RPC: ' , extension_loaded('xml') ? 'Yes': 'No' , "\n";
        echo 'ZIP: ' , extension_loaded('zlib') ? 'Yes': 'No' , "\n";
        
        echo "\n", 'EMAIL' , "\n";
        echo 'Native mail: ' , ini_get('sendmail_path') ? 'Yes': 'No' , "\n";
        echo 'SMTP mail: ' , 'Unknown' , "\n";
        echo 'Sendmail: ' , 'Unknown' , "\n";
        
        echo "\n", 'IMAGE MANIPULATION' , "\n";
        if (function_exists('gd_info'))
        {
            $gd_info = gd_info();
            preg_match('/\(([\d\.]+)/', $gd_info['GD Version'], $gd_data);
            $gd_version = $gd_data[1];
        }
        echo 'GD: ' , isset($gd_version) && version_compare($gd_version, '2.0', '<') ? 'Yes': 'No' , "\n";
        echo 'GD2: ' , isset($gd_version) && version_compare($gd_version, '2.0', '>=') ? 'Yes': 'No' , "\n";
        echo 'IMAGEMAGICK: ' , 'Unknown' , "\n";
        echo 'NETPBM: ' , 'Unknown' , "\n";
        
        echo "\n", 'DB CLIENT' , "\n";
        echo 'MSSQL: ' , extension_loaded('mssql') ? 'Yes': 'No' , "\n";
        echo 'MySQL: ' , extension_loaded('mysql') ? 'Yes': 'No' , "\n";
        echo 'MySQLi : ' , extension_loaded('mysqli') ? 'Yes': 'No' , "\n";
        echo 'ODBC: ' , extension_loaded('odbc') ? 'Yes': 'No' , "\n";
        echo 'OCI8: ' , extension_loaded('oci8') ? 'Yes': 'No' , "\n";
        echo 'POSTGRE: ' , extension_loaded('postgre') ? 'Yes': 'No' , "\n";
        echo 'SQLITE: ' , extension_loaded('sqlite') ? 'Yes': 'No' , "\n";
        echo "\n";
        echo 'Reserved controller methods:' , "\n";
        foreach (get_class_methods('Controller') as $m)
        {
            echo "\t" , $m , "\n";
        }
        echo '</pre>';
#8

[eluser]MadZad[/eluser]
Glad this had gotten some attention. I also started thinking about this a bit and believe there are two separate concerns requiring two different approaches.

First, find issues that will cause an outright failure when you try to fire up CodeIgniter (system/codeigniter/CodeIgniter.php). The write permissions on the logs directory fall in this category, and is what got me started on this journey. Any controller trying to use the Verifier class to check existence/permission can't work, because you'll never get to the controller - CodeIgniter.php will fail while loading classes. The check has to be after you've defined where the system directory is, and before getting to the class loading. So, I think this will be a system directory hack until it is deemed worthy (if ever) to be placed in a future CI release. Here's a not-too-dirty approach:

Require a new file before the last line of index.php:
Code:
require_once BASEPATH . 'codeigniter/Diagnostic' . EXT;
require_once BASEPATH . 'codeigniter/CodeIgniter' . EXT;
and add Diagnostic.php to your system/codeigniter directory:
Code:
&lt;?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Diagnostic checks for early show-stopping issues.
*
* Meant to be run before codeigniter/CodeIgniter.php (in the system
* directory) starts loading classes.
*
* Should only check for conditions that would cause CodeIgniter.php to
* outright fail.  Any other diagnostics belong after CI has fired up.
*/

  $diagnostic_preface = "Fatal configuration error before CodeIgniter was reached<br />\n";
  //needed BASEPATH to get here, so no need to test for existence of system folder
  if (!is_dir(APPPATH)) {
    exit ($diagnostic_preface . "Application folder does not exist: " . APPPATH);
  }
  $logdir = BASEPATH . "logs";
  if (!(is_dir($logdir) and is_writable($logdir))) {
    exit ($diagnostic_preface . "Log directory is not writable: " . $logdir);
  }
  $cachedir = BASEPATH . "cache";
  if (!(is_dir($cachedir)  and is_writable($cachedir))) {
    exit ($diagnostic_preface . "Cache directory is not writable: " . $cachedir);
  }
?&gt;
Lots of alternative approaches, including adding this code into system/codeigniter/CodeIgniter.php instead of a new file.

Now, this does place directory checking overhead into every single page load, which is obviously inefficient - but that should be minuscule compared to the rest of a page request's processing. I also thought was that it's good to have this in a separate file for readability/expansion ease, the location deserves to be "core", and you can always comment out the ''require_once'' in index.php when you're confident with the app. Exiting on failure is pretty draconian, but justified (imho) for fatal situations like this. So I see this approach as "OK", but would welcome better ideas.

The second kind of verification would be any Verifier checks that should/could be performed assuming CI itself is functional. That would be the code wonderfully supplied by Pygon and Seppo. I'm going to take on some expansion/packaging of that, and will hopefully be able to add some value. Testing help will be greatly appreciated, as I may accidentally tailor my code to our app setup instead of a normal CI install.
#9

[eluser]Tom Glover[/eluser]
Very Good idea, this would save dev's time in location faults in why there logs or cache is not being written. it would also reduce the number of cache and session related bugs reported.
#10

[eluser]Pygon[/eluser]
Finally had a little time again to play around on this:

-Added extension checks ( check_has_extension() )
-Added extension dependancy ( check_dependancy(), check_all_dependancies() )
-Added get array of extensions=>versions ( get_extensions() )
-Fixed check_writeable()

http://pastebin.com/f424243bc

please post comments/suggestions

Time test:

Code:
get_extensions();
check_all_dependancies();
0.000113 seconds

above including:
Code:
$this->load->library('verifier');
0.00213 seconds




Theme © iAndrew 2016 - Forum software by © MyBB