The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

API returns js and/or html in json responses

Discussion in 'cPanel Developers' started by Cristi4n, Feb 19, 2014.

  1. Cristi4n

    Cristi4n Well-Known Member
    PartnerNOC

    Joined:
    Jul 2, 2006
    Messages:
    73
    Likes Received:
    0
    Trophy Points:
    6
    I was wondering if there is a way to get rid of the js and html from a json response.
    I don't believe it's a very good practice to let some js/html code in an answer that's supposed to be simple.
    Can we separate that in a 'raw' key at least, as it's already done with other messages ?
    I am expecting statusmsg to be a simple text so I can return it directly to a user.

    An example is here, at the bottom of the page, the json response (the same is returned in a production environment):
    SuspendAccount < SoftwareDevelopmentKit < TWiki

    {'result': [{'status': 1,
    'statusmsg': '<script>if (window.clear_ui_status) clear_ui_status();</script>.....}]}
     
  2. morissette

    morissette Well-Known Member

    Joined:
    May 24, 2009
    Messages:
    119
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Austin, TX
    cPanel Access Level:
    Root Administrator
    Able to replicate:

    root@dev [~]# php test.php
    object(SimpleXMLElement)#2 (1) {
    ["result"]=>
    object(SimpleXMLElement)#3 (2) {
    ["status"]=>
    string(1) "1"
    ["statusmsg"]=>
    string(750) "<script>if (window.clear_ui_status) clear_ui_status();</script>
    Changing Shell to /bin/false...Changing shell for kyle.
    Warning: "/bin/false" is not listed in /etc/shells
    Shell changed.
    Done
    Locking Password...Locking password for user kyle.
    passwd: Success
    Done
    1Suspending email account logins for kyle.dev.box.net .... Done
    Suspending email account logins for kyle.box.net .... Done
    Suspending mysql users
    Using Universal Quota Support (quota=0)
    Suspended document root /home/kyle/public_html
    Using Universal Quota Support (quota=0)
    Updating ftp passwords for kyle
    Ftp password files updated.
    Ftp vhost passwords synced
    kyle's account has been suspended
    "
    }
    }

    I'd recommend just using the status returned and creating your own statusmsg otherwise you can strip <script>.*?</script> using preg_replace in php or =~ s///g in perl
     
Loading...

Share This Page