コード例 #1
0
 public function Run()
 {
     //--
     $title = 'Extended Markers Template Test';
     //--
     $test_switch_arr = ['a', 'b', 'c', 'd'];
     $this->PageViewSetVars(['title' => $title, 'main' => SmartMarkersTemplating::render_file_template($this->ControllerGetParam('module-path') . 'views/templating-test.htm', ['TITLE' => $title, 'TEST-COMPARE' => 'a', 'TESTURL' => 'a"b\'c', 'DATA' => ['This is a sample table', ['id' => 1, 'slug' => 'a', 'name' => 'Letter A', 'is_vowel' => true], ['id' => 2, 'slug' => 'b', 'name' => 'Letter B', 'is_vowel' => false], ['id' => 3, 'slug' => 'c', 'name' => 'Letter C', 'is_vowel' => false], ['id' => 4, 'slug' => 'd', 'name' => 'Letter D', 'is_vowel' => false], ['id' => 5, 'slug' => 'e', 'name' => 'Letter E', 'is_vowel' => true], ['id' => 6, 'slug' => 'f', 'name' => 'Letter F', 'is_vowel' => false], ['id' => 7, 'slug' => 'g', 'name' => 'Letter G', 'is_vowel' => false], ['id' => 8, 'slug' => 'h', 'name' => 'Letter H', 'is_vowel' => false], ['id' => 9, 'slug' => 'i', 'name' => 'Letter I', 'is_vowel' => true], ['id' => 10, 'slug' => 'j', 'name' => 'Letter J', 'is_vowel' => false], ['id' => 11, 'slug' => 'k', 'name' => 'Letter K', 'is_vowel' => false], ['id' => 12, 'slug' => 'l', 'name' => 'Letter L', 'is_vowel' => false], ['id' => 13, 'slug' => 'm', 'name' => 'Letter M', 'is_vowel' => false], ['id' => 14, 'slug' => 'n', 'name' => 'Letter N', 'is_vowel' => false], ['id' => 15, 'slug' => 'o', 'name' => 'Letter O', 'is_vowel' => true]], 'DAT2' => ['key1' => ['id' => 'val1', 'name' => 'Value 1'], 'key2' => 'val2', 'key3' => 'val3', 'key4' => 'val4'], 'TEST1' => 3, 'TEST2' => Smart::random_number(2, 3), 'TEST3' => 3, 'STATUS' => (string) $test_switch_arr[Smart::random_number(0, 3)]])]);
     //--
 }
