"; fwrite($fd,$data); fflush($fd); fclose($fd); }; function adminheaders($baseURL) { echo "\n"; echo "\n"; echo "\n"; echo " \n"; echo " Yappa: Administration web photo album\n"; echo " \n"; echo " \n"; echo ""; echo ""; echo "
Yappa generatedAdministration center  |   Base of the photo album
"; } function adminendhtml() { echo "
"; echo "

.

\n"; echo " \n"; echo "\n"; } // cut the begin of a path function stripbeginfrompath($base,$dir) { $data=split($base,$dir); return($data[1]); } // display directories recurslivy, $base is used to strip the begin of path. function recursdir($adir,$base) { $handle=opendir($adir); while ($file = readdir($handle)) { if (is_dir($adir."/".$file) && ($file!=".") && ($file!="..")&& ($file!=".tn") && ($file!="admin")) { $dir=$adir."/".$file; $actiondir=stripbeginfrompath($base,$dir); echo " $actiondir "; echo "delete directory"; recursdir($dir,$base); } }; }; function writealldirectories() { $basedir=dirname(mygetcwd()); $base=basename($basedir); echo ""; // Add a line for the base directory. so users can create directories on base. echo ""; echo ""; recursdir($basedir,$base); echo "
Base directory  
"; } //return 1 if version in $contentversion > $version function goodversion($version,$content) { $data=explode("\n",$content); for($i=0;$i0) { echo "New version detected"; return 1; } else { echo "No new version"; return 0; }; } } return(0); } //write operation available on main admin page function sendnormaloperations($basedir,$baseURL) { global $actiondir, $deletedir,$addaccess,$pass,$email,$PHP_AUTH_USER,$autoinstall,$version, $testunarchiver, $index; echo ""; //gestion des actions if (isset($deletedir)) { // we must clean up misc files: .tn directory and index.php rmdir($basedir."/".$deletedir."/.tn"); unlink($basedir."/".$deletedir.$index); if (rmdir($basedir."/".$deletedir)) { echo "
Directory $deletedir deleted.
"; } else { echo "
The directory $deletedir couldn't be deleted (access denied, not empty or nonexistant)
"; }; }; if (isset($addaccess)) { if ($pass=="") { echo "Password can't be empty. No action taken"; } else { if (!file_exists("$basedir/admin/.htaccess")) { $fd=fopen("$basedir/admin/.htaccess","w"); $data="AuthName \"Acces administration de yappa. give your admin email as login\"\n"; $data.="AuthType Basic\n"; $data.="AuthUserFile $basedir/admin/.htpasswd\n"; $data.="AuthGroupFile None\n"; $data.="require valid-user"; fwrite($fd,$data); fclose($fd); }; if (file_exists("$basedir/admin/.htpasswd")) { $command="htpasswd -mb $basedir/admin/.htpasswd $email $pass"; } else { $command="htpasswd -cmb $basedir/admin/.htpasswd $email $pass"; }; mail($email,"Yappa administration","From: yappa@localhost\nThe password for administration is :\n$pass\nSee you later"); echo "Change done"; system($command); }; }; if (isset($autoinstall)) { $url="http://manu.agat.net/yappa/yappa.txt"; //$url="http://mi16.turbo.fr/~blindaue/yappa.txt"; $fcontents = join( '', file( $url ) ); if ($fcontents!="" && goodversion($version,$fcontents)==1) { $fd=fopen($basedir."/yappa.txt","w"); fwrite($fd,$fcontents); fclose($fd); if (file_exists("$basedir/index.php.old")) { unlink("$basedir/index.php.old"); }; rename("$basedir/$index","$basedir/index.php.old"); rename("$basedir/yappa.txt","$basedir/$index"); echo "Update done"; }; }; if (isset($testunarchiver)) { exec("which unrar",$devnull,$data); if ($data==0) { echo "unrar available"; } else { echo "unrar unavailable"; } echo "
"; exec("which unzip",$devnull,$data); if ($data==0) { echo "unzip available"; } else { echo "unzip unavailable"; } echo "
"; exec("which tar",$devnull,$data); if ($data==0) { echo "tar available"; } else { echo "tar unavailable"; } echo "
"; }; echo "
"; echo ""; }; function listallphotofromdir($actiondir,$basedir,$baseURL) { global $index; $handle=opendir($basedir."/".rawurldecode($actiondir)); echo "\n";$nbphotos=0; while ($file = readdir($handle)) { $filename=$basedir."/".$actiondir."/".$file; if (is_file($filename) && ($file!=$index)) { echo ""; if ((eregi(".jpg$",$filename)) || (eregi(".jpeg$",$filename))) { echo ""; } else { if (ereg(".*\.txt$",$filename)) { echo ""; } else { if (ereg("config.php$",$filename)) { echo ""; } else { echo ""; } } } echo " " ; if ((eregi(".jpg$",$filename)) || (eregi(".jpeg$",$filename))) { echo ""; } else { if (ereg("config.php$",$filename)) { echo ""; } else { echo ""; } } echo "\n"; $nbphotos=1; }; }; echo "
".$file."photo's commentconfig file delete fileadd a comment:"; echo "
"; echo ""; echo ""; echo ""; echo "
To use general options for comments and number of thumbnails per line, delete this file 
"; if ($nbphotos==0) { echo "No photo in this directory"; }; }; function workonadirectory($actiondir,$basedir,$baseURL) { global $deletefile,$directory,$nom,$sendfile,$sendfile_name,$sendfile_type,$file,$commentfile,$createthetn,$version,$comment,$allow_comments,$img_per_row,$newallowcom,$newimgperrow; // en gras pour montrer les actions effectués. echo ""; //gestion de l'effacement d'un fichier if (isset($deletefile)) { if (unlink($basedir."/".$actiondir."/".$deletefile) ) { if (file_exists($basedir."/".$actiondir."/.tn/tn_".$deletefile)) {unlink($basedir."/".$actiondir."/.tn/tn_".$deletefile);}; if (file_exists($basedir."/".$actiondir."/".$deletefile.".txt")) {unlink($basedir."/".$actiondir."/".$deletefile.".txt");}; echo "
File $deletefile deleted.
"; } else { echo "
The file $deletefile couldn't bze deleted (acces denied or non existent)
"; }; }; //gestion de la creation d'un répertoire if (isset($directory)) { if ($directory=="create") { if (mkdir($basedir."/".$actiondir."/".$nom,0755)) { echo "Directory $nom created
"; } else { echo "Directory couldn't be created. Check permissions on $actiondir
"; }; }; }; // gestion des envois de fichiers if (isset($sendfile)) { // On vérifie qu'on a des fichiers jpeg rar ou zip. un system("file") devrait etre tres efficace poru connaitre le contenu if (eregi(".*\.jpg$",$sendfile_name) || ereg(".*\.jpeg$",$sendfile_name)) { echo "File $sendfile_name accepted
"; move_uploaded_file($sendfile, $basedir."/".rawurldecode($actiondir)."/".$sendfile_name); } else { if (eregi(".*\.tar$",$sendfile_name)) { move_uploaded_file($sendfile, $basedir."/".rawurldecode($actiondir)."/".$sendfile_name); $command="tar xf \"$basedir".rawurldecode($actiondir)."/$sendfile_name\" -C \"$basedir".rawurldecode($actiondir)."\" && rm -f \"$basedir".rawurldecode($actiondir)."/$sendfile_name\""; system($command); echo "File in place."; }; if (eregi(".*\.tar\.gz$",$sendfile_name)) { move_uploaded_file($sendfile, $basedir."/".rawurldecode($actiondir)."/".$sendfile_name); $command="tar xfz \"$basedir".rawurldecode($actiondir)."/$sendfile_name\" -C \"$basedir".rawurldecode($actiondir)."\" && rm -f \"$basedir".rawurldecode($actiondir)."/$sendfile_name\""; system($command); echo "File in place."; }; if (eregi(".*\.tgz$",$sendfile_name)) { move_uploaded_file($sendfile, $basedir."/".rawurldecode($actiondir)."/".$sendfile_name); $command="tar xfz \"$basedir".rawurldecode($actiondir)."/$sendfile_name\" -C \"$basedir".rawurldecode($actiondir)."\" && rm -f \"$basedir".rawurldecode($actiondir)."/$sendfile_name\""; system($command); }; if (eregi(".*\.zip$",$sendfile_name)) { move_uploaded_file($sendfile, $basedir."/".rawurldecode($actiondir)."/".$sendfile_name); $command="unzip \"$basedir".rawurldecode($actiondir)."/$sendfile_name\" -d \"$basedir".rawurldecode($actiondir)."\" && rm -f \"$basedir".rawurldecode($actiondir)."/$sendfile_name\""; system($command); echo "File in place."; }; if (eregi(".*\.rar$",$sendfile_name)) { move_uploaded_file($sendfile, $basedir."/".rawurldecode($actiondir)."/".$sendfile_name); $command="unrar x \"$basedir".rawurldecode($actiondir)."/$sendfile_name\" -C \"$basedir".rawurldecode($actiondir)."\" && rm -f \"$basedir".rawurldecode($actiondir)."/$sendfile_name\""; system($command); echo "file in place."; }; } }; //gestion de l'ajout d'un commentaire a une photo. if (isset($commentfile)) { $fd=fopen($basedir."/".rawurldecode($actiondir)."/".rawurldecode($file).".txt","a+"); fwrite($fd,"127.0.0.1|".date("Y-m-d H:i")."|admin|$nom\n"); fclose($fd); echo "Added comment"; }; //gestion add a comment for all photos comment wil be written in comment.html in the dir. if (isset($comment)) { $fd=fopen($basedir."/".rawurldecode($actiondir)."/comment.html","w"); fputs($fd,$nom); fclose($fd); }; //gestion de la creation des thumbnails if (isset($createthetn)) { createtn($basedir."/".$actiondir,$createthetn) ; echo "Thumbnails created"; }; //gestion de l'autorisation des commentaires if (isset($newallowcom)) { writeconfig($basedir."/".rawurldecode($actiondir),$newallowcom,$img_per_row); if ($allow_comments==0) { echo "Comments are now denied."; } else { echo "Comments are now allowed."; }; }; if (isset($newimgperrow)) { writeconfig($basedir."/".rawurldecode($actiondir),$allow_comments,$newimgperrow); echo "Now, $img_per_row picture(s) per line will be displayed"; }; // affichage du menu echo "
\n"; echo "

Work directory: $actiondir"; echo "\n"; echo "You have found a bug ? no problems, the bug will disappear in a few minutes/hours/days/weeks/months/never if you write me what you have done, the yappa version and of course the error :)"; echo "
Write me (please don't change the subject)"; }; // No need to touch these variable unless you nkow exactly what happens. // default values are *best* values :) // Propagate the index.php file in subdirectories. 1 = activate it. 0 disable it. default=1 $autopropagateindex=1; // Name of the file to block autopropagation $blockautopropagate=".yappa.nopropage"; //autocreate thumbnails on fly 1 = enabled. 0 = disabled. default=1 $autocreatethumbnails=1; // allow comment. Available value: 0/1 (0 disable, default: 1) /* *************** Configuration stop here. ********** */ /* * FUNCTIONS */ /* return html code to create link running in the following directories.*/ function mysplit($thestring2) { global $base_dir_picture; if (ereg("\?",$thestring2)) { $thestring3=explode("?",$thestring2); $thestring=$thestring3[0]; } else { $thestring=$thestring2; }; $res=explode("/",$thestring); for($i=0;(strcmp($res[$i],$base_dir_picture)!=0) && ($i<1000) ;$i++); if ($i>999) {echo "ERROR";}; for($j=$i;$j".rawurldecode($res[$j])." / \n"; } } /* return html code to create link running in the following directories.*/ function mydirectorylist($thestring2) { global $basedir,$base_dir_picture,$autopropagateindex; if (ereg("\?",$thestring2)) { $thestring3=explode("?",$thestring2); $thestring= $thestring3[0]; } else { $thestring=$thestring2; }; $res=explode("/",$thestring); if (basename($thestring)!=basename($basedir)) { $parent=dirname($thestring); echo "
Parent directory

"; }; // May be confusing. We have to wait some users comment .... // echo "Thumbnails view
(current album)


"; $subdirsexists=0; $handle=opendir("."); while ($file = readdir($handle)) { if (($file=="admin") && (is_dir($file)) && (!file_exists("$file/$index"))) { symlink("$basedir/$index","$file/$index"); } if (($file != ".") && ($file != "..") && ($file != "admin") && ($file != ".tn") && (is_dir($file))) { echo "$file
\n"; $subdirsexists=1; if (($autopropagateindex==1) && (!file_exists($blockautopropagate)) &&(!file_exists("$file/$index"))) { symlink("$basedir/$index","$file/$index"); }; // count and write number of photos $d=dir($file); $a=0;$b=0; while ($subfile=$d->read()) { if ( (( eregi("\.jpg$",$file."/".$subfile) ) || (eregi("\.jpeg$",$file."/".$subfile))) && (is_file($file."/".$subfile)) ) { $a++; }; if ( is_dir($file."/".$subfile) && (($subfile!=".") && ($subfile!="..") && ($subfile!=".tn")) ) { $b++; }; } // count and write subdirs echo "$a pictures
"; echo "$b subdirs


"; } } closedir($handle); if ($subdirsexists==0) { echo "
No subdirectories."; } } // Create thumbnails function createtn($dir,$style) { if (file_exists("$dir/.tn") && (is_dir("$dir/.tn"))) { } else { mkdir("$dir/.tn",0775); } $d=dir("$dir"); while ($file=$d->read()) { if ( ((eregi("\.jpg$",$dir."/".$file)) || (eregi("\.jpeg$",$dir."/".$file))) && (is_file($dir."/".$file)) && (!file_exists($dir."/.tn/tn_".$file)) ) { if ($style=="gray") { $commstyle=" -colorspace GRAY ";}; system("convert -quality 30 $commstyle -geometry 120x100 \"$dir/$file\" \"$dir/.tn/tn_$file\""); }; } }; function displaytn($thestring2) { global $img_per_row; if (ereg("\?",$thestring2)) { $thestring3=explode("?",$thestring2); $thedir= $thestring3[0]; } else { $thedir=$thestring2; }; //da is a sorted array of available files. $da=GetDirArray("."); $counter=0; if (count($da)>0) { while (list($key,$file)=each($da)) { if ( ((eregi(".*\.jpg$",$file)) || (eregi(".*\.jpeg$",$file))) && (is_file($file)) ) { $oneimageexist=1; if ($counter==0) { echo "\n\n";} echo "\n" ; $counter++; if ($counter==$img_per_row+1) { echo "

$file

"; displaycomment($file); echo "
\n"; $counter=0;} }; }; }; if ( $oneimageexist==1) { if ($counter!=0) { for ($i=$counter;$i<$img_per_row+1;$i++) { echo " "; }; echo "\n"; $counter=0;} } else { echo "
No images in this directory
"; } }; function fulldisplay($image,$da) { global $allow_comments,$yappanom; $current=""; $counter=0; while (($image!=$da[$counter]) && ($counter PREV "; }; echo " [".($counter+1)."/".count($da)."] "; if ($suiv!="") { echo " NEXT"; }; echo "

