public function Run()
 {
     //--
     $op = $this->RequestVarGet('op', '', 'string');
     //--
     switch ((string) $op) {
         case 'ckeditor':
         default:
             //--
             $this->PageViewSetCfg('template-file', 'template-modal.htm');
             $main = '<h1>Advanced WYSIWYG EDITOR</h1>';
             $main .= SmartComponents::js_init_away_page();
             $main .= SmartComponents::js_init_editarea();
             // codemirror is optional for CKEditor, but if found, will use it ;)
             $main .= \SmartModExtLib\JsComponents\ExtraJsComponents::js_init_html_area();
             $main .= \SmartModExtLib\JsComponents\ExtraJsComponents::js_draw_html_area('test_html_area', 'test_html_area', '', '920px', '470px', true);
             $main .= '<button class="ux-button" onClick="alert($(\'#test_html_area\').val());">Get HTML Source</button>';
             //--
             break;
     }
     //end switch
     //--
     //--
     $this->PageViewSetVars(array('title' => 'Test Mod Js Components', 'main' => $main));
     //--
 }
 /**
  * Displays the SQLite Errors and HALT EXECUTION (This have to be a FATAL ERROR as it occur when a FATAL SQLite ERROR happens or when a Query Syntax is malformed)
  * PRIVATE
  *
  * @return :: HALT EXECUTION WITH ERROR MESSAGE
  *
  */
 private static function error($db, $y_area, $y_error_message, $y_query, $y_params_or_title, $y_warning = '')
 {
     //--
     $def_warn = 'Execution Halted !';
     $y_warning = (string) trim((string) $y_warning);
     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
         $width = 750;
         $the_area = (string) $y_area;
         if ((string) $y_warning == '') {
             $y_warning = (string) $def_warn;
         }
         //end if
         $the_error_message = 'Operation FAILED: ' . $def_warn . "\n" . $y_error_message;
         if (is_array($y_params_or_title)) {
             $the_params = '*** Params ***' . "\n" . print_r($y_params_or_title, 1);
         } elseif ((string) $y_params_or_title != '') {
             $the_params = '[ Reference Title ]: ' . $y_params_or_title;
         } else {
             $the_params = '- No Params or Reference Title -';
         }
         //end if
         $the_query_info = (string) trim((string) $y_query);
         if ((string) $the_query_info == '') {
             $the_query_info = '-';
             // query cannot e empty in this case (templating enforcement)
         }
         //end if
     } else {
         $width = 550;
         $the_area = '';
         $the_error_message = 'Operation FAILED: ' . $def_warn;
         $the_params = '';
         $the_query_info = '';
         // do not display query if not in debug mode ... this a security issue if displayed to public ;)
     }
     //end if else
     //--
     $out = SmartComponents::db_error_message('SQLite Client', 'SQLite', 'Embedded', 'SQL/DB', 'lib/core/img/db/sqlite_logo.png', $width, $the_area, $the_error_message, $the_params, $the_query_info);
     //--
     if (!$db instanceof SQLite3) {
         $the_conn = (string) $db;
     } else {
         $the_conn = (string) self::get_connection_id($db);
     }
     //end if else
     //--
     Smart::raise_error('#SQLITE-DB@' . $the_conn . '# :: Q# // SQLite Client :: ERROR :: ' . $y_area . "\n" . '*** Error-Message: ' . $y_error_message . "\n" . '*** Params / Title:' . "\n" . print_r($y_params_or_title, 1) . "\n" . '*** Query:' . "\n" . $y_query, $out);
     die('');
     // just in case
     //--
 }
