From db6fb4a06a895436d28f2bbee6dd0128b098ca8e Mon Sep 17 00:00:00 2001 From: Abdulrahman Date: Thu, 23 May 2019 20:56:24 +0300 Subject: [PATCH] hello! --- admin_phpbb_settings.html | 212 ++++++++++++++++++++++++++++++++++++++ index.html | 63 +++++++++++ init.php | 209 +++++++++++++++++++++++++++++++++++++ kjauth.php | 92 +++++++++++++++++ phpbb.php | 119 +++++++++++++++++++++ phpbb_settings.php | 119 +++++++++++++++++++++ 6 files changed, 814 insertions(+) create mode 100755 admin_phpbb_settings.html create mode 100644 index.html create mode 100644 init.php create mode 100644 kjauth.php create mode 100755 phpbb.php create mode 100644 phpbb_settings.php diff --git a/admin_phpbb_settings.html b/admin_phpbb_settings.html new file mode 100755 index 0000000..443f8b6 --- /dev/null +++ b/admin_phpbb_settings.html @@ -0,0 +1,212 @@ + +
+ ... + +
+ + + + + + +
+ + +
+ +
+
+
{lang.CONFIG_KLJ_MENUS_GENERAL}
+
+ + +
+ +
+ + {olang.PHPBB_INTR_TEST_NOTE} +
+
+ + +
+ +
+ + + {olang.PHPBB_INTR_PATH_EXP} + +
+
+ + +
+ +
+ +
+
+ + +
+ + +
+ +
+
+ + +{H_FORM_KEYS} +
+ + + diff --git a/index.html b/index.html new file mode 100644 index 0000000..19b7061 --- /dev/null +++ b/index.html @@ -0,0 +1,63 @@ + + + + + + Powered by Kleeja + + + +
+
+

403 - Access forbidden!

+
+
+
Powered by Kleeja +
+ + + \ No newline at end of file diff --git a/init.php b/init.php new file mode 100644 index 0000000..eeeeedb --- /dev/null +++ b/init.php @@ -0,0 +1,209 @@ + [ + 'en' => 'phpBB Integration', + 'ar' => 'التكامل مع phpBB' + ], + // who wrote this plugin? + 'plugin_developer' => 'kleeja.com', + // this plugin version + 'plugin_version' => '1.0', + // explain what is this plugin, why should i use it? + 'plugin_description' => [ + 'en' => 'phpBB Membership Integration', + 'ar' => 'التكامل مع عضويات phpBB' + ], + //settings page, if there is one (what after ? like cp=j_plugins) + 'settings_page' => 'cp=phpbb_settings', + // min version of kleeja that's required to run this plugin + 'plugin_kleeja_version_min' => '3.0.2', + // max version of kleeja that support this plugin, use 0 for unlimited + 'plugin_kleeja_version_max' => '3.9.9', + // should this plugin run before others?, 0 is normal, and higher number has high priority + 'plugin_priority' => 0 +]; + +//after installation message, you can remove it, it's not requiered +$kleeja_plugin['phpbb_integration']['first_run']['ar'] = ' +يجب ضبط إعدادات الإضافة من خلال صفحة الإضافة لضمان عملها وتفعيلها

+شكراً لاستخدامك الإضافة، قم بمراسلتنا بالأخطاء عند ظهورها على:
+https://github.com/kleeja-official/kleeja/issues +'; + +$kleeja_plugin['phpbb_integration']['first_run']['en'] = ' +In order for this plugin to works, you need to adjust its settings from its page.