"; if ($allow_comments==1) { echo "
\n"; echo "\n"; echo "
\n"; if (!isset($yappanom)) { $nom="your name"; } else { $nom=$yappanom; }; echo "
\n"; echo " \n"; echo "
\n"; } } //write a file in the current directory with al data for a comment function addcomment($remote,$date,$text,$name,$file) { if (is_writable(".")) { $fd=fopen($file.".txt","a+"); fwrite($fd,"$remote|$date|$name|$text\n"); fclose($fd); } else { echo "pb pour ecrire"; }; }; // display a text file passed as argument function displaycomment($file) { if ((file_exists($file.".txt")) && (is_readable($file))) { $fd=fopen($file.".txt","r"); $data=fread($fd,filesize($file)); fclose($fd); $dataexploded=explode("\n",$data); for($i=0;$i(".$dataexploded2[1].")
"; } } }; //return a table of all pictures. function GetDirArray($sPath) { //Load Directory Into Array $handle=opendir($sPath); while ($file = readdir($handle)) if ( ((eregi(".*\.jpg$",$file)) || (eregi(".*\.jpeg$",$file))) && (is_file($file)) ) { $retVal[count($retVal)] = $file; }; //Clean up and sort closedir($handle); if (count($retVal)>0) { sort($retVal); }; return $retVal; }; function sendHTMLhead($TITLE) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "$TITLE\n"; echo "\n"; echo "\n"; echo "\n"; }; function footerandendHTML() { echo "\n"; echo "\n"; }; // in normal operation, display picturess and menu. function normalaction($uri,$ip) { global $big,$text,$nom,$img,$Valider,$allow_comments,$autocreatethumbnails, $index; echo "\n"; // ############## START OF TOP LINE echo "\n"; echo "\n"; echo "\n"; // end of top line // // ############### BEGIN left side for sub dirs echo "\n"; echo "\n"; // end left side // ############### begin for right side for photos echo "\n"; // ############### end right side echo "\n"; echo "
Yappa generated\n"; mysplit($uri); echo "\n"; echo ""; echo "
\n"; mydirectorylist($uri); echo "\n"; // If we are on the base directory, add admin link and forgotten pass if (!is_link($index)) { echo "

