Jump to content

javaguy

Members
  • Posts

    16
  • Joined

  • Last visited

javaguy's Achievements

Apprentice

Apprentice (3/14)

  • First Post
  • Collaborator
  • Conversation Starter
  • Week One Done
  • One Month Later

Recent Badges

0

Reputation

  1. I don't know if this is the right forum for this or not, but I can't seem to get a response any other way. I don't seem to be receiving e-mail any more. I sent myself a few test e-mails to make sure, and none of them ever came through. I filed a support ticket, number TAH-18964, but I never got a response. When I attempted to log in to check the ticket status it said that either the ticket number or the e-mail address was wrong. So I filed another support ticket, number GLC-43060, and this time I immediately logged in to check the status but got the exact same result. I use my e-mail for business purposes, so this is rather urgent.
  2. I keep getting automated e-mails saying I needed to upgrade my phpBB: "Installed: v2.0.20 Latest: v2.0.19" Can this be right? I'm having flashbacks to 1984 when Winston's chocolate ration was increased from 30g to 20g.
  3. I installed phpCOIN from Fantastico but am unable to log in. It says my password is incorrect, though I'm reasonably sure it is correct. When I click the forgot-my-password thingy and fill out my username and e-mail, it says that username was not found in the database, although phpMyAdmin shows that it is in the table.
  4. I understand that certificates are either "wildcard" or "ordinary" certificates, and that I need the (more expensive) wildcard certificate if I want it to secure my subdomains. My question is this: Is "www.****.com" considered a subdomain of ****.com? Or would a single, non-wildcard certificate secure the site regardless of whether the user types in the "www" in the url?
  5. Maybe I don't understand my question well enough. I guess I'm trying to figure out how the script can control whether the message still gets delivered after the script is done. I know in some environments a filter can return a 0, 1, 2 or whatever to indicate whether the message gets delivered, discarded, bounced to sender or whatever. Does my script have to actively delete a message to prevent its being delivered? If so, how?
  6. Okay, I got it working. This'll be a little long, so bear with me. If anybody wants I can just e-mail you the scripts. This is how you set up your Coppermine gallery so that you can mail photos to an address in your domain and have them appear in the gallery. First, obviously, create your gallery. Mine is just called album, and I called the mail uploads directory mail_uploads, so all the pathing info in these scripts will say something like "album/albums/mail_uploads". Your mileage my vary. Under the albums directory create the mail_uploads directory (or whatever you want to call it). Next you need to add a new table to your album database. I'll explain later what you use this for: >CREATE TABLE `my_photo_album_db`.`sequences` ( `name` varchar( 25 ) NOT NULL default '', `value` int( 11 ) NOT NULL default '0' ) TYPE = InnoDB; Next insert one record into your new table: >INSERT INTO `sequences` ( `name` , `value` ) VALUES ( 'filenumber', '0' ); Now go to the Mail filtering thingy in your control panel and click Add Filter. You want to filter messages where the To field equals something like myphotoaddress@ blahblahblah. The destination will be |/home/cpanel_login_name/public_html/cgi-bin/pichandler.php, and that first character is the pipe character if you're wondering. This will pipe the incoming messages to this script, which you should save in your public_html/cgi-bin directory under the name pichandler.php. Make sure you set it as executable by others. pichandler.php: >#!/usr/bin/php -q <?php include 'albumupdate.php'; function findSender( $message ) { $index = strpos( $message, "From " ); if ( $index === FALSE ) { return FALSE; } $index += 5; $end = strpos( $message, " ", $index ); return substr($message, $index, $end-$index ); } function getFilename() { $db=mysql_connect ("localhost", "blahblahblah", "myawesomepassword") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("blahblahblah"); $query = "SELECT value FROM sequences WHERE name = 'filenumber'"; mysql_query( "BEGIN" ); $result = mysql_query( $query ) or die ( 'Could not execute query because: ' . mysql_error()); $record = mysql_fetch_array( $result, MYSQL_ASSOC ); $value = $record['value']; $value += 1; $query = "UPDATE sequences set value = $value where name = 'filenumber'"; mysql_query( $query ) or die ( 'Could not execute query because: ' . mysql_error()); mysql_query("COMMIT"); mysql_close(); $filename = "cpg" . $value . ".jpg"; return $filename; } function parseImageAttachments( $message ) { $boundary = "Content-Type: image"; $indexpath = " "; $index = strpos( $message, $boundary ); while ( $index !== FALSE ) { $index = strpos( $message, "name=\"", $index ); if ( $index > 0 ) { $index += 6; $name = getFilename(); decodeImage( $message, $index, $name ); $index = strpos( $message, $boundary, $index ); } } } function decodeImage( $message, $start, $name ) { $boundary = "--__CONTENT_64564_PART_BOUNDARY__33243242__"; if ( strpos( $message, $boundary ) === FALSE ) { $boundary = "Boundary"; } $start = strpos( $message, "\n\n", $start ); if ( $start === FALSE ) { return FALSE; } $start += 2; $end = strpos( $message, $boundary, $start ); if ( $end === FALSE ) { return FALSE; } $image = substr( $message, $start, $end - $start ); $name = "/home/cpanel_login_name/public_html/album/albums/mail_uploads/$name"; if ( file_exists( $name ) === FALSE ) { $ifp = fopen( $name, "xb" ); fwrite( $ifp, base64_decode($image) ); fclose( $ifp ); } } function validateSender( $from ) { $db=mysql_connect ("localhost", "blahblahblah", "myawesomepassword") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("my_album_db"); $query = "SELECT distinct( user_email ) FROM cpg135_users where user_email = '$from'"; $result = mysql_query( $query ) or die ( 'Could not execute query because: ' . mysql_error()); $record = mysql_fetch_array( $result, MYSQL_ASSOC ); if ( $record ) { return TRUE; } mail( $from, "Photo Album", "You are not authorized to send photos to the album " . "from this e-mail address. Sign up at http://blahblahblah." ); return FALSE; } // read from stdin define("STDIN", fopen("php://stdin", "r")); $message = ""; while (!feof(STDIN)) { $message .= fread(STDIN, 1024); } fclose(STDIN); $from = findSender( $message ); if ( validateSender( $from ) === FALSE ) exit(); parseImageAttachments( $message ); //Add images to Coppermine. updateAlbum(); ?> Okay, step-by-step, here's what this script does. Here's the meat of it: >// read from stdin define("STDIN", fopen("php://stdin", "r")); $message = ""; while (!feof(STDIN)) { $message .= fread(STDIN, 1024); } fclose(STDIN); $from = findSender( $message ); if ( validateSender( $from ) === FALSE ) exit(); parseImageAttachments( $message ); //Add images to Coppermine. updateAlbum(); It reads from the standard input until it reaches the end of the file. Now it has the entire e-mail message--that means headers, text, attachments, everything. It's all text as far as the script is concerned. Next we call findSender. This parses the incoming message to find the e-mail address of the sender. Whatever for? Glad you asked. I don't want just any bozo to be able to send naked pictures of his girlfriend to my Coppermine gallery (that's what my personal e-mail is for--sheesh!), so I call validateSender( $from ), which executes this query: >SELECT distinct( user_email ) FROM cpg135_users where user_email = '$from' The cpg135_users table lists all the registered users of my Coppermine gallery. If your e-mail address isn't in it, then I don't want your attachment. If the script is happy with the sender's e-mail address, then it calls parseImageAttachments, which is where the interesting stuff happens: >$boundary = "Content-Type: image"; $indexpath = " "; $index = strpos( $message, $boundary ); The $index variable is a pointer to how far through the message I've parsed so far. In my mind it's my index finger as I trace through it like lines of text on a page. My first stop is wherever it says "Content-Type: image" because that's the interesting part. Note that if there is no such place, the strpos function returns FALSE. Now my while loop: >while ( $index !== FALSE ) { $index = strpos( $message, "name=\"", $index ); if ( $index > 0 ) { $index += 6; $name = getFilename(); decodeImage( $message, $index, $name ); $index = strpos( $message, $boundary, $index ); } } After it finds the boundary it gets a new filename, then calls decodeImage to decode the attachment and save it to the mail_upload directory. Why does it get a new filename? Because the incoming attachment may have a name that conflicts with files already there. When I wrote this my intention was to send pictures to it from my camera phone. The phone gives pictures default names like PIX_1.jpg, PIX_2.jpg... If I delete the latest one from my phone, the number gets reused. If my wife is sending pix from her phone, the names will conflict there too. So it calls getFilename, which uses the new table we added to the album database: >$query = "SELECT value FROM sequences WHERE name = 'filenumber'"; mysql_query( "BEGIN" ); $result = mysql_query( $query ) or die ( 'Could not execute query because: ' . mysql_error()); $record = mysql_fetch_array( $result, MYSQL_ASSOC ); $value = $record['value']; $value += 1; $query = "UPDATE sequences set value = $value where name = 'filenumber'"; mysql_query( $query ) or die ( 'Could not execute query because: ' . mysql_error()); mysql_query("COMMIT"); mysql_close(); The new table, sequences, is of type InnoDB because that's what it has to be in order to participate in transactions in MySQL. We want it in a transaction because when we fetch the number and increment it, we only want the number used once. I gave the table a name field in case I want to write scripts that require other sequences in the album database at a later time. For now my sequences table contains only the one called "filenumber" which it uses to create a file name. After it has a file name it calls decodeImage, which uses strpos to find the boundaries of the attachment, make a string called $image that contains only the attachment, and then calls: >$result = fwrite( $ifp, base64_decode($image) ); And that's really all there is to putting the image in the mail_uploads directory. The parseImageAttachments function's while-loop continues looping as long as it finds attachments. I wrote this with the assumption that all image attachments are valid and of type JPEG. If anybody wants to augment it for other image types, that would rock. After parsing all the image attachments, pichandler.php makes one last call, to function updateAlbum, which is in albumupdate.php, which should also be saved to your cgi-bin directory: >#!/usr/bin/php -q <?php //Returns TRUE if and only if login is successful. function loginCoppermine() { $url="http://blahblahblah/album/login.php?referer=index.php"; $ch = curl_init(); //Post login data. curl_setopt($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_POST, TRUE); curl_setopt ($ch, CURLOPT_COOKIEFILE, "../images/cookie.txt" ); curl_setopt ($ch, CURLOPT_COOKIEJAR, "../images/cookie.txt" ); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); //username/password are required. Login form looks for "submitted" and won't login without it. $postdata="username=javaguy&password=myawesomepassword&remember_me=1&submitted=login"; curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); $content = curl_exec ($ch); curl_close ($ch); if ( strpos($content, "You are already logged in !") ) return TRUE; if ( strpos( $content, "Welcome javaguy ..." ) ) return TRUE; return FALSE; } function getUploads() { $url = "http://sammckee.com/album/searchnew.php?startdir=mail_uploads"; $ch = curl_init(); //Post login data. curl_setopt($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_COOKIEFILE, "../images/cookie.txt" ); curl_setopt ($ch, CURLOPT_COOKIEJAR, "../images/cookie.txt" ); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); $content = curl_exec ($ch); curl_close ($ch); return $content; } function buildPostdata( $uploads_page ) { $postdata = "d0000=1&insert=1"; //iterate through checkboxes. $index = strpos( $uploads_page, "<input name=\"pics[]" ); while ( $index !== FALSE ) { //First the checkbox. $index = strpos( $uploads_page, "value=\"", $index ) + 7; $end = strpos ( $uploads_page, "\"", $index ); $value = substr( $uploads_page, $index, $end - $index ); $postdata .= "&pics[]=$value"; //Then the first hidden field. $index = strpos( $uploads_page, "name=\"", $index ) + 6; $end = strpos( $uploads_page, "\"", $index ); $name = substr( $uploads_page, $index, $end - $index ); $index = strpos( $uploads_page, "value=\"", $index ) + 7; $end = strpos ( $uploads_page, "\"", $index ); $value = substr( $uploads_page, $index, $end - $index ); $postdata .= "&$name=$value"; //And the third hidden field. $index = strpos( $uploads_page, "name=\"", $index ) + 6; $end = strpos( $uploads_page, "\"", $index ); $name = substr( $uploads_page, $index, $end - $index ); $index = strpos( $uploads_page, "value=\"", $index ) + 7; $end = strpos ( $uploads_page, "\"", $index ); $value = substr( $uploads_page, $index, $end - $index ); $postdata .= "&$name=$value"; //Find the next checkbox, if there is one. $index = strpos( $uploads_page, "<input name=\"pics[]", $index ); } return $postdata; } function batchAdd( $postdata ) { $url="http://sammckee.com/album/searchnew.php?insert=1"; $ch = curl_init(); //Post login data. curl_setopt($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_POST, TRUE); curl_setopt ($ch, CURLOPT_COOKIEFILE, "../images/cookie.txt" ); curl_setopt ($ch, CURLOPT_COOKIEJAR, "../images/cookie.txt" ); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); $content = curl_exec ($ch); curl_close ($ch); $urllist = ""; $index = strpos( $content, "a href=\"addpic.php?" ); while ($index !== FALSE ) { $index = strpos( $content, "src=\"addpic.php?", $index ) + 16; $end = strpos ($content, "\"", $index ); $url = "http://sammckee.com/album/addpic.php?" . substr( $content, $index, $end - $index ); $urllist .= ", $url"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_COOKIEFILE, "../images/cookie.txt" ); curl_setopt ($ch, CURLOPT_COOKIEJAR, "../images/cookie.txt" ); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec ($ch); curl_close ($ch); if ( $index < strlen( $content) ) $index = strpos( $content, "a href=\"addpic.php?", $index ); else $index = FALSE; } } function updateAlbum() { //Log into gallery. loginCoppermine(); $uploads_page = getUploads(); $postdata = buildPostdata( $uploads_page ); batchAdd( $postdata ); } ?> This one's fairly self-explanatory, but a note on the buildPostData function: >$postdata = "d0000=1&insert=1"; //iterate through checkboxes. $index = strpos( $uploads_page, "<input name=\"pics[]" ); while ( $index !== FALSE ) { //First the checkbox. $index = strpos( $uploads_page, "value=\"", $index ) + 7; $end = strpos ( $uploads_page, "\"", $index ); $value = substr( $uploads_page, $index, $end - $index ); $postdata .= "&pics[]=$value"; //Then the first hidden field. $index = strpos( $uploads_page, "name=\"", $index ) + 6; $end = strpos( $uploads_page, "\"", $index ); $name = substr( $uploads_page, $index, $end - $index ); $index = strpos( $uploads_page, "value=\"", $index ) + 7; $end = strpos ( $uploads_page, "\"", $index ); $value = substr( $uploads_page, $index, $end - $index ); $postdata .= "&$name=$value"; ... To understand this, walk through the process of a manual Batch Add in your Coppermine gallery. First you click Batch Add and select the directory you want. This script assumes it's always mail_upload. Next you'll be presented with a screen containing a list of all the pictures in that directory, checkboxes to indicate whether you want to include them in the album, and some hidden fields for each one. At the top is a drop-down list where you select the album to which you want to add them--if you forget to select one and click the submit button, Coppermine will yack at you and make you go back. The first thing put into the post data is "d0000=1&insert=1", which is your selection from the drop-down list of albums. In my gallery I only have one album, and that's always how it looks. If this script fails, here, this is a possible culprit, so double-check that d0000 is the one you want. Next, the while-loop iterates through all the checkboxes. For every picture in the mail_uploads directory, there is a checkbox and three hidden fields. All of them must be posted to the form for the Batch Add to work. Just to make things interesting, they all have different names that are programmatically generated. Lastly it calls batchAdd, which starts a curl session and posts the picture data. I thought it would be that simple, but it turns out posting that form doesn't actually do it. In the browser when you post that form it brings up a page listing all the pictures, and for each picture there's a little icon that says "OK" or "DP" or whatever. Well if you right-click on that icon and look at its properties, you'll see that the image source is actually something called addpic.php. It turns out that addpic.php is where the actual work of adding each picture to the album is done. This is fine when you do a Batch Add in the browser, because when the results window comes up the browser tries to load all the images, which means it calls addpic.php for each and every results icon on the page. The script's curl session, however, just retrieves the HTML text. So the last thing the script has to do is parse the results page for every addpic.php tag and initialize a curl session to retrieve each one, thus forcing Coppermine to each each picture to the gallery. Enjoy, Sam
  7. You'll need to put in your username, password and database name and may need to tweak the file path to match your setup. Save this to a file called randompic.php and put a tag in a page like this: ><img src="randompic.php"> ><?php header("Content-type: image/png"); //Select random thumbnail file. $link = mysql_connect('localhost', 'username', 'PASSWORD') or die('Could not connect: ' . mysql_error()); mysql_select_db('album_db') or die('Could not select database'); // Performing SQL query $query = "SELECT filepath, filename FROM cpg135_pictures ORDER BY rand() limit 1"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); $line = mysql_fetch_array($result, MYSQL_ASSOC); $filepath = 'album/albums/' . $line['filepath']; $filename = $line['filename']; mysql_free_result($result); mysql_close($link); $thumbnail_img = imagecreatefromjpeg($filepath . '/' . $filename); imagejpeg($thumbnail_img); imagedestroy($thumbnail_img); ?>
  8. If I have a filter running on messages to someguy@ mydomain, and that address is a real address at my domain, does the message still get delivered after the script runs?
  9. Doh! Okay, it worked great when I was testing it by running it the browser and had some echo statements to display the results page. However, those little icons that say "OK", "DP" and the like? If you dig into the code, the source for those image tags is a file called addpic.php, and it turns out that addpic.php is where the function to add the picture is actually called. So the pictures all get added if it's run in a browser and you echo the results page because the browser will try to display those images, thus invoking addpic.php. When it's part of a mail filter, however, it needs a little help to call addpic.php for each image. I should probably sleep now.
  10. I figured it out. This is only the part of the script that does a batch add of new photos, but it's easy to copy-paste it into the mail filter script. This script assumes that the mail filter dumps all incoming image attachments into a directory called mail_uploads under your album and that all the appropriate chmods 'n' stuff have been done. Obviously you'll have to change the URLs to use your own. I used my images directory to put the cookie.txt file in because...um, actually that's probably a bad place for it, but it was convenient. So without further ado, here is automated Coppermine login and batch add. >#!/usr/bin/php <?php //Returns TRUE if and only if login is successful. function loginCoppermine() { $url="http://sammckee.com/album/login.php?referer=index.php"; $ch = curl_init(); //Post login data. curl_setopt($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_POST, TRUE); curl_setopt ($ch, CURLOPT_COOKIEFILE, "../images/cookie.txt" ); curl_setopt ($ch, CURLOPT_COOKIEJAR, "../images/cookie.txt" ); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); //username/password are required. Login form looks for "submitted" and won't login without it. $postdata="username=javaguy&password=myawesomepassword&remember_me=1&submitted=login"; curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); $content = curl_exec ($ch); curl_close ($ch); if ( strpos($content, "You are already logged in !") ) return TRUE; if ( strpos( $content, "Welcome javaguy ..." ) ) return TRUE; return FALSE; } function getUploads() { $url = "http://sammckee.com/album/searchnew.php?startdir=mail_uploads"; $ch = curl_init(); //Post login data. curl_setopt($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_COOKIEFILE, "../images/cookie.txt" ); curl_setopt ($ch, CURLOPT_COOKIEJAR, "../images/cookie.txt" ); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); $content = curl_exec ($ch); curl_close ($ch); return $content; } function buildPostdata( $uploads_page ) { $postdata = "d0000=1&insert=1"; //iterate through checkboxes. $index = strpos( $uploads_page, "<input name=\"pics[]" ); while ( $index !== FALSE ) { //First the checkbox. $index = strpos( $uploads_page, "value=\"", $index ) + 7; $end = strpos ( $uploads_page, "\"", $index ); $value = substr( $uploads_page, $index, $end - $index ); $postdata .= "&pics[]=$value"; //Then the first hidden field. $index = strpos( $uploads_page, "name=\"", $index ) + 6; $end = strpos( $uploads_page, "\"", $index ); $name = substr( $uploads_page, $index, $end - $index ); $index = strpos( $uploads_page, "value=\"", $index ) + 7; $end = strpos ( $uploads_page, "\"", $index ); $value = substr( $uploads_page, $index, $end - $index ); $postdata .= "&$name=$value"; //And the third hidden field. $index = strpos( $uploads_page, "name=\"", $index ) + 6; $end = strpos( $uploads_page, "\"", $index ); $name = substr( $uploads_page, $index, $end - $index ); $index = strpos( $uploads_page, "value=\"", $index ) + 7; $end = strpos ( $uploads_page, "\"", $index ); $value = substr( $uploads_page, $index, $end - $index ); $postdata .= "&$name=$value"; //Find the next checkbox, if there is one. $index = strpos( $uploads_page, "<input name=\"pics[]", $index ); } return $postdata; } function batchAdd( $postdata ) { $url="http://sammckee.com/album/searchnew.php?insert=1"; $ch = curl_init(); //Post login data. curl_setopt($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_POST, TRUE); curl_setopt ($ch, CURLOPT_COOKIEFILE, "../images/cookie.txt" ); curl_setopt ($ch, CURLOPT_COOKIEJAR, "../images/cookie.txt" ); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); $content = curl_exec ($ch); curl_close ($ch); } //Log into gallery. loginCoppermine(); $uploads_page = getUploads(); $postdata = buildPostdata( $uploads_page ); batchAdd( $postdata ); ?>
  11. I figured out how to write an e-mail filter that parses jpeg attachments and writes them to a directory under my Coppermine album. (I'll write a post explaining how this works when I have time. ) I plan to use this as a way to send photos directly from my camera phone to my album. I can send a photo from the phone to an e-mail address, and the e-mail filter parses the attachments and dumps them into the album directory. That part is working. However, the pictures don't automatically appear in my album when they are written to the directory; I have to do a batch add. It would be really slick if the filter could invoke a script that makes this happen automagically. Failing that, I'd be satisfied with a cron job that does it.
  12. Okay, I found a nifty little script here to do that. I haven't tried it yet but will let you know when I get it working.
×
×
  • Create New...