Temporary fixes for php encoding library bugs ending with segfault.
[fa-stable.git] / includes / packages.inc
index f203a10168f257876e7328d67b9b90afe884885a..c3aa518cd3de40f0d305c77eb1a3a5248f74751e 100644 (file)
@@ -19,7 +19,8 @@ define('PUBKEY_PATH', $path_to_root);
 // FrontAccounting package class
 //
 class package extends gzip_file {
-       function package($filename, $basedir=null)
+
+       function __construct($filename, $basedir=null)
        {
                global $path_to_root;
 
@@ -30,7 +31,7 @@ class package extends gzip_file {
                        } else
                        mkdir($basedir);
                }
-               $this->archive($filename);
+               parent::__construct($filename);
                $this->set_options(array('basedir'=> $basedir));
                $this->options['type'] = "pkg";
        }
@@ -299,6 +300,10 @@ function get_pkg_or_list($type = null, $pkgname = null, $filter=array(), $outkey
                $sig = url_get_contents($repo.'/Release.sig');
                $data = file_get_contents($loclist);
                $cert = file_get_contents(PUBKEY_PATH.'/FA.pem');
+               if (!function_exists('openssl_verify')) {
+                       display_error(_("OpenSSL have to be available on your server to use extension repository system."));
+                       return null;
+               }       
                if (openssl_verify($data, $sig, $cert) <= 0) {
                        if ($refresh) {
                                if (!@unlink($loclist))
@@ -468,7 +473,8 @@ function get_languages_list()
                else
                        $pkgs[$l['package']] = array_merge($pkgs[$l['package']], $l);
        }
-       ksort($pkgs);
+       if ($pkgs)
+               ksort($pkgs);
        return $pkgs;
 }
 //---------------------------------------------------------------------------------------
@@ -531,7 +537,8 @@ function get_extensions_list($type = null)
 //             else
                        $pkgs[$ext['package']] = array_merge($pkgs[$ext['package']], $ext);
        }
-       ksort($pkgs);
+       if ($pkgs)
+               ksort($pkgs);
        return $pkgs;
 }
 //
@@ -558,8 +565,8 @@ function get_themes_list()
                }
        }
        // TODO: Add other themes from themes directory
-       
-       ksort($pkgs);
+       if ($pkgs)
+               ksort($pkgs);
        return $pkgs;
 }
 //---------------------------------------------------------------------------------------
@@ -592,7 +599,8 @@ function get_charts_list()
                else
                        $pkgs[$ext['package']] = array_merge($pkgs[$ext['package']], $ext);
        }
-       ksort($pkgs);
+       if ($pkgs)
+               ksort($pkgs);
        return $pkgs;
 }
 //---------------------------------------------------------------------------------------------
@@ -668,12 +676,6 @@ function install_extension($pkg_name)
                                'active' => @$pkg['DefaultStatus'] == 'active' ? true : false,
                                'path' => $pkg['InstallPath'],
                        );
-//                     if (isset($pkg['MenuTabs']))
-//                             $ext['tabs'] = $pkg['MenuTabs'];
-//                     if (isset($pkg['MenuEntries']))
-//                             $ext['entries'] = $pkg['MenuEntries'];
-//                     if (isset($pkg['AccessExtensions']))
-//                             $ext['acc_file'] = $pkg['AccessExtensions'];
                        if (isset($pkg['SqlScript']))
                                $ext['sql'] = $pkg['SqlScript'];
 
@@ -725,4 +727,21 @@ function get_package_info($pkg, $type=null, $filter=array(), $outkey=null, $down
        return get_pkg_or_list($type, $pkg, $filter, null, false);
 }
 
-?>
\ No newline at end of file
+/*
+       Check basic extension source compatibility.
+*/
+function check_src_ext_version($ext_v)
+{
+       global $src_version;
+
+       $compat_levels = 2;     // current policy is keeping compatibility on major version level.
+       $app = explode('.', substr($src_version, 0, strspn($src_version, "0123456789.")));
+       $pkg = explode('.', substr($ext_v, 0, strspn($ext_v, "0123456789.")));
+
+       for ($i=0; $i < min($compat_levels, count($app)); $i++)
+               if ($pkg[$i] < $app[$i])
+                       return false;
+
+       return true;
+}
+