示例#3
0
 public function Run()
 {
     //--
     require_once 'lib/core/lib_smart_test_suite.php';
     // test suite
     //--
     //--
     SmartSession::start();
     // start the session
     //--
     //--
     if (SmartPersistentCache::isActive()) {
         SmartPersistentCache::getKey('test-unit', 'version');
         // just test if redis re-uses the connection ...
     }
     //end if
     //--
     //--
     $op = $this->RequestVarGet('op', 'testunit.main', 'string');
     //--
     switch ((string) $op) {
         case 'testunit.phpinfo':
             //--
             $this->PageViewSetCfg('rawpage', true);
             ob_start();
             phpinfo();
             $main = ob_get_contents();
             ob_end_clean();
             break;
         case 'testunit.captcha':
             //--
             $this->PageViewSetCfg('rawpage', 'yes');
             // should work both: true or 'yes'
             $this->PageViewSetCfg('rawmime', 'image/png');
             $this->PageViewSetCfg('rawdisp', 'inline');
             $main = SmartTestSuite::test_captcha('png');
             //--
             break;
         case 'testunit.post-form-by-ajax':
             //--
             sleep(1);
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::post__answer__by__ajax($this->RequestVarGet('tab'), $this->RequestVarGet('frm'));
             //--
             break;
         case 'testunit.strings-test':
             //--
             sleep(1);
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_strings();
             //--
             break;
         case 'testunit.crypto-test':
             //--
             sleep(1);
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_crypto();
             //--
             break;
         case 'testunit.filesys-test':
             //--
             sleep(1);
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_fs();
             //--
             break;
         case 'testunit.pgsql-server-test':
             //--
             sleep(1);
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_pgsqlserver();
             //--
             break;
         case 'testunit.redis-server-test':
             //--
             sleep(1);
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_redisserver();
             //--
             break;
         case 'testunit.json-sqlite3-smartgrid':
             //--
             $this->PageViewSetCfg('rawpage', true);
             //--
             $ofs = $this->RequestVarGet('ofs', 0, 'integer+');
             $sortby = $this->RequestVarGet('sortby', 'id', 'string');
             $sortdir = $this->RequestVarGet('sortdir', 'ASC', 'string');
             $sorttype = $this->RequestVarGet('sorttype', 'text', 'string');
             $src = $this->RequestVarGet('src', '', 'string');
             // filter var
             //--
             $main = SmartTestSuite::test_sqlite3_json_smartgrid($ofs, $sortby, $sortdir, $sorttype, $src);
             //--
             break;
         case 'testunit.html-editor':
             //--
             $this->PageViewSetCfg('template-file', 'template-modal.htm');
             $main = SmartComponents::js_init_away_page();
             $main .= SmartComponents::js_init_html_area();
             $main .= SmartComponents::js_draw_html_area('test_html_area', 'test_html_area', '', '920px', '500px');
             $main .= '<button class="ux-button" onClick="alert($(\'#test_html_area\').val());">Get HTML Source</button>';
             //--
             break;
         case 'testunit.code-editor':
             //--
             $this->PageViewSetCfg('template-file', 'template-modal.htm');
             $main = SmartComponents::js_init_away_page('The changes will be lost !');
             $main .= SmartComponents::js_init_editarea();
             $main .= SmartComponents::js_draw_editarea('test_code_editor', 'test_code_editor', '', 'html', true, '920px', '450px');
             //--
             break;
         case 'testunit.load-url-or-file':
             //--
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::load__url__or__file('http://www.unix-world.org');
             //--
             break;
         case 'testunit.barcodes-qrcode':
             //--
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_barcode2d_qrcode();
             //--
             break;
         case 'testunit.barcodes-semcode':
             //--
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_barcode2d_datamatrix();
             //--
             break;
         case 'testunit.barcodes-pdf417':
             //--
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_barcode2d_pdf417();
             //--
             break;
         case 'testunit.barcodes-code128':
             //--
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_barcode1d_128B();
             //--
             break;
         case 'testunit.barcodes-code93':
             //--
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_barcode1d_93();
             //--
             break;
         case 'testunit.barcodes-code39':
             //--
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_barcode1d_39();
             //--
             break;
         case 'testunit.barcodes-rm4kix':
             //--
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_barcode1d_kix();
             //--
             break;
         case 'testunit.charts-biz':
             //--
             $this->PageViewSetCfg('rawpage', true);
             $this->PageViewSetCfg('expires', 120);
             // cache expire test
             //--
             $chart = new SmartImgBizCharts('matrix', 'Marketing Chart', array('Chart 1' => array('red label' => array('x' => Smart::random_number(5, 7), 'y' => Smart::random_number(100, 120), 'z' => Smart::random_number(45, 75), 'color' => '#FF3300'), 'blue' => array('x' => Smart::random_number(100, 115), 'y' => Smart::random_number(200, 210), 'z' => Smart::random_number(20, 50), 'color' => '#003399'), 'green' => array('x' => Smart::random_number(150, 175), 'y' => Smart::random_number(250, 270), 'z' => Smart::random_number(2, 8), 'color' => '#33CC33', 'labelcolor' => '#11AA11'), 'yellow' => array('x' => Smart::random_number(400, 420), 'y' => Smart::random_number(70, 90), 'z' => Smart::random_number(50, 90), 'color' => '#FFCC00'), 'default' => array('x' => Smart::random_number(300, 325), 'y' => Smart::random_number(300, 320)))), 'png');
             $chart->width = 500;
             $chart->height = 500;
             $chart->axis_x_label = 'Relative Market Share';
             $chart->axis_y_label = 'Market Growth Rate';
             //--
             $this->PageViewSetCfg('rawmime', $chart->mime_header());
             $this->PageViewSetCfg('rawdisp', $chart->disposition_header());
             $main = $chart->generate();
             //--
             break;
         case 'testunit.charts-gfx':
             //--
             $this->PageViewSetCfg('rawpage', true);
             //--
             $showgraph2 = Smart::random_number(0, 1);
             $showgraphdepths = Smart::random_number(0, 1);
             $showtype = Smart::random_number(1, 6);
             switch ((string) $showtype) {
                 case 1:
                     $mode = 'vbars';
                     break;
                 case 2:
                     $mode = 'hbars';
                     break;
                 case 3:
                     $mode = 'dots';
                     break;
                 case 4:
                     $mode = 'lines';
                     break;
                 case 5:
                     $mode = 'pie';
                     break;
                 case 6:
                 default:
                     $mode = 'donut';
             }
             //end if
             //--
             $chart = new SmartImgGfxCharts($mode, "Type [" . $mode . "]", array(array('x' => "white", 'y' => Smart::random_number(10, 90), 'z' => Smart::random_number(10, 90), 'w' => 10, 'v' => '#ECECEC'), array('x' => "red", 'y' => 22.45, 'z' => Smart::random_number(10, 90), 'w' => 25, 'v' => '#FF3300'), array('x' => "blue", 'y' => Smart::random_number(10, 90), 'z' => Smart::random_number(10, 90), 'w' => 7, 'v' => '#003399'), array('x' => "yellow", 'y' => Smart::random_number(10, 90), 'z' => Smart::random_number(10, 90), 'w' => 17, 'v' => '#FFCC00'), array('x' => "green", 'y' => Smart::random_number(10, 90), 'z' => Smart::random_number(10, 90), 'w' => 31, 'v' => '#33CC33'), array('x' => "black", 'y' => Smart::random_number(10, 90), 'z' => Smart::random_number(10, 90), 'w' => 17, 'v' => '#333333')), 'png', $showgraph2, $showgraphdepths);
             $chart->axis_x = 'X-Axis';
             $chart->axis_y = 'Y-Axis';
             //--
             $this->PageViewSetCfg('rawmime', $chart->mime_header());
             $this->PageViewSetCfg('rawdisp', $chart->disposition_header());
             $main = $chart->generate();
             //--
             break;
         case 'testunit.ods':
             //--
             $this->PageViewSetCfg('rawpage', true);
             $oo = new SmartExportToOpenOffice();
             $this->PageViewSetCfg('rawmime', $oo->ODS_Mime_Header());
             $this->PageViewSetCfg('rawdisp', $oo->ODS_Disposition_Header('myfile.ods', 'attachment'));
             $main = $oo->ODS_SpreadSheet('A Table', array('<column 1>', 'column " 2', 'column & 3'), array('data 1.1', 'data 1.2', 1.3, 'data 2.1', 'data 2.2', 2.31), array('', '', 'decimal4'));
             //--
             break;
         case 'testunit.json-test':
             //--
             $mixed_data = ['Unicode Text' => '"Unicode78źź:ăĂîÎâÂșȘțȚşŞţŢグッド\'#@<tag>!$%^&*()-_=+' . "\r\n\t" . '</tag>', 'Numbers' => 1234567890.99, 'Boolean TRUE:' => true, 'Boolean FALSE:' => false];
             //--
             $main = '<h1> Json Test</h1>';
             $main .= '<pre style="background:#ECECEC; border:1px solid #CCCCCC; line-height:32px; padding:8px;">';
             $main .= '<b>Default (Unicode Unescaped) Json:</b>' . "\n" . Smart::json_encode($mixed_data) . "\n";
             $main .= '<hr>';
             $main .= '<b>Default (Unicode Unescaped) Json / Pretty Print:</b>' . "\n" . Smart::json_encode($mixed_data, true) . "\n";
             $main .= '<hr>';
             $main .= '<b>Unicode Escaped Json:</b>' . "\n" . Smart::json_encode($mixed_data, false, false) . "\n";
             $main .= '<hr>';
             $main .= '<b>Unicode Escaped Json / Pretty Print:</b>' . "\n" . Smart::json_encode($mixed_data, true, false) . "\n";
             $main .= '</pre>';
             //--
             break;
         case 'testunit.interractions':
             //--
             $this->PageViewSetCfg('template-file', 'template-modal.htm');
             $main = SmartTestSuite::test_interractions($this->RequestVarGet('mode'));
             //--
             break;
         case 'testunit.autocomplete':
             //--
             $src = $this->RequestVarGet('src', '', 'string');
             //--
             $this->PageViewSetCfg('rawpage', true);
             $main = SmartTestSuite::test_sqlite3_json_autocomplete($src);
             //--
             break;
         case 'testunit.main':
             //--
             $is_modal = false;
             if ($this->IfRequestModalPopup() or $this->IfRequestPrintable()) {
                 $is_modal = true;
                 $this->PageViewSetCfg('template-file', 'template-modal.htm');
             }
             //end if
             //--
             $main = SmartTestSuite::main_screen($this->RequestVarGet('tab'), $this->RequestVarGet('frm'), $this->RequestVarGet('testformdata'));
             //--
             if (!$is_modal) {
                 SmartTestSuite::test_load_libs();
                 // just for testing all libs
                 if ($this->IfDebug()) {
                     $this->SetDebugData('TestUnit.Main', 'Loading all staticload libs at once for test purposes ...');
                 }
                 //end if
             }
             //end if
             //--
             break;
         default:
             //--
             $this->PageViewSetCfg('error', 'Invalid TestUnit Operation ! ...');
             return 400;
             //--
     }
     //end switch
     //--
     //--
     $this->PageViewSetVars(array('title' => 'Test Suite', 'main' => $main));
     //--
 }
    public static function movie_player($y_url, $y_title, $y_movie, $y_type, $y_width = '720', $y_height = '404')
    {
        //--
        $player_title = (string) Smart::escape_html($y_title);
        //--
        //--
        if ((string) $y_url == '') {
            $y_url = SmartUtils::get_server_current_url();
        }
        //end if
        //--
        $player_movie = (string) $y_url . $y_movie;
        //--
        $tmp_movie_id = 'smartframework_movie_player_' . sha1($player_movie);
        //--
        //--
        $tmp_div_width = $y_width + 5;
        //--
        $tmp_bgcolor = '#222222';
        $tmp_color = '#FFFFFF';
        //--
        //--
        if ((string) $y_type == 'ogv' or (string) $y_type == 'webm' or (string) $y_type == 'mp4') {
            // {{{SYNC-MOVIE-TYPE}}}
            //--
            if ((string) $y_type == 'webm') {
                $tmp_vtype = 'type="video/webm; codecs=&quot;vp8.0, vorbis&quot;"';
            } else {
                $tmp_vtype = 'type="video/ogg; codecs=&quot;theora, vorbis&quot;"';
            }
            //end if else
            //--
            $html = <<<HTML_CODE
<div align="center" style="padding-top:4px;">
<div style="z-index:1; background-color:{$tmp_bgcolor}; padding:2px; width:725px;">
<!-- start HTML5 Open-Media Player v.120415 -->
<video id="{$tmp_movie_id}" width="{$y_width}" height="{$y_height}" controls="controls" autoplay="autoplay">
\t<source src="{$player_movie}" {$tmp_vtype}>
\tWARNING: Your browser does not support the HTML5 Video Tag.
</video>
<br>
<h2 style="color:{$tmp_color}">{$player_title}</h2>
</div>
<!-- end HTML5 Open-Media Player -->
</div>
</div>
<br>
HTML_CODE;
        } else {
            $html = SmartComponents::operation_notice('Invalid Media Type / Video: ' . Smart::escape_html((string) $y_type), '725px');
        }
        //end if else
        //--
        return $html;
        //--
    }
示例#5
0
/**
 * Function: Custom 503 Answer (can be customized on your needs ...)
 *
 * @access 		private
 * @internal
 *
 */
function custom_http_message_503_serviceunavailable($y_message, $y_extra_message = '')
{
    //--
    return SmartComponents::http_error_message('*Custom* 503 Service Unavailable', $y_message, $y_extra_message);
    //--
}
 public static function High_Load_Monitor()
 {
     //--
     if (is_array(self::$HighLoadMonitorStats)) {
         return (array) self::$HighLoadMonitorStats;
         // avoid re-run and serve from cache
     }
     //end if
     //--
     $tmp_sysload_avg = array();
     //--
     if (defined('SMART_FRAMEWORK_NETSERVER_MAXLOAD')) {
         $tmp_max_load = (int) SMART_FRAMEWORK_NETSERVER_MAXLOAD;
     } else {
         $tmp_max_load = 0;
     }
     //end if
     if ($tmp_max_load > 0) {
         // run only if set to a value > 0
         if (function_exists('sys_getloadavg')) {
             $tmp_sysload_avg = (array) @sys_getloadavg();
             $tmp_sysload_avg[0] = (int) $tmp_sysload_avg[0];
             if ($tmp_sysload_avg[0] > $tmp_max_load) {
                 // protect against system overload over max
                 if (!headers_sent()) {
                     http_response_code(503);
                 } else {
                     Smart::log_notice('#SMART-FRAMEWORK-HIGH-LOAD-PROTECT#' . "\n" . 'SmartFramework // Web :: System Overload Protection: The System is Too Busy ... Try Again Later. The Load Averages reached the maximum allowed value by current settings ... [' . $tmp_sysload_avg[0] . ' of ' . $tmp_max_load . ']');
                 }
                 //end if else
                 die(SmartComponents::http_message_503_serviceunavailable('<h1>503 Service Unavailable - Too busy, try again later</h1><br><b>SmartFramework // Web :: System Overload Protection</b><br>The Load Averages reached the maximum allowed value by current settings ...'));
             }
             //end if
         }
         //end if
     }
     //end if
     //--
     self::$HighLoadMonitorStats = (array) $tmp_sysload_avg;
     //--
     return (array) self::$HighLoadMonitorStats;
     //--
 }
