PHP - Calling Shell Scripts And Waiting For Output
Hey guys.
I'll be doing a frontend for some router testing scripts and I'll need to launch some shell scripts in php. The user will be allowed to check some checkboxes - choose which tests to run and run them using a button. I want to show them some kind of "Testing in progress" string and then show them the result when it's done. What do you think is the best solution ? I was thinking the shell script should create the whole output in some sensible form and then I would just parse it. Should I use a database for storing the error strings, or do you think they should be a part of the script ? Also, I would like to do it with AJAX (I never did it before and I could use some experience). So I need some advice on this. I want the form to disappear after the button was pressed, replace it with the "testing in progress" string (or maybe a temporary popup window would be better) and then if the script is done, display the result. I guess I need to use the Code: [Select] shell_exec command. What would you suggest ? btw I guess there is no way to run a script on a different server than one which runs the webpage, is there ? Similar TutorialsHaven't done much in PHP for a while, and as a refresher and a bit of a challenge to myself I have decided to write up a simple game of sorts. Basically in the game I have townships, every play has their own town. And I want these towns to have events every 3-10 hours, and have these events have results such as births/deaths/fires/flooding/etc. At the moment I'm looking at this kind of setup: A database table with the city information.. city_id, city_owner_id, city_name, etc. I figure I can make another field such as city_nextevent and fill it with a timestamp plus a random number of seconds. then when the user views their city if city_nextevent is older than current time then run the event function and set the next event time. In my head this idea seems to work well, until I realised that if the user doesn't log on for 20+ hours the events will not stack, they will only get the one event when they next view their town when several events should have passed. I realise I could use a cronjob to check all events across all towns, but is there a better way of doing it. I had also though about adding several fields to the database containing say the next five event times, then updating each field after time had passed. Which gives more events if the user has been offline for 20+ hours. So if the play was offline for say a week, their town would pretty much dry up until they returned. Basically, I want their town to run while they're offline. But was trying to avoid using a cronjob. Anyone have any thoughts on how this could be done? I am in the process of creating a waiting list that I want to work automatically. When a new member registers for membership, the member must be on a waiting list for a while before the member gets permanent membership. When the membership is activated by me, I want this to work like when I delete the person who is number 1 in the list, and number 2 will be number 1. the remaining numbers in the list will automatically move a number up, just now . 5 will be number 4 and so on. PErson number one is the person that allways will be deleted from the waiting list. An idea would be that this persons name ande rest of data connected to hes membership number will be moved automaticaly to the permanent members list when hi is deleted from the waiting list. Only the name will be displayed in the member list, but the form that the new member submits will have several fields. There are t12 fields to be filled in in the MySQL database, but only the name and surname to be displayed in the list. The numbers will be generated automatically in front of the name. I have tried to do this by myself. I have tried to do this myself, but I do not succeed. I am very new when it comes to PHP and programming in general. Hope someone here can help me with this. I can not find out. Edited February 26 by LeonLatexHello; I know there is a way but I just can't get it out of my head. I have my code that i want to show to the user and then i have code i want to execute but not show anything to user. I no am not making my self clear which i am sorry for so ill give you an example. <? show_my_site(true); // Now i have code which will never output anything but the webbrowser will always wait for it to complete my_function_that_takes_time(true, 'Very Long'); ?> So what i want is some code to tell the browser thats it! You have everything. I cant use die; or exit; because i want to execute the code. Thank-you Paul Hi all, I have a tool currently in place that pulls information from one server and displays it. Currently in the setup, whenever the status of a chat has "Waiting". It's grouped with all other's as $num_waiting. The problem I am having is do to the server it pulls the information from, 1 session would equal 11 if there are 11 reps answering chats. The issue with divising by the number of active agents is on occasion the server reports more or less than the number of agents which in turn generates responses like 3.3333 and so on. And no the number with that status has never actually equaled to a single instance. As such you can see my dilemma here, I need to find a way of taking all sessions with that status and most likely cross-referencing another attribute such as $customername to prevent the doubles and finally provide only a single instance for each of these sessions. I am including the bulk of the current code below. Any help is much appreciated. Code: [Select] <?php $num_waiting = 0; foreach($loginParams as $login){ $soapclient = new soapclient("https://secure.logmeinrescue.com/API/API.asmx?WSDL"); $loginResult = $soapclient->login($login); if($login[sEmail] == "lmitnifron@telenetwork.com"){ } $hierparams = array(""=>""); $hierarchyResult = $soapclient->getHierarchy($hierparams); $hierarchy = $hierarchyResult->aHierarchy; $nodes = $hierarchy->HIERARCHY; $numberofnodes = count($nodes); $eNodeRef = "NODE"; echo "<table border =\"5\" cellspacing = \"5\">"; $totalsessioncount = 0; $numberoftechs = 0; for ($iNodes = 0; $iNodes < $numberofnodes; $iNodes += 1) { if($nodes[$iNodes]->eStatus == "Online" && $nodes[$iNodes]->eType == "Technician"){ if($nodes[$iNodes]->iParentID == 000000 || $nodes[$iNodes]->iParentID == 00000000){ print_r("<tr>"); $techname = $nodes[$iNodes]->sName; $emailaddress = findaddress($techname); echo '<td><a href="xmpp:' . $emailaddress . '?message&subject=chat">' . $techname .'</a><br /></td>'; $iNodeID = $nodes[$iNodes]->iNodeID; $sessionparams = array( 'iNodeID' => $iNodeID, 'eNodeRef' => $eNodeRef ); $sessionresult = $soapclient->getSession($sessionparams); $session = $sessionresult->aSessions; $sessionnodes = $session->SESSION; $numberofsessionnodes = count($sessionnodes); $totalsessioncount = $totalsessioncount + $numberofsessionnodes; $numberoftechs = $numberoftechs + 1; if($numberofsessionnodes >= 2) { for ($isessionNodes = 0; $isessionNodes < $numberofsessionnodes; $isessionNodes += 1) { $session_status = $sessionnodes[$isessionNodes]->sStatus; $session_customername = $sessionnodes[$isessionNodes]->sCustomField0; $isdouble = check_doubles($session_customername); if(!$isdouble && ($session_status != "Waiting")) { if(isset($session_status)){postsessioninfo($session_status, $session_customername);} }else{ $num_waiting++; } } } unset($session_customername); unset($session_starttime); print_r("</td>"); } } } print_r("</table>"); $soapclient->logout(); clear_table(); } $session_que = $num_waiting; echo "Sessions Waiting -- " . $session_que . "<br><br>"; ?> MOD EDIT: [code] . . . [/code] BBCode tags added. Hello all. I have a php script which will insert csv data into database using PDO. But it's slow even with just few thousands records. So how can I prevent client from waiting for it when they want to upload data? I tried INSERT DELAYED but it's not working... Thank you. I've written some code to move a bunch of mp3's from one folder on a network server, rename them...based on the day of the week and date of the month...and then put them on another folder on the original server. Here's the code Code: [Select] #!/usr/bin/php <?php $today = date('m.d.y'); $week = date('W'); $weekplus = $week + 1; $daynumber = date('w'); //$dayofweek = date('D'); if (date('D') == "Mon") { $dayofweek = "mon"; } elseif (date('D') == "Tue") { $dayofweek = "tue"; } elseif (date('D') == "Wed") { $dayofweek = "wed"; } elseif (date('D') == "Thu") { $dayofweek = "thu"; } elseif (date('D') == "Fri") { $dayofweek = "fri"; } //original filenames are in this format 10361MRS-H01T01.mp3 $file1 = "10" . "$weekplus" . "$daynumber" . "MRS-H01T01.mp3"; $file2 = "10" . "$weekplus" . "$daynumber" . "MRS-H01T02.mp3"; $file3 = "10" . "$weekplus" . "$daynumber" . "MRS-H01T03.mp3"; $file4 = "10" . "$weekplus" . "$daynumber" . "MRS-H01S01.mp3"; $file5 = "10" . "$weekplus" . "$daynumber" . "MRS-H01S02.mp3"; $file6 = "10" . "$weekplus" . "$daynumber" . "MRS-H01S03.mp3"; $file7 = "10" . "$weekplus" . "$daynumber" . "MRS-H02T01.mp3"; $file8 = "10" . "$weekplus" . "$daynumber" . "MRS-H02T02.mp3"; $file9 = "10" . "$weekplus" . "$daynumber" . "MRS-H02T03.mp3"; $file10 = "10" . "$weekplus" . "$daynumber" . "MRS-H02S01.mp3"; $file11 = "10" . "$weekplus" . "$daynumber" . "MRS-H02S02.mp3"; $file12 = "10" . "$weekplus" . "$daynumber" . "MRS-H02S03.mp3"; $file13 = "10" . "$weekplus" . "$daynumber" . "MRS-H03T01.mp3"; $file14 = "10" . "$weekplus" . "$daynumber" . "MRS-H03T02.mp3"; $file15 = "10" . "$weekplus" . "$daynumber" . "MRS-H03T03.mp3"; $file16 = "10" . "$weekplus" . "$daynumber" . "MRS-H03S01.mp3"; $file17 = "10" . "$weekplus" . "$daynumber" . "MRS-H03S02.mp3"; $file18 = "10" . "$weekplus" . "$daynumber" . "MRS-H03S03.mp3"; $file19 = "10" . "$weekplus" . "$daynumber" . "MRS-H04T01.mp3"; $file20 = "10" . "$weekplus" . "$daynumber" . "MRS-H04T02.mp3"; $file21 = "10" . "$weekplus" . "$daynumber" . "MRS-H04T03.mp3"; $file22 = "10" . "$weekplus" . "$daynumber" . "MRS-H04S01.mp3"; $file23 = "10" . "$weekplus" . "$daynumber" . "MRS-H04S02.mp3"; $file24 = "10" . "$weekplus" . "$daynumber" . "MRS-H04S03.mp3"; $deletepath = "/var/www/showdownloads/mrshow/"; exec("scp 'root@192.168.2.245:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file1' /var/www/showdownloads/mrshow/"); exec("scp 'root@192.168.2.245:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file2' /var/www/showdownloads/mrshow/"); exec("scp 'root@192.168.2.245:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file3' /var/www/showdownloads/mrshow/"); exec("scp 'root@192.168.2.245:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file4' /var/www/showdownloads/mrshow/"); exec("scp 'root@192.168.2.245:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file5' /var/www/showdownloads/mrshow/"); exec("scp 'root@192.168.2.245:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file6' /var/www/showdownloads/mrshow/"); exec("scp 'root@192.168.2.245:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file7' /var/www/showdownloads/mrshow/"); exec("scp 'root@192.168.2.245:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file8' /var/www/showdownloads/mrshow/"); exec("scp 'root@192.168.2.245:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file9' /var/www/showdownloads/mrshow/"); exec("scp 'root@192.168.2.245:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file10' /var/www/showdownloads/mrshow/"); exec("scp 'root@192.168.2.245:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file11' /var/www/showdownloads/mrshow/"); exec("scp 'root@192.168.2.245:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file12' /var/www/showdownloads/mrshow/"); exec("scp 'root@192.168.2.245:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file13' /var/www/showdownloads/mrshow/"); exec("scp 'root@192.168.2.245:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file14' /var/www/showdownloads/mrshow/"); exec("scp 'root@192.168.2.245:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file15' /var/www/showdownloads/mrshow/"); exec("scp 'root@192.168.2.245:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file16' /var/www/showdownloads/mrshow/"); exec("scp 'root@192.168.2.245:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file17' /var/www/showdownloads/mrshow/"); exec("scp 'root@192.168.2.245:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file18' /var/www/showdownloads/mrshow/"); exec("scp 'root@192.168.2.245:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file19' /var/www/showdownloads/mrshow/"); exec("scp 'root@192.168.2.245:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file20' /var/www/showdownloads/mrshow/"); exec("scp 'root@192.168.2.245:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file21' /var/www/showdownloads/mrshow/"); exec("scp 'root@192.168.2.245:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file22' /var/www/showdownloads/mrshow/"); exec("scp 'root@192.168.2.245:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file23' /var/www/showdownloads/mrshow/"); exec("scp 'root@192.168.2.245:/Volumes/Big\ Disk/Media\ Shooter\ downloads/Matt\ and\ Ramona\ Content\ $today/$file24' /var/www/showdownloads/mrshow/"); rename("$deletepath/$file1", "$deletepath/mr_$dayofweek-2-1.mp3"); rename("$deletepath/$file2", "$deletepath/mr_$dayofweek-2-3.mp3"); rename("$deletepath/$file3", "$deletepath/mr_$dayofweek-2-5.mp3"); rename("$deletepath/$file4", "$deletepath/mr_$dayofweek-2-2.mp3"); rename("$deletepath/$file5", "$deletepath/mr_$dayofweek-2-4.mp3"); rename("$deletepath/$file6", "$deletepath/mr_$dayofweek-2-6.mp3"); rename("$deletepath/$file7", "$deletepath/mr_$dayofweek-3-1.mp3"); rename("$deletepath/$file8", "$deletepath/mr_$dayofweek-3-3.mp3"); rename("$deletepath/$file9", "$deletepath/mr_$dayofweek-3-5.mp3"); rename("$deletepath/$file10", "$deletepath/mr_$dayofweek-3-2.mp3"); rename("$deletepath/$file11", "$deletepath/mr_$dayofweek-3-4.mp3"); rename("$deletepath/$file12", "$deletepath/mr_$dayofweek-3-6.mp3"); rename("$deletepath/$file13", "$deletepath/mr_$dayofweek-4-1.mp3"); rename("$deletepath/$file14", "$deletepath/mr_$dayofweek-4-3.mp3"); rename("$deletepath/$file15", "$deletepath/mr_$dayofweek-4-5.mp3"); rename("$deletepath/$file16", "$deletepath/mr_$dayofweek-4-2.mp3"); rename("$deletepath/$file17", "$deletepath/mr_$dayofweek-4-4.mp3"); rename("$deletepath/$file18", "$deletepath/mr_$dayofweek-4-6.mp3"); rename("$deletepath/$file19", "$deletepath/mr_$dayofweek-5-1.mp3"); rename("$deletepath/$file20", "$deletepath/mr_$dayofweek-5-3.mp3"); rename("$deletepath/$file21", "$deletepath/mr_$dayofweek-5-5.mp3"); rename("$deletepath/$file22", "$deletepath/mr_$dayofweek-5-2.mp3"); rename("$deletepath/$file23", "$deletepath/mr_$dayofweek-5-4.mp3"); rename("$deletepath/$file24", "$deletepath/mr_$dayofweek-5-6.mp3"); exec("scp '/$deletepath/mr_$dayofweek-2-1.mp3' 'root@192.168.2.245:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-2-1.mp3'"); exec("scp '/$deletepath/mr_$dayofweek-2-2.mp3' 'root@192.168.2.245:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-2-2.mp3'"); exec("scp '/$deletepath/mr_$dayofweek-2-3.mp3' 'root@192.168.2.245:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-2-3.mp3'"); exec("scp '/$deletepath/mr_$dayofweek-2-4.mp3' 'root@192.168.2.245:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-2-4.mp3'"); exec("scp '/$deletepath/mr_$dayofweek-2-5.mp3' 'root@192.168.2.245:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-2-5.mp3'"); exec("scp '/$deletepath/mr_$dayofweek-2-6.mp3' 'root@192.168.2.245:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-2-6.mp3'"); exec("scp '/$deletepath/mr_$dayofweek-3-1.mp3' 'root@192.168.2.245:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-3-1.mp3'"); exec("scp '/$deletepath/mr_$dayofweek-3-2.mp3' 'root@192.168.2.245:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-3-2.mp3'"); exec("scp '/$deletepath/mr_$dayofweek-3-3.mp3' 'root@192.168.2.245:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-3-3.mp3'"); exec("scp '/$deletepath/mr_$dayofweek-3-4.mp3' 'root@192.168.2.245:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-3-4.mp3'"); exec("scp '/$deletepath/mr_$dayofweek-3-5.mp3' 'root@192.168.2.245:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-3-5.mp3'"); exec("scp '/$deletepath/mr_$dayofweek-3-6.mp3' 'root@192.168.2.245:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-3-6.mp3'"); exec("scp '/$deletepath/mr_$dayofweek-4-1.mp3' 'root@192.168.2.245:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-4-1.mp3'"); exec("scp '/$deletepath/mr_$dayofweek-4-2.mp3' 'root@192.168.2.245:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-4-2.mp3'"); exec("scp '/$deletepath/mr_$dayofweek-4-3.mp3' 'root@192.168.2.245:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-4-3.mp3'"); exec("scp '/$deletepath/mr_$dayofweek-4-4.mp3' 'root@192.168.2.245:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-4-4.mp3'"); exec("scp '/$deletepath/mr_$dayofweek-4-5.mp3' 'root@192.168.2.245:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-4-5.mp3'"); exec("scp '/$deletepath/mr_$dayofweek-4-6.mp3' 'root@192.168.2.245:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-4-6.mp3'"); exec("scp '/$deletepath/mr_$dayofweek-5-1.mp3' 'root@192.168.2.245:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-5-1.mp3'"); exec("scp '/$deletepath/mr_$dayofweek-5-2.mp3' 'root@192.168.2.245:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-5-2.mp3'"); exec("scp '/$deletepath/mr_$dayofweek-5-3.mp3' 'root@192.168.2.245:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-5-3.mp3'"); exec("scp '/$deletepath/mr_$dayofweek-5-4.mp3' 'root@192.168.2.245:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-5-4.mp3'"); exec("scp '/$deletepath/mr_$dayofweek-5-5.mp3' 'root@192.168.2.245:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-5-5.mp3'"); exec("scp '/$deletepath/mr_$dayofweek-5-6.mp3' 'root@192.168.2.245:/Volumes/Big\ Disk/Show\ Downloads/mrshow/mr_$dayofweek-5-6.mp3'"); ?> The problem is, this is the only way I can get this to work. I actually want to name the files in this format Quote mr_mon_2-1.mp3 Instead of the format now Quote mr_mon-2-1.mp3 The difference being that after the three letter version of the date, I have to have a dash...I want an underscore there. If I try to rename the file to use an underscore...it doesn't use the day of the week...so it turns out to be mr_2-1.mp3 Any ideas what I'm doing wrong? Thanks. Please tell me how to call, getimagesize() in exec command. http://www.example.com/images!/logos/ps_logo2.png I am using the linux enviroment. If the uRL has "!" symbol, it prints event not found. Please tell me how to avoid this. It was suggested that I add a ‘report’ parameter to the code, after revising with the ‘scale2ref’ code which appears to prevent the video from uploading/proceeding: $ffmpegCommand =''.$ffmpeg_b.' -y -i '.$video_file_full_path.' -i '.$watermark_image_full_path.' -filter_complex "[0]scale=426:-2[vid];[1][vid]scale2ref='oh*mdar':'ih/10'[wm][vid];[vid][wm]overlay=5:5:format=rgb,format=yuv420p" -vcodec libx264 -preset '.$pt->config->convert_speed.' -crf 26 -report'.$video_output_full_path_240.' 2>&1'; $shell = shell_exec($ffmpegCommand); I couldn’t see where the -report parameter was supposed to output (error.log has a filesize of 0). So I was asked to “run command from the shell and check”? But, I’m not sure what command and where/how to do that. I tried adding this to the php code, and attempted to upload again, same result echo shell_exec("/usr/local/bin/ffmpeg -report log.txt 2>&1");
any additional help is appreciated
Hello, I am developing an account manager for our local network and I want people to be able to login to my website and change their UNIX & Mailbox password. These people have SSH access so that is why the UNIX passwd should also be changed. So what I want to do is get the values $username, $currentpwd , $newpwd and $newpwdcnfrm from the HTML form and execute the following shell commands : Quote su -l $username passwd Enter current UNIX Passwd : $currentpwd Enter new UNIX Passwd : $newpwd Confirm UNIX Passwd : $newpwdcnfrm The problem here is, passwd takes old and new passwords as input, not as command parameters. So I cant just do shell_exec("passwd $currentpwd $newpwd $newpwdcnfrm") ; Do you guys know how to give input to the command? thanks. Btw : Please do not argue about the security issues. I am aware of everything and I am perfectly sure that the script will run securely. Hello dear friends, i've very simple php script for my website and it has feature that visitor can register and upload image for own profile. somone has uploaded PHP Shell as image and succeed to control on my website using that shell. so the problem is in uploading image can pass any file so can someone please help me how how to prevent it and here are the codes of image upload form and function. * Image upload form code Code: [Select] <form action="profile.php" method="post" enctype="multipart/form-data" name="form" id="form"> My Picture : <input name="userpic" type="file" id="userpic"/> <input type="submit" name="Submit" value="Update"/> * Profile.php code (it rename the image by add time to its name then put the image in path /users/ then insert the new name of the image into the database table) $ImageName = $_FILES[userpic][name]; // Get the image $t = time(); // Get Time $NewImageName = "$t$ImageName"; // New name copy($_FILES[userpic][tmp_name], "users/$NewImageName"); $sql= "update users SET userpic='$NewImageName'"; How then i can stop they upload shell thanks Hi, I recently updraded PHP to 5.3.3 and Apache to 2.2.17 on a Linux Centos 5.4 Box using yum. Since then the Web pages running under Apache cannot connect to the database using mysql. If I run a manual PHP script, I am able to. When I run phpinfo() on PHP under Apache I get this (note: --without-mysql): './configure' '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--target=x86_64-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--cache-file=../config.cache' '--with-libdir=lib64' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--disable-debug' '--with-pic' '--disable-rpath' '--without-pear' '--with-bz2' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--with-xpm-dir=/usr' '--enable-gd-native-ttf' '--without-gdbm' '--with-gettext' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-pcre-regex=/usr' '--with-zlib' '--with-layout=GNU' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--with-kerberos' '--enable-ucd-snmp-hack' '--enable-shmop' '--enable-calendar' '--without-mime-magic' '--without-sqlite' '--with-libxml-dir=/usr' '--enable-xml' '--with-system-tzdata' '--with-apxs2=/usr/sbin/apxs' '--without-mysql' '--without-gd' '--disable-dom' '--disable-dba' '--without-unixODBC' '--disable-pdo' '--disable-xmlreader' '--disable-xmlwriter' '--without-sqlite3' '--disable-phar' '--disable-fileinfo' '--disable-json' '--without-pspell' '--disable-wddx' '--without-curl' '--disable-posix' '--disable-sysvmsg' '--disable-sysvshm' '--disable-sysvsem' When I run phpinfo() on PHP that I run manually from the shell: ('--with-mysql=shared,/usr' '--with-mysqli=shared,/usr/bin/mysql_config') './configure' '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--target=x86_64-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--cache-file=../config.cache' '--with-libdir=lib64' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--disable-debug' '--with-pic' '--disable-rpath' '--without-pear' '--with-bz2' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--with-xpm-dir=/usr' '--enable-gd-native-ttf' '--without-gdbm' '--with-gettext' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-pcre-regex=/usr' '--with-zlib' '--with-layout=GNU' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--with-kerberos' '--enable-ucd-snmp-hack' '--enable-shmop' '--enable-calendar' '--without-mime-magic' '--without-sqlite' '--without-sqlite3' '--with-libxml-dir=/usr' '--enable-xml' '--with-system-tzdata' '--enable-force-cgi-redirect' '--enable-pcntl' '--with-imap=shared' '--with-imap-ssl' '--enable-mbstring=shared' '--enable-mbregex' '--with-gd=shared' '--enable-bcmath=shared' '--enable-dba=shared' '--with-db4=/usr' '--with-xmlrpc=shared' '--with-ldap=shared' '--with-ldap-sasl' '--with-mysql=shared,/usr' '--with-mysqli=shared,/usr/bin/mysql_config' '--enable-dom=shared' '--with-pgsql=shared' '--enable-wddx=shared' '--with-snmp=shared,/usr' '--enable-soap=shared' '--with-xsl=shared,/usr' '--enable-xmlreader=shared' '--enable-xmlwriter=shared' '--with-curl=shared,/usr' '--enable-fastcgi' '--enable-pdo=shared' '--with-pdo-odbc=shared,unixODBC,/usr' '--with-pdo-mysql=shared,/usr' '--with-pdo-pgsql=shared,/usr' '--with-pdo-sqlite=shared,/usr' '--with-pdo-dblib=shared,/usr' '--enable-json=shared' '--enable-zip=shared' '--with-readline' '--with-pspell=shared' '--enable-phar=shared' '--with-mcrypt=shared,/usr' '--with-tidy=shared,/usr' '--with-mssql=shared,/usr' '--enable-sysvmsg=shared' '--enable-sysvshm=shared' '--enable-sysvsem=shared' '--enable-posix=shared' '--with-unixODBC=shared,/usr' '--enable-fileinfo=shared' '--enable-intl=shared' '--with-icu-dir=/usr' '--with-recode=shared,/usr' Both phpinfo() show PHP 5.3.3 how can I configure PHP under Apache? Do I need to rebuild / reintall Apache manually? Thanks very much! Frank I'm experimenting with the shell_exec function to gain shell capability on a Linux host that doesn't provide it otherwise. I've found that I can see what is in different directories by entering a command line like: Code: [Select] cd ..; ls but if I enter two consecutive command lines: Code: [Select] cd .. ls The cd command has no effect. Apparently shell_exec is using a new shell every time I call it. Is there a way to start a shell in a PHP script and keep it active while I pass it multiple commands, so that this won't happen? Hello, If we have large amount of data we always use SCP to copy data from remote server. scp -P 100 user@192.168.2.3: /home/user/folder /home/user1/folder/. But if DSL (Internet) of local computer disconnects I observed failure of transfer many times and this whole process becomes irritating. Is there any alternative way to use scp or rsync with php so that we can execute it with script ? Something like this ? <?php // Having shell access but its not working 4 me... $conn = ssh2_connect('ftp.server.com', 100); ssh2_auth_password($conn 'user', 'pass'); ssh2_scp_send($conn, '/local/filename', '/remote/filename', 0644); ?> Another question is there any way we can run such code with the help of shell_exec() or is this implementation is secure? Thanks in Advance! Hi all I have this problem on a server using php5, unix based, safe_mode is On globally, i have turned it off locally through php.ini. Ok, this is testing example script i used: $cmd = ( "php -v" ); $out = shell_exec( $cmd ); print $out; On my own server this returns php version. On this mentioned server i'm using (commercial) this causes complete server breakdown, when logged in with SSH, i can't even issue "ls" command after that, nor find and kill the process. What could be so wrong with it? I don't think calling php-cli would make any difference. For those not knowing about this, is a new security hole found in all linux/unix based operating systems that should be patched.
http://arstechnica.c...with-nix-in-it/
Hi guys, I am new here, and I am a bit stuck with doing something unusual. I want to create a script that can turn on a program (dynamips and dynagen). So far, I have tried 'exec' and 'shell_exec'. Soon I realized that apache runs the commands as 'www-data' user (apache2 in ubuntu) and it's very limited on what you can execute. Is there any way to do that at all? What would be the best practice? I am not concerned about security as this is not a production environment... Thanks In my php web program I'm trying to execute a bash shell script on the web server passing to it some parameters gathered within the program. Ideally I wouldl ike to run this script as another user. However, I get only a return code of "1" and no other error messages that I can see. I tried using system and passthru as well and I'm sure the script is executable by anyone. I've also tried the sticky bit on the target shell script. Can someone/anyone please provide some gotcha pointers about doing this? As can be expected, after playing with this for a week now I'm extremely frustrated and nearly exhausted my resources (except for this forum). Ideas/suggestions please? Thanks I'm trying to get a php script working to download the latest CNN news podcast each hour. CNN names the file based on the year, month, day, and time. Here's what I'm trying: Code: [Select] <?php $year = date('Y'); $month = date('m'); $day = date('d'); $now = date('Y-m-d-h'); $hour = date('gA'); $hourplus1 = ($hour + 1); $hourminus1 = ($hour - 1); $ampm = date('A'); $url = "http://podcasts.cnn.net/cnn/services/podcasting/newscast/" . "audio/" . "$year" . "/" . "$month" . "/" . "$day" . "/CNN-News-" . "$month" . "-" . "$day" . "-" . "$year" . "-" . "$hourplus1" . "$ampm" . ".mp3"; echo $url; echo system('wget "$url"'); ?> When running from the shell, I get an "http://: invalid hostname" error. The echo of $url looks right...but it won't run from shell. Any ideas? I want to get a simple true/false to check if my ffmpeg is still converting a video. You can check out the shell command I executed below. convertToFlv( $input, $output ); function convertToFlv( $input, $output ) { echo "Converting $input to $output"; $command = "ffmpeg -y -i $input -acodec libfaac -ar 44100 -ab 96k -vcodec libx264 -level 41 -crf 20 -bufsize 20000k -maxrate 25000k -g 250 -r 20 -s 640x480 -coder 1 -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -flags2 +brdo+dct8x8+bpyramid -me umh -subq 7 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -rc_eq 'blurCplx^(1-qComp)' -bf 16 -b_strategy 1 -bidir_refine 1 -refs 6 -deblockalpha 0 -deblockbeta 0 $output"; shell_exec( $command ); } Can someone provide me some code that will help me check if ffmpeg is still doing the conversion? I am a bit desperate about this problem that I have been trying to solve for several days now. I'm trying to run a Python script from the exec() function in php. The script is called but the print job is never executed. This process has been running for several years and for no clear reason it suddenly stopped working. On my home computer, it works without any problem. In my virtual machine, nothing happens. The print() functions present in the script are well displayed by the return value received by php but the printing is not executed. The virtual machine is a test environment, in production it is also an physical machine. PHP <?php exec("py C:\xampp\htdocs\test\test.py", $out, $res); echo "<pre>"; print_r($out); echo "</pre>"; echo "<pre>"; print_r($res); echo "</pre>"; ?>
if __name__ == "__main__": try: filename = "C:/xampp/htdocs/test/test.pdf" win32api.ShellExecute(0, "print", filename, None, ".", 0) except Exception as e: print(f "An error occured during print_pdf : {e}")
The two environments are approximately the same: I'd like to point out that running the script directly from the CLI works on both machines. On the problematic machine, exec() only returns the result of print(..) I already opened a thread a few months ago about this problem but received no response.
Thank you in advance. |