]> 472bisson.ca Git - magnet.git/blob - index.php
Small Changes
[magnet.git] / index.php
1 <?php
2
3 $infohash = null;
4 $tor_name = null;
5 $trackers = null;
6 $webseeds = null;
7
8 $trackers = str_replace("&tr="," ",$trackers);
9
10 if(filter_has_var(INPUT_GET, 'submit'))
11 {
12 $infohash = filter_input(INPUT_GET, 'infohash');
13 $tor_name = filter_input(INPUT_GET, 'tname');
14 $trackers = filter_input(INPUT_GET, 'trackers');
15 $webseeds = filter_input(INPUT_GET, 'webseeds');
16
17 $infohash = strtoupper($infohash);
18
19 if(strlen($infohash) == 0)
20 {
21 $error_code = 1;
22 }
23 else if(strlen($infohash) == 40 && ctype_xdigit($infohash))
24 {
25 $magnetlink = "magnet:?xt=urn:btih:" . $infohash;
26
27 if($tor_name != "")
28 {
29 $magnetlink = $magnetlink . "&dn=" . $tor_name;
30 }
31 if($trackers != "")
32 {
33 $trackers = str_replace("\r","&tr=",$trackers);
34 $trackers = str_replace(" ","&tr=",$trackers);
35 $magnetlink = $magnetlink . "&tr=" . $trackers;
36 }
37 if ($webseeds != "")
38 {
39 $magnetlink = $magnetlink . "&ws=" . $webseeds;
40 }
41 }
42 else
43 {
44 $error_code = 2;
45 }
46 //$magnetlink = "magnet:?xt=urn:btih:" .$infohash . "&dn=" . $tor_name . "&tr=" . $trackers;
47 }
48 ?>
49 <!DOCTYPE html>
50 <html lang="en">
51 <head>
52 <title>Magnet</title>
53 <meta charset="utf-8" />
54 <meta name="viewport" content="width=device-width, initial-scale=1">
55 <link rel="icon" type="image/png" sizes="32x32" href="magnet.png">
56 <link rel="stylesheet" type="text/css" href="https://www.w3schools.com/w3css/4/w3.css">
57 <link rel="stylesheet" type="text/css" href="https://www.w3schools.com/lib/w3-theme-red.css">
58 <link rel="stylesheet" type="text/css" href="style.css">
59 </head>
60 <body>
61 <section class="w3-panel">
62 <div class="w3-card-4">
63 <div class="w3-container w3-theme">
64 <h2>Magnet Info</h2>
65 </div>
66 <form class="w3-container" name="magnet" method="get" action="#">
67 <p>
68 <label>Infohash</label>
69 <input class="w3-input" type="text" name="infohash" value='<?php echo $infohash ?>' placeholder="Hash of the Torrent Ex: DA39A3EE5E6B4B0D3255BFEF95601890AFD80709" />
70 </p>
71 <p>
72 <label>Name</label>
73 <input class="w3-input" type="text" name="tname" value='<?php echo $tor_name ?>' placeholder="Name of the Torrent Ex:Linux 5.7" />
74 </p>
75 <p>
76 <label>Trackers</label>
77 <textarea class="w3-input" name="trackers" placeholder="One tracker per line Ex: udp://tracker.opentrackr.org:1337/announce"><?php echo $trackers ?></textarea>
78 </p>
79 <p>
80 <label>Webseeds</label>
81 <input class="w3-input" type="text" name="webseeds" value='<?php echo $webseeds ?>' placeholder="Web Seeds Ex: http://example.com/linux.iso" />
82 </p>
83 <p>
84 <input class="w3-button w3-theme-l3" type="submit" name="submit" value="Create"/>
85 <input class="w3-button w3-theme-l3" type="reset" name="reset" value="Reset">
86 </p>
87 </form>
88 </div>
89 <?php
90 if(isset($error_code))
91 {
92 if($error_code == 1)
93 {
94 ?>
95 <div class="w3-panel w3-pale-red w3-leftbar w3-border-red">
96 <p>Error : Infohash cannot be empty.</p>
97 </div>
98 <?php
99 }
100 else if($error_code == 2)
101 {
102 ?>
103 <div class="w3-panel w3-pale-red w3-leftbar w3-border-red">
104 <p>Error : Invalid Infohash.</p>
105 </div>
106 <?php
107 }
108 }
109 else if(isset($magnetlink))
110 {
111 ?>
112 <div id="magnet" class="w3-panel w3-pale-green w3-leftbar w3-border-green">
113 <p><a href = "<?php echo $magnetlink; ?>"><?php echo $magnetlink; ?></a></p>
114 </div>
115 <?php
116 }
117 else
118 {
119 ?>
120 <div class="w3-panel w3-pale-blue w3-leftbar w3-border-blue">
121 <p>Enter Some Torrent Info Hash</p>
122 </div>
123 <?php
124 }
125 ?>
126 </section>
127 <footer class="w3-panel">
128 <a href="https://www.w3schools.com/w3css/" target="_blank" >W3.css</a>
129 <a href="https://github.com/cvmanjoo/magnet/" target="_blank" >Github</a>
130 </footer>
131 </body>
132 </html>