I encountered the same issue and was able to resolve it by following a tutorial from Arworld, which Iāve adapted to make it easier. The issue arises because CyberPanel detects an IP address change during a session, which leads to an automatic logout. If youāre using Cloudflare or another proxy, this can happen frequently due to IP address changes.
Open the secMiddleware.py file with nano for editing:
nano /usr/local/CyberCP/CyberCP/secMiddleware.py
Replace all occurrences of (request) with 'True-Client-IP' in the IP check code by using the code below exactly as presented:
try:
uID = request.session['userID']
admin = Administrator.objects.get(pk=uID)
ipAddr = request.META.get('True-Client-IP') # Use 'True-Client-IP' for Cloudflare
if ipAddr.find('.') > -1:
if request.session['ipAddr'] == ipAddr or admin.securityLevel == secMiddleware.LOW:
pass
else:
del request.session['userID']
del request.session['ipAddr']
logging.writeToFile(request.META.get('True-Client-IP'))
final_dic = {'error_message': "Session reuse detected, IPAddress logged.",
"errorMessage": "Session reuse detected, IPAddress logged."}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
else:
ipAddr = request.META.get('True-Client-IP').split(':')[:3]
if request.session['ipAddr'] == ipAddr or admin.securityLevel == secMiddleware.LOW:
pass
else:
del request.session['userID']
del request.session['ipAddr']
logging.writeToFile(request.META.get('True-Client-IP'))
final_dic = {'error_message': "Session reuse detected, IPAddress logged.",
"errorMessage": "Session reuse detected, IPAddress logged."}
final_json = json.dumps(final_dic)
return HttpResponse(final_json)
except:
pass
Save and close nano:
Press Ctrl + O to save.
Press Enter to confirm.
Then, press Ctrl + X to exit.
Step 3: Restart CyberPanel Service
To apply the changes, restart the CyberPanel service with this command:
systemctl restart lscpd
Step 4: Test the Connection
Go back to your browser, log into CyberPanel again, and check if the IP session reuse error is resolved.
Conclusion
By following this tutorial, youāve adjusted the IP check so that CyberPanel recognizes the userās real IP address, even if youāre using a proxy service like Cloudflare. This should resolve the unexpected logout issue without compromising security.
Note: Keep a record of these changes for future CyberPanel updates.
I use Cloudflare with the proxy enabled for the panel accessible from the web and having made the replacement only for the part indicated above, for me everything works correctly, you must surely have a problem elsewhere
I also use Cloudflare with proxy set up, i.e. without Cloudlfare the access works without port 8090. I have changed the code part, but also get an error 500.
Had you seen that the secMiddleware.py file was updated two days ago? Do you have the full code for us?
Good morning,
with all due respect, this really doesnāt solve anything. Changing control panel files makes no sense at all! Especially considering the high frequency of updates released by developers.
Is this a compatibility problem with Cloudflare? Is it sufficient to change the global variable used in the secMiddleware.py file?
Very well then, the developers will work on it and insert a checkbox or something similar within the panel to signal that Cloudflare is being used and thus the behaviour in the code of the file is changed. Or they will find a way to detect the presence of the clodflare proxy and thus, again, change the behaviour of the file.
There is NO way that users would regularly have to modify a panel file to compensate for such a problem.