Remoting Framework

Discussion in 'General' started by dayjahone, Oct 25, 2008.

  1. dayjahone

    dayjahone Member

    Which brand of Linux was remoting access written for? I don't mind re-installing everything...I just want it to work.
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    For all linux distributions supported by ISPCOnfig.
     
  3. jnsc

    jnsc rotaredoM Moderator

    You shouhld set this debuging variables just after

    Code:
    $reseller_id = $nusoap_client->call('service',$params);
    and if you still does not seen the debuging info, you should place it just after

    Code:
    // Login into 42go Server
    $session_id = $nusoap_client->call('login',$parameters);
    I just saw that you also renamed the $soapclient variable to $nusoap_client so the text sould also be

    Code:
    echo '<h2>Request</h2>';
    echo '<pre>' . htmlspecialchars($nusoap_client->request, ENT_QUOTES) . '</pre>';
    echo '<h2>Response</h2>';
    echo '<pre>' . htmlspecialchars($nusoap_client->response, ENT_QUOTES) . '</pre>';
    I'm using the remoting framework with debian, and everything is working fine.
     
  4. dayjahone

    dayjahone Member

    When I placed it under
    Code:
    // Login into 42go Server
    $session_id = $nusoap_client->call('login',$parameters);
    I got the following:
    Code:
    Request
    
    POST /remote/index.php HTTP/1.0
    Host: server1.mydomain.com:81
    User-Agent: NuSOAP/0.7.3 (1.51)
    Content-Type: text/xml; charset=ISO-8859-1
    SOAPAction: ""
    Content-Length: 538
    
    <?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns3263:login xmlns:ns3263="http://tempuri.org"><user xsi:type="xsd:string">roach</user><pass xsi:type="xsd:string">two</pass></ns3263:login></SOAP-ENV:Body></SOAP-ENV:Envelope>
    Response
    
    HTTP/1.1 200 OK
    Date: Wed, 29 Oct 2008 12:48:41 GMT
    Server: Apache
    X-Powered-By: PHP/5.2.6
    Set-Cookie: PHPSESSID=607fd47af0588e1e48411ca5fd901b00; path=/
    Expires: Thu, 19 Nov 1981 08:52:00 GMT
    Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    Pragma: no-cache
    Transfer-Encoding: chunked
    Content-Type: text/html
    
    <br />
    <b>Fatal error</b>:  Class 'soap_server' not found in <b>/home/admispconfig/ispconfig/web/remote/index.php</b> on line <b>10</b><br />
    Error: Response not of type text/xml: text/html
    I was asking about which brand of Linux because I've done this twice, neither time doing anything custom and neither time deviating from the perfect setup for ubuntu, and both times, it hasn't worked too well. The first time took a lot of posts and tinkering to get it to work. I was wondering if it was smoother with other brands. I picked ubuntu because I thought it was most common.
     
  5. jnsc

    jnsc rotaredoM Moderator

    In /home/admispconfig/ispconfig/web/remote/index.php replace soap_server with nusoap_server
     
  6. dayjahone

    dayjahone Member

    Here is that index.php file:

    Code:
    <?php
    
    include("../../lib/config.inc.php");
    include("../../lib/app.inc.php");
    
    // Lade Soap Klasse
    $go_api->uses_obj("soap");
    
    
    $s = new nusoap_server;
    
    
    $s->register('service');
    $s->register('login');
    $s->register('logout');
    
    
    function login($user, $pass) {
    
            global $go_api, $go_info;
    
            // alte Sessions löschen
            $go_api->db->query("DELETE FROM remote_session WHERE tstamp < '".(time() - 1800)."'");
    
            if(empty($user) or empty($pass)) {
                    return new soap_fault('Client','','username or password empty.');
            } else {
    
                    $user = addslashes($user);
                    $pass = addslashes($pass);
    
                    $user = $go_api->db->queryOneRecord("SELECT * FROM remote_user WHERE username = '$user' and passwort = md5('$pass')");
    
                    // Checke IP
                    if($user["ip"] != '') {
                            if($_SERVER['REMOTE_ADDR'] != $user["ip"]) return new soap_fault('Client','','IP-Address not allowed.');
                    }
    
                    if($user["ruserid"] > 0) {
    
                            $session["user"] = $user;
                            $session_data = addslashes(serialize($session));
                            $session_id = md5 (uniqid (rand()));
                            $go_api->db->query("INSERT INTO remote_session (sid,ruserid,data,tstamp) VALUES ('$session_id','".$user["ruserid"]."','$session_data','".time()."')");
                            return $session_id;
    
                    } else {
                            return new soap_fault('Client','','username or password incorrect.');
                    }
            }
    }
    
    function logout($sid) {
            global $go_api, $go_info;
            if(empty($sid)) {
                    return new soap_fault('Client','','sid empty.');
            } else {
                    $sid = addslashes($sid);
                    $sql = "DELETE FROM remote_session WHERE sid = '$sid'";
                    $go_api->db->query($sql);
                    return true;
            }
    }
    
    
    function service($sid, $module, $function, $params) {
            global $go_api, $go_info;
    
            // prüfe ob session aktiv
            $session = addslashes($session);
    
            // lösche abgelaufene session records ( älter als 30 minuten)
            $go_api->db->query("DELETE FROM remote_session WHERE tstamp < ".time() + 1800);
    
            // hole Session
            $session_record = $go_api->db->queryOneRecord("SELECT * FROM remote_session WHERE sid = '$sid'");
            if(empty($session_record["data"])) {
                    return new soap_fault('Server','','session not available.');
            } else {
                    $session = unserialize(stripslashes($session_record["data"]));
                    $ruserid = $session_record["ruserid"];
                    unset($session_record);
            }
    
            // allowed Modules
            $allowed_modules[] = 'dns';
            $allowed_modules[] = 'slave';
            $allowed_modules[] = 'reseller';
            $allowed_modules[] = 'kunde';
            $allowed_modules[] = 'web';
    
            // überprüfen ob modul und funktion übergeben wurden
    
    
            // Checke IP
            if($session["ip"] != '') {
                    if($_SERVER['REMOTE_ADDR'] != $session["ip"]) return new soap_fault('Client','','IP-Address not allowed.');
            }
    
    
            if(in_array($module,$allowed_modules)) {
                    $go_api->uses($module);
                    if(class_exists($module)) {
                            if(method_exists($go_api->$module,$function)) {
                                    $retval = $go_api->$module->$function($session,$params);
                                    if($go_api->$module->errorMessage == '') {
                                            return $retval;
                                    } else {
                                            return new soap_fault('Client','',$go_api->$module->errorMessage);
                                    }
                            } else {
                                    return new soap_fault('Client','','function does not exist.');
                            }
                    } else {
                            return new soap_fault('Client','','moduleclass not available.');
                    }
            } else {
                    return new soap_fault('Client','','module not allowed.');
            }
    
    }
    
    
    
    
    
    $s->service($HTTP_RAW_POST_DATA);
    
    ?>
    and here is the error I'm still getting:

    Code:
    Request
    
    POST /remote/index.php HTTP/1.0
    Host: server1.mydomain.com:81
    User-Agent: NuSOAP/0.7.3 (1.51)
    Content-Type: text/xml; charset=ISO-8859-1
    SOAPAction: ""
    Content-Length: 538
    
    <?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns2885:login xmlns:ns2885="http://tempuri.org"><user xsi:type="xsd:string">roach</user><pass xsi:type="xsd:string">two</pass></ns2885:login></SOAP-ENV:Body></SOAP-ENV:Envelope>
    Response
    
    HTTP/1.1 200 OK
    Date: Wed, 29 Oct 2008 13:44:42 GMT
    Server: Apache
    X-Powered-By: PHP/5.2.6
    Set-Cookie: PHPSESSID=08d4043c1357535830f5f22b779bc9c6; path=/
    Expires: Thu, 19 Nov 1981 08:52:00 GMT
    Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    Pragma: no-cache
    Transfer-Encoding: chunked
    Content-Type: text/html
    
    <br />
    <b>Fatal error</b>:  Call to undefined function xml_parser_create() in <b>/home/admispconfig/ispconfig/lib/classes/ispconfig_soap.obj.php</b> on line <b>6409</b><br />
    Error: Response not of type text/xml: text/html
     
  7. jnsc

    jnsc rotaredoM Moderator

    This looks like you didn't had libxml2-dev installed when you installed ISPConfig.

    what is the output of
    Code:
    sudo dpkg-query -W -f='${Status} ${Version}\n' libxml2-dev
    If it's not installed you will need to install it
    Code:
    sudo apt-get install libxml2-dev
    and then either recompile ISPConfigs PHP with XML support, or, the simply method, reinstall ISPConfig. Since 2.2.24 ISPConfig detects if libxml2-dev is installed and if yes it enables XML in the bundled PHP.
     
  8. dayjahone

    dayjahone Member

    Wow! So, it worked. The problem must have been that I installed the package after installing ISPConfig. So, I am still having problems with the form that I used on my old system. I am trying to check for a user and if the username doesn't exist, create it. If I just have the add user script, it works, but if it's already there, it doesn't give me an error, but echos the following:

    Code:
    Error: Response not of type text/xml: text/html
    When I have both scripts, I get that error regardless and it doesn't create a user. Here are the functions I am using:

    Code:
    // Get a User
    $params = array ( 'sid' => $session_id,
    'module' => 'web',
    'function' => 'user_get',
    'params' => array ( user_username => $new_username_field // user_username or user_id
    ));
    
    $user = $nusoap_client->call('service',$params);
    if($err = $nusoap_client->getError()) die("Error: ".$err);
    Code:
    // Add User
    $params = array (         'sid'        => $session_id,
                                            'module'         => 'web',
                                            'function'         => 'user_add',
                                            'params'        => array ( web_title => 'mydomain.com',  // web_title or web_id
                                            user_username => $new_username_field,
                                            user_name => $first_name,
                                            user_email => $new_username_field,
                                            user_passwort => $new_password_field,
                                            user_speicher => 0,
                                            user_mailquota => 1000,
                                            user_admin => 0
                                            ));
    
    $user_id = $nusoap_client->call('service',$params);
    if($err = $nusoap_client->getError()) die("Error: ".$err);
    
    // 42go Server logout
    $nusoap_client->call('logout',array('sid' => $session_id));
    
    // Error Check
    if($err = $nusoap_client->getError()) die("Error: ".$err);
    This same code worked fine on the old system. I'm not sure what's wrong.
     
    Last edited: Oct 30, 2008
  9. dayjahone

    dayjahone Member

    Jnsc,

    C'mon, it's soooo close....Please help with this last little piece.
     
  10. jnsc

    jnsc rotaredoM Moderator

    Try also to use the debugging function in the case you get "Error: Response not of type text/xml: text/html"
     
  11. dayjahone

    dayjahone Member

    I don't understand this, but I did a fresh install (for multiple reasons), uploaded the test file and it didn't work. I changed the remoting access user's password to something without numbers or any fancy stuff and it worked fine.
     

Share This Page