paulomanrique / MySQLBackupMegaCoNZ

PHP script to backup a MySQL database and upload on mega.co.nz
The Unlicense
9 stars 7 forks source link

How to get url link from uploaded file ? #1

Open kaizerbacter opened 8 years ago

kaizerbacter commented 8 years ago

Any way to get the download url ? of uploaded file ?

miranos commented 6 years ago

Interested too.

Did you figured it out please ?

Thank's.

rfminelli commented 6 years ago

You can list and download the contents of your Mega drive by adding the following function to MySQLBackupMegaCoNZ.php. Use with caution.

Function list drive contents: function getfiles() { global $master_key, $root_id, $inbox_id, $trashbin_id;

$files = api_req(array('a' => 'f', 'c' => 1)); foreach ($files->f as $file) { if ($file->t == 0 || $file->t == 1) { $key = substr($file->k, strpos($file->k, ':') + 1); $key = decrypt_key(base64_to_a32($key), $master_key); if ($file->t == 0) { $k = array($key[0] ^ $key[4], $key[1] ^ $key[5], $key[2] ^ $key[6], $key[3] ^ $key[7]); $iv = array_merge(array_slice($key, 4, 2), array(0, 0)); $meta_mac = array_slice($key, 6, 2); } else { $k = $key; } $attributes = base64urldecode($file->a); $attributes = dec_attr($attributes, $k); if ($file->h == 'gldU3Tab') { downloadfile($file, $attributes, $k, $iv, $meta_mac); } } else if ($file->t == 2) { $root_id = $file->k; } else if ($file->t == 3) { $inbox_id = $file->k; } else if ($file->t == 4) { $trashbin_id = $file->k; } } }

Function download files: function downloadfile($file, $attributes, $k, $iv, $meta_mac) { $dl_url = api_req(array('a' => 'g', 'g' => 1, 'n' => $file->h));

$data_enc = file_get_contents($dl_url->g); $data = aes_ctr_decrypt($data_enc, a32_to_str($k), a32_to_str($iv)); file_put_contents($attributes->n, $data);

$file_mac = cbc_mac($data, $k, $iv); if (array($file_mac[0] ^ $file_mac[1], $file_mac[2] ^ $file_mac[3]) != $meta_mac) { echo "MAC mismatch"; } }