From 46ce5061071b84d52db032d3ebb5fca8ec8297cf Mon Sep 17 00:00:00 2001 From: Zack Spear Date: Mon, 20 Nov 2023 18:34:50 -0800 Subject: [PATCH] refactor: SelectCase caseModel cookie setting --- emhttp/plugins/dynamix/include/SelectCase.php | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/emhttp/plugins/dynamix/include/SelectCase.php b/emhttp/plugins/dynamix/include/SelectCase.php index d509cbda9..faf2b2912 100644 --- a/emhttp/plugins/dynamix/include/SelectCase.php +++ b/emhttp/plugins/dynamix/include/SelectCase.php @@ -16,22 +16,28 @@ $model = $_POST['model']??''; $root = "/boot/config/plugins/dynamix"; $name = "$root/$file"; +/** + * reset cookie so emhttp/plugins/dynamix.my.servers/include/state.php doesn't need to read the flash each page load + * cookie is read in emhttp/plugins/dynamix.my.servers/include/state.php + */ +function setCaseModelCookie($modelName) { + $cookieOptions = array ( + 'expires' => time() + (10 * 365 * 24 * 60 * 60), // overkill + 'path' => '/', + 'secure' => false, + 'httponly' => false, + 'samesite' => 'Strict', + ); + setcookie('caseModel', $modelName, $cookieOptions); +} + if (realpath(dirname($name)) == $root) { switch ($_POST['mode']??'') { case 'set': - if ($model) file_put_contents($name,$model); - /** - * reset cookie so emhttp/plugins/dynamix.my.servers/include/state.php doesn't need to read the flash each page load - * cookie is read in emhttp/plugins/dynamix.my.servers/include/state.php - */ - $cookieOptions = array ( - 'expires' => time() + (10 * 365 * 24 * 60 * 60), // overkill - 'path' => '/', - 'secure' => false, - 'httponly' => false, - 'samesite' => 'Strict', - ); - setcookie('caseModel', file_get_contents($name), $cookieOptions); + if ($model) { + file_put_contents($name,$model); + setCaseModelCookie($model); + } break; case 'get': if (is_file($name)) echo file_get_contents($name); @@ -40,6 +46,7 @@ if (realpath(dirname($name)) == $root) { $case = 'case-model.png'; file_put_contents($name,$case); file_put_contents("$root/$case",base64_decode(str_replace('data:image/png;base64,','',$_POST['data']??''))); + setCaseModelCookie('custom'); break; } }