コード例 #2
0
 /**
  * Set the (in-memory) Auth Login Data
  * It can be used just once per execution (session) as it stores the data using constants,
  * and the data cannot be changed after a successful or failed authentication has set.
  *
  * @param 	STRING 	$y_user_id 				:: The user (login) ID used to authenticate the user ; Mandatory ; it can be the UserID from DB or if not using a DB must supply a unique ID to identify the user like username
  * @param 	STRING 	$y_user_alias			:: The user (login) Alias, used to display the logged in user ; Mandatory ; can be the same as the login ID or different (Ex: login ID can be 'myUserName' and this 'myUserName' ; or: login ID can be 5017 and this 'myUserName')
  * @param 	STRING 	$y_user_email 			:: *OPTIONAL* The user Email ; if email is used as login ID this may be redundant !
  * @param 	STRING 	$y_user_fullname 		:: *OPTIONAL* The user Full Name (First Name + Last Name)
  * @param 	ARRAY 	$y_user_privileges_list :: *OPTIONAL* The user Privileges List as array that list all the current user privileges
  * @param 	STRING 	$y_user_quota 			:: *OPTIONAL* The user (storage) Quota
  * @param 	ARRAY 	$y_user_metadata 		:: *OPTIONAL* The user metainfo, associative array key => value
  * @param 	STRING 	$y_realm 				:: *OPTIONAL* The user Authentication Realm(s)
  * @param 	ENUM 	$y_method 				:: *OPTIONAL* The authentication method used: HTTP-BASIC / HTTP-DIGEST / OTHER
  * @param 	STRING 	$y_pass					:: *OPTIONAL* The user login password (will be stored in memory as Blowfish encrypted to avoid exposure)
  *
  * @return 	BOOLEAN							:: TRUE if all data is OK, FALSE if not or try to reauthenticate under the same execution (which is not allowed ; must be just once per execution)
  */
 public static function set_login_data($y_user_id, $y_user_alias, $y_user_email = '', $y_user_fullname = '', $y_user_privileges_list = array('none', 'no-privilege'), $y_user_quota = -1, $y_user_metadata = array(), $y_realm = 'DEFAULT', $y_method = '', $y_pass = '')
 {
     //--
     if (self::$AuthCompleted !== false) {
         // avoid to re-auth
         Smart::log_warning('Re-Authentication is not allowed ...');
         return;
     }
     //end if
     self::$AuthCompleted = true;
     //--
     self::$AuthData = array();
     // reset the auth data
     //--
     $y_user_id = trim((string) $y_user_id);
     // user ID
     $y_user_alias = trim((string) $y_user_alias);
     // username (user alias ; can be the same as userID or different)
     $y_user_email = trim((string) $y_user_email);
     $y_user_fullname = trim((string) $y_user_fullname);
     //--
     if (is_array($y_user_privileges_list)) {
         $y_user_privileges_list = (string) strtolower((string) Smart::array_to_list((array) $y_user_privileges_list));
     } else {
         $y_user_privileges_list = (string) strtolower((string) trim((string) $y_user_privileges_list));
         // in this case can be provided a raw list of privileges (Example: '<none>, <no-privilege>')
     }
     //end if else
     //--
     $y_user_quota = Smart::format_number_int($y_user_quota);
     // can be also negative
     //--
     switch (strtoupper((string) $y_method)) {
         case 'HTTP-BASIC':
             $y_method = 'HTTP-BASIC';
             break;
         case 'HTTP-DIGEST':
             $y_method = 'HTTP-DIGEST';
             break;
         case 'OTHER':
         default:
             $y_method = 'OTHER';
     }
     //end switch
     //--
     $the_key = '#' . Smart::random_number(10000, 99999) . '#';
     $the_pass = '';
     if ((string) $y_pass != '') {
         $the_pass = SmartCipherCrypto::encrypt('hash/sha1', (string) $the_key, (string) $y_pass);
     }
     //end if
     //--
     if ((string) $y_user_id != '') {
         //--
         self::$AuthData['USER_ID'] = (string) $y_user_id;
         self::$AuthData['USER_EMAIL'] = (string) $y_user_email;
         self::$AuthData['USER_ALIAS'] = (string) $y_user_alias;
         self::$AuthData['USER_FULLNAME'] = (string) $y_user_fullname;
         self::$AuthData['USER_PRIVILEGES'] = (string) $y_user_privileges_list;
         self::$AuthData['USER_QUOTA'] = (int) $y_user_quota;
         self::$AuthData['USER_METADATA'] = (array) $y_user_metadata;
         self::$AuthData['USER_LOGIN_REALM'] = (string) $y_realm;
         self::$AuthData['USER_LOGIN_METHOD'] = (string) $y_method;
         self::$AuthData['USER_LOGIN_PASS'] = (string) $the_pass;
         self::$AuthData['KEY'] = (string) $the_key;
         //--
         return true;
         //--
     } else {
         //--
         return false;
         //--
     }
     //end if
     //--
 }
コード例 #3
0
 private function generate_captcha_hashed()
 {
     // v.130328
     // based on CodeIgniter
     //--
     $img_width = (int) 0 + $this->width;
     $img_height = (int) 0 + $this->height;
     //--
     //--
     $use_ttf_font = false;
     if (is_int($this->charfont)) {
         $font = $this->charfont;
     } else {
         if (is_file($this->charfont)) {
             if (function_exists('imagettftext') and substr($this->charfont, -4, 4) == '.ttf') {
                 $font = (string) $this->charfont;
                 $use_ttf_font = true;
             } else {
                 // gdf font
                 $font = @imageloadfont($this->charfont);
                 if ($font == false) {
                     $font = 5;
                 }
                 //end if
             }
             //end if else
         } else {
             $font = 5;
             // on error
         }
         //end if else
     }
     //end if
     //--
     //--
     $word = $this->generate_word();
     //--
     //--
     $length = strlen($word);
     $angle = $length >= 6 ? Smart::random_number(-($length - 6), $length - 6) : 0;
     $x_axis = Smart::random_number(6, 360 / $length - 16);
     $y_axis = $angle >= 0 ? Smart::random_number($img_height, $img_width) : Smart::random_number(6, $img_height);
     //--
     //--
     if (function_exists('imagecreatetruecolor')) {
         $im = @imagecreatetruecolor($img_width, $img_height);
     } else {
         $im = @imagecreate($img_width, $img_height);
     }
     //end if else
     //--
     //--
     @imagefilledrectangle($im, 0, 0, $img_width, $img_height, 0xffffff);
     //--
     //--
     $theta = 1;
     $thetac = 7;
     $radius = 16;
     //--
     $circles = (int) ($this->noise / 1.5);
     if ($circles < 1) {
         $circles = 1;
     }
     //end if
     //--
     $points = (int) ($this->noise - $circles);
     if ($points < 1) {
         $points = 1;
     }
     //end if
     //--
     for ($i = 0; $i < $circles * $points - 1; $i++) {
         //--
         $theta = $theta + $thetac;
         $rad = $radius * ($i / $points);
         $x = $rad * cos($theta) + $x_axis;
         $y = $rad * sin($theta) + $y_axis;
         $theta = $theta + $thetac;
         $rad1 = $radius * (($i + 1) / $points);
         $x1 = $rad1 * cos($theta) + $x_axis;
         $y1 = $rad1 * sin($theta) + $y_axis;
         //--
         @imageline($im, $x, $y, $x1, $y1, $this->generate_noise_color());
         //--
         $theta = $theta - $thetac;
         //--
     }
     //end for
     //--
     //--
     $first_x = Smart::random_number(5, $this->charxvar);
     //--
     for ($i = 0; $i < strlen($word); $i++) {
         //--
         $w = substr($word, $i, 1);
         $c = $this->generate_color();
         //--
         if ($use_ttf_font != true) {
             // GDF font
             $y = Smart::random_number(2, $this->charyvar);
             @imagestring($im, $font, $first_x, $y, $w, $c);
         } else {
             // TTF font
             $y = $img_height / 2 + $this->charttfsize / 2 - Smart::random_number(2, $this->charyvar);
             $angle = Smart::random_number(0, 20);
             @imagettftext($im, $this->charttfsize, $angle, $first_x, $y, $c, $font, $w);
         }
         //end if else
         //--
         $first_x += (int) $this->charspace + Smart::random_number(1, 15);
         //--
     }
     //end for
     //--
     //--
     return array('word' => $word, 'rawimage' => $im);
     //--
 }
コード例 #4
0
    public static function test_pgsqlserver()
    {
        global $configs;
        //--
        if (SMART_FRAMEWORK_TESTUNIT_ALLOW_PGSQL_TESTS !== true) {
            return SmartComponents::operation_notice('Test Unit for PgSQL Server is DISABLED ...');
        }
        //end if
        //--
        //--
        $value = date('Y-m-d H:i:s');
        $comments = '"Unicode78źź:ăĂîÎâÂșȘțȚşŞţŢグッド' . '-' . Smart::random_number(1000, 9999) . "'";
        //--
        //-- PgSQL Tests
        if ((string) $configs['pgsql']['server-host'] != '' and (string) $configs['pgsql']['server-port'] != '' and (string) $configs['pgsql']['dbname'] != '' and (string) $configs['pgsql']['username'] != '') {
            //--
            $time = microtime(true);
            //--
            $tests = array();
            $tests[] = '##### PostgreSQL / TESTS: #####';
            //--
            $err = '';
            //--
            if (Smart::random_number(1, 9) >= 5) {
                $tests[] = 'Random Test Dynamic Connection: Open / Drop Test Table (If Exists)';
                $pgsql = new SmartPgsqlExtDb((array) $configs['pgsql']);
                $pgsql->write_data('DROP TABLE IF EXISTS "public"."_test_unit_db_server_tests"');
                unset($pgsql);
            }
            //end if
            //--
            $tests[] = 'PostgreSQL Server Version: ' . SmartPgsqlDb::check_server_version();
            //--
            $tests[] = 'Start Transaction';
            SmartPgsqlDb::write_data('BEGIN');
            //--
            $tests[] = 'Create a Temporary Table for this Test, after transaction to test DDL';
            if (SmartPgsqlDb::check_if_table_exists('_test_unit_db_server_tests', 'public') == 1) {
                SmartPgsqlDb::write_data('DROP TABLE "public"."_test_unit_db_server_tests"');
            }
            //end if
            SmartPgsqlDb::write_data('CREATE TABLE "public"."_test_unit_db_server_tests" ( "variable" character varying(100) NOT NULL, "value" character varying(16384) DEFAULT \'\'::character varying, "comments" text DEFAULT \'\'::text NOT NULL, CONSTRAINT _test_unit_db_server_tests__check__variable CHECK ((char_length((variable)::text) >= 1)), CONSTRAINT _test_unit_db_server_tests__uniq__variable UNIQUE(variable) )');
            //--
            $variable = '"' . 'Ș' . "'" . substr(SmartPgsqlDb::new_safe_id('uid10seq', 'variable', '_test_unit_db_server_tests', 'public'), 3, 7);
            //--
            if ((string) $err == '') {
                $tests[] = 'Check if the Test Table exists [ Positive ; Variable is: ' . $variable . ' ]';
                $data = SmartPgsqlDb::check_if_table_exists('_test_unit_db_server_tests', 'public');
                if ($data !== 1) {
                    $err = 'Table Creation FAILED ... Table does not exists in the `public` schema ...';
                }
                //end if
            }
            //end if
            //--
            if ((string) $err == '') {
                $tests[] = 'Write [ Insert ]';
                $quer_str = 'INSERT INTO "public"."_test_unit_db_server_tests" ' . SmartPgsqlDb::prepare_write_statement(array('variable' => $variable, 'value' => $value, 'comments' => $comments), 'insert');
                $data = SmartPgsqlDb::write_data($quer_str);
                if ($data[1] !== 1) {
                    $err = 'Write / Insert Test Failed, should return 1 but returned: ' . $data[1];
                }
                //end if
            }
            //end if
            //--
            if ((string) $err == '') {
                $tests[] = 'Write [ Insert if not exists, with Insert-SubSelect ]';
                $quer_str = 'INSERT INTO "public"."_test_unit_db_server_tests" ' . SmartPgsqlDb::prepare_write_statement(array('variable' => $variable, 'value' => $value, 'comments' => $comments), 'insert-subselect');
                $data = SmartPgsqlDb::write_igdata($quer_str);
                if ($data[1] !== 0) {
                    $err = 'Write / Insert if not exists with insert-subselect Test Failed, should return 0 but returned: ' . $data[1];
                }
                //end if
            }
            //end if
            //--
            if ((string) $err == '') {
                $tests[] = 'Write Ignore [ Update ]';
                $quer_str = 'UPDATE "public"."_test_unit_db_server_tests" SET "comments" = $2 WHERE ("variable" = $1)';
                $data = SmartPgsqlDb::write_igdata($quer_str, array($variable, $comments));
                if ($data[1] !== 1) {
                    $err = 'Write Ignore / Update Test Failed, should return 1 but returned: ' . $data[1];
                }
                //end if
            }
            //end if
            //--
            if ((string) $err == '') {
                $tests[] = 'Count [ One Row ]';
                $quer_str = 'SELECT COUNT(1) FROM "public"."_test_unit_db_server_tests" WHERE (("variable" = $1) AND ("comments" = ' . SmartPgsqlDb::escape_literal($comments) . '))';
                $data = SmartPgsqlDb::count_data($quer_str, array($variable));
                if ($data !== 1) {
                    $err = 'Count Test Failed, should return 1 but returned: ' . $data;
                }
                //end if
            }
            //end if
            //--
            if ((string) $err == '') {
                $tests[] = 'Read [ LIKE / Literal Escape +% ]';
                $data = SmartPgsqlDb::read_adata('SELECT * FROM "public"."_test_unit_db_server_tests" WHERE ("variable" LIKE ' . SmartPgsqlDb::escape_literal('%' . $variable . '_%', 'yes') . ')');
                if (Smart::array_size($data) !== 0) {
                    $err = 'Read Like / Literal-Escape +% Test Failed, should return 0 rows but returned: ' . Smart::array_size($data);
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $tests[] = 'Read [ LIKE / Literal Escape ]';
                $data = SmartPgsqlDb::read_adata('SELECT * FROM "public"."_test_unit_db_server_tests" WHERE ("variable" LIKE ' . SmartPgsqlDb::escape_literal('%' . $variable . '%') . ')');
                if (Smart::array_size($data) !== 1) {
                    $err = 'Read Like / Literal-Escape Test Failed, should return 1 row but returned: ' . Smart::array_size($data);
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $tests[] = 'Read [ LIKE / Str Escape +% ]';
                $data = SmartPgsqlDb::read_adata('SELECT * FROM "public"."_test_unit_db_server_tests" WHERE ("variable" ILIKE \'' . SmartPgsqlDb::escape_str('%' . $variable . '_%', 'yes') . '\')');
                if (Smart::array_size($data) !== 0) {
                    $err = 'Read Like / Str-Escape +% Test Failed, should return 0 rows but returned: ' . Smart::array_size($data);
                }
                //end if
            }
            //end if
            if ((string) $err == '') {
                $tests[] = 'Read [ LIKE / Str Escape ]';
                $data = SmartPgsqlDb::read_adata('SELECT * FROM "public"."_test_unit_db_server_tests" WHERE ("variable" ILIKE \'' . SmartPgsqlDb::escape_str('%' . $variable . '%') . '\')');
                if (Smart::array_size($data) !== 1) {
                    $err = 'Read Like / Str-Escape Test Failed, should return 1 row but returned: ' . Smart::array_size($data);
                }
                //end if
            }
            //end if
            //--
            if ((string) $err == '') {
                $tests[] = 'Read [ IN (SELECT) ]';
                $quer_str = 'SELECT * FROM "public"."_test_unit_db_server_tests" WHERE ("variable" ' . SmartPgsqlDb::prepare_write_statement(array('\'a', '"b"', '3^$', $variable, '@?%'), 'in-select') . ') LIMIT 100 OFFSET 0';
                $data = SmartPgsqlDb::read_adata($quer_str);
                if (Smart::array_size($data) !== 1) {
                    $err = 'Read IN SELECT Test Failed, should return 1 row but returned: ' . Smart::array_size($data) . ' rows ...';
                }
                //end if
            }
            //end if
            //--
            if ((string) $err == '') {
                $tests[] = 'Read [ (DATA) ARRAY[] ]';
                $quer_str = 'SELECT * FROM "public"."_test_unit_db_server_tests" WHERE ("variable" = ANY(' . SmartPgsqlDb::prepare_write_statement(array('\'a', '"b"', '3^$', $variable, '@?%'), 'data-array') . ')) LIMIT 100 OFFSET 0';
                $data = SmartPgsqlDb::read_adata($quer_str);
                if (Smart::array_size($data) !== 1) {
                    $err = 'Read (DATA) ARRAY[] Test Failed, should return 1 row but returned: ' . Smart::array_size($data) . ' rows ...';
                }
                //end if
            }
            //end if
            //--
            $quer_str = 'SELECT "comments" FROM "public"."_test_unit_db_server_tests" WHERE ("variable" = $1) LIMIT 1 OFFSET 0';
            //--
            if ((string) $err == '') {
                $tests[] = 'Read [ Non-Associative + Param Query $ ]';
                //$data = SmartPgsqlDb::read_data($quer_str, array($variable));
                //$param_query = str_replace('$1', '?', $quer_str); // convert $1 to ?
                $param_query = (string) $quer_str;
                // no more necessary to convert $1 to ? as prepare_param_query() has been extended to support ? or $#
                $param_query = SmartPgsqlDb::prepare_param_query($param_query, array($variable));
                $data = SmartPgsqlDb::read_data($param_query, 'Test Param Query');
                if (trim($data[0]) !== (string) $comments) {
                    $err = 'Read / Non-Associative Test Failed, should return `' . $comments . '` but returned `' . $data[0] . '`';
                }
                //end if
            }
            //end if
            //--
            if ((string) $err == '') {
                $tests[] = 'Read [ Associative: One-Row ]';
                $data = SmartPgsqlDb::read_asdata($quer_str, array($variable));
                if (trim($data['comments']) !== (string) $comments) {
                    $err = 'Read / Associative / One-Row Test Failed, should return `' . $comments . '` but returned `' . $data['comments'] . '`';
                }
                //end if
            }
            //end if
            //--
            if ((string) $err == '') {
                $tests[] = 'Read [ Associative: Multi-Rows ]';
                $data = SmartPgsqlDb::read_adata($quer_str, array($variable));
                if (trim($data[0]['comments']) !== (string) $comments) {
                    $err = 'Read / Associative / Multi-Rows Test Failed, should return `' . $comments . '` but returned `' . $data[0]['comments'] . '`';
                }
                //end if
            }
            //end if
            //--
            if ((string) $err == '') {
                $tests[] = 'Write [ Delete ]';
                $quer_str = 'DELETE FROM "public"."_test_unit_db_server_tests" WHERE ("variable" = \'' . SmartPgsqlDb::escape_str($variable) . '\')';
                $data = SmartPgsqlDb::write_data($quer_str);
                if ($data[1] !== 1) {
                    $err = 'Write / Delete Test Failed, should return 1 but returned: ' . $data[1];
                }
                //end if
            }
            //end if
            //--
            if ((string) $err == '') {
                $tests[] = 'Write Ignore Duplicates [ Insert Ignore Positive ]';
                $quer_str = 'INSERT INTO "public"."_test_unit_db_server_tests" ' . SmartPgsqlDb::prepare_write_statement(array('variable' => $variable, 'value' => null, 'comments' => $comments), 'insert');
                $data = SmartPgsqlDb::write_igdata($quer_str);
                if ($data[1] !== 1) {
                    $err = 'Write / Insert Ignore Positive Test Failed, should return 1 but returned: ' . $data[1];
                }
                //end if
            }
            //end if
            //--
            if ((string) $err == '') {
                $tests[] = 'Write Ignore Duplicates [ Insert Ignore Negative ]';
                $quer_str = 'INSERT INTO "public"."_test_unit_db_server_tests" ' . SmartPgsqlDb::prepare_write_statement(array('variable' => $variable, 'value' => $value, 'comments' => $comments), 'insert');
                $data = SmartPgsqlDb::write_igdata($quer_str);
                if ($data[1] !== 0) {
                    $err = 'Write / Insert Ignore Negative Test Failed, should return 0 but returned: ' . $data[1];
                }
                //end if
            }
            //end if
            //--
            $tests[] = 'Commit Transation';
            SmartPgsqlDb::write_data('COMMIT');
            //--
            if ((string) $err == '') {
                $tests[] = 'Check if the Test Table Exists (Param Query ?) after Drop [ Negative ], using a new Constructor (should be able to re-use connection)';
                $pgsql2 = new SmartPgsqlExtDb((array) $configs['pgsql']);
                $pgsql2->write_data('DROP TABLE IF EXISTS "public"."_test_unit_db_server_tests"');
                $data = $pgsql2->check_if_table_exists('_test_unit_db_server_tests', 'public');
                $pgsql2->prepare_param_query('SELECT ?', array('\'1"'));
                unset($pgsql2);
                if ($data == 1) {
                    $err = 'Table Drop FAILED ... Table still exists ...';
                }
                //end if
            }
            //end if
            //--
            $title = 'SmartFramework PostgreSQL Server Tests: DONE ...';
            //--
            $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 PostgreSQL Server 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 PostgreSQL Server Operations.<span style="color:#FF5500;"><hr>FAILED Test Details</span>:</h2><br><span style="font-size:14px;"><pre>' . Smart::escape_html($err) . '</pre></span>');
            }
            //end if else
            //--
        } else {
            //--
            $title = 'SmartFramework PostgreSQL Server Tests - PostgreSQL Server was NOT SET ...';
            //--
            $img_sign = 'lib/core/img/sign_info.png';
            $img_check = 'lib/core/img/q_warning.png';
            $text_main = Smart::escape_js('<span style="color:#778899;">No PostgreSQL Server Tests performed ...</span>');
            $text_info = '<h2>The current configuration have not set the PostgreSQL Server ...</h2>';
            //--
        }
        //end if
        //--
        //--
        $html = <<<HTML
<h1>{$title}</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'PostgreSQL Server Test Suite for SmartFramework: PHP',
\t\t'725',
\t\t'480'
\t);
</script>
HTML;
        //--
        //--
        return $html;
        //--
    }
