From 932ac26bae6e1249c12ab5ba0c314b20115402a0 Mon Sep 17 00:00:00 2001 From: Dev Date: Fri, 6 Nov 2026 10:55:55 +0100 Subject: [PATCH] Restore public intake destinations after native SSO renewal (328) --- .../osticket/SUPPORT-POLISH-328.md | 2 ++ .../integrations/osticket/authenticate.php | 5 +-- website/integrations/osticket/dune-sso.php | 13 +++++++- .../osticket/intake-navigation.php | 31 +++++++++++++++++++ .../osticket/tests/intake-navigation-test.php | 23 ++++++++++++++ 5 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 website/integrations/osticket/intake-navigation.php create mode 100644 website/integrations/osticket/tests/intake-navigation-test.php diff --git a/website/integrations/osticket/SUPPORT-POLISH-328.md b/website/integrations/osticket/SUPPORT-POLISH-328.md index e1b0e22d..fb1a9f1a 100644 --- a/website/integrations/osticket/SUPPORT-POLISH-328.md +++ b/website/integrations/osticket/SUPPORT-POLISH-328.md @@ -6,6 +6,8 @@ This package implements consolidated sources 119, 133 and 134. It changes presen The homepage resolves an explicit list through `Topic::getPublicHelpTopics()`. It presents parental requests (with the separate child-removal link), GDPR removal, general help, Sales, forum help, technical problems, access issues, ban appeals and Alpha signup. Missing/non-public topics produce no card. Existing priority relationships and specialised appeal/Alpha handlers remain intact. Cards use two equal desktop columns and one mobile column; the final card has the same treatment as every other card. +Native parent-prefixed topic labels are matched by their unique leaf name; ambiguous public branches are omitted. A public intake selected before sign-in is remembered for five minutes and consumed once after successful existing SSO/native authentication. Only relative `/open.php`, a currently public positive topic ID, or `/alpha-signup.php` is accepted. Recheck topic visibility after sign-in. Staff/Dev/appeal flows retain precedence; external URLs, private topics and POST payloads are excluded. The common SSO nonce validation and account/native authorisation checks are unchanged. + `configure-public-sales.php` defaults to a read-only plan. Run it with `--apply` only for an authorised rollout. It creates **Customer sales enquiries**, routed through the existing Sales department/team, using only standard Ticket Details form 2. The existing private **Sales enquiries** email/internal topic remains private and unchanged. The installer requires transactional topic tables, serialises creation with a named lock, validates repeat runs and refuses routing/form drift. It does not create a ticket or process a payment/refund. ## Shared actions diff --git a/website/integrations/osticket/authenticate.php b/website/integrations/osticket/authenticate.php index 133fe101..ff6076b9 100644 --- a/website/integrations/osticket/authenticate.php +++ b/website/integrations/osticket/authenticate.php @@ -4,11 +4,12 @@ require_once '/home/dunerealms/apps/integrations/shared-header.php'; require_once INCLUDE_DIR.'class.auth.php'; require_once '/home/dunerealms/apps/integrations/bridge.php'; require_once '/home/dunerealms/apps/integrations/osticket/staff-scope.php'; +require_once '/home/dunerealms/apps/integrations/osticket/intake-navigation.php'; function dune_ticket_identity(){return dune_bridge('identity',['sessionRef'=>$_SESSION['dune_session_ref']??'']);} class DuneClientAuthentication extends ExternalUserAuthenticationBackend { static $id='dunerealms-client';static $name='DuneRealms';static $service_name='DuneRealms'; function authenticate($username,$password){return false;} - function triggerAuth(){header('Location: /dune-sso.php');exit;} + function triggerAuth(){$next=dune_requested_intake_path(basename($_SERVER['SCRIPT_NAME']??''),$_GET,$_SERVER['REQUEST_METHOD']??'GET');header('Location: /dune-sso.php'.($next!==null?'?intake='.rawurlencode($next):''));exit;} function signOn(){ $identity=dune_ticket_identity();if(!$identity)return null; $email=$identity['id'].'@accounts.dunerealms.invalid'; @@ -43,7 +44,7 @@ class DuneAccountsPlugin extends Plugin { if(in_array($file,['dune-sso.php','cron.php','api.php'],true))return; if(strtolower($_SERVER['HTTP_X_REQUESTED_WITH']??'')!=='xmlhttprequest')ob_start('dune_shared_header'); $identity=dune_ticket_identity(); - if(!is_array($identity)||!is_array($identity['permissions']??null)){if(in_array($file,['index.php','service-targets.php'],true)&&!str_contains($_SERVER['SCRIPT_NAME']??'','/scp/'))return;if(strtolower($_SERVER['HTTP_X_REQUESTED_WITH']??'')==='xmlhttprequest'){http_response_code(401);exit('Sign in again to continue.');}$target='/dune-sso.php';if($file==='dev-tasks.php')$target.='?dev=1';if(str_contains($_SERVER['SCRIPT_NAME']??'','/scp/'))$target.='?staff=1';elseif($file==='appeal.php')$target.='?appeal='.rawurlencode($_GET['banId']??'');header('Location: '.$target);exit;} + if(!is_array($identity)||!is_array($identity['permissions']??null)){if(in_array($file,['index.php','service-targets.php'],true)&&!str_contains($_SERVER['SCRIPT_NAME']??'','/scp/'))return;if(strtolower($_SERVER['HTTP_X_REQUESTED_WITH']??'')==='xmlhttprequest'){http_response_code(401);exit('Sign in again to continue.');}$target='/dune-sso.php';if($file==='dev-tasks.php')$target.='?dev=1';if(str_contains($_SERVER['SCRIPT_NAME']??'','/scp/'))$target.='?staff=1';elseif($file==='appeal.php')$target.='?appeal='.rawurlencode($_GET['banId']??'');elseif($next=dune_requested_intake_path($file,$_GET,$_SERVER['REQUEST_METHOD']??'GET'))$target.='?intake='.rawurlencode($next);header('Location: '.$target);exit;} if($file==='login.php'&&str_contains($_SERVER['SCRIPT_NAME']??'','/scp/')&&($_SERVER['REQUEST_METHOD']??'')==='GET'){ if(!in_array('web.tickets.staff',$identity['permissions'],true)){http_response_code(403);exit('Staff ticket permission required.');} $now=time();if($now-(int)($_SESSION['dune_staff_renew_attempt']??0)<5){http_response_code(503);exit('Support sign-in could not be renewed. Return to the Account centre and retry the staff ticket desk.');} diff --git a/website/integrations/osticket/dune-sso.php b/website/integrations/osticket/dune-sso.php index 5a78db60..6d9443b2 100644 --- a/website/integrations/osticket/dune-sso.php +++ b/website/integrations/osticket/dune-sso.php @@ -1,13 +1,23 @@ signOn())||!$backend->login($user,$backend)){http_response_code(503);exit('Support sign-in unavailable. Contact the operator.');} +$intakeReturn=dune_take_intake_path($_SESSION,time()); if(!empty($_SESSION['dune_staff_requested'])&&in_array('web.tickets.staff',$identity['permissions'],true)){ if(!empty($_SESSION['dune_support_admin_requested'])&&!in_array('web.tickets.admin',$identity['permissions'],true)){unset($_SESSION['dune_support_admin_requested']);http_response_code(403);exit('Support administration permission required.');} unset($_SESSION['dune_staff_requested']);$name=str_replace('-','',$identity['id']); @@ -28,4 +38,5 @@ if(!empty($_SESSION['dune_staff_requested'])&&in_array('web.tickets.staff',$iden } if(isset($_SESSION['dune_appeal_requested'])){$id=$_SESSION['dune_appeal_requested'];unset($_SESSION['dune_appeal_requested']);header('Location: /appeal.php?banId='.rawurlencode($id));exit;} if(!empty($_SESSION['dune_dev_requested'])){unset($_SESSION['dune_dev_requested']);header('Location: /dev-tasks.php');exit;} +if($intakeReturn!==null){header('Location: '.$intakeReturn,true,303);exit;} header('Location: /tickets.php');exit; diff --git a/website/integrations/osticket/intake-navigation.php b/website/integrations/osticket/intake-navigation.php new file mode 100644 index 00000000..40f6eb7d --- /dev/null +++ b/website/integrations/osticket/intake-navigation.php @@ -0,0 +1,31 @@ +128) return null; + if ($candidate==='/alpha-signup.php' || $candidate==='/open.php') return $candidate; + if (!preg_match('~^/open\.php\?topicId=([1-9][0-9]{0,8})$~D',$candidate,$match)) return null; + $public=Topic::getPublicHelpTopics(); + return is_array($public) && array_key_exists((int)$match[1],$public) ? $candidate : null; +} +function dune_requested_intake_path($file, $query, $method) { + if (!in_array($method,['GET','HEAD'],true)) return null; + if ($file==='alpha-signup.php') return '/alpha-signup.php'; + if ($file!=='open.php') return null; + if (!array_key_exists('topicId',$query)) return '/open.php'; + if (!is_string($query['topicId'])) return null; + return dune_public_intake_path('/open.php?topicId='.$query['topicId']); +} +function dune_remember_intake_path(&$session, $query, $now, $method='GET') { + unset($session['dune_intake_return']); + if (!in_array($method,['GET','HEAD'],true)) return; + // Explicit staff, Dev and appeal flows retain their existing destinations. + if (($query['staff']??'')==='1' || ($query['admin']??'')==='1' || ($query['dev']??'')==='1' || array_key_exists('appeal',$query)) return; + $path=dune_public_intake_path($query['intake']??null); + if ($path!==null) $session['dune_intake_return']=['path'=>$path,'expires'=>$now+300]; +} +function dune_take_intake_path(&$session, $now) { + $saved=$session['dune_intake_return']??null;unset($session['dune_intake_return']); + if (!is_array($saved) || !is_int($saved['expires']??null) || $saved['expires']<=$now || $saved['expires']>$now+300) return null; + // Recheck the current catalogue: a topic may have become private during sign-in. + return dune_public_intake_path($saved['path']??null); +} diff --git a/website/integrations/osticket/tests/intake-navigation-test.php b/website/integrations/osticket/tests/intake-navigation-test.php new file mode 100644 index 00000000..f469f002 --- /dev/null +++ b/website/integrations/osticket/tests/intake-navigation-test.php @@ -0,0 +1,23 @@ +'General support',11=>'Report a Problem / Access Issue',14=>'Parental consent request [Preview]',21=>'Customer sales enquiries'];static function getPublicHelpTopics(){return self::$public;}} +require dirname(__DIR__).'/intake-navigation.php'; +$checks=0; +function intake_check($value,$label){global $checks;$checks++;if(!$value)throw new RuntimeException($label);} +foreach(['/open.php','/alpha-signup.php','/open.php?topicId=21','/open.php?topicId=11','/open.php?topicId=14']as$path)intake_check(dune_public_intake_path($path)===$path,'Public intake rejected'); +foreach([null,[],false,'https://example.test/open.php','//example.test/open.php','/\\example.test','/../open.php','/%6fpen.php','/open.php#x',"/open.php\r\nLocation: https://example.test",'/open.php?topicId=17','/open.php?topicId=20','/open.php?topicId=0','/open.php?topicId=01','/open.php?topicId=-1','/open.php?topicId=999','/open.php?topicId=21&topicId=14','/open.php?topicId=21&next=https://example.test','/open.php?topicId[]=21','/open.php?topicId=999999999999999999','/scp/tickets.php','/dev-tasks.php','/tickets.php?id=1','/alpha-signup.php?anything=1']as$path)intake_check(dune_public_intake_path($path)===null,'Unsafe or private intake accepted'); +intake_check(dune_requested_intake_path('open.php',['topicId'=>'21'],'GET')==='/open.php?topicId=21','Selected public topic lost'); +intake_check(dune_requested_intake_path('open.php',[],'HEAD')==='/open.php','Generic intake lost'); +intake_check(dune_requested_intake_path('alpha-signup.php',[],'GET')==='/alpha-signup.php','Alpha route lost'); +foreach([['open.php',['topicId'=>['21']],'GET'],['open.php',['topicId'=>'17'],'GET'],['open.php',['topicId'=>'21'],'POST'],['tickets.php',[],'GET']]as$args)intake_check(dune_requested_intake_path(...$args)===null,'Invalid request remembered'); +$session=['dune_sso_state'=>'existing-nonce','dune_session_ref'=>'existing-reference']; +dune_remember_intake_path($session,['intake'=>'/open.php?topicId=21'],100); +intake_check(dune_take_intake_path($session,101)==='/open.php?topicId=21','Successful sign-in route lost'); +intake_check(dune_take_intake_path($session,102)===null,'Return context replayed'); +intake_check($session===['dune_sso_state'=>'existing-nonce','dune_session_ref'=>'existing-reference'],'Authentication state changed'); +foreach([['staff'=>'1'],['admin'=>'1'],['dev'=>'1'],['appeal'=>'']]as$special){dune_remember_intake_path($session,['intake'=>'/open.php?topicId=21'],100);dune_remember_intake_path($session,$special+['intake'=>'/open.php?topicId=21'],101);intake_check(dune_take_intake_path($session,102)===null,'Specialised flow overridden');} +dune_remember_intake_path($session,['intake'=>'/open.php?topicId=21'],100,'POST');intake_check(dune_take_intake_path($session,101)===null,'POST context remembered'); +dune_remember_intake_path($session,['intake'=>'/open.php?topicId=21'],100);intake_check(dune_take_intake_path($session,400)===null,'Expired context accepted'); +dune_remember_intake_path($session,['intake'=>'/open.php?topicId=21'],100);intake_check(dune_take_intake_path($session,99)===null,'Future context accepted'); +dune_remember_intake_path($session,['intake'=>'/open.php?topicId=21'],100);unset(Topic::$public[21]);intake_check(dune_take_intake_path($session,101)===null,'Now-private topic accepted'); +Topic::$public=null;intake_check(dune_public_intake_path('/open.php?topicId=21')===null,'Unavailable catalogue accepted'); +echo "$checks public-intake navigation checks passed; nonce, identity, specialised flows and POST contents preserved.\n";