Browse Source

Populate "source" field of uploaded torrents

Value added to source field contains the site name and a random string.
This change prevents uploaders from using self-generated torrent files
unless they also add the source value themselves. This value is provided
to them on the upload page, but is still more inconvenient than before.
spaghetti 8 years ago
parent
commit
a55b972580

+ 16
- 0
classes/bencodetorrent.class.php View File

106
     return true;
106
     return true;
107
   }
107
   }
108
 
108
 
109
+  /**
110
+   * Add the "source" field to the torrent
111
+   *
112
+   * @return true if a change was required
113
+   */
114
+  public function make_sourced() {
115
+    $Sources = Users::get_upload_sources();
116
+    if (empty($this->Dec)) { return false; }
117
+    if (isset($this->Dec['info']['source']) && ($this->Dec['info']['source'] == $Sources[0] || $this->Dec['info']['source'] == $Sources[1])) {
118
+      return false;
119
+    }
120
+    $this->Dec['info']['source'] = $Sources[0];
121
+    ksort($this->Dec['info']);
122
+    return true;
123
+  }
124
+
109
   /**
125
   /**
110
    * Calculate the torrent's info hash
126
    * Calculate the torrent's info hash
111
    *
127
    *

+ 8
- 2
classes/torrent_form.class.php View File

77
 <div class="thin">
77
 <div class="thin">
78
 <?    if ($this->NewTorrent) { ?>
78
 <?    if ($this->NewTorrent) { ?>
79
   <p style="text-align: center;">
79
   <p style="text-align: center;">
80
-    Your personal announce URL is:<br />
81
-    <input type="text" value="<?= ANNOUNCE_URLS[0][0] . '/' . G::$LoggedUser['torrent_pass'] . '/announce'?>" size="71" onclick="this.select();" readonly="readonly" />
80
+    If you would like to use your own torrent file, add the following to it:<br />
81
+<?      $Announces = call_user_func_array('array_merge', ANNOUNCE_URLS);
82
+        foreach ($Announces as $Announce) {
83
+?>
84
+    Announce: <input type="text" value="<?=$Announce . '/' . G::$LoggedUser['torrent_pass'] . '/announce'?>" size="74" onclick="this.select();" readonly="readonly" /> <br />
85
+<?      } ?>
86
+Source: <input type="text" value="<?=Users::get_upload_sources()[0]?>" size="20" onclick="this.select();" readonly="readonly" />
82
     <p style="text-align: center;">
87
     <p style="text-align: center;">
88
+        Otherwise, add none of it and simply redownload the torrent after uploading it. All of the above data will be added by the site.<br /><br />
83
     <strong<?=((!$Uploads)?' class="important_text"':'')?>>
89
     <strong<?=((!$Uploads)?' class="important_text"':'')?>>
84
         If you never have before, be sure to read this list of <a href="wiki.php?action=article&name=uploadingpitfalls">uploading pitfalls</a>
90
         If you never have before, be sure to read this list of <a href="wiki.php?action=article&name=uploadingpitfalls">uploading pitfalls</a>
85
       </strong>
91
       </strong>

+ 22
- 0
classes/users.class.php View File

679
 
679
 
680
     Misc::send_email($Email, 'Login from new location for '.SITE_NAME, $TPL->get(), 'noreply');
680
     Misc::send_email($Email, 'Login from new location for '.SITE_NAME, $TPL->get(), 'noreply');
681
   }
681
   }
682
+  /*
683
+   * @return array of strings that can be added to next source flag ( [current, old] )
684
+   */
685
+  public static function get_upload_sources() {
686
+    if (!($SourceKey = G::$Cache->get_value('source_key_new'))) {
687
+      G::$Cache->cache_value('source_key_new', $SourceKey = [Users::make_secret(), time()]);
688
+    }
689
+    $SourceKeyOld = G::$Cache->get_value('source_key_old');
690
+    if ($SourceKey[1]-time() > 3600) {
691
+      G::$Cache->cache_value('source_key_old', $SourceKeyOld = $SourceKey);
692
+      G::$Cache->cache_value('source_key_new', $SourceKey = [Users::make_secret(), time()]);
693
+    }
694
+    G::$DB->query("
695
+      SELECT
696
+        COUNT(ID)
697
+      FROM torrents
698
+      WHERE UserID = ".G::$LoggedUser['ID']);
699
+    list($Uploads) = G::$DB->next_record();
700
+    $Source[0] = SITE_NAME.'-'.substr(hash('sha256', $SourceKey[0].G::$LoggedUser['ID'].$Uploads),0,10);
701
+    $Source[1] = $SourceKeyOld ? SITE_NAME.'-'.substr(hash('sha256', $SourceKeyOld[0].G::$LoggedUser['ID'].$Uploads),0,10) : $Source[0];
702
+    return $Source;
703
+  }
682
 }
704
 }

+ 7
- 6
sections/upload/upload_handle.php View File

26
 
26
 
27
 define('QUERY_EXCEPTION', true); // Shut up debugging
27
 define('QUERY_EXCEPTION', true); // Shut up debugging
28
 
28
 
29
-//******************************************************************************//
30
-//--------------- Set $Properties array ----------------------------------------//
31
-// This is used if the form doesn't validate, and when the time comes to enter  //
32
-// it into the database.                            //
33
-// Haha wow god i'm trying to restrict the database to only have fields for //
34
-// movies and not add anything for other categories but this is fucking dumb //
29
+//*****************************************************************************//
30
+//--------------- Set $Properties array ---------------------------------------//
31
+// This is used if the form doesn't validate, and when the time comes to enter //
32
+// it into the database.                                                       //
33
+// Haha wow god i'm trying to restrict the database to only have fields for    //
34
+// movies and not add anything for other categories but this is fucking dumb   //
35
 
35
 
36
 $Properties = array();
36
 $Properties = array();
37
 $Type = $Categories[(int)$_POST['type']];
37
 $Type = $Categories[(int)$_POST['type']];
254
 
254
 
255
 $Tor = new BencodeTorrent($TorrentName, true);
255
 $Tor = new BencodeTorrent($TorrentName, true);
256
 $PublicTorrent = $Tor->make_private(); // The torrent is now private.
256
 $PublicTorrent = $Tor->make_private(); // The torrent is now private.
257
+$UnsourcedTorrent = $Tor->make_sourced(); // The torrent now has the source field set.
257
 $TorEnc = $Tor->encode();
258
 $TorEnc = $Tor->encode();
258
 $InfoHash = pack('H*', $Tor->info_hash());
259
 $InfoHash = pack('H*', $Tor->info_hash());
259
 
260
 

Loading…
Cancel
Save