"; echo "Administration (restricted area)"; echo "
"; echo "
Forgotten password? type your admin email to get a new password: "; echo ""; echo "
(email will be verified before)"; } echo "
\n"; // compute a table of all files. $indexpictures=GetDirArray(realpath(".")); if (isset($big)) { fulldisplay($big,$indexpictures); } else { if ((isset($Valider)) && ($allow_comments==1) ) { addcomment($ip,date("Y-m-d H:i"),$text,$nom,$img); } // create thumbnails if they don't exists. if ($autocreatethumbnails==1) { createtn(mygetcwd(),"color"); } displaygeneralcomment(); // display them displaytn($uri); } echo "\n"; echo "
\n"; }; // display a comment general for the current album function displaygeneralcomment() { if (file_exists("comment.html")) { readfile("comment.html"); }; }; function compareandall($email) { global $basedir; // first compage email and an entry in .htpasswd $fd=fopen("admin/.htpasswd","r"); $found=""; while (!feof($fd) && ($found=="")) { $buffer = fgets($fd, 4096); $bufferexploded=explode(":",$buffer); if ($bufferexploded[0]==rawurldecode($email)) { $found=$bufferexploded[0]; }; }; fclose ($fd); if ($found!="") { echo "I've found Email
"; $time=gettimeofday(); $pass=$time["usec"]; $time=gettimeofday(); $pass.=$time["usec"]; if (file_exists("$basedir/admin/.htpasswd")) { $command="htpasswd -mb $basedir/admin/.htpasswd $email $pass"; } else { $command="htpasswd -cmb $basedir/admin/.htpasswd $email $pass"; }; mail($email,"Yappa administration","From: yappa@localhost\nPassword is :\n$pass\nSee you later"); system($command); echo "Update is done"; } else { echo "No corresponding email found"; } } /* END OF FUNCTIONS */ //begin of CODE $index=getmyownname(); if (is_link($index)) { //we are not in the base of the admin dir. $basedir=dirname(readlink($index)); } else { //we are on the base of the photo album $basedir=mygetcwd(); }; $base_dir_picture=basename($basedir); if ((!file_exists("$basedir/config.php")) ) { writeconfig($basedir,1,3); }; include("$basedir/config.php"); if (file_exists("config.php")) { include("config.php"); } //echo "basedir=$basedir
"; //echo "base_dir_picture:$base_dir_picture
"; $base=basename($basedir); //echo "base:$base
"; $data1=explode("?",$GLOBALS["REQUEST_URI"]); $baseURL=$data1[0]; //echo "baseURL:$baseURL"; // START OF PAGE if ((basename(mygetcwd())!=$base) || (file_exists("admin") && is_dir("admin"))) { //normal stuff. look if we are in admin or not: if (basename(mygetcwd())=="admin") { //ADMIN PART adminheaders($baseURL); if (isset($actiondir)) { //test valididy of $actiondir: ../.. and other tricks must be intercepted. //if realpath don't contain $base, $actiondir must have ../.. or something like that. $realpath=realpath($basedir."/".$actiondir); if (ereg(".*$base.*",$realpath)) { if (file_exists("$realpath/config.php")) { include("$realpath/config.php"); } workonadirectory($actiondir,$basedir,$baseURL); } else { echo "Sorry cannot read the specified dir"; } } else { sendnormaloperations($basedir,$baseURL); } adminendhtml(); } else { // NORMAL PAGE sendHTMLhead($TITLE); if (isset($email)) { compareandall($email); }; normalaction($GLOBALS["REQUEST_URI"],$GLOBALS["REMOTE_ADDR"]); footerandendHTML(); } } else { if (!isset($firsttime)) { sendHTMLhead($TITLE); if (is_writeable(".")) { echo "Welcome to yappa. Please write your email, so I can send you a new password to administrate your Yet Another PHP Photo Album"; echo "

