Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sarun Mungthanya
SpnPatch-Laravel
Commits
d9ee275c
Commit
d9ee275c
authored
Sep 03, 2024
by
Sarun Mungthanya
Browse files
add call smartupdate api
parent
6681090a
Changes
8
Hide whitespace changes
Inline
Side-by-side
app/Http/Controllers/SmartUpdateController.php
0 → 100644
View file @
d9ee275c
<?php
namespace
App\Http\Controllers
;
use
App\Models\ConfServerPendding
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Facades\DB
;
class
SmartUpdateController
extends
Controller
{
public
function
checkAction
(
Request
$request
)
{
$serviceName
=
$request
->
input
(
'SERVICENAME'
);
$action
=
$request
->
input
(
'ACTION'
);
$serverKeyClient
=
$request
->
input
(
'SERVERKEYCLIENT'
);
// if ($serviceName !== 'SMARTUPDATE' || $action !== 'HISTORY_PATCH') {
// return response()->json(['error' => 'Invalid request'], 400);
// }
if
(
$action
===
'HISTORY_PATCH'
)
{
$this
->
historyPatch
(
$serverKeyClient
);
}
else
if
(
$action
===
'LIST_PATCH'
)
{
$this
->
listPatch
(
$request
);
}
}
public
function
historyPatch
(
$serverKeyClient
)
{
$serverId
=
DB
::
table
(
'conf_server_license'
)
->
where
(
'SNKEY'
,
$serverKeyClient
)
->
value
(
'ID'
);
if
(
!
$serverId
)
{
return
response
()
->
json
([
'error'
=>
'Invalid SERVERKEYCLIENT'
],
404
);
}
$patchHistory
=
$this
->
queryToSimpleTable
(
"
SELECT
TaskFinish as 'Update Date',
TaskRunner as 'Update By',
PDATE as 'Patch Date',
PATCHNAME as 'Title',
PLEVEL as 'Level',
PDESC as 'Description'
FROM conf_server_pendding AS t0
INNER JOIN conf_smartupdate AS t1
ON t0.PatchID = t1.PID
WHERE ServerId = '
$serverId
'
AND TaskStatus = 999
AND PAPPROVEDATE < NOW()
AND PAPPROVEDATE <> '0000-00-00 00:00:00'
AND TaskDate < NOW()
AND TaskDate <> '0000-00-00 00:00:00'
"
);
return
$patchHistory
;
}
public
function
listPatch
(
$request
)
{
$serverKeyClient
=
$request
->
input
(
'SERVERKEYCLIENT'
);
$clientVersion
=
$request
->
input
(
'CLIENTVERSION'
);
// ดึง Server ID จากฐานข้อมูล
$serverId
=
$this
->
getServerId
(
$serverKeyClient
);
if
(
!
$serverId
)
{
return
response
()
->
json
([
'error'
=>
'Invalid SERVERKEYCLIENT'
],
404
);
}
$pendingUpdates
=
ConfServerPendding
::
select
(
't1.PDATE as PatchDate'
,
't1.PATCHNAME as Title'
,
't1.PLEVEL as Level'
,
't1.PDESC as Description'
,
DB
::
raw
(
"IF('
{
$clientVersion
}
' <= t1.major_version, 'Update', 'Version incompatible') AS Action"
)
)
->
from
(
'conf_server_pendding as t0'
)
->
join
(
'conf_smartupdate as t1'
,
't0.PatchID'
,
'='
,
't1.PID'
)
->
where
(
't0.ServerId'
,
$serverId
)
->
where
(
't0.TaskStatus'
,
'<'
,
999
)
->
where
(
't1.PAPPROVEDATE'
,
'<'
,
now
())
->
where
(
't1.PAPPROVEDATE'
,
'<>'
,
'0000-00-00 00:00:00'
)
->
where
(
't0.TaskDate'
,
'<'
,
now
())
->
where
(
't0.TaskDate'
,
'<>'
,
'0000-00-00 00:00:00'
)
->
orderBy
(
't0.PatchID'
,
'ASC'
)
->
get
();
$cannotUpdateAll
=
false
;
foreach
(
$pendingUpdates
as
$index
=>
$update
)
{
if
(
$index
>
0
&&
$update
->
Action
==
'Update'
)
{
$update
->
Action
=
'Require previous update'
;
}
if
(
$update
->
Action
==
'Version incompatible'
)
{
$cannotUpdateAll
=
true
;
}
}
DB
::
table
(
'log_history'
)
->
insert
([
'HDATE'
=>
now
(),
'HSID'
=>
$serverId
,
'HACTION'
=>
'LIST_PATCH'
,
]);
ConfServerPendding
::
where
(
'ServerID'
,
$serverId
)
->
where
(
'TaskStatus'
,
'<'
,
999
)
->
where
(
'TaskDate'
,
'<'
,
now
())
->
update
([
'TaskStatus'
=>
1
]);
echo
view
(
'smartupdate.patch_update'
,
[
'serverKeyClient'
=>
$serverKeyClient
,
'pendingUpdates'
=>
$pendingUpdates
,
'clientVersion'
=>
$clientVersion
,
'cannotUpdateAll'
=>
$cannotUpdateAll
,
]);
}
public
function
queryToSimpleTable
(
$query
,
$numberSortOpt
=
"YES"
,
$columnSortOpt
=
"YES"
,
$colorPack
=
[
'#DDDDDD'
,
'#F2F2F2'
,
'#FFFFFF'
,
'#F2F2FF'
],
$noCodeIfEmpty
=
"NO"
)
{
$result
=
DB
::
select
(
$query
);
if
(
empty
(
$result
))
{
return
$noCodeIfEmpty
===
"YES"
?
''
:
'<p>No data found.</p>'
;
}
$columns
=
array_keys
((
array
)
$result
[
0
]);
$tabID
=
'table'
.
rand
()
+
50
;
$res
=
$columnSortOpt
===
"YES"
?
"<script src=
\"
core/resource/sortTable.js
\"
></script>"
:
""
;
$res
.
=
"<center><table id='
$tabID
' border=0 cellpadding=5 cellspacing=1 bgcolor='
{
$colorPack
[
0
]
}
' width=100% nowrap='nowrap'><thead class='simpleThead'><tr>"
;
foreach
(
$columns
as
$column
)
{
$res
.
=
"<td bgcolor='
{
$colorPack
[
1
]
}
'><b><font face='Arial, Helvetica, sans-serif' size=1>"
.
(
$column
)
.
"</font></b></td>"
;
}
$res
.
=
"</tr></thead><tbody class='simpleTbody'>"
;
foreach
(
$result
as
$index
=>
$row
)
{
$bgColor
=
$colorPack
[(
$index
%
2
)
+
2
];
$res
.
=
"<tr>"
;
foreach
(
$columns
as
$column
)
{
// $cellValue = iconv('UTF-8','TIS-620', $row->$column);
$align
=
is_numeric
(
str_replace
(
','
,
''
,
$row
->
$column
))
&&
$numberSortOpt
===
"YES"
?
" align='right' "
:
''
;
$res
.
=
"<td valign='top'
$align
bgcolor='
$bgColor
' nowrap='nowrap'><font face='Arial, Helvetica, sans-serif' size=2>"
.
(
$row
->
$column
)
.
"</font></td>"
;
}
$res
.
=
"</tr>"
;
}
$res
.
=
"</tbody></table></center>"
;
if
(
$columnSortOpt
===
"YES"
)
{
$res
.
=
"<script language='javascript'>initTable(
\"
$tabID
\"
);</script>"
;
}
return
$res
;
}
public
static
function
getServerId
(
$serverKeyClient
)
{
return
DB
::
table
(
'conf_server_license'
)
->
where
(
'SNKEY'
,
$serverKeyClient
)
->
value
(
'ID'
);
}
}
app/Http/Livewire/Pages/Patch/PatchMasterFile.php
View file @
d9ee275c
...
...
@@ -83,6 +83,7 @@ class PatchMasterFile extends Component
}
private
function
sendMasterFileToEcc
(
$url
,
$postData
)
{
return
Http
::
attach
(
'file'
,
$postData
[
'file'
])
->
asMultipart
()
->
post
(
$url
,
[
...
...
@@ -104,7 +105,7 @@ class PatchMasterFile extends Component
]);
}
function
processPatches
(
$sqlPackAll
,
$fileFormat
,
$gen
s
pn
s
mart
u
pdate
d
ecode
)
function
processPatches
(
$sqlPackAll
,
$fileFormat
,
$gen
S
pn
S
mart
U
pdate
D
ecode
)
{
$uid
=
auth
()
->
user
()
->
id
;
$pLevel
=
"Critical"
;
...
...
@@ -128,7 +129,7 @@ class PatchMasterFile extends Component
$patchCode
=
'$ALL64="'
.
$ALL64
.
'";'
.
"
\n
"
;
if
(
$gen
s
pn
s
mart
u
pdate
d
ecode
)
{
if
(
$gen
S
pn
S
mart
U
pdate
D
ecode
)
{
$updatedecode
=
'$ALLVAR=gzuncompress(spnsmartupdatedecode($ALL64));'
.
"
\n
"
;
}
else
{
$updatedecode
=
'$ALLVAR=gzuncompress(base64_decode($ALL64));'
.
"
\n
"
;
...
...
app/Http/Livewire/Pages/SendPatch/SendMultiPatchBox.php
View file @
d9ee275c
...
...
@@ -94,7 +94,7 @@ class SendMultiPatchBox extends Component
$serverPedding
->
TaskDate
=
date
(
"Y-m-d H:i:s"
);
$serverPedding
->
TaskType
=
""
;
$serverPedding
->
TaskStatus
=
"0"
;
$serverPedding
->
TaskRunner
=
auth
()
->
user
()
->
USERNAME
;
$serverPedding
->
TaskRunner
=
auth
()
->
user
()
->
username
;
$serverPedding
->
save
();
SendPatchEdit
::
logSendPatch
(
$patch
,
$serverLicense
->
ID
,
"Add Patch"
);
...
...
app/Http/Livewire/Pages/SendPatch/SendPatchEdit.php
View file @
d9ee275c
...
...
@@ -175,7 +175,7 @@ class SendPatchEdit extends Component
public
static
function
logSendPatch
(
$patchId
,
$serverId
,
$logDesc
)
{
$log
=
new
LogSendPath2customer
;
$log
->
UID
=
auth
()
->
user
()
->
UID
;
$log
->
UID
=
auth
()
->
user
()
->
uid
;
$log
->
PATCHID
=
$patchId
;
$log
->
SERVERKEYID
=
$serverId
;
$log
->
ACTDATETIME
=
date
(
"Y-m-d H:i:s"
);
...
...
app/Models/ConfServerPendding.php
View file @
d9ee275c
...
...
@@ -17,4 +17,9 @@ class ConfServerPendding extends Model
'TaskFinish'
,
'TaskRunner'
,
];
public
function
confSmartupdate
()
{
return
$this
->
belongsTo
(
ConfSmartupdate
::
class
,
'PatchID'
,
'PID'
);
}
}
app/Models/ConfSmartupdate.php
View file @
d9ee275c
...
...
@@ -39,5 +39,8 @@ class ConfSmartupdate extends Model
// }
// // ฟังก์ชันสำหรับการตรวจสอบและแปลง encoding
public
function
confServerPendding
()
{
return
$this
->
hasMany
(
ConfServerPendding
::
class
,
'PatchID'
,
'PID'
);
}
}
resources/views/smartupdate/patch_update.blade.php
0 → 100644
View file @
d9ee275c
<head>
<title>
Patch Updates
</title>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"css/ui-darkness/jquery-ui-1.8.12.custom.css"
>
<script
src=
"core/resource/sortTable.js"
></script>
</head>
<style>
.list-patch
>
tbody
>
tr
>
td
,
.list-patch
>
thead
>
tr
>
th
{
background-color
:
#F2F2F2
;
font-family
:
'Arial, Helvetica, sans-serif'
;
font-size
:
1em
;
}
.update-btn
{
background-color
:
#336699
;
padding
:
5px
10px
;
color
:
#F2F2F2
;
border-radius
:
10px
;
text-decoration
:
none
;
margin
:
5px
;
}
.update-btn
:hover
,
.update-btn
:active
{
background-color
:
#1a3855
;
}
</style>
<div
class=
"card"
>
{{-- @if ($cannotUpdateAll)
<p
class=
"text-danger"
>
Not all updates can be applied due to version incompatibility.
</p>
@endif --}}
@if ($pendingUpdates->isEmpty())
<p>
No updates available.
</p>
@else
@php
$tabID = 'table' . rand() + 50;
@endphp
<table
class=
"table list-patch bg-primary"
id=
"{{ $tabID }}"
width=
100%
nowrap=
'nowarp'
cellpadding=
6
cellspacing=
1
bgcolor=
'#DDDDDD'
>
<thead
class=
'simpleThead'
>
<tr>
<th>
Patch Date
</th>
<th>
Title
</th>
<th>
Level
</th>
<th>
Description
</th>
<th>
Action
</th>
</tr>
</thead>
<tbody>
@foreach ($pendingUpdates as $update)
<tr>
<td>
{{ $update->PatchDate }}
</td>
<td>
{{ $update->Title }}
</td>
<td>
{{ $update->Level }}
</td>
<td>
{{ $update->Description }}
</td>
<td
style=
"text-align: center;"
>
@if ($update->Action === 'Update')
<a
href=
"{{ route('smart_update', ['patchId' => $update->PatchID]) }}"
class=
"btn update-btn"
>
Update
</a>
@else
<span
class=
"text-muted"
>
{{ $update->Action }}
</span>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
@endif
</div>
routes/api.php
View file @
d9ee275c
<?php
use
App\Http\Controllers\SmartUpdateController
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Facades\Route
;
...
...
@@ -17,3 +18,5 @@ use Illuminate\Support\Facades\Route;
Route
::
middleware
(
'auth:sanctum'
)
->
get
(
'/user'
,
function
(
Request
$request
)
{
return
$request
->
user
();
});
Route
::
post
(
'/smartupdate'
,
[
SmartUpdateController
::
class
,
'checkAction'
])
->
name
(
'smart_update'
);
Route
::
get
(
'/smartupdate'
,
[
SmartUpdateController
::
class
,
'checkAction'
]);
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment