X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=web%2Fuploader.php;h=0cb1c18409b5c030d263160f996d474fc53c399b;hp=467c51c04e7e0e4af1a22f3aa1419d00ff056df7;hb=30b5119b127b739e369cf497d830e8f2a97591f7;hpb=d2c982b37f3c4373e99e7c60c19d048de02b5919 diff --git a/web/uploader.php b/web/uploader.php index 467c51c0..0cb1c184 100644 --- a/web/uploader.php +++ b/web/uploader.php @@ -22,22 +22,12 @@ if($_FILES["uploadedfile"]["type"] == "application/x-gzip" $tempfolder . $_FILES["uploadedfile"]["name"]); //extracting code - if($_FILES["uploadedfile"]["type"] == "application/zip") { + if($_FILES["uploadedfile"]["type"] == "application/zip") exec('unzip '.$tempfolder.$_FILES["uploadedfile"]["name"].' -d '.$tempfolder, $op, $status); - } - else { + else exec('tar -xf '.$tempfolder.$_FILES["uploadedfile"]["name"].' -C '.$tempfolder, $op, $status); - } - checkerror($status[0],"Error: cannot extract(tar error)."); + checkerror($status,"Error: cannot extract(tar error)."); - //chmod - exec('chmod -R 0777 '. $tempfolder.$folder, $status); - checkerror($status[0],"Error: chmod execution error."); - - //running ccanlint - exec($ccanlint.$tempfolder.$folder, $score, $status); - //checkerror($status,"Error: ccanlint execution error."); - //if user not logged in if($_SESSION["slogged"] == false) { //move to temp folder @@ -47,56 +37,107 @@ if($_FILES["uploadedfile"]["type"] == "application/x-gzip" //send mail for review to admins $subject = "Review: code upload at temporary repository"; - $message = "Some developer has uploaded code who has not logged in.\n\nModule is stored in ".$temprepo.$folder.".\n\nOutput of ccanlint: \n"; - foreach($score as $disp) - $message = $message.$disp."\n"; + $message = "Some developer has uploaded code who has not logged in.\n\nModule is stored in ". + $temprepo.$folder.".\n\nOutput of ccanlint: \n"; $toaddress = getccanadmin($db); mail($toaddress, $subject, $message, "From: $frommail"); - echo "
Stored to temporary repository. Mail will be send to admin to get verification of the code."; + echo "
Stored to temporary repository. + Mail will be send to admin to get verification of the code."; unlink($tempfolder.$_FILES["uploadedfile"]["name"]); exit(); } + //running ccanlint + exec($ccanlint.$tempfolder.$folder, $score, $status); + //if not junk code if($status == 0) { $rename = $folder; + $exactpath = $repopath . $_SESSION['susername'] .'/'; + + if (file_exists($exactpath)) { + echo "
Your another upload is in progress please wait...
"; + exit(); + } + + //bzr local repo for commit + chdir($repopath); + unset($op); exec($bzr_clone . $_SESSION['susername'], $op, $status); + checkerror($status, "Error: bzr local repo."); + chdir('..'); + //if module already exist - if (file_exists($repopath.$ccan_home_dir . $folder)) { + if (file_exists($exactpath . $ccan_home_dir . $folder)) { + // if owner is not same - if(!(getowner($repopath.$ccan_home_dir.$folder, $db) == $_SESSION['susername'])) { - if(!file_exists($repopath . $ccan_home_dir. $folder.'-'.$_SESSION['susername'])) - echo "
".$repopath . $ccan_home_dir. $folder . " already exists. Renaming to ". $folder."-".$_SESSION['susername']."
"; + if(!(getowner($ccan_home_dir . $folder, $db) == $_SESSION['susername'])) { + if(!file_exists($repopath . $ccan_home_dir . $folder . '-' . $_SESSION['susername'])) + echo "
". $ccan_home_dir . $folder . + " already exists. Renaming to " . $folder . "-" . $_SESSION['susername'] . "
"; else - echo "
".$repopath . $ccan_home_dir. $folder."-".$_SESSION['susername'] . " already exists. Overwriting ". $folder."-".$_SESSION['susername']."
"; + echo "
". $ccan_home_dir . $folder . + "-" . $_SESSION['susername'] . " already exists. Overwriting " . + $folder. "-" . $_SESSION['susername'] . "
"; $rename = $folder."-".$_SESSION['susername']; } + else - echo "
".$repopath. $ccan_home_dir. $folder. " already exists(uploaded by you). Overwriting ". $repopath. $folder."
"; + echo "
".$repopath. $ccan_home_dir. $folder. + " already exists(uploaded by you). Overwriting ". $repopath. $folder."
"; + } + //module not exist. store author to db else { - storefileowner($repopath . $ccan_home_dir. $folder, $_SESSION['susername'], $db); + storefileowner($ccan_home_dir . $folder, $_SESSION['susername'], $db); } - rmdirr($repopath. $ccan_home_dir. $rename); - rename($tempfolder.$folder, $repopath. $ccan_home_dir. $rename); - echo "
Stored to ".$repopath . $ccan_home_dir. $rename . "
"; + + rmdirr($exactpath . $ccan_home_dir . $rename); + rename($tempfolder . $folder, $exactpath . $ccan_home_dir . $rename); + + chdir($exactpath); + unset($op); exec($infotojson . $ccan_home_dir . $rename . " " . $ccan_home_dir. + $rename."/_info.c ". $ccan_home_dir . $rename . "/json_" . $rename . " " + . $_SESSION['susername']. " ../../" . $db, $op, $status); + checkerror($status,"Error: In infotojson."); + + unset($op); exec('bzr add', $op, $status); + checkerror($status,"Error: bzr add error."); + + unset($op); exec('bzr commit --unchanged -m "commiting from ccan web ' . $rename . + " " . $_SESSION['susername'] . '"', $op, $status); + checkerror($status,"Error: bzr commit error."); + + unset($op); exec($bzr_push, $op, $status); + checkerror($status,"Error: bzr push error."); - exec($infotojson . $repopath. $ccan_home_dir. $rename."/_info.c ". $repopath. $ccan_home_dir. $rename."/json_".$rename. " ". $_SESSION['susername']." ".$db, $status); - checkerror($status[0],"Error: In infotojson."); - //createsearchindex($rename, $repopath.$rename, $infofile, $db, $_SESSION['susername']); + unset($op); exec($create_dep_tar . " " . $ccan_home_dir. $rename . " ../../" . + $tar_dir . " ../../" . $db , $op, $status); + checkerror($status,"Error: bzr push error."); + + chdir('../..'); + rmdirr($exactpath); + echo "
Stored to ". $ccan_home_dir . $rename . "
"; } //if junk code (no _info.c etc) else { + rmdirr($junkcode.$folder.'-'.$_SESSION['susername']); rename($tempfolder.$folder, $junkcode.$folder.'-'.$_SESSION['susername']); + if($score == '') $msg = 'Below is details for test.'; - echo "
Score for code is low. Cannot copy to repository. Moving to ". $junkcode.$folder.'-'.$_SESSION['susername']."...

". $msg ."

"; + + echo "
Score for code is low. + Cannot copy to repository. Moving to ". $junkcode.$folder.'-'. + $_SESSION['susername']."...

". $msg ."

"; + foreach($score as $disp) echo "$disp
"; echo "
"; + } unlink($tempfolder.$_FILES["uploadedfile"]["name"]); }