Your email:
"; echo "Thanks for using YAPPA!"; echo "
NOTE: for best performances, yappa need access to mail() and system() functions in php4. If your server don't support them, some functions will be unavailable"; echo "such as import zip photos, change password, or generate thumbnails."; echo "Redhat users: Default installation don't allow .htaccess files. see your httpd.conf for changing this, or everybody will be able to access to your photos."; } else { echo "Please make your current dir (".mygetcwd().") writeable by the web server!!!"; } footerandendHTML(); } else { mkdir("admin","0755"); sendHTMLhead($TITLE); if (!file_exists("$basedir/admin/.htaccess")) { $fd=fopen("$basedir/admin/.htaccess","w"); $data="AuthName \"Acces administation de yappa. Mettez votre email comme login\"\n"; $data.="AuthType Basic\n"; $data.="AuthUserFile $basedir/admin/.htpasswd\n"; $data.="AuthGroupFile None\n"; $data.="require valid-user"; fwrite($fd,$data); fclose($fd); }; // TODO: test email validity $time=gettimeofday(); $pass=$time["usec"]; $time=gettimeofday(); $pass.=$time["usec"]; $command="htpasswd -cmb $basedir/admin/.htpasswd $firstemail $pass"; mail($firstemail,"Yappa administration","\n\nFrom: yappa@localhost\nThe password is :\n$pass\nSee you later"); system($command); echo "Thanks for using YAPPA!
"; echo "Click here to access to the photo album"; footerandendHTML(); } } ?>