示例#7
0
 public static final function Raise504Error($y_msg)
 {
     //--
     if (!headers_sent()) {
         http_response_code(504);
     } else {
         Smart::log_warning('Headers Already Sent before 504 ...');
     }
     //end if else
     die(SmartComponents::http_message_504_gatewaytimeout(Smart::escape_html((string) $y_msg)));
     //--
 }
 private static function print_log_runtime()
 {
     //--
     $log = '';
     //--
     $log .= '<div class="smartframework_debugbar_status smartframework_debugbar_status_head"><font size="4"><b>Client / Server :: RUNTIME Log</b></font></div>';
     //--
     $log .= '<div class="smartframework_debugbar_status smartframework_debugbar_status_highlight" style="width:450px;"><b>App Runtime - Powered by</b></div>';
     $log .= '<div class="smartframework_debugbar_inforow">' . SmartComponents::draw_powered_info('yes') . '</div>';
     //--
     if (SMART_FRAMEWORK_ADMIN_AREA === true) {
         $the_area = 'admin';
     } else {
         $the_area = 'index';
     }
     //end if else
     //--
     $arr = ['Server Runtime: Smart.Framework' => ['Smart.Framework Middleware Area' => $the_area, 'Smart.Framework Release / Tag / Branch' => SMART_FRAMEWORK_RELEASE_VERSION . ' / ' . SMART_FRAMEWORK_RELEASE_TAGVERSION . ' / ' . SMART_FRAMEWORK_VERSION, 'Smart.Framework Encoding: Internal / DB' => SMART_FRAMEWORK_CHARSET . ' / ' . SMART_FRAMEWORK_DBSQL_CHARSET], 'Server Runtime: PHP' => ['PHP OS' => (string) PHP_OS, 'PHP Version' => 'PHP ' . PHP_VERSION . ' / ' . @php_sapi_name(), 'PHP Locales: ' => (string) setlocale(LC_ALL, 0), 'PHP Encoding: Internal / MBString' => ini_get('default_charset') . ' / ' . @mb_internal_encoding(), 'PHP Memory' => (string) ini_get('memory_limit'), 'PHP Loaded Modules' => (string) strtolower(implode(', ', (array) @get_loaded_extensions()))], 'Server Domain Info' => ['Server Full URL' => SmartUtils::get_server_current_url(), 'Server Script' => SmartUtils::get_server_current_script(), 'Server IP' => SmartUtils::get_server_current_ip(), 'Server Port' => SmartUtils::get_server_current_port(), 'Server Protocol' => SmartUtils::get_server_current_protocol(), 'Server Path' => SmartUtils::get_server_current_path(), 'Server Domain' => SmartUtils::get_server_current_domain_name(), 'Server Base Domain' => SmartUtils::get_server_current_basedomain_name()], 'Client Runtime' => (string) $_SERVER['HTTP_USER_AGENT'] . ' # ' . SmartUtils::get_ip_client() . ' # ' . SmartUtils::get_ip_proxyclient()];
     //--
     foreach ($arr as $debug_key => $debug_val) {
         $log .= '<div class="smartframework_debugbar_status smartframework_debugbar_status_highlight" style="width:450px;"><b>' . Smart::escape_html($debug_key) . '</b></div>';
         if (is_array($debug_val)) {
             $log .= '<table cellspacing="0" cellpadding="2" width="100%">';
             foreach ($debug_val as $key => $val) {
                 $log .= '<tr valign="top"><td width="295"><div class="smartframework_debugbar_inforow"><b>' . Smart::escape_html($key) . '</b></div></td><td><div class="smartframework_debugbar_inforow">' . Smart::escape_html(self::print_value_by_type($val)) . '</div></td></tr>';
             }
             //end foreach
             $log .= '</table>';
         } else {
             $log .= '<div class="smartframework_debugbar_inforow">' . Smart::escape_html((string) $debug_val) . '</div>';
         }
         //end if else
     }
     //end while
     //--
     return $log;
     //--
 }
 /**
  * Displays the Redis Errors and HALT EXECUTION (This have to be a FATAL ERROR as it occur when a FATAL Redis ERROR happens or when Data Exchange fails)
  * PRIVATE
  *
  * @param BOOL $is_fatal :: TRUE / FALSE if the Error is Fatal or Not
  * @param STRING $y_area :: The Area
  * @param STRING $y_error_message :: The Error Message to Display
  * @param STRING $y_query :: The query
  * @param STRING $y_warning :: The Warning Title
  *
  * @return :: HALT EXECUTION WITH ERROR MESSAGE
  *
  */
 private function error($is_fatal, $y_area, $y_error_message, $y_query = '', $y_warning = '')
 {
     //--
     $this->err = true;
     // required, to halt driver
     //--
     $is_fatal = (bool) $is_fatal;
     //--
     if ($is_fatal !== false) {
         // FATAL ERROR
         //--
         $def_warn = 'Execution Halted !';
         $y_warning = (string) trim((string) $y_warning);
         if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
             $width = 750;
             $the_area = (string) $y_area;
             if ((string) $y_warning == '') {
                 $y_warning = (string) $def_warn;
             }
             //end if
             $the_error_message = 'Operation FAILED: ' . $def_warn . "\n" . $y_error_message;
             $the_params = '- ' . $this->description . ' -';
             $the_query_info = (string) $y_query;
             if ((string) $the_query_info == '') {
                 $the_query_info = '-';
                 // query cannot e empty in this case (templating enforcement)
             }
             //end if
         } else {
             $width = 550;
             $the_area = '';
             $the_error_message = 'Operation FAILED: ' . $def_warn;
             $the_params = '';
             $the_query_info = '';
             // do not display query if not in debug mode ... this a security issue if displayed to public ;)
         }
         //end if else
         //--
         $out = SmartComponents::db_error_message('Redis Client', 'Redis', 'Caching', 'Server', 'lib/core/img/db/redis_logo_trans.png', $width, $the_area, $the_error_message, $the_params, $the_query_info);
         //--
         Smart::raise_error('#REDIS@' . $this->socket . '# :: Q# // Redis Client :: ERROR :: ' . $y_area . "\n" . '*** Error-Message: ' . $y_error_message . "\n" . '*** Command:' . "\n" . $y_query, $out);
         die('');
         // just in case
         //--
     } else {
         // SILENT WARNING
         //--
         if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
             //--
             SmartFrameworkRegistry::setDebugMsg('db', 'redis|log', ['type' => 'metainfo', 'data' => 'Redis SILENT WARNING: ' . $y_area . "\n" . $y_query . "\n" . 'Error-Message: ' . $y_error_message . "\n" . 'The settings for this Redis instance allow just silent warnings on connection fail.' . "\n" . 'All next method calls to this Redis instance will be discarded silently ...']);
             //--
         }
         //end if
         //--
         Smart::log_warning('#REDIS@' . $this->socket . '# :: Q# // Redis :: WARNING :: ' . $y_area . "\n" . '*** Error-Message: ' . $y_error_message . "\n" . '*** Command:' . "\n" . $y_query);
         //--
     }
     //end if else
     //--
 }
示例#10
0
/**
 * Function: Custom 401 Answer (can be customized on your needs ...)
 *
 * @access 		private
 * @internal
 *
 */
function custom_http_message_401_unauthorized($y_message, $y_extra_message = '')
{
    //--
    return SmartComponents::http_error_message('*Custom* 401 Unauthorized', $y_message, $y_extra_message);
    //--
}
 public static function Authenticate($area)
 {
     //--
     global $configs;
     //--
     if (self::$authCompleted !== false) {
         http_response_code(500);
         die(SmartComponents::http_message_500_internalerror('App Boostrap Auth already loaded ...'));
     }
     //end if
     self::$authCompleted = true;
     //--
     switch ((string) $area) {
         case 'index':
             require 'modules/app/app-auth-index.inc.php';
             break;
         case 'admin':
             require 'modules/app/app-auth-admin.inc.php';
             break;
         default:
             $msg = 'Invalid Authentication Realm: ' . $area;
             Smart::raise_error('App Bootstrap / Authenticate: ' . $msg, 'App Bootstrap / Authenticate: ' . $msg);
             die('Invalid Auth Realm');
             // just in case
     }
     //end switch
     //--
 }
示例#12
0
/**
 * Function: Custom 504 Answer (can be customized on your needs ...)
 *
 * @access 		private
 * @internal
 *
 */
function custom_http_message_504_gatewaytimeout($y_message, $y_extra_message = '')
{
    //--
    return SmartComponents::http_error_message('*Custom* 504 Gateway Timeout', $y_message, $y_extra_message);
    //--
}
示例#13
0
/**
 * Function: Custom 400 Answer (can be customized on your needs ...)
 *
 * @access 		private
 * @internal
 *
 */
function custom_http_message_400_badrequest($y_message, $y_extra_message = '')
{
    //--
    return SmartComponents::http_error_message('*Custom* 400 Bad Request', $y_message, $y_extra_message);
    //--
}
示例#14
0
/**
 * Function: Custom 429 Answer (can be customized on your needs ...)
 *
 * @access 		private
 * @internal
 *
 */
