webjive Posted December 20, 2021 Share Posted December 20, 2021 I wrote this hook a while back and sidelined it due to Chrome and Firefox having FTP embedded. On Macs, there was just about no way of not invoking the built in FTP vs using the OS set FTP client. Now that all of that mess is gone from browsers, I decided to dig back into this hook. The reason for the hook is that we build a LOT of sites and having an FTP url lining out to a local FTP client is SUPER convenient vs having to copy/paste credentials into Transmit FTP. The problem I'm having is with the SQL not picking up on user and password if there's a single account. If they have multiple and I switch to another client account, the server/user/pass all get populated correctly. Also, the FTP credentials are showing twice on the account admin screen. Attached is the code and a screenshot of what's happening on a single account (ftp server/user/pass missing) and if I switch accounts, how it fills in and shows in the admin screen. Any help is TRULY appreciated! P.S. Can't embed the code, I keep getting a 403 so attaching a file! UGH! https://www.dropbox.com/s/duxm8y318xxelzc/My hook code.txt?dl=0 0 Quote Link to comment Share on other sites More sharing options...
string Posted December 20, 2021 Share Posted December 20, 2021 (edited) Unfortunately there are multiple issues in the code. And it's unsafe, i will quote myself regarding mysql_real_escape_string: Quote I want to note: This update query is insecure and makes you vulnerable to SQL injections. <snip> security risk as mysql_real_escape_string does not protect against all kinds of SQL injections. And mysql_real_escape_string has been removed from recent PHP versions. As far i know, WHMCS has rebuilt this function so it still works, but they may remove it in a later version. I have rewritten this hook for you: <?php use WHMCS\Service\Service; add_hook('AdminClientServicesTabFields', 1, function($vars) { try { $getService = Service::findOrFail($vars['id']); } catch (Exception $e) { return; } $getPassword = localAPI('DecryptPassword', ['password2' => $getService['password'] ]); if ($getPassword['result'] !== 'success') { return; } $username = $getService['username']; $password = $getPassword['password']; $domain = $getService['domain']; if (empty(trim($domain))) { $domain = $getService->serverModel['hostname']; } echo " <script> jQuery(document).ready(function() { jQuery('#inputPassword').closest('tr').after(` <tr> <td class='fieldlabel' width='20%'>Live Site FTP URL</td> <td class='fieldarea'>{$username} {$password} and so on</td> </tr> <tr> <td class='fieldlabel' width='20%'>Server FTP URL</td> <td class='fieldarea'>{$username} {$password} and so on</td> </tr> `); }); </script> asdfasdfsafs "; }); You just need to update the output according to your needs 🙂 Edited December 20, 2021 by string - 0 Quote Link to comment Share on other sites More sharing options...
webjive Posted December 20, 2021 Author Share Posted December 20, 2021 (edited) Thank you SO much. As you can see, my coding skills are uh.. you get the pic. My final code if someone needs a hook for opening FTP <?php use WHMCS\Service\Service; add_hook('AdminClientServicesTabFields', 1, function($vars) { try { $getService = Service::findOrFail($vars['id']); } catch (Exception $e) { return; } $getPassword = localAPI('DecryptPassword', ['password2' => $getService['password'] ]); if ($getPassword['result'] !== 'success') { return; } $username = $getService['username']; $password = $getPassword['password']; $domain = $getService['domain']; $ftpurl = '<a href="ftp://'.$username.':'.$password.'@'.$domain.'">Connect</a>'; if (empty(trim($domain))) { $domain = $getService->serverModel['hostname']; } echo " <script> jQuery(document).ready(function() { jQuery('#inputPassword').closest('tr').after(` <tr> <td class='fieldlabel' width='20%'>Live Site FTP URL</td> <td class='fieldarea'>{$ftpurl}</td> </tr> `); }); </script> asdfasdfsafs "; }); Edited December 20, 2021 by webjive 0 Quote Link to comment Share on other sites More sharing options...
webjive Posted December 20, 2021 Author Share Posted December 20, 2021 Updated it to have a button instead of a link <?php use WHMCS\Service\Service; add_hook('AdminClientServicesTabFields', 1, function($vars) { try { $getService = Service::findOrFail($vars['id']); } catch (Exception $e) { return; } $getPassword = localAPI('DecryptPassword', ['password2' => $getService['password'] ]); if ($getPassword['result'] !== 'success') { return; } $username = $getService['username']; $password = $getPassword['password']; $domain = $getService['domain']; $ftpurl = '<a href="ftp://'.$username.':'.$password.'@'.$domain.'"><input type="button" value="Connect"></a>'; if (empty(trim($domain))) { $domain = $getService->serverModel['hostname']; } echo " <script> jQuery(document).ready(function() { jQuery('#inputPassword').closest('tr').after(` <tr> <td class='fieldlabel' width='20%'>Live Site FTP URL</td> <td class='fieldarea'>{$ftpurl}</td> </tr> `); }); </script> asdfasdfsafs "; }); 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.