+Thank you for using our plugin. If you encounter any bugs and errors, report them on:
+https://github.com/kleeja-official/kleeja/issues +'; + + +// plugin installation function +$kleeja_plugin['phpbb_integration']['install'] = function ($plg_id) { + //new options + $options = [ + 'phpbb_intr_enabled' => + [ + 'value' => '0', + 'plg_id' => $plg_id, + 'type' => 'phpbb_integration' + ], + 'phpbb_intr_path' => + [ + 'value' => '../phpbb', + 'plg_id' => $plg_id, + 'type' => 'phpbb_integration' + ], + 'phpbb_intr_link' => + [ + 'value' => 'http://example.com/phpbb', + 'plg_id' => $plg_id, + 'type' => 'phpbb_integration' + ], + 'phpbb_intr_api_key' => + [ + 'value' => sha1(mt_rand()), + 'plg_id' => $plg_id, + 'type' => 'phpbb_integration' + ], + ]; + + + add_config_r($options); + + + //new language variables + add_olang([ + 'R_PHPBB_SETTINGS' => 'إعدادات phpBB', + 'PHPBB_INTR_ENABLE' => 'تفعيل التكامل مع عضويات phpBB', + 'PHPBB_INTR_PATH' => 'مسار مجلد phpBB بالنسبة لمجلد كليجا', + 'PHPBB_INTR_PATH_EXP' => 'غير اجباري, سنستخدمه لمحاولة نسخ ملف kjauth.php لمجلد المنتدى المربوط به إن كان في نفس الإستضافة.', + 'PHPBB_INTR_LINK' => 'رابط منتدى phpBB', + 'PHPBB_INTR_API_KEY' => 'مفتاح الربط العشوائي', + 'PHPBB_INTR_KJAUTH_FILE_EXP' => 'قم بنسخ المحتويات ووضعها في ملف باسم kjauth.php في مجلد المنتدى المربوط فيه.', + 'PHPBB_INTR_REGENERATE' => 'إعادة إنشاء مفتاح الربط', + 'PHPBB_INTR_KJAUTH_FILE' => 'إنشاء ملف kjauth.php', + 'PHPBB_INTR_REGENERATE_NOTE' => 'هل أنت متأكد؟ عملية إعادة الإنشاء للمفتاح تتطلب منك نسخ المفتاح ووضفعه في ملف kjauth.php من جديد!', + 'PHPBB_INTR_TEST' => 'فحص التكامل', + 'PHPBB_INTR_TEST_NOTE' => 'لتفعيل التكامل قم بعمل فحص للتكامل.', + 'PHPBB_INTR_TEST_NOTE_ERR' => 'فشل الإتصال، قم بالتأكد من الإعدادات قبل التجربة مرة أخرى!', + 'PHPBB_INTR_TEST_NOTE_SUCCESS' => 'الاتصال ناجح! يمكنك الآن تفعيل التكامل لو أردت ذلك.', + ], + 'ar', + $plg_id); + + add_olang([ + 'R_PHPBB_SETTINGS' => 'phpBB Intergration', + 'PHPBB_INTR_ENABLE' => 'Enable phpBB membership Integration', + 'PHPBB_INTR_PATH' => 'phpBB relative path', + 'PHPBB_INTR_PATH_EXP' => 'Optional, we will try to copy kjauth.php to phpbb folder if in same hosting space.', + 'PHPBB_INTR_LINK' => 'Link to phpBB forum', + 'PHPBB_INTR_API_KEY' => 'Integration generated key', + 'PHPBB_INTR_KJAUTH_FILE_EXP' => 'With this content, create a file called kjauth.php in the integrated-with phpBB folder.', + 'PHPBB_INTR_REGENERATE' => 'Re-generate Api Key', + 'PHPBB_INTR_KJAUTH_FILE' => 'Create kjauth.php file', + 'PHPBB_INTR_REGENERATE_NOTE' => 'Are you sure? regenerating the key will disable current integration and will require copying the key to kjauth.php again!', + 'PHPBB_INTR_TEST' => 'Test Integration', + 'PHPBB_INTR_TEST_NOTE' => 'In order to enable integration, test the integration first.', + 'PHPBB_INTR_TEST_NOTE_ERR' => 'Connection failed! Check settings and test again!', + 'PHPBB_INTR_TEST_NOTE_SUCCESS' => 'Connection succeeded! You can enable integration now if you want.', + ], + 'en', + $plg_id); +}; + + +//plugin update function, called if plugin is already installed but version is different than current +$kleeja_plugin['phpbb_integration']['update'] = function ($old_version, $new_version) { + // if(version_compare($old_version, '0.5', '<')){ + // //... update to 0.5 + // } + // + // if(version_compare($old_version, '0.6', '<')){ + // //... update to 0.6 + // } + + //you could use update_config, update_olang +}; + + +// plugin uninstalling, function to be called at uninstalling +$kleeja_plugin['phpbb_integration']['uninstall'] = function ($plg_id) { + //delete options + delete_config([ + 'phpbb_intr_enabled', + 'phpbb_intr_path', + 'phpbb_intr_link', + 'phpbb_intr_api_key', + ]); + + + //delete language variables + foreach (['ar', 'en'] as $language) + { + delete_olang(null, $language, $plg_id); + } +}; + + +// plugin functions +$kleeja_plugin['phpbb_integration']['functions'] = [ + //add to admin menu + 'begin_admin_page' => function ($args) { + $adm_extensions = $args['adm_extensions']; + $ext_icons = $args['ext_icons']; + + $adm_extensions[] = 'phpbb_settings'; + $ext_icons['phpbb_settings'] = 'users'; + return compact('adm_extensions', 'ext_icons'); + }, + //add as admin page to reach when click on admin menu item we added. + 'not_exists_phpbb_settings' => function() { + $include_alternative = dirname(__FILE__) . '/phpbb_settings.php'; + + return compact('include_alternative'); + }, + 'data_func_usr_class' => function ($args) { + global $config; + + if (defined('DISABLE_INTR') || $config['phpbb_intr_enabled'] != 1) + { + return; + } + + $return_now = true; + + $login_status = phpbb_auth_login($args['name'], $args['pass'], $args['hashed'], $args['expire'], $args['loginadm']); + + return compact('return_now', 'login_status'); + }, + + 'auth_func_usr_class' => function ($args) { + global $config; + + if (defined('DISABLE_INTR') || $config['phpbb_intr_enabled'] != 1) + { + return; + } + + $return_now = true; + + $auth_status = phpbb_auth_username($args['user_id']); + + return compact('return_now', 'auth_status'); + } +]; + +//includes integration functions +include_once __DIR__ . '/phpbb.php'; diff --git a/kjauth.php b/kjauth.php new file mode 100644 index 0000000..27180e7 --- /dev/null +++ b/kjauth.php @@ -0,0 +1,92 @@ +variable('api_key', '', true)) != $script_api_key) +{ + exit('9000'); +} + +if ($request->is_set('test')) +{ + exit('9999'); +} + +if (! $request->is_set('userid') && ! $request->is_set('username')) +{ + exit('8000'); +} + + +//hashed ? +$hashed = $request->is_set('userid'); + +$c = [ + 'pass' => base64_decode($request->variable('pass', '', true)), + 'username' => urldecode($request->variable('username', '', true)), + 'userid' => $request->variable('userid', 0, true), +]; + + +$sql = 'SELECT user_id, username, user_password, user_email, user_type + FROM ' . USERS_TABLE . ' + WHERE '; + +if ($hashed) +{ + $sql .= 'user_id = ' . $c['userid'] . " AND user_password = '" . $db->sql_escape($c['pass']) . "'"; +} +elseif (isset($_GET['return_username'])) +{ + $sql .= 'user_id = ' . $c['userid']; +} +else +{ + $sql .= "username_clean = '" . $db->sql_escape(utf8_clean_string($c['username'])) . "'"; +} + +$result = $db->sql_query($sql); +$row = $db->sql_fetchrow($result); +$db->sql_freeresult($result); + +if (! $row) +{ + exit('7000'); +} + +//check for password +if (! $hashed) +{ + $passwords_manager = $phpbb_container->get('passwords.manager'); + + if (! $passwords_manager->check($c['pass'], $row['user_password'])) + { + exit('6000'); + } +} + +//return only username +if ($request->is_set('return_username')) +{ + exit(base64_encode('1' . $content_separator . $row['username'])); +} + +$is_admin_or_no = $row['user_type'] == 3 ? '1' : '0'; + +exit( + base64_encode('1' . $content_separator . $row['user_id'] . $content_separator . $row['username'] . $content_separator . $row['user_email'] . $content_separator . $row['user_password'] . $content_separator . $is_admin_or_no) +); diff --git a/phpbb.php b/phpbb.php new file mode 100755 index 0000000..4c756ff --- /dev/null +++ b/phpbb.php @@ -0,0 +1,119 @@ +get(); + + if (! empty($remote_data) && intval($remote_data) == 9999) + { + return true; + } + + return false; + } +} + +if (! function_exists('phpbb_auth_login')) +{ + function phpbb_auth_login($name, $pass, $hashed = false, $expire, $loginadm = false, $return_username = false) + { + global $config, $usrcp, $userinfo; + + $api_http_query = 'api_key=' . urlencode(base64_encode($config['phpbb_intr_api_key'])) . '&' + . ($hashed ? 'userid' : 'username') . '=' . urlencode($name) . '&pass=' . urlencode(base64_encode($pass)); + + //if only username, let's add it to the query + $api_http_query .= $return_username ? '&return_username=1' : ''; + + + //get it + $phpbbLink = rtrim($config['phpbb_intr_link'], '/') . '/kjauth.php'; + + $remote_data = FetchFile::make($phpbbLink . '?' . $api_http_query) + ->get(); + + //no response + //empty or can not connect + if (empty($remote_data) || is_numeric($remote_data)) + { + return false; + } + + $user_info = explode('%|%', base64_decode($remote_data)); + + //1 == success + if ((int) $user_info[0] !== 1) + { + return false; + } + + // + //if we want username only we have to return it quickly and die here + // + if ($return_username) + { + return $user_info[1]; + } + + // + //in case of admin, we just want a check, no data setup .. + // + if (! $loginadm) + { + define('USER_ID', $user_info[1]); + define('USER_NAME', $user_info[2]); + define('USER_MAIL', $user_info[3]); + define('GROUP_ID', (intval($user_info[5]) == 1 ? 1 : 3)); + } + + //user ifo + //and this must be filled with user data comming from url + $userinfo = []; + $userinfo['group_id'] = intval($user_info[5]) == 1 ? 1 : 3; + $user_y = base64_encode(serialize(['id'=>$user_info[1], 'name'=>$user_info[2], 'mail'=>$user_info[3], 'last_visit'=>time()])); + + + //add cookies + if (! $hashed && ! $loginadm) + { + $usrcp->kleeja_set_cookie( + 'ulogu', $usrcp->en_de_crypt($user_info[1] . '|' . $user_info[4] . '|' . $expire . '|' . + sha1(md5($config['h_key'] . $user_info[4]) . $expire) . '|' . (intval($user_info[5]) == 1 ? 1 : 3) . '|' . $user_y), $expire + ); + } + + return true; + } +} + + +if (! function_exists('phpbb_auth_username')) +{ + function phpbb_auth_username($user_id) + { + return phpbb_auth_login($user_id, false, false, 0, false, true); + } +} diff --git a/phpbb_settings.php b/phpbb_settings.php new file mode 100644 index 0000000..9f4b8cc --- /dev/null +++ b/phpbb_settings.php @@ -0,0 +1,119 @@ +