コード例 #5
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));
     //--
 }
コード例 #6
0
 public function add_attachment($message, $name = '', $ctype = '', $disp = 'attachment', $cid = '', $realattachment = 'no')
 {
     //--
     switch (strtolower($ctype)) {
         //-- text parts
         case 'text/plain':
         case 'text/html':
             //--
             if ((string) $disp != 'attachment') {
                 $disp = 'inline';
                 // default
             }
             //end if
             //--
             $encode = 'base64';
             // quoted-printable
             //--
             if ((string) $disp == 'inline') {
                 $charset = SmartUnicode::str_toupper(trim($this->charset));
             }
             //end if
             //--
             break;
             //-- email messages
         //-- email messages
         case 'message/rfc822':
         case 'message/partial':
         case 'partial/message':
             // fake type to avoid Google and Yahoo to show the Un-Encoded part
             //-- OLD method :: rewrite type to avoid conflicts (gmail, yahoo, thunderbird)
             //$ctype = 'partial/message';
             //$encode = 'base64';
             //$disp = 'attachment';
             //-- NEW Method (tested with Thunderbird and GMail)
             $ctype = 'message/rfc822';
             $encode = '7bit';
             // this is known to work with Thunderbird and GMail
             //$encode = 'base64'; this does not work with Thunderbird ...
             $disp = 'inline';
             //--
             $name = 'forwarded_message_' . date('YmdHis') . '_' . Smart::random_number(10000, 99999) . '.eml';
             $filename = $name;
             //--
             break;
             //-- the rest ...
         //-- the rest ...
         default:
             //--
             if ((string) $ctype == '') {
                 $ctype = 'application/octet-stream';
             }
             //end if
             //--
             $encode = 'base64';
             //--
             if ((string) $ctype == 'image' or (string) $ctype == 'image/jpeg' or (string) $ctype == 'image/jpg' or (string) $ctype == 'image/png' or (string) $ctype == 'image/gif') {
                 if ((string) $disp != 'inline') {
                     $disp = 'attachment';
                     // default
                 }
                 //end if
             } else {
                 $disp = 'attachment';
             }
             //end if else
             //--
             $filename = $name;
             //--
     }
     //end switch
     //--
     if ((string) $realattachment == 'yes') {
         // real attachments
         $this->atts[] = array('ctype' => $ctype, 'message' => $message, 'charset' => $charset, 'encode' => $encode, 'disp' => $disp, 'name' => $name, 'filename' => $filename, 'cid' => $cid);
     } else {
         $this->parts[] = array('ctype' => $ctype, 'message' => $message, 'charset' => $charset, 'encode' => $encode, 'disp' => $disp, 'name' => $name, 'filename' => $filename, 'cid' => $cid);
     }
     //end if else
     //--
 }
