-
-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Downloadable Windows Script #626
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,83 @@ public function getShareXConfig(Request $request, Response $response, int $id): | |
return json($response, $json, 200, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT) | ||
->withHeader('Content-Disposition', 'attachment;filename="' . $fileName . '"'); | ||
} | ||
|
||
/** | ||
* @param Request $request | ||
* @param Response $response | ||
* @param int $id | ||
* | ||
* @return Response | ||
*/ | ||
public function getWindowsConfig(Request $request, Response $response, int $id): Response | ||
{ | ||
// Retrieve the user | ||
$user = make(UserRepository::class)->get($request, $id, true); | ||
|
||
if (!$user->token) { | ||
$this->session->alert(lang('no_upload_token'), 'danger'); | ||
return redirect($response, $request->getHeaderLine('Referer')); | ||
} | ||
|
||
// Load the app name from your config.php file | ||
$config = include __DIR__ . '/../../config.php'; // Adjust the path as necessary | ||
$appName = $config['app_name'] ?? 'XBackBone'; // Provide a default if not set | ||
|
||
// Define the file base name and extension | ||
$fileBaseName = $user->username . " - 'Send to' Windows Context Menu Script"; // Base file name without extension | ||
$fileName = $fileBaseName . '.bat'; // Full file name with extension | ||
|
||
// Prepare the content of the .txt file | ||
$batscript = '@echo off' . PHP_EOL; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔨 issue: Can you please put the script in a proper template like for the others? This is very hard to understand and maintain |
||
$batscript .= 'setlocal' . PHP_EOL; | ||
$batscript .= '' . PHP_EOL; | ||
$batscript .= 'if "%~1"=="" (' . PHP_EOL; | ||
$batscript .= ' call :CreateSendToShortcut' . PHP_EOL; | ||
$batscript .= ' exit /b' . PHP_EOL; | ||
$batscript .= ')' . PHP_EOL; | ||
$batscript .= '' . PHP_EOL; | ||
$batscript .= 'set "Token=' .$user->token. '"' . PHP_EOL; | ||
$batscript .= 'set "UploadUrl=' .route('upload'). '"' . PHP_EOL; | ||
$batscript .= '' . PHP_EOL; | ||
$batscript .= ':UploadToXBackBone' . PHP_EOL; | ||
$batscript .= 'curl -k -s -F "token=%Token%" -F "upload=@%1" %UploadUrl%' . PHP_EOL; | ||
$batscript .= 'echo.' . PHP_EOL; | ||
$batscript .= 'if %errorlevel% neq 0 (' . PHP_EOL; | ||
$batscript .= ' echo Upload failed. Curl error code: %errorlevel%' . PHP_EOL; | ||
$batscript .= ') else (' . PHP_EOL; | ||
$batscript .= ' echo File uploaded successfully to ' .$appName.'.' . PHP_EOL; | ||
$batscript .= ')' . PHP_EOL; | ||
$batscript .= 'exit /b' . PHP_EOL; | ||
$batscript .= '' . PHP_EOL; | ||
$batscript .= ':CreateSendToShortcut' . PHP_EOL; | ||
$batscript .= 'set "ShortcutName=Upload to ' .$appName. ' (@'.$user->username.').lnk"' . PHP_EOL; | ||
$batscript .= 'set "ShortcutPath=%APPDATA%\\Microsoft\\Windows\\SendTo\\%ShortcutName%"' . PHP_EOL; | ||
$batscript .= 'set "IconUrl=https://xbackbone.app/favicon.ico"' . PHP_EOL; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔨 issue: This shuld point to the current instance, not the xbb website. |
||
$batscript .= 'set "IconPath=%APPDATA%\\Microsoft\\Windows\\SendTo\\xbackbone.ico"' . PHP_EOL; | ||
$batscript .= 'set "ScriptPath=%~dp0%~nx0"' . PHP_EOL; | ||
$batscript .= '' . PHP_EOL; | ||
$batscript .= 'curl -k -s -o "%IconPath%" "%IconUrl%" > nul 2>&1' . PHP_EOL; | ||
$batscript .= '' . PHP_EOL; | ||
$batscript .= 'echo Set oWS = WScript.CreateObject("WScript.Shell") > CreateShortcut.vbs' . PHP_EOL; | ||
$batscript .= 'echo sLinkFile = "%ShortcutPath%" >> CreateShortcut.vbs' . PHP_EOL; | ||
$batscript .= 'echo Set oLink = oWS.CreateShortcut(sLinkFile) >> CreateShortcut.vbs' . PHP_EOL; | ||
$batscript .= 'echo oLink.TargetPath = "cmd.exe" >> CreateShortcut.vbs' . PHP_EOL; | ||
$batscript .= 'echo oLink.Arguments = "/c ""%ScriptPath%""" >> CreateShortcut.vbs' . PHP_EOL; | ||
$batscript .= 'echo oLink.IconLocation = "%IconPath%" >> CreateShortcut.vbs' . PHP_EOL; | ||
$batscript .= 'echo oLink.Save >> CreateShortcut.vbs' . PHP_EOL; | ||
$batscript .= 'cscript /nologo CreateShortcut.vbs' . PHP_EOL; | ||
$batscript .= 'del CreateShortcut.vbs' . PHP_EOL; | ||
$batscript .= '' . PHP_EOL; | ||
$batscript .= 'echo Send To shortcut created: %ShortcutPath%' . PHP_EOL; | ||
$batscript .= 'exit /b' . PHP_EOL; | ||
|
||
// Return the .txt file as a downloadable response | ||
$response->getBody()->write($batscript); | ||
|
||
return $response | ||
->withHeader('Content-Type', 'application/octet-stream') | ||
->withHeader('Content-Disposition', 'attachment;filename="' . $fileName . '"'); | ||
} | ||
|
||
/** | ||
* @param Request $request | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔨 issue: config must be fetch from the container, as it can be altered during bootstrapping. The config file is never read during the app runtime