r4364 renderProgressBarImage(): add range check for parameter
authorDenis Ovsienko <infrastation@yandex.ru>
Thu, 17 Mar 2011 22:30:41 +0000 (22:30 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Thu, 17 Mar 2011 22:30:41 +0000 (22:30 +0000)
renderProgressBarError(): new function to output inline image
index.php: use above to handle errors

wwwroot/inc/solutions.php
wwwroot/index.php

index d92692eb52cfca2d33b6f795f134592fa402968b..14d89259a2a2940b4f9b8693b8bea9842ffb49bb 100644 (file)
@@ -147,6 +147,8 @@ function generateMiniRack ($rack_id)
 
 function renderProgressBarImage ($done)
 {
+       if ($done > 100)
+               throw new InvalidArgException ('done', $done);
        $img = @imagecreatetruecolor (100, 10);
        switch (isset ($_REQUEST['theme']) ? $_REQUEST['theme'] : 'rackspace')
        {
@@ -176,6 +178,21 @@ function renderProgressBarImage ($done)
        imagedestroy ($img);
 }
 
+function renderProgressBarError()
+{
+       header ('Content-type: image/png');
+       // 100x10, red on pink, "progr. bar error"
+       echo base64_decode
+       (
+               'iVBORw0KGgoAAAANSUhEUgAAAGQAAAAKCAYAAABCHPt+AAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A' .
+               '/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sDERYTJrBhF8sAAACvSURBVEjH' .
+               '7VdRDoAgCMXmQbz/qbhJfdnMQQiDTZ3vL6MHvEA03Yg3rIRSABBhV1xwMBXyp/JatFVYq7La1Hft' .
+               'N709xcXxWLqE4tbGr+GXdNDqw8STxSS0z9S695ZD+e05pXhHt8RRHqtebIdoRPASM2K+ePi18Gjz' .
+               'Yuwz7AKpM2cpmjPUVx3qf0OIqyLKvl+POMp6+R3Jy9oxnD4C0nsPiTrfb35viO2QiOF6foYKD57g' .
+               'f1uXQb2mAAAAAElFTkSuQmCC'
+       );
+}
+
 function renderFilePreview ($file_id)
 {
        if ($image = getFileCache ($file_id)) //Cache Hit
index f84d917bb652f7e40daa526d8f271ba0cfeb5870..13b8339cb7d00a88d2474095ad559e87f66cc01e 100644 (file)
@@ -85,11 +85,19 @@ try {
                # without a permission check, but only for authenticated users.
                require_once 'inc/init.php';
                require_once 'inc/solutions.php';
-               genericAssertion ('done', 'uint0');
-               // 'progressbar's never change, make browser cache the result
-               if (checkCachedResponse (0, CACHE_DURATION))
-                       break;
-               renderProgressBarImage ($_REQUEST['done']);
+               try
+               {
+                       genericAssertion ('done', 'uint0');
+                       // 'progressbar's never change, make browser cache the result
+                       if (checkCachedResponse (0, CACHE_DURATION))
+                               break;
+                       renderProgressBarImage ($_REQUEST['done']);
+               }
+               catch (Exception $e)
+               {
+                       ob_clean();
+                       renderProgressBarError();
+               }
                break;
        case 'ajax' == $_REQUEST['module']:
                require_once 'inc/ajax-interface.php';