Remote question...

Discussion in 'Developers' Forum' started by BorderAmigos, Jun 11, 2010.

  1. BorderAmigos

    BorderAmigos New Member

    I'm writing some PHP scripts to be used in Drupal pages as front ends to the SOAP remote functions. For my first testing and debugging I'm using the mail_user add, delete, and update functions. It seems to be working at this point and doing the proper changes in the database.

    The question is that when I delete a mail user the /www/vmail/domain/user files do not get deleted. Is this the expected function and should I write the file deletion routine into my script?

    Also just noticed that the quota value shown in the ISPConfig 3 interface does not match the value sent to the SOAP function.
     
    Last edited: Jun 11, 2010
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    Thats all handled by ISPConfig. Do not write it in your script.

    Be aware that you have to send the quota in bytes when you use the API as the internal quota handling of courier is in bytes and not MB. 1 kb has 1024 bytes and 1 MB has 1024*1024 bytes when you calculyte the quota.
     
  3. BorderAmigos

    BorderAmigos New Member

    Thanks Till. I added some mail users, sent and received emails to them, then deleted them. All seems to work as far as mail and database functions. But now, 3 days after deleting the users (and verifying they are deleted in the database), the files are still in /var/vmail so ISPConfig doesn't seem to be deleting them as it should. The directory owner appears to be set by ISPConfig 3 as vmail with permissions 700.

    Here is the script:
    Code:
    <?php
    
    // Configuration values
    $username = 'admin';
    $password = 'password';
    $server_ip = '123.456.789.123.';
    $server_port = '8080';
    $db_user='root';
    $db_password='password';
    $db_host='localhost';
    $db_name='dbispconfig';
    $db_table='mail_user';
    
    function get_mailuser_id($db_host, $db_user, $db_password,$db_name,$db_table,$soap_email) {
    	$conn = mysql_connect($db_host, $db_user, $db_password) or die('Error connecting to mysql');
    	$db_found=mysql_select_db($db_name);
    	if ($db_found) {
    		$SQL = "SELECT mailuser_id FROM $db_table WHERE email='$soap_email'";
    		$dbread = mysql_fetch_row(mysql_query($SQL));
    		$mailuser_id = $dbread[0];
    	} else {
    		$soap_result .= 'Database Not Found ';
    	}
    	mysql_close($conn);
    	return $mailuser_id;
    }
    
    if (isset($_REQUEST['SOAP_FUNCTION'])) {
    
    	$soap_location = 'http://'.$server_ip.':'.$server_port.'/remote/index.php';
    	$soap_uri = 'http://'.$server_ip.':'.$server_port.'/remote/';
    	$soap_result = 'Results: ';
    	$soap_function = $_REQUEST['SOAP_FUNCTION'];
    	$soap_user = $_REQUEST['SOAP_USER'];
    	$soap_domain = $_REQUEST['SOAP_DOMAIN'];
    	$soap_email = $soap_user.'@'.$soap_domain;
    	$soap_password = $_REQUEST['SOAP_PASSWORD'];
    	$soap_quota = $_REQUEST['SOAP_QUOTA'];
    	$soap_maildir = '/var/vmail/'.$soap_domain.'/'.$soap_user;
    	$client = new SoapClient(null, array('location' => $soap_location,'uri' => $soap_uri,'trace'=>1));
    
    	//echo htmlentities($client->__getFunctions());
    
    	try {
    
    		if($session_id = $client->login($username,$password)) {
    			$soap_result .= 'Logged In...&nbsp;Session:&nbsp;'.$session_id.'...&nbsp;';   // Zalogowany. Sesja:
    		}
    
    		switch ($soap_function){
    
    			case 'Add':
    				$params = array(
    					'server_id' => 1,
    					'email' => $soap_email,
    					'password' => $soap_password,
    					'quota' => $soap_quota,
    					'maildir' => $soap_maildir,
    					'homedir' => '/var/vmail',							
    					'uid' => '5000',
    					'gid' => '5000',
    					'postfix' => 'y',
    					'disableimap' => 'n',
    					'disablepop3' => 'n'
    				);
    				$client_id = 0;
    				$domain_id = $client->mail_user_add($session_id,$client_id,$params);
    			break;
    
    			case 'Update':
    				$params = array(	
    					'server_id' => 1,
    					'email' => $soap_email,
    					'password' => $soap_password,
    					'quota' => $soap_quota,
    					'maildir' => $soap_maildir,
    					'homedir' => '/var/vmail',							
    					'uid' => '5000',
    					'gid' => '5000',
    					'postfix' => 'y',
    					'disableimap' => 'n',
    					'disablepop3' => 'n'
    				);
    				$client_id = 0;
    				$mailuser_id = get_mailuser_id($db_host, $db_user, $db_password,$db_name,$db_table,$soap_email);
    				$domain__id = $client->mail_user_update($session_id, $client_id, $mailuser_id , $params);
    			break;
    
    			case 'Delete':
    				$client_id = 0;				
    				$mailuser_id = get_mailuser_id($db_host, $db_user, $db_password,$db_name,$db_table,$soap_email);
    				$domain__id = $client->mail_user_delete($session_id,$mailuser_id);
    				$soap_user = '';
    				$soap_domain = '';
    				$soap_password = '';
    				$soap_quota = '';
    			break;
    
    		}
    
    		if($client->logout($session_id)) {
    			$soap_result .= 'Logged Out!<br /><br />';   // Wylogowany
    		}
    
    	} catch (SoapFault $soapFault) {
    		echo "Request :<br><pre>", htmlentities($client->__getLastRequest()), "</pre><br>";
    		echo "Response :<br><pre>", htmlentities($client->__getLastResponse()), "</pre><br>";
    		die('SOAP Error: '.$e->getMessage());   // SOAP Blad
    	}
    
    	print $soap_result;
    
    } else {
    	print 'Please select function (Add, Update or Delete).<br><br>';
    }
    
    $output = '
    	<form action="http://domain.com/this-page" method="post">
    		<table><tr><td>
    		<table>
    		<tr><td>Username:</td><td><input type="text" name="SOAP_USER" value="'.$soap_user.'" /></td></tr>
    		<tr><td>Domain:</td><td><input type="text" name="SOAP_DOMAIN" value="'.$soap_domain.'"  /></td></tr>
    		<tr><td>Password:</td><td><input type="text" name="SOAP_PASSWORD" value="'.$soap_password.'"  /></td></tr>
    		<tr><td>Quota:</td><td><input type="text" name="SOAP_QUOTA" value="'.$soap_quota.'"  /></td></tr>
    		</table>
    		</td><td>
    		<input type="radio" name="SOAP_FUNCTION" value="Add"> Add<br>
    		<input type="radio" name="SOAP_FUNCTION" value="Update"> Update<br>
    		<input type="radio" name="SOAP_FUNCTION" value="Delete"> Delete<br>
    		<input type="submit" value="Submit" />
    		</td></tr></table>
    	</form>';
    print $output;
    ?>
    
     
    Last edited: Jun 13, 2010
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    Which ISPConfig version do you use?

    Thats the correct setting.
     
  5. BorderAmigos

    BorderAmigos New Member

    Version 3.0.2.1. Some permissions are set as root as well.

    ls -la

    total 52
    drwx------ 10 vmail vmail 4096 2010-06-09 15:26 .
    drwx------ 28 vmail vmail 4096 2010-06-14 06:09 ..
    drwx------ 2 vmail vmail 4096 2010-06-09 15:26 courierimapkeywords
    -rw-r--r-- 1 vmail vmail 48 2010-06-09 15:26 courierimapsubscribed
    -rw-r--r-- 1 vmail vmail 15 2010-06-09 15:26 courierimapuiddb
    drwx------ 2 vmail vmail 4096 2010-06-09 15:26 cur
    drwx------ 5 vmail root 4096 2010-06-09 15:26 .Drafts
    drwx------ 5 vmail root 4096 2010-06-09 15:26 .Junk
    drwx------ 2 vmail vmail 4096 2010-06-09 15:26 new
    drwx------ 5 vmail root 4096 2010-06-09 15:26 .Sent
    -rw-r--r-- 1 vmail vmail 24 2010-06-09 15:26 subscriptions
    drwx------ 2 vmail vmail 4096 2010-06-09 15:26 tmp
    drwx------ 6 vmail root 4096 2010-06-09 15:26 .Trash
     
  6. BorderAmigos

    BorderAmigos New Member

    There appear to be pending actions related to inserting and deleting the mail_user in the sys_datalog table but they stay there for days. There are 5 pages of pending actions there (mail_user, content_filter, dns_rr, etc), is that normal?
     
  7. till

    till Super Moderator Staff Member ISPConfig Developer

    You can see if a action is pending or not only in the ispconfig monitor > jobqueue. You can not see this in the datalog, as the dalaog does not track the status of a action and it contains alwysa all actions from the last 30 days.
     
  8. BorderAmigos

    BorderAmigos New Member

    Ok, thanks. ispconfig monitor > jobqueue is empty. sys_datalog contains data for the last 4 months (from the day I first installed ISPConfig 3).

    Still the /var/vmail files and directories are not being deleted when the user is.
     
  9. till

    till Super Moderator Staff Member ISPConfig Developer

    Then I recommend that you post a request in the bugtracker so that the developers can review it (if you run the latest released ISPConfig version), otherwise update your system.

    Then you dont seem to use the latest ispconfig version (3.0.2.1 or 3.0.2.2 beta) as this has beens olved some time ago.
     
  10. BorderAmigos

    BorderAmigos New Member

    "Then you dont seem to use the latest ispconfig version (3.0.2.1 or 3.0.2.2 beta) as this has been solved some time ago."

    From ispconfig > help > version

    ISPConfig Version: 3.0.2.1
     
  11. till

    till Super Moderator Staff Member ISPConfig Developer

    Is this a multiserver install? If yes, have you choosen to reconfigure the DB permissions as you updated the slaves?
     
  12. BorderAmigos

    BorderAmigos New Member

    No. It is a single server install. There are no slaves.
     
  13. till

    till Super Moderator Staff Member ISPConfig Developer

    Then you should update to 3.0.2.2 when it gets released and check a few days later if the datalog gets cleared. It is just a cleanup job and you can have records for months in the datalog without affecting ispconfig.
     
  14. BorderAmigos

    BorderAmigos New Member

    Thanks. The sys_datalog doesn't really affect anything so not important. I did a bug report on the non-deleted files as suggested. Will just leave them for now.
     

Share This Page