DirectAdmin Forums

Go Back   DirectAdmin Forums > Modifications / Add-ons > Scripting / API

Reply
 
Thread Tools Display Modes
  #1  
Old 04-26-2006, 03:30 PM
natterjacks natterjacks is offline
Verified User
 
Join Date: Apr 2006
Posts: 17
Setting a users vacation message through the api

I've been busy working on this today and figured that others may benefit from what I've done.
I've written some php using l0rdphi1's php class (nice one btw!!) to log in an email user and allow them to set their own vacation message.
It's still a work in progress and needs the modification / delete sections added, but you'll get the jist.

I hope this helps!!

The HTML Logon Form:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Verify Users Email Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body><center><br><br>
<form action="login.php" method="post">
<table width="70%" border="0">
<tr>
<td width="21%">Full Email Address:</td>
<td width="54%"><input name="email" type="text" size="64" maxlength="64"></td>
<td width="25%">(e.g. user@domain.com) </td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" name="passwd"></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="submit" type="submit" value="Login"></td>
<td>&nbsp;</td>
</tr>
</table>
</form>
</center>
</body>
</html>
Reply With Quote
  #2  
Old 04-26-2006, 03:31 PM
natterjacks natterjacks is offline
Verified User
 
Join Date: Apr 2006
Posts: 17
The login.php:

<?php

session_start();

// Setting variables for this script only
$email = $_POST["email"];
$passwd = $_POST["passwd"];

// Beginning API call
include 'httpsocket.php';

$sock = new HTTPSocket;

$sock->connect('ssl://domain.com',2222);
$sock->set_login('username','password');

$sock->set_method('POST');

// Authenticate User
$sock->query('/CMD_API_EMAIL_AUTH',

array(

'email' => $email,
'passwd' => $passwd,

));

$result = $sock->fetch_parsed_body();

if ($result["error"] == 1) {
echo "<br><br><center>";
echo "Invalid Email Address or Password<br><br>";
echo "Click <a href=\"login.html\">here </a>to return to the login screen<br></center>";
die();

} else {

// Setting Session wide variables for further scripts
$_SESSION['email'] = $_POST['email'];

$domain = "@niandj.com";
$_SESSION['user'] = str_replace($domain, "", $_SESSION['email']);

}

// Checking to see if a Vacation message already exists
$sock = new HTTPSocket;

$sock->connect('ssl://domain.com',2222);
$sock->set_login('username','password');

$sock->set_method('POST');


$sock->query('/CMD_API_EMAIL_VACATION_MODIFY',

array(

'domain' => 'domain.com',
'user' => $_SESSION['user'],
));

$result = $sock->fetch_parsed_body();

// If the vacation text is returned as null then we prompt the user to create a new message using the form displayed
if ($result["text"] == "") {

echo "<center><br><br>You do not have a Vacation Message, please enter your new message below<br><br><br></center>";

// Otherwise they are prompted to modify their existing message
} else {

echo "<center><br><br>Click <a href=\"modifyedit.php\">here</a> to modify your existing Vacation Message</center>";
die();

}

?>

<html>
<HEAD>
<title>Vacation Entry</title>
</HEAD>
<body>
<br><br>
<table class=list cellpadding=3 cellspacing=1>
<form name=info action="submitvacation.php" method="post">
<tr><td class=list>Email Account: </td><td><?PHP print_r($email); ?></td></tr>
<tr><td class=list>Vacation Message:</td><td class=list align=center><textarea rows=15 cols=60 name=text></textarea></td></tr>
<tr><td class=list>Vacation Start: </td><td class=list>
<select class=selectclass name=starttime>
<option value="morning">Morning</option >
<option value="afternoon">Afternoon</option >
<option value="evening">Evening</option >
</select >
of
<select class=selectclass name=startmonth>
<option selected value="01">Jan</option >
<option value="02">Feb</option >
<option value="03">Mar</option >
<option value="04">Apr</option >
<option value="05">May</option >
<option value="06">Jun</option >
<option value="07">Jul</option >
<option value="08">Aug</option >
<option value="09">Sep</option >
<option value="10">Oct</option >
<option value="11">Nov</option >
<option value="12">Dec</option >
</select >
<select class=selectclass name=startday>
<option selected value="01">01</option >
<option value="02">02</option >
<option value="03">03</option >
<option value="04">04</option >
<option value="05">05</option >
<option value="06">06</option >
<option value="07">07</option >
<option value="08">08</option >
<option value="09">09</option >
<option value="10">10</option >
<option value="11">11</option >
<option value="12">12</option >
<option value="13">13</option >
<option value="14">14</option >
<option value="15">15</option >
<option value="16">16</option >
<option value="17">17</option >
<option value="18">18</option >
<option value="19">19</option >
<option value="20">20</option >
<option value="21">21</option >
<option value="22">22</option >
<option value="23">23</option >
<option value="24">24</option >
<option value="25">25</option >
<option value="26">26</option >
<option value="27">27</option >
<option value="28">28</option >
<option value="29">29</option >
<option value="30">30</option >
<option value="31">31</option >
</select >
<select class=selectclass name=startyear>
<option value="2002">2002</option >
<option value="2003">2003</option >
<option value="2004">2004</option >
<option value="2005">2005</option >
<option selected value="2006">2006</option >
<option value="2007">2007</option >
<option value="2008">2008</option >
<option value="2009">2009</option >
<option value="2010">2010</option >
<option value="2011">2011</option >
<option value="2012">2012</option >
<option value="2013">2013</option >
<option value="2014">2014</option >
<option value="2015">2015</option >
<option value="2016">2016</option >
<option value="2017">2017</option >
<option value="2018">2018</option >
<option value="2019">2019</option >
<option value="2020">2020</option >
<option value="2021">2021</option >
<option value="2022">2022</option >
<option value="2023">2023</option >
<option value="2024">2024</option >
<option value="2025">2025</option >
<option value="2026">2026</option >
<option value="2027">2027</option >
<option value="2028">2028</option >
<option value="2029">2029</option >
</select >
</td></tr>
<tr><td class=list>Vacation End:</td><td class=list>
<select class=selectclass name=endtime>
<option value="morning">Morning</option >
<option selected value="afternoon">Afternoon</option >
<option value="evening">Evening</option >
</select >
of
<select class=selectclass name=endmonth>
<option selected value="01">Jan</option >
<option value="02">Feb</option >
<option value="03">Mar</option >
<option value="04">Apr</option >
<option value="05">May</option >
<option value="06">Jun</option >
<option value="07">Jul</option >
<option value="08">Aug</option >
<option value="09">Sep</option >
<option value="10">Oct</option >
<option value="11">Nov</option >
<option value="12">Dec</option >
</select >
<select class=selectclass name=endday>
<option selected value="01">01</option >
<option value="02">02</option >
<option value="03">03</option >
<option value="04">04</option >
<option value="05">05</option >
<option value="06">06</option >
<option value="07">07</option >
<option value="08">08</option >
<option value="09">09</option >
<option value="10">10</option >
<option value="11">11</option >
<option value="12">12</option >
<option value="13">13</option >
<option value="14">14</option >
<option value="15">15</option >
<option value="16">16</option >
<option value="17">17</option >
<option value="18">18</option >
<option value="19">19</option >
<option value="20">20</option >
<option value="21">21</option >
<option value="22">22</option >
<option value="23">23</option >
<option value="24">24</option >
<option value="25">25</option >
<option value="26">26</option >
<option value="27">27</option >
<option value="28">28</option >
<option value="29">29</option >
<option value="30">30</option >
<option value="31">31</option >
</select >
<select class=selectclass name=endyear>
<option value="2002">2002</option >
<option value="2003">2003</option >
<option value="2004">2004</option >
<option value="2005">2005</option >
<option selected value="2006">2006</option >
<option value="2007">2007</option >
<option value="2008">2008</option >
<option value="2009">2009</option >
<option value="2010">2010</option >
<option value="2011">2011</option >
<option value="2012">2012</option >
<option value="2013">2013</option >
<option value="2014">2014</option >
<option value="2015">2015</option >
<option value="2016">2016</option >
<option value="2017">2017</option >
<option value="2018">2018</option >
<option value="2019">2019</option >
<option value="2020">2020</option >
<option value="2021">2021</option >
<option value="2022">2022</option >
<option value="2023">2023</option >
<option value="2024">2024</option >
<option value="2025">2025</option >
<option value="2026">2026</option >
<option value="2027">2027</option >
<option value="2028">2028</option >
<option value="2029">2029</option >
</select ></td></tr>

<tr><td class=listtitle colspan=3 align=right>

<input type=submit name=create value="Create">
</td></tr>
</form>
</table>
</body>
</html>
Reply With Quote
  #3  
Old 04-26-2006, 03:33 PM
natterjacks natterjacks is offline
Verified User
 
Join Date: Apr 2006
Posts: 17
and the submitvacation.php:

<?php

session_start();

if ($result["error"] == 1) {
die("You are not authorized, please login first");

} else {

// Setting Session Wide Variables
$_SESSION['text'] = stripslashes($_POST['text']);
$_SESSION['starttime'] = $_POST['starttime'];
$_SESSION['startmonth'] = $_POST['startmonth'];
$_SESSION['startday'] = $_POST['startday'];
$_SESSION['startyear'] = $_POST['startyear'];
$_SESSION['endtime'] = $_POST['endtime'];
$_SESSION['endmonth'] = $_POST['endmonth'];
$_SESSION['endday'] = $_POST['endday'];
$_SESSION['endyear'] = $_POST['endyear'];

// Calling the DA API
include 'httpsocket.php';

$sock = new HTTPSocket;

$sock->connect('ssl://domain.com',2222);
$sock->set_login('username','password');

$sock->set_method('POST');

$sock->query('/CMD_API_EMAIL_VACATION',

array(

'domain' => 'domain.com',
'action' => 'create',
'user' => $_SESSION['user'],
'text' => $_SESSION['text'],
'starttime' => $_SESSION['starttime'],
'startmonth' => $_SESSION['startmonth'],
'startday' => $_SESSION['startday'],
'startyear' => $_SESSION['startyear'],
'endtime' => $_SESSION['endtime'],
'endmonth' => $_SESSION['endmonth'],
'endday' => $_SESSION['endday'],
'endyear' => $_SESSION['endyear'],
'create' => 'Create'
));

$result = $sock->fetch_parsed_body();

if ($result["details"] == "A message for that user already exists") {

echo "Submit Failed for: ";
print_r($_SESSION['user']);
echo "<br>";
echo "email: ";
print_r($email);
echo "<br>";
echo "Vacation Message: ";
print_r($text);
echo "<br><br>";
echo "A message for that user already exists";
echo "<br><br>";
echo "Click <a href=\"modifyoverwrite.php\">here</a> to overwrite your old message or click <a href=\"modifyedit.php\">here</a> to edit your old message.";


} else {

print_r($result);

}

}

?>
Reply With Quote
  #4  
Old 04-26-2006, 03:34 PM
natterjacks natterjacks is offline
Verified User
 
Join Date: Apr 2006
Posts: 17
I'm new to php, but this code is working

Please let me know if I'm going about it totally wrong!

Cheers!!
Reply With Quote
  #5  
Old 07-24-2006, 10:57 PM
zaphod zaphod is offline
Verified User
 
Join Date: Jan 2005
Posts: 42
Hi natterjacks,

Any chance of seing the modify*.php files too? Thanks!
Reply With Quote
  #6  
Old 07-25-2006, 12:01 AM
natterjacks natterjacks is offline
Verified User
 
Join Date: Apr 2006
Posts: 17
Hi,

Since then I've changed the code quite a bit to tidy things up. The text is all in Dutch now, which probably won't help you much.

Give me a couple of days and I'll run through the files, translate it back to english and put it all in a zip file.

Cheers,

Nathan
Reply With Quote
  #7  
Old 06-05-2007, 03:28 PM
drenalin drenalin is offline
Verified User
 
Join Date: Jan 2006
Location: Oakland, CA
Posts: 8
Any chance you're still willing to share the work you've done? I tried working with the information you shared, but haven't ever hacked on php code before and haven't been able to get things working yet.
Reply With Quote
  #8  
Old 06-06-2007, 12:20 AM
natterjacks natterjacks is offline
Verified User
 
Join Date: Apr 2006
Posts: 17
here's the zip with all files included.

hth,

Nathan
Attached Files
File Type: zip vacation.zip (10.6 KB, 383 views)
Reply With Quote
  #9  
Old 06-06-2007, 10:43 AM
drenalin drenalin is offline
Verified User
 
Join Date: Jan 2006
Location: Oakland, CA
Posts: 8
Thank you! I've got it working now!
Reply With Quote
  #10  
Old 09-06-2007, 02:46 PM
jechilt jechilt is offline
Verified User
 
Join Date: Jun 2004
Posts: 225
mine is not working. when we submit, it says the vacation message was entered and when we click the link to go back and look at the message, it is not there and the system can't find it.
We log into DA and it is not in there either.

Any suggestions?
__________________
Kind Regards,
John
One of the two dads
Reply With Quote
  #11  
Old 09-07-2007, 02:36 PM
drenalin drenalin is offline
Verified User
 
Join Date: Jan 2006
Location: Oakland, CA
Posts: 8
Have you checked that all your files are owner.group apache.apache? And have you edited vacation.php to include the domain for which you are trying to set things up?
Reply With Quote
  #12  
Old 09-07-2007, 04:36 PM
jechilt jechilt is offline
Verified User
 
Join Date: Jun 2004
Posts: 225
no. instructions did not indicate owner/group had to be changed.

I do not have the access to change the owner/group anyway.
If I am not able to change the owner/group, will I not be able to run this on my client site? This has to be installed on the client site...
__________________
Kind Regards,
John
One of the two dads

Last edited by jechilt; 09-08-2007 at 06:48 AM.
Reply With Quote
  #13  
Old 11-30-2007, 01:52 AM
DirectAdmin Support DirectAdmin Support is offline
Administrator
 
Join Date: Feb 2003
Posts: 6,693
Hello,

I've created an Email Level plugin:
http://www.directadmin.com/forum/showthread.php?t=22715

John
Reply With Quote
  #14  
Old 12-02-2007, 03:57 PM
jlasman's Avatar
jlasman jlasman is offline
NoBaloney
 
Join Date: Jun 2003
Location: Riverside, Calif., USA
Posts: 20,706
Quote:
Originally Posted by DirectAdmin Support View Post
Hooray!

Thanks, John.

Jeff
__________________

Jeff Lasman <directadmin@nobaloney.net> +1 951 643-5345
Third-Party DirectAdmin administration and support
Dedicated Servers, Dedicated Reseller Accounts
NoBaloney Internet Services
P.O. Box 52200
Riverside, Calif. 92517
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 07:32 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
DirectAdmin © 2007 JBMC Software