403Webshell
Server IP : 173.209.174.21  /  Your IP : 216.73.216.89
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux wcfs-server 6.8.0-124-generic #124-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 13:00:45 UTC 2026 x86_64
User : nodor ( 1000)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/wcfs/fuelmapping/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/wcfs/fuelmapping/copy-column-acd.php
<?php
// combine_columns.php
// Upload a CSV and rewrite Column C => "original C, A, D" (preserving C; skip empties)

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['csv_file'])) {
    $err = null;

    if (!is_uploaded_file($_FILES['csv_file']['tmp_name'])) {
        $err = "No file uploaded.";
    } else {
        $tmp  = $_FILES['csv_file']['tmp_name'];
        $name = basename($_FILES['csv_file']['name']);
        $firstRowHeader = isset($_POST['header']) && $_POST['header'] === '1';

        // Open input
        $in = fopen($tmp, 'r');
        if (!$in) $err = "Unable to open uploaded file.";

        if (!$err) {
            // Prepare an in-memory output stream
            $out = fopen('php://temp', 'w+');
            if (!$out) $err = "Unable to create output stream.";

            if (!$err) {
                $rowIndex = 0;
                while (($row = fgetcsv($in)) !== false) {
                    // Optionally leave the header row untouched
                    if ($rowIndex === 0 && $firstRowHeader) {
                        fputcsv($out, $row);
                        $rowIndex++;
                        continue;
                    }

                    // Ensure indexes exist (A=0, C=2, D=3)
                    for ($i = count($row); $i < 4; $i++) $row[$i] = '';

                    $colA = isset($row[0]) ? trim((string)$row[0]) : '';
                    $colC = isset($row[2]) ? trim((string)$row[2]) : '';
                    $colD = isset($row[3]) ? trim((string)$row[3]) : '';

                    // Build list of non-empty fields to append after C, in order: A, D
                    $toAppend = [];
                    if ($colA !== '') $toAppend[] = $colA;
                    if ($colD !== '') $toAppend[] = $colD;

                    if (!empty($toAppend)) {
                        if ($colC !== '') {
                            // C exists -> append ", A[, D]"
                            $row[2] = $colC . ', ' . implode(', ', $toAppend);
                        } else {
                            // C empty -> becomes "A[, D]"
                            $row[2] = implode(', ', $toAppend);
                        }
                    } else {
                        // Nothing to append; leave C as-is
                        $row[2] = $colC;
                    }

                    fputcsv($out, $row);
                    $rowIndex++;
                }

                // Ship the file back to the browser
                rewind($out);
                $downloadName = 'combined_C_with_A_D_' . preg_replace('/[^A-Za-z0-9._-]/', '_', $name);
                header('Content-Type: text/csv');
                header('Content-Disposition: attachment; filename="'.$downloadName.'"');
                header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
                fpassthru($out);
                fclose($out);
                fclose($in);
                exit;
            }
        }
    }

    if ($err) {
        http_response_code(400);
        echo "<!doctype html><html><body><p style='color:red;'>$err</p><p><a href='".$_SERVER['PHP_SELF']."'>Go back</a></p></body></html>";
        exit;
    }
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Combine CSV Columns (C = C, A, D)</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
  body{font-family:system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;line-height:1.45;padding:2rem;background:#f7f7fb;color:#222}
  .card{max-width:640px;margin:0 auto;background:#fff;border-radius:14px;box-shadow:0 8px 24px rgba(0,0,0,.08);padding:24px;}
  h1{font-size:1.25rem;margin:0 0 1rem}
  .hint{color:#555;margin:.5rem 0 1rem}
  label{display:block;margin:.5rem 0 .25rem}
  input[type="file"]{display:block;margin:.25rem 0 1rem}
  .row{display:flex;align-items:center;gap:.5rem;margin:.25rem 0 1rem}
  button{appearance:none;border:0;background:#111;color:#fff;padding:.75rem 1rem;border-radius:10px;cursor:pointer}
  button:hover{background:#000}
  small{color:#666}
</style>
</head>
<body>
  <div class="card">
    <h1>Combine Columns: C = (original C) + �, � + A + �, � + D</h1>
    <p class="hint">For each data row, Column C keeps its original value, then appends Column A and Column D (in that order), separated by commas. Empty A/D are skipped so no extra commas appear. If C is empty, it becomes �A[, D]�.</p>

    <form method="post" enctype="multipart/form-data">
      <label for="csv_file">CSV file</label>
      <input type="file" id="csv_file" name="csv_file" accept=".csv" required>

      <div class="row">
        <input type="checkbox" id="header" name="header" value="1" checked>
        <label for="header" style="margin:0;">First row is a header</label>
      </div>

      <button type="submit">Process & Download</button>
      <div style="margin-top:.75rem;">
        <small>Notes: standard comma-separated CSV; works with any number of columns. Only Column C is rewritten; A and D are read-only.</small>
      </div>
    </form>
  </div>
</body>
</html>

Youez - 2016 - github.com/yon3zu
LinuXploit