Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] "cyberpanel listWebsitesJson" requires json.loads() to be ran twice to get compliant JSON #842

Closed
Tracked by #9
Lvl4Sword opened this issue Apr 1, 2022 · 5 comments

Comments

@Lvl4Sword
Copy link
Contributor

Describe the bug
"cyberpanel listWebsitesJson" requires json.loads() to be ran twice to get compliant JSON

NOTE: Do not include any personal or sensitive information, such as email addresses or passwords.

To Reproduce
Run the following Python:

import json
import subprocess

a = subprocess.check_output(['cyberpanel', 'listWebsitesJson'])
print(json.loads(json.loads(a)))

You'll see that json.loads() needs to be ran twice rather than once.

Expected behavior
Only one json.loads() to be needed

Screenshots
If applicable, add screenshots to help explain your problem.
Not needed

Operating system:
Please enter your answer here (e.g. Ubuntu 20.04 LTS)
Ubuntu 20.04 LTS

CyberPanel version:
Please enter your answer here (e.g. 2.1.1).
"cyberpanel version" says 2.1.1

Additional context
No additional context

@Lvl4Sword
Copy link
Contributor Author

Looks like this has been fixed. Not sure what commit did this, but thanks regardless.

@Lvl4Sword
Copy link
Contributor Author

Correction, this has not been fixed.

@Lvl4Sword
Copy link
Contributor Author

Lvl4Sword commented Nov 17, 2023

Since I've gotten no input on this at all, here's the fix for this. I'll also send a PR for this as well.
No reason to assign json_data to "[" and fake being a list, when you can just actually append to a real list.

    def listWebsitesJson(self):
        try:

            websites = Websites.objects.all()
            ipFile = "/etc/cyberpanel/machineIP"
            with open(ipFile, 'r') as f:
                ipData = f.read()
            ipAddress = ipData.split('\n', 1)[0]

            json_data = []

            for items in websites:
                if items.state == 0:
                    state = "Suspended"
                else:
                    state = "Active"
                dic = {'domain': items.domain, 'adminEmail': items.adminEmail, 'ipAddress': ipAddress,
                       'admin': items.admin.userName, 'package': items.package.packageName, 'state': state}
                json_data.append(dic)

            final_json = json.dumps(json_data)
            print(final_json)

        except BaseException as msg:
            logger.writeforCLI(str(msg), "Error", stack()[0][3])
            print(0)

@Lvl4Sword
Copy link
Contributor Author

#1155 has been created for this.

@Lvl4Sword
Copy link
Contributor Author

This has been fixed in #1155

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant