PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/frontend/php/files/add.php

#
PHP | 166 lines | 117 code | 23 blank | 26 comment | 17 complexity | 1a08bb7ae76cdde8b18c04e6019ff208 MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php
  2. # <one line to give a brief idea of what this does.>
  3. #
  4. # Copyright 2002-2003 (c) Mathieu Roy <yeupou--at--gnu.org>
  5. #
  6. # This file is part of Savane.
  7. #
  8. # Savane is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # Savane is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. # FIXME: this page wont show up if there is nothing for the filelist
  21. # in the download area. It is problematic for people that want to use
  22. # it without having already files in their download area
  23. require_once('../include/init.php');
  24. extract(sane_import('get', array('pkg', 'version',
  25. 'input_file1', 'input_file2', 'input_file3', 'input_file4',
  26. 'input_file5', 'input_file6', 'input_file7', 'input_file8',
  27. 'input_file9', 'submit_command_list')));
  28. $project=project_get_object($group_id);
  29. if ($group_id) {
  30. if (member_check(0,$group_id)) {
  31. site_project_header(array('title'=>_("Add"),
  32. 'group'=>$group_id,
  33. 'context'=>'download'));
  34. # NOTE: because it was not really needed for the backend and frontend,
  35. # the download host configuration per group type has been removed.
  36. # However, if you really need Download type host that would be group
  37. # specific and not equal to the TypeHost, write to savannah-dev@gnu.org
  38. # Will find a way to configure that.
  39. $files_dir = $project->getTypeDir("download").$project->getUnixName();
  40. $files_path = $project->getTypeUrl("download").$project->getUnixName();
  41. $scp_dir = $project->getTypeBaseHost().":".$files_dir;
  42. if ( $project->getTypeName() == 'GNU' ){
  43. $scp_dir = "*not available*".$files_dir;
  44. echo '<h3 class="error">'._("Note for GNU projects").'</h3>';
  45. echo '<p>'._("Currently, since file uploads to ftp.gnu.org are not supported by Savannah at present (You should get in touch with accounts@gnu.org to get permissions to do them), the form below cannot be used.").'</p>';
  46. echo '<p>'._("But, file release system should work if you respect the standard tree explained below.").'</p>';
  47. }
  48. printf ('<h2>'._("How does file list work on %s?").'</h2>',$GLOBALS['sys_name']);
  49. echo '<p>'.sprintf(_("On %s, you must use scp, sftp or rsync via SSH to upload your files."),$GLOBALS['sys_name']);
  50. echo _("We prefer this way of managing files for security matters and also because scp and rsync are designed for this kind of usage, unlike a web browser.");
  51. echo ' '._("We want the file management system to be usable with a shell.").'</p>';
  52. echo '<p>'._("The following form won't upload files. It will display a list of commands that you will have to copy and paste in a terminal.").'</p>';
  53. printf ('<p>'._("If you follow the directory organisation outlined below, the %s %s Filelist for your project%s (available once you have checked the corresponding box in your %s Project Public Info %s) will display the versions in a user friendly way. Otherwise, the visitor of your project will be presented a regular directory listing.").'</p>','<a href="'.$GLOBALS['sys_home'].'files/?group_id='.$group_id.'">',$GLOBALS['sys_name'],'</a>','<a href="'.$GLOBALS['sys_home'].'project/admin/editgroupinfo.php?group_id='.$group_id.'">','</a>');
  54. echo '<p>'._("The suggested layout is as follows:").'<br />';
  55. echo '&nbsp;&nbsp;'.$files_dir.' &nbsp;&nbsp;&nbsp;<em>'._("is your dedicated area").'</em><br />';
  56. echo '&nbsp;&nbsp;&nbsp;&nbsp;'.$files_dir.'/unstable.pkg &nbsp;&nbsp;&nbsp;<em>'._("is the package/branch name, since you can have as many packages/branches as you want.").' '._("It must end with .pkg.").'</em><br />';
  57. echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$files_dir.'/unstable.pkg/1.0.0 &nbsp;&nbsp;&nbsp;<em>'._("is the version name/number for the package/branch we call unstable.").'</em><br />';
  58. echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$files_dir.'/unstable.pkg/1.0.0/my_project-1.0.0.tar.gz &nbsp;&nbsp;&nbsp;<em>'._("is a package that users can download for this version of this package/branch.").'</em></p>';
  59. echo '<p class="error">'._("Note that the package name should be the name of the .tar.gz file. Or whatever you want, but it must not contain characters as \" \" (whitespace) or \"/\" (slash).").'</p>';
  60. echo '<p><strong class="error">'._("Help!").'</strong> '.sprintf (_("You may take a look at the %s FAQ about %sHow do I add files in the download area%s, especially the \"Tips\" part.").'</p>',$GLOBALS['sys_name'],'<a href="'.$GLOBALS['sys_home'].'faq/?group_id=11&question=How_do_I_add_files_in_the_download_area.txt">','</a>');
  61. echo '<h2>'._("Getting a command list to upload the files:").'</h2>';
  62. echo '<form action="'. $_SERVER['PHP_SELF'] .'#list" method="get">
  63. <table>';
  64. echo '<input type="hidden" name="group_id" value="'.$group_id.'" />';
  65. echo '<tr><td>'._("Package / Branch:").' </td><td><input type="text" name="pkg" value="'.$pkg.'" size="20" maxlength="30" /> ('._("ex: the project name, or stable / unstable").')</td></tr>';
  66. echo '<tr><td>'._("Version:").' </td><td><input type="text" name="version" value="'.$version.'" size="20" maxlength="30" /> ('._("ex: 1.0.0 or 20020427").')</td></tr>';
  67. echo '<tr><td>'._("1st File:").' </td><td><input type="text" name="input_file1" size="40" value="'.$input_file1.'" /> ('
  68. ._("this should be the absolute path of the file on your machine").')</td></tr>';
  69. echo '<tr><td>'._("2nd File:").' </td><td><input type="text" name="input_file2" size="40" value="'.$input_file2.'" /> ('._("this should be the absolute path of the file on your machine").')</td></tr>';
  70. echo '<tr><td>'._("3rd File:").' </td><td><input type="text" name="input_file3" size="40" value="'.$input_file3.'" /> ('._("this should be the absolute path of the file on your machine").')</td></tr>';
  71. echo '<tr><td>'._("4th File:").' </td><td><input type="text" name="input_file4" size="40" value="'.$input_file4.'" /> ('._("this should be the absolute path of the file on your machine").')</td></tr>';
  72. echo '<tr><td>'._("5th File:").' </td><td><input type="text" name="input_file5" size="40" value="'.$input_file5.'" /> ('._("this should be the absolute path of the file on your machine").')</td></tr>';
  73. echo '<tr><td>'._("6th File:").' </td><td><input type="text" name="input_file6" size="40" value="'.$input_file6.'" /> ('._("this should be the absolute path of the file on your machine").')</td></tr>';
  74. echo '<tr><td>'._("7th File:").' </td><td><input type="text" name="input_file7" size="40" value="'.$input_file7.'" /> ('._("this should be the absolute path of the file on your machine").')</td></tr>';
  75. echo '<tr><td>'._("8th File:").' </td><td><input type="text" name="input_file8" size="40" value="'.$input_file8.'" /> ('._("this should be the absolute path of the file on your machine").')</td></tr>';
  76. echo '<tr><td>'._("9th File:").' </td><td><input type="text" name="input_file9" size="40" value="'.$input_file9.'" /> ('._("this should be the absolute path of the file on your machine").')</td></tr>
  77. </table>';
  78. echo '<br /><input type="submit" name="submit_command_list" value="'._("Show me the commands list").'"" />&nbsp;&nbsp;&nbsp;&nbsp;';
  79. #echo '<INPUT TYPE="SUBMIT" NAME="submit_last_release" VALUE="Set this version as latest release">';
  80. echo '<form>';
  81. function scp_command($input_file,$scp_dir,$pkg,$version){
  82. if ($input_file!=""){
  83. echo '<br />&nbsp;&nbsp;&nbsp;# package '.$input_file;
  84. echo '<br />&nbsp;&nbsp;&nbsp;mkdir -pv /tmp/sv_upload/'.$pkg.'.pkg/'.$version.'/ && cp "'.$input_file.'" /tmp/sv_upload/'.$pkg.'.pkg/'.$version.'/';
  85. echo '<br />&nbsp;&nbsp;&nbsp;scp -vr /tmp/sv_upload/* '.user_getname().'@'.$scp_dir.'/';
  86. echo '<br />&nbsp;&nbsp;&nbsp;rm -rf /tmp/sv_upload';
  87. }
  88. }
  89. if ($submit_command_list) {
  90. echo '<h3>'._("Here is the command list:").'</h3>';
  91. if($pkg=="") {
  92. echo '<span class="error">'._("You must specify a Package / Branch name.").'</span>';
  93. } elseif($version=="") {
  94. echo '<span class="error">'._("You must specify a Version name.").'</span>';
  95. } else {
  96. echo '<a name="list"></a><p>'._("Here is the result of the information you give.").' '._("Basically, you just have to copy and paste those commands in a terminal.").'';
  97. scp_command($input_file1,$scp_dir,$pkg,$version);
  98. scp_command($input_file2,$scp_dir,$pkg,$version);
  99. scp_command($input_file3,$scp_dir,$pkg,$version);
  100. scp_command($input_file4,$scp_dir,$pkg,$version);
  101. scp_command($input_file5,$scp_dir,$pkg,$version);
  102. scp_command($input_file6,$scp_dir,$pkg,$version);
  103. scp_command($input_file7,$scp_dir,$pkg,$version);
  104. scp_command($input_file8,$scp_dir,$pkg,$version);
  105. scp_command($input_file9,$scp_dir,$pkg,$version);
  106. }
  107. }
  108. if (isset($submit_last_release)) {
  109. echo '<a name="list"></a>';
  110. if(file_exists($files_dir."/".$pkg.".pkg/".$version)) {
  111. $latest_release_is_file = $files_dir."/".$pkg.".pkg/LATEST_RELEASE_IS";
  112. $fopened = fopen($latest_release_is_file,"w");
  113. fputs($fopened,$version);
  114. fclose($fopened);
  115. echo '<h3 class="error">'._("UPDATED: now the specified version is highlighted").'</h3>';
  116. printf (_("Note that you can also add a #%s to the HTML links to your filelist, as %s"),$pkg.$version,'<a href="'.$GLOBALS['sys_home'].'files/?group='.$group.'#'.$pkg.$version.'">http://'.$GLOBALS['sys_default_domain'].$GLOBALS['sys_home'].'files/?group='.$group_name.'#'.$pkg.$version.'</a>');
  117. printf ('<p>'._("Alternatively, you can make a link to %s").'</p>', '<a href="'.$GLOBALS['sys_home'].'files/?group='.$group.'#'.pkg.'latest">http://'.$GLOBALS['sys_default_domain'].$GLOBALS['sys_home'].'files/?group='.$group_name.'#'.$pkg.'latest</a>');
  118. echo '<h3>'._("How does it work, how to do this without a web browser?").'</h3>
  119. '._("It just creates a nice LATEST_RELEASE_IS file in the package dir with the version name as content.").'
  120. <p>'._("You can do this job exactly by making a similar file and upload it:").'<br />
  121. <br />&nbsp;&nbsp;&nbsp;echo "'.$version.'" &gt; LATEST_RELEASE_IS
  122. <br />&nbsp;&nbsp;&nbsp;scp LATEST_RELEASE_IS '.user_getname().'@'.$scp_dir.'/'.$pkg.'.pkg/</p>';
  123. } else {
  124. printf ('<h3 class="error">'._("There is no such Package / Branch or Version online for %s"),$project->getUnixName());
  125. echo '</h3>';
  126. }
  127. }
  128. site_project_footer(array());
  129. } else {
  130. exit_error(_("Error"),_("You do not have the required privileges to access this page"));
  131. }
  132. } else {
  133. exit_no_group();
  134. }
  135. ?>