Subversion Repositories SvarDOS

Rev

Rev 631 | Rev 719 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 631 Rev 671
Line 3... Line 3...
3
/*
3
/*
4
  pkgnet interface
4
  pkgnet interface
5
  Copyright (C) 2021-2022 Mateusz Viste
5
  Copyright (C) 2021-2022 Mateusz Viste
6
 
6
 
7
 === API ===
7
 === API ===
8
  ?a=pull&p=PACKAGE           downloads the zip archive containing PACKAGE
8
  ?a=pull&p=PACKAGE           downloads the zip archive (svp) containing PACKAGE
9
  ?a=pull&p=PACKAGE-VER       downloads the zip containing PACKAGE in version VER
9
  ?a=pull&p=PACKAGE-VER       downloads the zip (svp) containing PACKAGE in version VER
10
  ?a=search&p=PHRASE          list packages that match PHRASE
10
  ?a=search&p=PHRASE          list packages that match PHRASE
11
  ?a=checkup                  list of packages+versions in $_POST
11
  ?a=checkup                  list of packages+versions in $_POST
12
*/
12
*/
13
 
13
 
14
 
14
 
Line 86... Line 86...
86
if (!empty($_GET['v'])) $v = $_GET['v'];
86
if (!empty($_GET['v'])) $v = $_GET['v'];
87
 
87
 
88
// pull action is easy (does not require looking into pkg list), do it now
88
// pull action is easy (does not require looking into pkg list), do it now
89
 
89
 
90
if ($a === 'pull') {
90
if ($a === 'pull') {
91
  if (file_exists($p . '.zip')) {
91
  if (file_exists($p . '.svp')) {
92
    header('Content-Disposition: attachment; filename="' . $p . '.zip"');
92
    header('Content-Disposition: attachment; filename="' . $p . '.svp"');
93
    header('Content-Type: application/octet-stream');
93
    header('Content-Type: application/octet-stream');
94
    readfile($p . '.zip');
94
    readfile($p . '.svp');
95
  } else {
95
  } else {
96
    http_response_code(404);
96
    http_response_code(404);
97
    echo "ERROR: package not found on server\r\n";
97
    echo "ERROR: package not found on server\r\n";
98
  }
98
  }
99
  exit(0);
99
  exit(0);
Line 118... Line 118...
118
 
118
 
119
if ($a === 'search') {
119
if ($a === 'search') {
120
  $matches = 0;
120
  $matches = 0;
121
  while (($pkg = fgetcsv($handle, 1024, "\t")) !== FALSE) {
121
  while (($pkg = fgetcsv($handle, 1024, "\t")) !== FALSE) {
122
    if ((stristr($pkg[0], $p)) || (stristr($pkg[2], $p))) {
122
    if ((stristr($pkg[0], $p)) || (stristr($pkg[2], $p))) {
123
      echo str_pad(strtoupper($pkg[0]), 12) . str_pad("ver: {$pkg[1]} ", 16) . str_pad("size: " . nicesize(filesize($pkg[0] . '.zip')), 16) . "BSUM: " . sprintf("%04X", $pkg[3]) . "\r\n";
123
      echo str_pad(strtoupper($pkg[0]), 12) . str_pad("ver: {$pkg[1]} ", 16) . str_pad("size: " . nicesize(filesize($pkg[0] . '.svp')), 16) . "BSUM: " . sprintf("%04X", $pkg[3]) . "\r\n";
124
      echo wordwrap($pkg[2], 79, "\r\n", true);
124
      echo wordwrap($pkg[2], 79, "\r\n", true);
125
      echo "\r\n";
125
      echo "\r\n";
126
      // do I have any alt versions?
126
      // do I have any alt versions?
127
      $altvers = glob("{$pkg[0]}-*.zip");
127
      $altvers = glob("{$pkg[0]}-*.svp");
128
      if (!empty($altvers)) {
128
      if (!empty($altvers)) {
129
        $alts = str_replace('.zip', '', $altvers);
129
        $alts = str_replace('.svp', '', $altvers);
130
        echo wordwrap("[alt versions: " . implode(', ', $alts), 79, "\r\n", true) . "]\r\n";
130
        echo wordwrap("[alt versions: " . implode(', ', $alts), 79, "\r\n", true) . "]\r\n";
131
      }
131
      }
132
      echo "\r\n";
132
      echo "\r\n";
133
      $matches++;
133
      $matches++;
134
    }
134
    }