@@ -29,7 +29,7 @@ class HomeController extends Controller
2929{
3030 private const LOGKEY = 'CHc ' ;
3131
32- private const INTERNAL_POST = ['_auto_value ' ,'_key ' ,'_rdn ' ,'_rdn_value ' ,'_step ' ,'_template ' ,'_token ' ,'_userpassword_hash ' ];
32+ private const INTERNAL_POST = ['_auto_value ' ,'_key ' ,'_rdn ' ,'_rdn_new ' , ' _rdn_value ' ,'_step ' ,'_template ' ,'_token ' ,'_userpassword_hash ' ];
3333
3434 /**
3535 * Create a new object in the LDAP server
@@ -307,6 +307,31 @@ public function entry_pending_update(EntryRequest $request): \Illuminate\Http\Re
307307 ->with ('o ' ,$ o );
308308 }
309309
310+ public function entry_rename (Request $ request ): \Illuminate \Http \RedirectResponse |\Illuminate \View \View
311+ {
312+ $ from_dn = Crypt::decryptString ($ request ->post ('dn ' ));
313+ Log::info (sprintf ('%s:Renaming [%s] to [%s] ' ,self ::LOGKEY ,$ from_dn ,$ request ->post ('_rdn_new ' )));
314+
315+ $ o = config ('server ' )->fetch ($ from_dn );
316+
317+ if (! $ o )
318+ return back ()
319+ ->withInput ()
320+ ->with ('note ' ,__ ('DN doesnt exist ' ));
321+
322+ try {
323+ $ o ->rename ($ request ->post ('_rdn_new ' ));
324+
325+ } catch (\Exception $ e ) {
326+ return Redirect::to ('/ ' )
327+ ->with ('failed ' ,$ e ->getMessage ());
328+ }
329+
330+ return Redirect::to ('/ ' )
331+ ->withInput (['_key ' =>Crypt::encryptString ('*dn| ' .$ o ->getDN ())])
332+ ->with ('success ' ,sprintf ('%s: %s ' ,__ ('Entry renamed ' ),$ from_dn ));
333+ }
334+
310335 /**
311336 * Update a DN entry
312337 *
@@ -505,8 +530,8 @@ private function request_key(Request $request,?Collection $old=NULL): array
505530 // Setup
506531 $ cmd = NULL ;
507532 $ dn = NULL ;
508- $ key = $ request ->get ('_key ' ,old ('_key ' ))
509- ? Crypt::decryptString ($ request -> get ( ' _key ' , old ( ' _key ' )) )
533+ $ key = ( $ x = $ request ->get ('_key ' ,old ('_key ' ) ))
534+ ? Crypt::decryptString ($ x )
510535 : NULL ;
511536
512537 // Determine if our key has a command
@@ -518,9 +543,9 @@ private function request_key(Request $request,?Collection $old=NULL): array
518543 $ dn = ($ m [2 ] !== '_NOP ' ) ? $ m [2 ] : NULL ;
519544 }
520545
521- } elseif (old ('dn ' ,$ request ->get ('_key ' ))) {
546+ } elseif ($ x = old ('dn ' ,$ request ->get ('_key ' ))) {
522547 $ cmd = 'dn ' ;
523- $ dn = Crypt::decryptString (old ( ' dn ' , $ request -> get ( ' _key ' )) );
548+ $ dn = Crypt::decryptString ($ x );
524549 }
525550
526551 return ['cmd ' =>$ cmd ,'dn ' =>$ dn ];
0 commit comments