コード例 #7
0
 private function _generate_iv()
 {
     // Initialize pseudo random generator
     // seed rand: (double)microtime()*1000000 // no more needed
     // Collect very random data.
     // Add as many "pseudo" random sources as you can find.
     // Possible sources: Memory usage, diskusage, file and directory content...
     $iv = Smart::random_number();
     $iv .= Smart::unique_entropy();
     $iv .= SmartUtils::get_visitor_tracking_uid();
     $iv .= implode("\r", (array) $_SERVER);
     $iv .= implode("\r", (array) $_COOKIES);
     return $this->_hash($iv);
 }
コード例 #8
0
 /**
  * Get A UNIQUE (SAFE) ID for DB Tables / Schema
  *
  * @param ENUM 		$y_mode 					:: mode: uid10str | uid10num | uid10seq | uid36 | uid45
  * @param STRING 	$y_field_name 				:: the field name
  * @param STRING 	$y_table_name 				:: the table name
  * @param STRING 	$y_schema 					:: the schema
  * @param RESOURCE 	$y_connection 				:: pgsql connection
  * @return STRING 								:: the generated Unique ID
  *
  */
 public static function new_safe_id($y_mode, $y_id_field, $y_table_name, $y_schema = 'public', $y_connection = 'DEFAULT')
 {
     //==
     $y_connection = self::check_connection($y_connection, 'NEW-SAFE-ID');
     //==
     //--
     if (!self::validate_table_and_fields_names($y_id_field)) {
         self::error($y_connection, 'NEW-SAFE-ID', 'Get New Safe ID', 'Invalid Field Name', $y_id_field . ' / [Schema=' . $y_schema . ';Table=' . $y_table_name . ']');
         return '';
     }
     //end if
     if (!self::validate_table_and_fields_names($y_table_name)) {
         self::error($y_connection, 'NEW-SAFE-ID', 'Get New Safe ID', 'Invalid Table Name', $y_table_name);
         return '';
     }
     //end if
     if (!self::validate_table_and_fields_names($y_schema)) {
         self::error($y_connection, 'NEW-SAFE-ID', 'Get New Safe ID', 'Invalid Schema Name', $y_schema);
         return '';
     }
     //end if
     //--
     //--
     $use_safe_id_record = true;
     if (defined('SMART_SOFTWARE_DB_DISABLE_SAFE_IDS')) {
         if (SMART_SOFTWARE_DB_DISABLE_SAFE_IDS === true) {
             $use_safe_id_record = false;
         }
         //end if
     }
     //end if
     //--
     if ($use_safe_id_record === true) {
         //--
         if (self::check_if_table_exists('_safe_id_records', 'smart_runtime', $y_connection) !== 1) {
             if (self::check_if_schema_exists('smart_runtime', $y_connection) !== 1) {
                 self::write_data('CREATE SCHEMA "smart_runtime"', 'Initialize SafeID Schema', $y_connection);
             }
             //end if
             self::write_data((string) self::schema_safe_id_records_table(), 'Initialize SafeID Table', $y_connection);
         }
         //end if
         //--
         if ((int) Smart::random_number(0, 99) == 1) {
             // 1% chance to run it for cleanup records older than 24 hours
             self::write_data('DELETE FROM "smart_runtime"."_safe_id_records" WHERE ("date_time" < \'' . self::escape_str(date('Y-m-d H:i:s', @strtotime('-1 day')), 'no', $y_connection) . '\')', 'Safe ID Records Cleanup (OLDs)', $y_connection);
             // cleanup olds
         }
         //end if
         //--
     }
     //end if
     //--
     $tmp_result = 'NO-ID-INIT';
     //init (must be not empty)
     $counter = 0;
     $id_is_ok = false;
     //--
     while ($id_is_ok !== true) {
         // while we cannot find an unused ID
         //--
         $counter += 1;
         //--
         if ($counter > 7500) {
             // loop to max 7500
             self::error($y_connection, 'NEW-SAFE-ID', 'Get New Safe ID', 'Could Not Assign a Unique ID', '(timeout / 7500) ... try again !');
             return '';
         }
         //end if
         //--
         if ($counter % 500 == 0) {
             sleep(1);
         }
         //end if
         //--
         $new_id = 'NO-ID-ALGO';
         switch ((string) $y_mode) {
             case 'uid45':
                 $new_id = (string) Smart::uuid_45(SMART_FRAMEWORK_NETSERVER_ID . SmartUtils::get_server_current_url());
                 // will use the server ID.Host as Prefix to ensure it is true unique in a cluster
                 break;
             case 'uid36':
                 $new_id = (string) Smart::uuid_36(SMART_FRAMEWORK_NETSERVER_ID . SmartUtils::get_server_current_url());
                 // will use the server ID.Host as Prefix to ensure it is true unique in a cluster
                 break;
             case 'uid10seq':
                 if ($use_safe_id_record === true) {
                     // sequences are not safe without a second registry allocation table as the chance to generate the same ID in the same time moment is just 1 in 999
                     $new_id = (string) Smart::uuid_10_seq();
                 } else {
                     $new_id = (string) Smart::uuid_10_str();
                 }
                 //end if else
                 break;
             case 'uid10num':
                 $new_id = (string) Smart::uuid_10_num();
                 break;
             case 'uid10str':
             default:
                 $new_id = (string) Smart::uuid_10_str();
         }
         //end switch
         //--
         $result_arr = array();
         $chk_uniqueness = 'SELECT ' . self::escape_identifier($y_id_field, $y_connection) . ' FROM ' . self::escape_identifier($y_schema, $y_connection) . '.' . self::escape_identifier($y_table_name, $y_connection) . ' WHERE (' . self::escape_identifier($y_id_field, $y_connection) . ' = ' . self::escape_literal($new_id, 'no', $y_connection) . ') LIMIT 1 OFFSET 0';
         $result_arr = self::read_data($chk_uniqueness, 'Safe Check if NEW ID Exists into Table', $y_connection);
         $tmp_result = (string) trim((string) $result_arr[0]);
         $result_arr = array();
         //--
         if ((string) $tmp_result == '') {
             //--
             if ($use_safe_id_record === true) {
                 // with safety check against safe ID records table
                 //-- reserve this ID to bse sure will not be assigned to another instance
                 $uniqueness_mark = (string) $y_schema . '.' . $y_table_name . ':' . $y_id_field;
                 $write_res = self::write_igdata('INSERT INTO "smart_runtime"."_safe_id_records" ("id", "table_space", "date_time") ( SELECT \'' . self::escape_str($new_id, 'no', $y_connection) . '\', \'' . self::escape_str($uniqueness_mark, 'no', $y_connection) . '\', \'' . self::escape_str(date('Y-m-d H:i:s'), 'no', $y_connection) . '\' WHERE (NOT EXISTS ( SELECT 1 FROM "smart_runtime"."_safe_id_records" WHERE (("id" = \'' . self::escape_str($new_id, 'no', $y_connection) . '\') AND ("table_space" = \'' . self::escape_str($uniqueness_mark, 'no', $y_connection) . '\')) LIMIT 1 OFFSET 0 ) AND NOT EXISTS (' . $chk_uniqueness . ') ) )', 'Safe Record of NEW ID of Table into Zone Control', $y_connection);
                 //--
                 if ($write_res[1] === 1) {
                     $id_is_ok = true;
                 }
                 //end if
                 //--
             } else {
                 // default (not safe in very high load environments ...
                 //--
                 $id_is_ok = true;
                 //--
             }
             //end if else
             //--
         }
         //end if
         //--
     }
     //end while
     //--
     //--
     return (string) $new_id;
     //--
 }