48if (isset($_SERVER[
'argv']) && isset($_SERVER[
'argv'][1]) && $_SERVER[
'argv'][1] ===
'startup') {
49 $flagFile = sys_get_temp_dir() .
'/bearsampp_no_admin.lock';
52 if (file_exists($flagFile) && (time() - filemtime($flagFile)) < 10) {
53 $currentPid = getmypid();
54 $killCmd =
'powershell.exe -WindowStyle Hidden -Command "Stop-Process -Id ' . (int)$currentPid .
' -Force -ErrorAction SilentlyContinue; Stop-Process -Name bearsampp -Force -ErrorAction SilentlyContinue"';
57 $wshKill =
new COM(
'WScript.Shell');
58 $wshKill->Run($killCmd, 0,
false);
59 }
catch (Exception $e) {
60 pclose(popen($killCmd,
'r'));
68 $wsh =
new COM(
'WScript.Shell');
71 $exitCode = $wsh->Run(
'net session', 0,
true);
72 $isElevated = ($exitCode === 0);
73 }
catch (Exception $e) {
75 $netOutput = @shell_exec(
'net session 2>&1');
76 if ($netOutput !==
null) {
77 if (stripos($netOutput,
'Access is denied') ===
false &&
78 stripos($netOutput,
'System error 5') ===
false &&
87 @file_put_contents($flagFile, time());
90 $langFile = dirname(__FILE__) .
'/langs/english.lang';
91 $langData = @parse_ini_file($langFile);
94 $title = isset($langData[
'errorAdminRequiredTitle']) ? $langData[
'errorAdminRequiredTitle'] :
'Administrator Rights Required';
95 $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.';
98 $messageText = sprintf($messageText,
APP_TITLE);
99 $messageText = str_replace(
'@nl@',
'|||NEWLINE|||', $messageText);
102 $messageParts = explode(
'|||NEWLINE|||', $messageText);
105 $psFile = sys_get_temp_dir() .
'/bearsampp_admin_error.ps1';
106 $flagFilePs = str_replace(
'/',
'\\', $flagFile);
107 $psFilePs = str_replace(
'/',
'\\', $psFile);
110 $title = str_replace(
"'",
"''", $title);
111 $currentPid = getmypid();
114 $psContent =
"# Show error message using Windows Forms\n";
115 $psContent .=
"Add-Type -AssemblyName System.Windows.Forms\n";
118 $psContent .=
"\$messageParts = @(\n";
119 $lastIndex = count($messageParts) - 1;
120 foreach ($messageParts as $index => $part) {
121 $part = str_replace(
"'",
"''", trim($part));
123 $comma = ($index < $lastIndex) ?
',' :
'';
124 $psContent .=
" '" . $part .
"'" . $comma .
"\n";
127 $psContent .=
"\$message = \$messageParts -join [Environment]::NewLine\n";
128 $psContent .=
"[System.Windows.Forms.MessageBox]::Show(\$message, '" . $title .
"', [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error) | Out-Null\n";
130 $psContent .=
"# After user clicks OK, kill only Bearsampp-related processes\n";
131 $psContent .=
"Stop-Process -Id " . (int)$currentPid .
" -Force -ErrorAction SilentlyContinue\n";
132 $psContent .=
"Stop-Process -Name bearsampp -Force -ErrorAction SilentlyContinue\n";
134 $psContent .=
"# Clean up\n";
135 $psContent .=
"Remove-Item -Path '" . $flagFilePs .
"' -Force -ErrorAction SilentlyContinue\n";
136 $psContent .=
"Remove-Item -Path '" . $psFilePs .
"' -Force -ErrorAction SilentlyContinue\n";
138 @file_put_contents($psFile, $psContent);
142 $wsh->Run(
'powershell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -File "' . $psFile .
'"', 0,
false);
144 pclose(popen(
'start "" powershell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -File "' . $psFile .
'"',
'r'));
159require_once dirname(__FILE__) .
'/classes/class.path.php';
160require_once dirname(__FILE__) .
'/classes/class.root.php';
176 stream_context_set_default(array(
178 'verify_peer' =>
true,
179 'verify_peer_name' =>
true,
180 'allow_self_signed' =>
false,
197 $currentAction = isset($_SERVER[
'argv'][1]) ? $_SERVER[
'argv'][1] :
'';
199 Log::debug(
'root.php: script ending, calling Util::stopLoading() for action: ' . $currentAction);
static debug($data, $file=null)
static getPhpPath($aetrayPath=false)
const APP_GITHUB_USERAGENT
if(is_file($bearsamppCacert)) $bearsamppAction
const APP_GITHUB_PROXY_URL
const APP_GITHUB_PROXY_KEY
const APP_GITHUB_LATEST_URL