24const QUICKPICK_API_URL =
'https://bearsampp.com/index.php?option=com_osmembership&task=api.get_active_plan_ids&api_key=';
27const QUICKPICK_JSON_URL =
'https://raw.githubusercontent.com/Bearsampp/Bearsampp/main/core/resources/quickpick-releases.json';
32if (isset($_SERVER[
'argv']) && isset($_SERVER[
'argv'][1]) && $_SERVER[
'argv'][1] ===
'startup') {
33 $flagFile = sys_get_temp_dir() .
'/bearsampp_no_admin.lock';
36 if (file_exists($flagFile) && (time() - filemtime($flagFile)) < 10) {
37 $currentPid = getmypid();
38 $killCmd =
'powershell.exe -WindowStyle Hidden -Command "Stop-Process -Id ' . (int)$currentPid .
' -Force -ErrorAction SilentlyContinue; Stop-Process -Name bearsampp -Force -ErrorAction SilentlyContinue"';
41 $wshKill =
new COM(
'WScript.Shell');
42 $wshKill->Run($killCmd, 0,
false);
43 }
catch (Exception $e) {
44 pclose(popen($killCmd,
'r'));
52 $wsh =
new COM(
'WScript.Shell');
55 $exitCode = $wsh->Run(
'net session', 0,
true);
56 $isElevated = ($exitCode === 0);
57 }
catch (Exception $e) {
59 $netOutput = @shell_exec(
'net session 2>&1');
60 if ($netOutput !==
null) {
61 if (stripos($netOutput,
'Access is denied') ===
false &&
62 stripos($netOutput,
'System error 5') ===
false &&
71 @file_put_contents($flagFile, time());
74 $langFile = dirname(__FILE__) .
'/langs/english.lang';
75 $langData = @parse_ini_file($langFile);
78 $title = isset($langData[
'errorAdminRequiredTitle']) ? $langData[
'errorAdminRequiredTitle'] :
'Administrator Rights Required';
79 $messageText = isset($langData[
'errorAdminRequiredText']) ? $langData[
'errorAdminRequiredText'] :
'%s requires administrator privileges to install and manage Windows services.@nl@@nl@Please right-click on bearsampp.exe and select "Run as administrator" to start the application.';
82 $messageText = sprintf($messageText,
APP_TITLE);
83 $messageText = str_replace(
'@nl@',
'|||NEWLINE|||', $messageText);
86 $messageParts = explode(
'|||NEWLINE|||', $messageText);
89 $psFile = sys_get_temp_dir() .
'/bearsampp_admin_error.ps1';
90 $flagFilePs = str_replace(
'/',
'\\', $flagFile);
91 $psFilePs = str_replace(
'/',
'\\', $psFile);
94 $title = str_replace(
"'",
"''", $title);
95 $currentPid = getmypid();
98 $psContent =
"# Show error message using Windows Forms\n";
99 $psContent .=
"Add-Type -AssemblyName System.Windows.Forms\n";
102 $psContent .=
"\$messageParts = @(\n";
103 $lastIndex = count($messageParts) - 1;
104 foreach ($messageParts as $index => $part) {
105 $part = str_replace(
"'",
"''", trim($part));
107 $comma = ($index < $lastIndex) ?
',' :
'';
108 $psContent .=
" '" . $part .
"'" . $comma .
"\n";
111 $psContent .=
"\$message = \$messageParts -join [Environment]::NewLine\n";
112 $psContent .=
"[System.Windows.Forms.MessageBox]::Show(\$message, '" . $title .
"', [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error) | Out-Null\n";
114 $psContent .=
"# After user clicks OK, kill only Bearsampp-related processes\n";
115 $psContent .=
"Stop-Process -Id " . (int)$currentPid .
" -Force -ErrorAction SilentlyContinue\n";
116 $psContent .=
"Stop-Process -Name bearsampp -Force -ErrorAction SilentlyContinue\n";
118 $psContent .=
"# Clean up\n";
119 $psContent .=
"Remove-Item -Path '" . $flagFilePs .
"' -Force -ErrorAction SilentlyContinue\n";
120 $psContent .=
"Remove-Item -Path '" . $psFilePs .
"' -Force -ErrorAction SilentlyContinue\n";
122 @file_put_contents($psFile, $psContent);
126 $wsh->Run(
'powershell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -File "' . $psFile .
'"', 0,
false);
128 pclose(popen(
'start "" powershell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -File "' . $psFile .
'"',
'r'));
143require_once dirname(__FILE__) .
'/classes/class.root.php';
const APP_GITHUB_USERAGENT
const APP_GITHUB_LATEST_URL