function custom_http_message_429_toomanyrequests($y_message, $y_extra_message = '')
{
    //--
    return SmartComponents::http_error_message('*Custom* 429 Too Many Requests', $y_message, $y_extra_message);
    //--
}
    public static function test_fs()
    {
        //--
        if (SMART_FRAMEWORK_TESTUNIT_ALLOW_FS_TESTS !== true) {
            return SmartComponents::operation_notice('Test Unit File System Tests are DISABLED ...');
        }
        //end if
        //--
        //--
        $time = microtime(true);
        //--
        //--
        $err = '';
        $tests = array();
        //--
        //--
        if ((string) DIRECTORY_SEPARATOR != '\\') {
            // broken links do not work on Windows !
            $tests[] = '##### FileSystem OPERATIONS / TESTS - ALL: #####';
        } else {
            $tests[] = '##### FileSystem OPERATIONS / TESTS *** PARTIAL SUPPORT ONLY (BY PLATFORM) ***: #####';
        }
        //end if else
        //--
        //--
        $test_string = '#START#' . "\n" . 'グッド' . "\n" . 'SmartFramework/Test/FileSystem' . "\n" . time() . "\n" . SMART_FRAMEWORK_HTACCESS_NOINDEXING . SMART_FRAMEWORK_HTACCESS_FORBIDDEN . SMART_FRAMEWORK_HTACCESS_NOEXECUTION . "\n" . '#END#';
        $test_str_cksum = SmartHashCrypto::sha512($test_string);
        $long_prefixed = SmartFileSysUtils::prefixed_sha1_path(sha1(time()));
        $short_prefixed = SmartFileSysUtils::prefixed_uuid10_dir(Smart::uuid_10_seq());
        //--
        $the_base_folder = 'tmp/tests/';
        $the_sufx_folder = 'Folder1';
        $the_base_file = 'NORMAL-Write_123_@#.txt';
        //--
        $the_folder = $the_base_folder . $the_sufx_folder . '/';
        $the_copy_folder = $the_base_folder . 'folder2';
        $the_move_folder = $the_base_folder . 'FOLDER3';
        $the_extra_folder = $the_folder . 'extra/';
        $the_file = $the_folder . $the_base_file;
        //--
        $get_folder = SmartFileSysUtils::add_dir_last_slash(SmartFileSysUtils::get_dir_from_path($the_folder));
        $get_file = SmartFileSysUtils::get_file_name_from_path($the_file);
        $get_xfile = SmartFileSysUtils::get_noext_file_name_from_path($the_file);
        $get_ext = SmartFileSysUtils::get_file_extension_from_path($the_file);
        //--
        $the_copy_file = $the_file . '.copy.txt';
        $the_move_file = $the_extra_folder . $the_base_file . '.copy.moved.txt';
        $the_broken_link = $the_extra_folder . 'a-broken-link';
        $the_broken_dir_link = $the_extra_folder . 'a-broken-dir-link';
        $the_good_link = $the_extra_folder . 'a-good-link';
        $the_good_dir_link = $the_extra_folder . 'a-good-dir-link';
        //--
        //--
        $tests[] = 'INITIAL-FOLDER: ' . $get_folder;
        $tests[] = 'NEW-FOLDER: ' . $the_folder;
        $tests[] = 'NEW-FILE: ' . $the_file;
        //--
        //--
        if ((string) $err == '') {
            $the_test = 'CHECK TEST SAFE PATH NAME: DIR / FILE ...';
            $tests[] = $the_test;
            if ((string) Smart::safe_pathname((string) $get_folder) !== (string) $get_folder or (string) Smart::safe_pathname((string) $the_copy_file) !== (string) $the_copy_file) {
                $err = 'ERROR: SAFE PATH NAME TEST ... FAILED !!!';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'CHECK TEST ABSOLUTE / BACKWARD PATHS ...';
            $tests[] = $the_test;
            if (!SmartFileSysUtils::check_file_or_dir_name('/this/is/absolute', 'no') or SmartFileSysUtils::check_file_or_dir_name('/this/is/absolute') or SmartFileSysUtils::check_file_or_dir_name('/this/is/../backward/path')) {
                $err = 'ERROR: CHECK TEST ABSOLUTE / BACKWARD PATHS ... FAILED !!!';
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'CHECK EXTRACT FOLDER FROM PATH ...';
            $tests[] = $the_test;
            if ((string) $get_folder != SmartFileSysUtils::add_dir_last_slash(Smart::dir_name($the_folder))) {
                $err = 'ERROR: Path Extraction FAILED: Dir=' . $get_folder . ' ; DirName=' . SmartFileSysUtils::add_dir_last_slash(Smart::dir_name($the_folder));
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'CHECK EXTRACT FILE AND EXTENSION FROM PATH (1) ...';
            $tests[] = $the_test;
            if ((string) $get_folder . SmartFileSysUtils::add_dir_last_slash($the_sufx_folder) . $get_file != $the_file) {
                $err = 'ERROR :: Path Extraction FAILED: Re-Composed-File=' . $get_folder . SmartFileSysUtils::add_dir_last_slash($the_sufx_folder) . $get_file . ' ; File=' . $the_file;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'CHECK EXTRACT FILE AND EXTENSION FROM PATH (2) ...';
            $tests[] = $the_test;
            if ((string) $get_file != $get_xfile . '.' . $get_ext) {
                $err = 'ERROR :: Path Extraction FAILED: File=' . $get_file . ' ; XFile=' . $get_xfile . ' ; Ext=' . $get_ext;
            }
            //end if
        }
        //end if
        //--
        SmartFileSysUtils::raise_error_if_unsafe_path($the_folder);
        if ((string) $err == '') {
            $the_test = 'CHECK PATH NAME DIR: check_file_or_dir_name() : ' . $the_folder;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSysUtils::check_file_or_dir_name($the_folder);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        SmartFileSysUtils::raise_error_if_unsafe_path($the_file);
        if ((string) $err == '') {
            $the_test = 'CHECK PATH NAME FILE: check_file_or_dir_name() : ' . $the_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSysUtils::check_file_or_dir_name($the_file);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        //--
        //--
        if ((string) $err == '') {
            $parent_folder = SmartFileSysUtils::add_dir_last_slash('');
            $the_test = 'Check Add Dir Last (trailing) Slash: Empty Folder Name';
            $tests[] = $the_test;
            if ((string) $parent_folder != './') {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $parent_folder = SmartFileSysUtils::add_dir_last_slash('.');
            $the_test = 'Check Add Dir Last (trailing) Slash: Dot Folder Name: ' . $parent_folder;
            $tests[] = $the_test;
            if ((string) $parent_folder != './') {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $parent_folder = SmartFileSysUtils::add_dir_last_slash('./');
            $the_test = 'Check Add Dir Last (trailing) Slash: DotSlash Folder Name: ' . $parent_folder;
            $tests[] = $the_test;
            if ((string) $parent_folder != './') {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $parent_folder = SmartFileSysUtils::add_dir_last_slash(Smart::dir_name($the_base_folder));
            $the_test = 'Check Parent Dir Name with Add Dir Last (trailing) Slash: ' . $parent_folder . ' # from: ' . $the_base_folder;
            $tests[] = $the_test;
            if ((string) $parent_folder != 'tmp/') {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        //--
        //--
        if ((string) $err == '') {
            if (is_dir($get_folder)) {
                $the_test = 'DIR DELETE - INIT CLEANUP: dir_delete() + recursive: ' . $get_folder;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::dir_delete($the_base_folder, true);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            } else {
                $tests[] = 'DIR DELETE - INIT CLEANUP: Test Not Run (folder does not exists): ' . $get_folder;
            }
            //end if else
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'DIR CREATE RECURSIVE: dir_recursive_create() : ' . $the_folder . $long_prefixed . $short_prefixed;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::dir_recursive_create($the_folder . $long_prefixed . $short_prefixed);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'DIR CREATE NON-RECURSIVE: dir_create() : extra/ in : ' . $the_extra_folder;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::dir_recursive_create($the_extra_folder);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        //--
        if ((string) DIRECTORY_SEPARATOR != '\\') {
            // broken links do not work on Windows !
            if ((string) $err == '') {
                $the_test = 'CREATE BROKEN FILE LINK FOR DELETION (1): link_create() : as : ' . $the_broken_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::link_create('tmp/cache', $the_broken_link);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $the_test = 'DELETE BROKEN FILE LINK (1): delete() : as : ' . $the_broken_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::delete($the_broken_link);
                if ($result !== 1 || is_link($the_broken_link)) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $the_test = 'CREATE BROKEN FILE LINK FOR DELETION (2): link_create() : as : ' . $the_broken_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::link_create('tmp/index.html', $the_broken_link);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $the_test = 'DELETE BROKEN FILE LINK (2): dir_delete() : as : ' . $the_broken_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::dir_delete($the_broken_link);
                if ($result !== 1 || is_link($the_broken_link)) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $the_test = 'CREATE BROKEN FILE LINK: link_create() : as : ' . $the_broken_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::link_create('tmp/index.html', $the_broken_link);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $the_test = 'CREATE BROKEN DIR LINK: link_create() : as : ' . $the_broken_dir_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::link_create('tmp/', $the_broken_dir_link);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $the_test = 'CREATE A FILE LINK: link_create() : as : ' . $the_good_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::link_create(Smart::real_path('tmp/index.html'), $the_good_link);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $the_test = 'CREATE A DIR LINK: link_create() : as : ' . $the_good_dir_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::link_create(Smart::real_path('tmp/'), $the_good_dir_link);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'FILE WRITE with empty content: write() : ' . $the_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::write($the_file, '');
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'FILE WRITE: write() / before append : ' . $the_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::write($the_file, $test_string);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'FILE WRITE: write() +append : ' . $the_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::write($the_file, $test_string, 'a');
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'FILE READ / Append: read() Full Size: ' . $the_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::read($the_file);
            if ((string) SmartHashCrypto::sha512($result) != (string) SmartHashCrypto::sha512($test_string . $test_string)) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'FILE WRITE: re-write() : ' . $the_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::write($the_file, $test_string);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        //--
        if ((string) DIRECTORY_SEPARATOR != '\\') {
            // broken links do not work on Windows !
            if ((string) $err == '') {
                $the_test = 'FILE WRITE TO A BROKEN LINK: write() : ' . $the_broken_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::write($the_broken_link, $test_string);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $the_test = 'DELETE THE BROKEN LINK AFTER write() and RE-CREATE IT : ' . $the_broken_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::delete($the_broken_link);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $the_test = 'RE-CREATE BROKEN FILE LINK [AFTER WRITE]: link_create() : as : ' . $the_broken_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::link_create('tmp/index.html', $the_broken_link);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $the_test = 'FILE WRITE: write_if_not_exists() with Content Compare to a broken link : ' . $the_broken_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::write_if_not_exists($the_broken_link, $test_string, 'yes');
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $the_test = 'DELETE THE BROKEN LINK AFTER write_if_not_exists() and RE-CREATE IT : ' . $the_broken_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::delete($the_broken_link);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $the_test = 'RE-CREATE BROKEN FILE LINK [AFTER WRITE-IF-NOT-EXISTS]: link_create() : as : ' . $the_broken_link;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::link_create('tmp/index.html', $the_broken_link);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'FILE WRITE: write_if_not_exists() without Content Compare : ' . $the_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::write_if_not_exists($the_file, $test_string, 'no');
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'FILE READ: read() Full Size: ' . $the_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::read($the_file);
            if ((string) SmartHashCrypto::sha512($result) != (string) $test_str_cksum) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'FILE READ: read() Partial Size, First 10 bytes: ' . $the_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::read($the_file, 10);
            if ((string) sha1($result) != (string) sha1(substr($test_string, 0, 10))) {
                // here we read bytes so substr() not SmartUnicode::sub_str() should be used
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'FILE STATIC-READ: staticread() Full Size: ' . $the_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::staticread($the_file);
            if ((string) SmartHashCrypto::sha512($result) != (string) $test_str_cksum) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'FILE STATIC-READ: staticread() Partial Size, First 10 bytes: ' . $the_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::staticread($the_file, 10);
            if ((string) sha1($result) != (string) sha1(substr($test_string, 0, 10))) {
                // here we read bytes so substr() not SmartUnicode::sub_str() should be used
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'FILE COPY: copy() : ' . $the_file . ' to: ' . $the_copy_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::copy($the_file, $the_copy_file);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'FILE COPY with OVERWRITE: copy() : ' . $the_file . ' to: ' . $the_copy_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::copy($the_file, $the_copy_file, true);
            // overwrite destination file(s)
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'FILE RE-COPY (test should re-write the destination): copy() : ' . $the_file . ' to: ' . $the_move_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::copy($the_file, $the_move_file);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            } else {
                $the_test = 'FILE DELETE: delete() : ' . $the_move_file;
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::delete($the_move_file);
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'FILE RENAME/MOVE: rename() : ' . $the_copy_file . ' to: ' . $the_move_file;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::rename($the_copy_file, $the_move_file);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            if (is_dir('__development/')) {
                //--
                $the_test = 'RECURSIVE COPY (CLONE) DIR [DEVELOPMENT]: dir_copy() : ' . '__development/' . ' to: ' . $the_folder . '__development';
                $tests[] = $the_test;
                $result = 0;
                $result = SmartFileSystem::dir_copy('__development/', $the_folder . '__development');
                if ($result !== 1) {
                    $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
                }
                //end if
                //--
                if ((string) $err == '') {
                    $the_test = 'DIR COMPARE THE [DEVELOPMENT] SOURCE WITH [DEVELOPMENT] DESTINATION AFTER DIR COPY AND DIR MOVE:' . "\n" . 'compare_folders() : ' . '__development/' . ' with: ' . $the_folder . '__development/';
                    $tests[] = $the_test;
                    $arr_diff = array();
                    $arr_diff = SmartFileSystem::compare_folders('__development', $the_folder . '__development', true, true);
                    if (Smart::array_size($arr_diff) > 0) {
                        $err = 'ERROR :: ' . $the_test . ' #DIFFERENCES=' . print_r($arr_diff, 1);
                    }
                    //end if
                }
                //end if
                //--
            } else {
                $tests[] = 'RECURSIVE COPY (CLONE) DIR [DEVELOPMENT]: Test Not Run (Development environment not detected) ...';
            }
            //end if else
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'RECURSIVE COPY (CLONE) DIR: dir_copy() : ' . $the_folder . ' to: ' . $the_copy_folder;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::dir_copy($the_folder, $the_copy_folder);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'MOVE/RENAME DIR: dir_rename() : ' . $the_copy_folder . ' to: ' . $the_move_folder;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::dir_rename($the_copy_folder, $the_move_folder);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'DIR COMPARE THE SOURCE WITH DESTINATION AFTER DIR COPY AND DIR MOVE: ' . $the_folder . ' with: ' . $the_move_folder;
            $tests[] = $the_test;
            $arr_diff = array();
            $arr_diff = SmartFileSystem::compare_folders($the_folder, $the_move_folder, true, true);
            if (Smart::array_size($arr_diff) > 0) {
                $err = 'ERROR :: ' . $the_test . ' #DIFFERENCES=' . print_r($arr_diff, 1);
            }
            //end if
        }
        //end if
        //--
        if ((string) $err == '') {
            $the_test = 'DIR DELETE - SIMPLE: dir_delete() non-recursive: ' . $the_extra_folder;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::dir_delete($the_extra_folder, false);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        if ((string) $err == '') {
            $the_test = 'DIR DELETE - LAST CLEANUP: dir_delete() + recursive: ' . $get_folder;
            $tests[] = $the_test;
            $result = 0;
            $result = SmartFileSystem::dir_delete($the_base_folder, true);
            if ($result !== 1) {
                $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result;
            }
            //end if
        }
        //end if
        //--
        //--
        $time = 'TOTAL TIME was: ' . (microtime(true) - $time);
        //--
        //--
        $end_tests = '##### END TESTS ... ' . $time . ' sec. #####';
        //--
        //--
        if ((string) $err == '') {
            $img_sign = 'lib/core/img/sign_info.png';
            $img_check = 'lib/core/img/q_completed.png';
            $text_main = Smart::escape_js('<span style="color:#83B953;">Good ... Perfect &nbsp;&nbsp;&nbsp; :: &nbsp;&nbsp;&nbsp; グッド ... パーフェクト</span>');
            $text_info = Smart::escape_js('<h2><span style="color:#83B953;">All</span> the SmartFramework FS Operations <span style="color:#83B953;">Tests PASSED on PHP</span><hr></h2><span style="font-size:14px;">' . Smart::nl_2_br(Smart::escape_html(implode("\n" . '* ', $tests) . "\n" . $end_tests)) . '</span>');
        } else {
            $img_sign = 'lib/core/img/sign_error.png';
            $img_check = 'lib/core/img/q_warning.png';
            $text_main = Smart::escape_js('<span style="color:#FF5500;">An ERROR occured ... &nbsp;&nbsp;&nbsp; :: &nbsp;&nbsp;&nbsp; エラーが発生しました ...</span>');
            $text_info = Smart::escape_js('<h2><span style="color:#FF5500;">A test FAILED</span> when testing FS Operations.<span style="color:#FF5500;"><hr>FAILED Test Details</span>:</h2><br><h3>' . Smart::escape_html($tests[Smart::array_size($tests) - 1]) . '</h3><br><span style="font-size:14px;"><pre>' . Smart::escape_html($err) . '</pre></span>');
        }
        //end if else
        //--
        //--
        $html = <<<HTML
<h1>SmartFramework LibFileSystem Tests: DONE ... [ Time: {$time} sec. ]</h1>
<script type="text/javascript">
\tSmartJS_BrowserUtils.alert_Dialog(
\t\t'<img src="{$img_sign}" align="right"><h1>{$text_main}</h1><hr><span style="color:#333333;"><img src="{$img_check}" align="right">{$text_info}<br>',
\t\t'',
\t\t'FileSystem Operations Test Suite for SmartFramework: PHP',
\t\t'920',
\t\t'480'
\t);
</script>
HTML;
        //--
        //--
        return $html;
        //--
    }
示例#16
0
/**
 * Function: Custom 404 Answer (can be customized on your needs ...)
 *
 * @access 		private
 * @internal
 *
 */
function custom_http_message_404_notfound($y_message, $y_extra_message = '')
{
    //--
    return SmartComponents::http_error_message('*Custom* 404 Not Found', $y_message, $y_extra_message);
    //--
}
//	* ask for authentication and set if successful
//	* if not authenticated, display the login form
//======================================================
// This code will be loaded into the App Boostrap automatically, to provide the Authentication for the admin.php ...
// By default this code does not contain any classes or functions.
// If you include classes or functions here they must be called to run here as the app boostrap just include this file at runtime
//======================================================
//-------------------------------------------
// This file can be customized as you need.
//-------------------------------------------
// NOTICE: As this is just a sample will use a fixed authentication with:
// 		username = admin
// 		password = pass
// This sample can be extended to read the authentication from a database or to use session in combination with SmartAuth.
// The best way to integrate with framework's authentication is using the SmartAuth:: object.
//-------------------------------------------
// v.160219 / Sample Auth based on Basic HTTP Authentication (for Admin Area, overall)
if ((string) $_SERVER['PHP_AUTH_USER'] == 'admin' and (string) $_SERVER['PHP_AUTH_PW'] == 'pass') {
    //-- OK, loggen in
    SmartAuth::set_login_data((string) $_SERVER['PHP_AUTH_USER'], (string) $_SERVER['PHP_AUTH_USER'], '*****@*****.**', 'Test Admin', array('admin', 'superadmin'), 0, array('title' => 'Mr.', 'name_f' => 'Test', 'name_l' => 'Admin'), 'SMART-FRAMEWORK.TEST', 'HTTP-BASIC', (string) $_SERVER['PHP_AUTH_PW']);
    //--
} else {
    //-- NOT OK, display the Login Form and Exit
    header('WWW-Authenticate: Basic realm="Administration Area"');
    http_response_code(401);
    die(SmartComponents::http_message_401_unauthorized('Authorization Required<br>Login Failed. Either you supplied the wrong credentials or your browser doesn\'t understand how to supply the credentials required.'));
    //--
}
//end if
//-------------------------------------------
// end of php code
示例#18
0
/**
 * Function: Custom 502 Answer (can be customized on your needs ...)
 *
 * @access 		private
 * @internal
 *
 */
function custom_http_message_502_badgateway($y_message, $y_extra_message = '')
{
    //--
    return SmartComponents::http_error_message('*Custom* 502 Bad Gateway', $y_message, $y_extra_message);
    //--
}
 /**
  * Displays the MySQL Errors and HALT EXECUTION (This have to be a FATAL ERROR as it occur when a FATAL MySQLi ERROR happens or when a Query Syntax is malformed)
  * PRIVATE
  *
  * @return :: HALT EXECUTION WITH ERROR MESSAGE
  *
  */
 private static function error($y_connection_id, $y_area, $y_error_message, $y_query, $y_params_or_title, $y_warning = '')
 {
     //--
     $err_log = $y_area . "\n" . '*** Error-Message: ' . $y_error_message . "\n" . '*** Params / Title:' . "\n" . print_r($y_params_or_title, 1) . "\n" . '*** Query:' . "\n" . $y_query;
     //--
     if (defined('SMART_SOFTWARE_SQLDB_FATAL_ERR') and SMART_SOFTWARE_SQLDB_FATAL_ERR === false) {
         Smart::log_warning('#MYSQL-DB@' . $y_connection_id . '# :: Q# // MySQL :: WARNING :: ' . $err_log);
         throw new Exception('#MYSQL-DB@' . $y_connection_id . '# :: Q# // MySQL :: EXCEPTION :: ' . $y_area . "\n" . $y_error_message);
         return;
     }
     //end if
     //--
     $def_warn = 'Execution Halted !';
     $y_warning = (string) trim((string) $y_warning);
     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
         $width = 750;
         $the_area = (string) $y_area;
         if ((string) $y_warning == '') {
             $y_warning = (string) $def_warn;
         }
         //end if
         $the_error_message = 'Operation FAILED: ' . $def_warn . "\n" . $y_error_message;
         if (is_array($y_params_or_title)) {
             $the_params = '*** Params ***' . "\n" . print_r($y_params_or_title, 1);
         } elseif ((string) $y_params_or_title != '') {
             $the_params = '[ Reference Title ]: ' . $y_params_or_title;
         } else {
             $the_params = '- No Params or Reference Title -';
         }
         //end if
         $the_query_info = (string) trim((string) $y_query);
         if ((string) $the_query_info == '') {
             $the_query_info = '-';
             // query cannot e empty in this case (templating enforcement)
         }
         //end if
     } else {
         $width = 550;
         $the_area = '';
         $the_error_message = 'Operation FAILED: ' . $def_warn;
         $the_params = '';
         $the_query_info = '';
         // do not display query if not in debug mode ... this a security issue if displayed to public ;)
     }
     //end if else
     //--
     $out = SmartComponents::db_error_message('MySQLi Client', 'MySQL', 'SQL/DB', 'Server', 'modules/smart-extra-libs/img/mysql_logo_trans.png', $width, $the_area, $the_error_message, $the_params, $the_query_info);
     //--
     Smart::raise_error('#MYSQL-DB@' . $y_connection_id . '# :: Q# // MySQL :: ERROR :: ' . $err_log, $out);
     die('');
     // just in case
     //--
 }
 public static function Run()
 {
     //--
     global $configs;
     //--
     //==
     //--
     if (self::$MiddlewareCompleted !== false) {
         // avoid to execute more than 1 this middleware !
         self::Raise500Error('Middleware App Execution already completed ...');
         return;
     }
     //end if
     self::$MiddlewareCompleted = true;
     //--
     $the_midmark = '[A]';
     //--
     if (SMART_FRAMEWORK_ADMIN_AREA !== true) {
         Smart::raise_error('Admin Middleware ERROR: SMART_FRAMEWORK_ADMIN_AREA is not set to TRUE', 'Invalid Area / This middleware is designed for Admin area and requires to turn ON the Administration flag ...');
         return;
     }
     //end if
     //--
     if (!defined('SMART_APP_TEMPLATES_DIR')) {
         self::Raise500Error('The SMART_APP_TEMPLATES_DIR not defined ...');
         return;
     }
     //end if
     //--
     if (defined('SMART_APP_MODULE_AREA')) {
         self::Raise500Error('Smart App Area must NOT be Defined outside controllers ...');
         return;
     }
     //end if
     if (defined('SMART_APP_MODULE_AUTH')) {
         self::Raise500Error('Smart App Module Auth must NOT be Defined outside controllers ...');
         return;
     }
     //end if
     if (defined('SMART_APP_MODULE_REALM_AUTH')) {
         self::Raise500Error('Smart App Module Realm Auth must NOT be Defined outside controllers ...');
         return;
     }
     //end if
     if (defined('SMART_APP_MODULE_DIRECT_OUTPUT')) {
         self::Raise500Error('Smart App Module Direct Output must NOT be Defined outside controllers ...');
         return;
     }
     //end if
     //--
     //==
     //--
     $smartframeworkservice = '';
     // special operation
     if (SmartFrameworkRegistry::issetRequestVar('smartframeworkservice') === true) {
         $smartframeworkservice = (string) strtolower((string) SmartUnicode::utf8_to_iso((string) SmartFrameworkRegistry::getRequestVar('smartframeworkservice')));
         switch ((string) $smartframeworkservice) {
             case 'status':
             case 'debug':
                 break;
             default:
                 // invalid value
                 $smartframeworkservice = '';
         }
         //end switch
     }
     //end if
     //--
     //==
     //-- switch language by cookie (this needs to be before loading the app core)
     if (strlen(trim((string) $_COOKIE['SmartApp_ADM_LANGUAGE_SET'])) > 0) {
         SmartTextTranslations::setLanguage(trim((string) $_COOKIE['SmartApp_ADM_LANGUAGE_SET']));
     }
     //end if
     //-- switch language by print cookie (this needs to be before loading the app core and after language by cookie)
     if (SmartFrameworkRegistry::issetRequestVar((string) SMART_FRAMEWORK_URL_PARAM_PRINTABLE) === true) {
         if (strtolower((string) SmartFrameworkRegistry::getRequestVar((string) SMART_FRAMEWORK_URL_PARAM_PRINTABLE)) == strtolower((string) SMART_FRAMEWORK_URL_VALUE_ENABLED)) {
             if (strlen(trim((string) $_COOKIE['SmartApp_ADM_PRINT_LANGUAGE_SET'])) > 0) {
                 SmartTextTranslations::setLanguage(trim((string) $_COOKIE['SmartApp_ADM_PRINT_LANGUAGE_SET']));
             }
             //end if
         }
         //end if
     }
     //end if
     //--
     //== RAW OUTPUT FOR STATUS
     //--
     if ((string) $smartframeworkservice == 'status') {
         //--
         if (SMART_SOFTWARE_DISABLE_STATUS_POWERED === true) {
             $status_powered_info = '';
         } else {
             $status_powered_info = (string) SmartComponents::draw_powered_info('no');
         }
         //end if else
         //--
         self::HeadersNoCache();
         // headers: cache control, force no-cache
         echo SmartComponents::http_status_message('Smart.Framework :: Status :: [OK]', '<script type="text/javascript">setTimeout(function(){ self.location = self.location; }, 60000);</script><img src="lib/core/img/busy_bar.gif"><div><h1>' . date('Y-m-d H:i:s O') . ' // Service Ready :: ' . $the_midmark . '</h1></div>' . $status_powered_info . '<br>');
         //--
         return;
         // break stop
         //--
     }
     //end if
     //--
     //== OVERALL AUTHENTICATION BREAKPOINT
     //--
     SmartAppBootstrap::Authenticate('admin');
     // if the auth uses session it may start now
     //--
     //== RAW OUTPUT FOR DEBUG
     //--
     if ((string) $smartframeworkservice == 'debug') {
         //--
         if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
             self::HeadersNoCache();
             // headers: cache control, force no-cache
             $the_debug_cookie = trim((string) $_COOKIE['SmartFramework__DebugAdmID']);
             echo SmartDebugProfiler::print_debug_info('adm', $the_debug_cookie);
         } else {
             http_response_code(404);
             echo SmartComponents::http_message_404_notfound('No Debug service has been activated on this server ...');
         }
         //end if
         //--
         return;
         // break stop
         //--
     }
     //end if else
     //--
     //== LOAD THE MODULE (OR DEFAULT MODULE)
     //--
     $reserved_controller_names = ['php', 'html', 'stml', 'css', 'js', 'json', 'xml', 'rss', 'txt', 'csv', 'sql', 'png', 'gif', 'jpg', 'pdf', 'svg', 'zip', '7z', 'netarch'];
     // these are reserved extensions and cannot be used as controller names because they need to be used also with friendly URLs as the 2nd param if module is missing from URL page param
     //--
     $err404 = '';
     $arr = array();
     //--
     $page = (string) SmartUnicode::utf8_to_iso((string) SmartFrameworkRegistry::getRequestVar('page'));
     $page = trim(str_replace(array('/', '\\', ':', '?', '&', '=', '%'), array('', '', '', '', '', '', ''), $page));
     // fix for get as it automatically replaces . with _ (so, reverse), but also fix some invalid characters ...
     if ((string) $page == '') {
         $page = (string) $configs['app']['admin-home'];
     }
     //end if
     //--
     if (strpos($page, '.') !== false) {
         // page can be as module.controller / module.controller(.php|html|stml|css|js|json|xml|rss|txt|csv|sql|png|gif|jpg|pdf|svg|zip|7z|netarch)
         //--
         $arr = (array) explode('.', (string) $page, 3);
         // separe 1st and 2nd from the rest
         //--
         //#
         //#
         $arr[0] = trim(strtolower((string) $arr[0]));
         // module
         $arr[1] = trim(strtolower((string) $arr[1]));
         // controller
         //#
         //# Admin will NOT integrate with friendly URLs SMART_FRAMEWORK_SEMANTIC_URL_SKIP_MODULE
         //# that feature is just for Index
         //#
         //--
     } elseif ((string) $configs['app']['admin-default-module'] != '') {
         //--
         $arr[0] = trim(strtolower((string) $configs['app']['admin-default-module']));
         // get default module
         $arr[1] = trim(strtolower((string) $page));
         // controller
         //--
     } else {
         //--
         if ((string) $err404 == '') {
             $err404 = 'Invalid Page (Invalid URL Page Segments Syntax): ' . $page;
         }
         //end if
         //--
     }
     //end if else
     //--
     if ((string) $arr[0] == '' or (string) $arr[1] == '') {
         if ((string) $err404 == '') {
             $err404 = 'Invalid Page (Empty or Missing URL Page Segments): ' . $page;
         }
         //end if
     }
     //end if
     if (!preg_match('/^[a-z0-9_\\-]+$/', (string) $arr[0]) or !preg_match('/^[a-z0-9_\\-]+$/', (string) $arr[1])) {
         if ((string) $err404 == '') {
             $err404 = 'Invalid Page (Invalid Characters in the URL Page Segments): ' . $page;
         }
         //end if
     }
     //end if
     if (in_array((string) $arr[1], (array) $reserved_controller_names)) {
         if ((string) $err404 == '') {
             $err404 = 'Invalid Page (Reserved Page Controller Name): [' . $arr[1] . '] in: ' . $page;
         }
         //end if
     }
     //end if
     //--
     $the_controller_name = (string) $arr[0] . '.' . $arr[1];
     $the_path_to_module = Smart::safe_pathname(SmartFileSysUtils::add_dir_last_slash('modules/mod-' . Smart::safe_filename($arr[0])));
     $the_module = Smart::safe_pathname($the_path_to_module . Smart::safe_filename($arr[1]) . '.php');
     if (!is_file($the_module)) {
         if ((string) $err404 == '') {
             $err404 = 'Page does not exist: ' . $page;
         }
         //end if
     }
     //end if
     //--
     if ((string) $err404 != '') {
         self::Raise404Error((string) $err404);
         return;
     }
     //end if
     //--
     if (!SmartFileSysUtils::check_file_or_dir_name($the_path_to_module) or !SmartFileSysUtils::check_file_or_dir_name($the_module)) {
         self::Raise400Error('Insecure Module Access for Page: ' . $page);
         return;
     }
     //end if
     //--
     if (class_exists('SmartAppIndexController') or class_exists('SmartAppAdminController')) {
         self::Raise500Error('Module Class Runtimes must be defined only in modules ...');
         return;
     }
     //end if
     //--
     require (string) $the_module;
     //--
     if ((string) SMART_APP_MODULE_AREA !== 'ADMIN' and (string) SMART_APP_MODULE_AREA !== 'SHARED') {
         self::Raise403Error('Page Access Denied for Admin Area: ' . $page);
         return;
     }
     //end if
     if (defined('SMART_APP_MODULE_AUTH')) {
         if (SmartAuth::check_login() !== true) {
             self::Raise403Error('Page Access Denied ! No Authentication: ' . $page);
             return;
         }
         //end if
         if (defined('SMART_APP_MODULE_REALM_AUTH')) {
             if ((string) SmartAuth::get_login_realm() !== (string) SMART_APP_MODULE_REALM_AUTH) {
                 self::Raise403Error('Page Access Denied ! Invalid Login Realm: ' . $page);
                 return;
             }
             //end if
         }
         //end if
     }
     //end if
     //--
     if (!class_exists('SmartAppAdminController')) {
         self::Raise500Error('Invalid Module Class Runtime for Page: ' . $page);
         return;
     }
     //end if
     if (!is_subclass_of('SmartAppAdminController', 'SmartAbstractAppController')) {
         self::Raise500Error('Invalid Module Class Inheritance for Controller Page: ' . $page);
         return;
     }
     //end if
     //--
     //== PATHS
     //--
     $base_script = SmartUtils::get_server_current_script();
     $base_full_path = SmartUtils::get_server_current_path();
     $base_full_url = SmartUtils::get_server_current_url();
     //--
     //== RUN THE MODULE
     //--
     $appModule = new SmartAppAdminController($the_path_to_module, $base_script, $base_full_path, $base_full_url, $page, $the_controller_name);
     //--
     if (SMART_APP_MODULE_DIRECT_OUTPUT !== true) {
         ob_start();
     }
     //end if
     $appStatusCode = (int) $appModule->Run();
     $appModule->ShutDown();
     if (SMART_APP_MODULE_DIRECT_OUTPUT !== true) {
         $ctrl_output = ob_get_contents();
         ob_end_clean();
         if ((string) $ctrl_output != '') {
             Smart::log_warning('The middleware service ' . $the_midmark . ' detected an illegal output in the controller: ' . $page . "\n" . 'The result of this output is: ' . $ctrl_output);
         }
         //end if
         $ctrl_output = '';
     } else {
         return;
         // break stop after the controller has terminated the direct output
     }
     //end if else
     //--
     $appSettings = (array) $appModule->PageViewGetCfgs();
     //--
     //== CACHE CONTROL
     //--
     if ((int) $appSettings['expires'] > 0 and (string) SMART_FRAMEWORK_DEBUG_MODE != 'yes') {
         self::HeadersCacheExpire((int) $appSettings['expires'], (int) $appSettings['modified']);
         // headers: cache expiration control
     } else {
         self::HeadersNoCache();
         // headers: cache control, force no-cache
     }
     //end if else
     //--
     //== STATUS CODE
     //--
     switch ((int) $appStatusCode) {
         //-- client errors
         case 400:
             self::Raise400Error((string) $appSettings['error']);
             return;
             break;
         case 401:
             self::Raise401Error((string) $appSettings['error']);
             return;
             break;
         case 403:
             self::Raise403Error((string) $appSettings['error']);
             return;
             break;
         case 404:
             self::Raise404Error((string) $appSettings['error']);
             return;
             break;
         case 429:
             self::Raise429Error((string) $appSettings['error']);
             return;
             break;
             //-- server errors
         //-- server errors
         case 500:
             self::Raise500Error((string) $appSettings['error']);
             return;
             break;
         case 502:
             self::Raise502Error((string) $appSettings['error']);
             return;
             break;
         case 503:
             self::Raise503Error((string) $appSettings['error']);
             return;
             break;
         case 504:
             self::Raise504Error((string) $appSettings['error']);
             return;
             break;
             //-- extended 2xx statuses: NOTICE / WARNING / ERROR that can be used for REST / API
         //-- extended 2xx statuses: NOTICE / WARNING / ERROR that can be used for REST / API
         case 202:
             // NOTICE
             if (!headers_sent()) {
                 http_response_code(202);
                 // Accepted (this should be used only as an alternate SUCCESS code instead of 200 for NOTICES)
             } else {
                 Smart::log_warning('Headers Already Sent before 202 ...');
             }
             //end if else
             break;
         case 203:
             // WARNING
             if (!headers_sent()) {
                 http_response_code(203);
                 // Non-Authoritative Information (this should be used only as an alternate SUCCESS code instead of 200 for WARNINGS)
             } else {
                 Smart::log_warning('Headers Already Sent before 203 ...');
             }
             //end if else
             break;
         case 208:
             // ERROR
             if (!headers_sent()) {
                 http_response_code(208);
                 // Already Reported (this should be used only as an alternate SUCCESS code instead of 200 for ERRORS)
             } else {
                 Smart::log_warning('Headers Already Sent before 208 ...');
             }
             //end if else
             break;
             //-- DEFAULT: OK
         //-- DEFAULT: OK
         case 200:
         default:
             // any other codes not listed above are not supported and will be interpreted as 200
             // nothing to do here ...
     }
     //end switch
     //--
     //== PREPARE THE OUTPUT
     //--
     if (stripos((string) $configs['js']['popup-override-mobiles'], '<' . SmartUtils::get_os_browser_ip('os') . '>') !== false) {
         $configs['js']['popup-mode'] = 'popup';
         // particular os settings for mobiles
     }
     //end if
     //--
     $rawpage = '';
     if (isset($appSettings['rawpage'])) {
         $rawpage = strtolower((string) $appSettings['rawpage']);
         if ((string) $rawpage == 'yes') {
             $rawpage = 'yes';
             // standardize the value
         }
         //end if
     }
     //end if
     if ((string) $rawpage != 'yes') {
         $rawpage = '';
     }
     //end if
     //--
     $rawmime = '';
     if (isset($appSettings['rawmime'])) {
         $rawmime = (string) $appSettings['rawmime'];
         if ((string) $rawmime != '') {
             $rawmime = SmartValidator::validate_mime_type($rawmime);
         }
         //end if
     }
     //end if else
     //--
     $rawdisp = '';
     if (isset($appSettings['rawdisp'])) {
         $rawdisp = (string) $appSettings['rawdisp'];
         if ((string) $rawdisp != '') {
             $rawdisp = SmartValidator::validate_mime_disposition($rawdisp);
         }
         //end if
     }
     //end if else
     //--
     $appData = (array) $appModule->PageViewGetVars();
     //--
     $appData['base-path'] = (string) $base_full_path;
     $appData['base-url'] = (string) $base_full_url;
     //--
     //== REDIRECTION HANDLER (this can be set only explicit from Controllers)
     //--
     if ((string) $appSettings['redirect-url'] != '') {
         // expects a valid URL
         //--
         $the_redirect_link = '<a href="' . Smart::escape_html((string) $appSettings['redirect-url']) . '">' . Smart::escape_html((string) $appSettings['redirect-url']) . '</a>';
         //--
         if (headers_sent()) {
             Smart::log_warning('Headers Already Sent before Redirection: [' . $appStatusCode . '] ; URL: ' . $appSettings['redirect-url']);
             self::Raise500Error('The app failed to Redirect to: ' . $the_redirect_link);
             return;
         }
         //end if
         switch ((int) $appStatusCode) {
             case 301:
                 http_response_code(301);
                 $the_redirect_text = 'Moved Permanently';
                 // permanent redirect for HTTP 1.0 / HTTP 1.1
                 break;
             case 302:
             default:
                 // any other code will be interpreted as 302 (the default redirection in PHP)
                 http_response_code(302);
                 $the_redirect_text = 'Found';
                 // temporary redirect for HTTP 1.0 / HTTP 1.1
                 break;
         }
         //end switch
         header('Location: ' . SmartFrameworkSecurity::FilterUnsafeString((string) $appSettings['redirect-url']));
         echo '<h1>' . Smart::escape_html($the_redirect_text) . '</h1>' . '<br>' . 'If the page redirection fails, click on the below link:' . '<br>' . $the_redirect_link;
         return;
         // break stop
     }
     //end if
     //--
     //== DOWNLOADS HANDLER (downloads can be set only explicit from Controllers)
     //--
     if ((string) $appSettings['download-packet'] != '' and (string) $appSettings['download-key'] != '') {
         // expects an encrypted data packet and a key
         $dwl_result = self::DownloadsHandler((string) $appSettings['download-packet'], (string) $appSettings['download-key']);
         if ((string) $dwl_result != '') {
             Smart::log_info('File Download - Client: ' . SmartUtils::get_visitor_signature(), (string) $dwl_result);
             // log result and mark it as finalized
         }
         //end if
         return;
         // break stop
     }
     //end if
     //--
     //== RAW OUTPUT FOR PAGES
     //--
     if ((string) $rawpage == 'yes') {
         //-- {{{SYNC-RESOURCES}}}
         if (function_exists('memory_get_peak_usage')) {
             $res_memory = @memory_get_peak_usage(false);
         } else {
             $res_memory = 'unknown';
         }
         //end if else
         $res_time = (double) (microtime(true) - (double) SMART_FRAMEWORK_RUNTIME_READY);
         //-- #END-SYNC
         if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
             //-- {{{SYNC-DEBUG-META-INFO}}}
             SmartFrameworkRegistry::setDebugMsg('stats', 'memory', $res_memory);
             // bytes
             SmartFrameworkRegistry::setDebugMsg('stats', 'time', $res_time);
             // seconds
             //-- #END-SYNC
             $the_debug_cookie = trim((string) $_COOKIE['SmartFramework__DebugAdmID']);
             SmartDebugProfiler::save_debug_info('adm', $the_debug_cookie, false);
         } else {
             $the_debug_cookie = '';
         }
         //end if
         //--
         if (headers_sent()) {
             Smart::raise_error('Middleware ERROR: Headers already sent', 'ERROR: Headers already sent !');
             return;
             // avoid serve raw pages with errors injections before headers
         }
         //end if
         //--
         if ((string) $rawmime != '') {
             header('Content-Type: ' . $rawmime);
         }
         //end if
         if ((string) $rawdisp != '') {
             header('Content-Disposition: ' . $rawdisp);
         }
         //end if
         header('Content-Length: ' . (0 + strlen((string) $appData['main'])));
         // must be strlen NOT SmartUnicode::str_len as it must get number of bytes not characters
         echo (string) $appData['main'];
         return;
         // break stop
         //--
     }
     //end if else
     //--
     //== DEFAULT OUTPUT
     //--
     if (isset($appSettings['template-path'])) {
         if ((string) $appSettings['template-path'] == '@') {
             // if template path is set to self (module)
             $the_template_path = '@';
             // this is a special setting
         } else {
             $the_template_path = Smart::safe_pathname(SmartFileSysUtils::add_dir_last_slash(trim((string) $appSettings['template-path'])));
         }
         //end if else
     } else {
         $the_template_path = Smart::safe_pathname(SmartFileSysUtils::add_dir_last_slash(trim((string) $configs['app']['admin-template-path'])));
         // use default template path
     }
     //end if else
     //--
     if (isset($appSettings['template-file'])) {
         $the_template_file = Smart::safe_filename(trim((string) $appSettings['template-file']));
     } else {
         $the_template_file = Smart::safe_filename(trim((string) $configs['app']['admin-template-file']));
         // use default template
     }
     //end if else
     //--
     if ((string) $the_template_path == '@') {
         $the_template_path = (string) $the_path_to_module . 'templates/';
         // must have the dir last slash as above
     } else {
         $the_template_path = (string) SMART_APP_TEMPLATES_DIR . $the_template_path;
         // finally normalize and set the complete template path
     }
     //end if else
     $the_template_file = (string) $the_template_file;
     // finally normalize
     //--
     if (!SmartFileSysUtils::check_file_or_dir_name($the_template_path)) {
         Smart::log_warning('Invalid Page Template Path: ' . $the_template_path);
         self::Raise500Error('Invalid Page Template Path. See the error log !');
         return;
     }
     //end if
     if (!is_dir($the_template_path)) {
         Smart::log_warning('Page Template Path does not Exists: ' . $the_template_path);
         self::Raise500Error('Page Template Path does not Exists. See the error log !');
         return;
     }
     //end if
     if (!SmartFileSysUtils::check_file_or_dir_name($the_template_path . $the_template_file)) {
         Smart::log_warning('Invalid Page Template File: ' . $the_template_path . $the_template_file);
         self::Raise500Error('Invalid Page Template File. See the error log !');
         return;
     }
     //end if
     if (!is_file($the_template_path . $the_template_file)) {
         Smart::log_warning('Page Template File does not Exists: ' . $the_template_path . $the_template_file);
         self::Raise500Error('Page Template File does not Exists. See the error log !');
         return;
     }
     //end if
     //--
     $the_template_content = trim(SmartMarkersTemplating::read_template_file($the_template_path . $the_template_file));
     if ((string) $the_template_content == '') {
         Smart::log_warning('Page Template File is Empty or cannot be read: ' . $the_template_path . $the_template_file);
         self::Raise500Error('Page Template File is Empty or cannot be read. See the error log !');
         return;
     }
     //end if
     //--
     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
         $the_template_content = str_ireplace('</head>', "\n" . SmartDebugProfiler::js_headers_debug('admin.php?smartframeworkservice=debug') . "\n" . '</head>', $the_template_content);
         $the_template_content = str_ireplace('</body>', "\n" . SmartDebugProfiler::div_main_debug() . "\n" . '</body>', $the_template_content);
     }
     //end if
     //--
     $appData['app-domain'] = (string) $configs['app']['admin-domain'];
     $appData['template-file'] = $the_template_path . $the_template_file;
     $appData['template-path'] = $the_template_path;
     $appData['js.settings'] = SmartComponents::js_inc_settings((string) $configs['js']['popup-mode'], true, (bool) SMART_APP_VISITOR_COOKIE);
     $appData['head-meta'] = (string) $appData['head-meta'];
     if ((string) $appData['head-meta'] == '') {
         $appData['head-meta'] = '<!-- Head Meta -->';
     }
     //end if
     $appData['title'] = (string) $appData['title'];
     $appData['main'] = (string) $appData['main'];
     $appData['lang'] = SmartTextTranslations::getLanguage();
     //--
     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
         //--
         $the_debug_cookie = 'adm-' . Smart::uuid_10_seq() . '-' . Smart::uuid_10_num() . '-' . Smart::uuid_10_str();
         @setcookie('SmartFramework__DebugAdmID', (string) $the_debug_cookie, 0, '/');
         // debug token cookie is set just on main request
         //--
     }
     //end if
     //--
     echo SmartMarkersTemplating::render_mixed_template((string) $the_template_content, (array) $appData, (string) $appData['template-path'], 'no', 'no');
     //-- {{{SYNC-RESOURCES}}}
     if (function_exists('memory_get_peak_usage')) {
         $res_memory = @memory_get_peak_usage(false);
     } else {
         $res_memory = 'unknown';
     }
     //end if else
     $res_time = (double) (microtime(true) - (double) SMART_FRAMEWORK_RUNTIME_READY);
     //-- #END-SYNC
     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
         //-- {{{SYNC-DEBUG-META-INFO}}}
         SmartFrameworkRegistry::setDebugMsg('stats', 'memory', $res_memory);
         // bytes
         SmartFrameworkRegistry::setDebugMsg('stats', 'time', $res_time);
         // seconds
         //-- #END-SYNC
         SmartDebugProfiler::save_debug_info('adm', $the_debug_cookie, true);
         //--
     }
     //end if else
     //--
     if (SMART_SOFTWARE_DISABLE_STATUS_POWERED !== true) {
         echo "\n" . '<!-- Smart.Framework スマート.フレームワーク :: ' . SMART_FRAMEWORK_RELEASE_TAGVERSION . ' / ' . SMART_FRAMEWORK_RELEASE_VERSION . ' @ ' . $the_midmark . ' :: ' . SMART_FRAMEWORK_RELEASE_URL . ' -->';
     }
     //end if
     echo "\n" . '<!-- Resources: [' . Smart::format_number_dec($res_time, 13, '.', '') . ' sec.] / [' . Smart::format_number_dec($res_memory, 0, '.', ' ') . ' by.]' . ' -->' . "\n";
     //--
 }
 /**
  * Displays the Solr Errors and HALT EXECUTION (This have to be a FATAL ERROR as it occur when a FATAL Solr ERROR happens or when a Data Query fails)
  * PRIVATE
  *
  * @param STRING $y_area :: The Area
  * @param STRING $y_error_message :: The Error Message to Display
  * @param STRING $y_query :: The query
  * @param STRING $y_warning :: The Warning Title
  *
  * @return :: HALT EXECUTION WITH ERROR MESSAGE
  *
  */
 private function error($y_area, $y_error_message, $y_query = '', $y_warning = '')
 {
     //--
     $def_warn = 'Execution Halted !';
     $y_warning = (string) trim((string) $y_warning);
     if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') {
         $width = 750;
         $the_area = (string) $y_area;
         if ((string) $y_warning == '') {
             $y_warning = (string) $def_warn;
         }
         //end if
         $the_error_message = 'Operation FAILED: ' . $def_warn . "\n" . $y_error_message;
         $the_params = '- Mode: ' . $this->mode . ' -';
         $the_query_info = (string) $y_query;
         if ((string) $the_query_info == '') {
             $the_query_info = '-';
             // query cannot e empty in this case (templating enforcement)
         }
         //end if
     } else {
         $width = 550;
         $the_area = '';
         $the_error_message = 'Operation FAILED: ' . $def_warn;
         $the_params = '';
         $the_query_info = '';
         // do not display query if not in debug mode ... this a security issue if displayed to public ;)
     }
     //end if else
     //--
     $out = SmartComponents::db_error_message('Solr Client', 'Apache-Solr', 'FTS', 'Server', 'modules/smart-extra-libs/img/solr_logo_trans.png', $width, $the_area, $the_error_message, $the_params, $the_query_info);
     //--
     Smart::raise_error('#SOLR-DB# :: Q# // Solr :: ERROR :: ' . $y_area . "\n" . '*** Error-Message: ' . $y_error_message . "\n" . '*** Stetement:' . "\n" . $y_query, $out);
     die('');
     // just in case
     //--
 }
示例#22
0
/**
 * Function: Custom 500 Answer (can be customized on your needs ...)
 *
 * @access 		private
 * @internal
 *
 */
function custom_http_message_500_internalerror($y_message, $y_extra_message = '')
{
    //--
    return SmartComponents::http_error_message('*Custom* 500 Internal Server Error', $y_message, $y_extra_message);
    //--
}
示例#23
0
/**
 * Function: Custom 403 Answer (can be customized on your needs ...)
 *
 * @access 		private
 * @internal
 *
 */
function custom_http_message_403_forbidden($y_message, $y_extra_message = '')
{
    //--
    return SmartComponents::http_error_message('*Custom* 403 Forbidden', $y_message, $y_extra_message);
    //--
}