xgit simple git

KISSmoPerl

KISSmo Perl

clone git clone https://kb.hax.al/KISSmoPerl

paste.pl

1 #!/usr/bin/env perl
2 
3 use Mojolicious::Lite;
4 use DBI;
5 use File::Slurp;
6 
7 # set up the sqlite database
8 my $dbh = DBI->connect("dbi:SQLite:dbname=pastes.db","","", { RaiseError => 1, AutoCommit => 1 });
9 $dbh->do("CREATE TABLE IF NOT EXISTS pastes (id INTEGER PRIMARY KEY, content TEXT, expires TIMESTAMP)");
10 
11 # set up the routes
12 get '/' => sub {
13     my $c = shift;
14     $c->render(template => 'index');
15 };
16 
17 get '/installation' => sub {
18     my $c = shift;
19     $c->render(template => 'installation');
20 };
21 
22 
23 post '/' => sub {
24     my $c = shift;
25     my $content = $c->param('content');
26 
27     # Trim leading and trailing whitespace
28     $content =~ s/^\s+|\s+$//g;
29 
30     if ($content =~ /\w/) {  # Check if content contains any word character
31         my $expires = time() + (60 * 60 * 24 * 60); # 60 days from now
32         my $id = int(rand(1000000000));
33         my $sth = $dbh->prepare("INSERT INTO pastes (id, content, expires) VALUES (?, ?, ?)");
34         $sth->execute($id, $content, $expires);
35         write_file("pastes/$id.txt", $content);
36         $c->redirect_to("/$id");
37     } else {
38         $c->render(template => 'invalid_content');
39     }
40 };
41 
42 get '/:id' => sub {
43     my $c = shift;
44     my $id = $c->param('id');
45     my $sth = $dbh->prepare("SELECT * FROM pastes WHERE id = ?");
46     $sth->execute($id);
47     my $paste = $sth->fetchrow_hashref;
48     if ($paste) {
49         $paste->{expires_human} = format_expires($paste->{expires});
50         $c->render(template => 'paste', paste => $paste);
51     } else {
52         $c->res->code(404);
53         $c->render(template => 'invalid_link');
54     }
55 };
56 
57 get '/raw/:id' => sub {
58     my $c = shift;
59     my $id = $c->param('id');
60     my $sth = $dbh->prepare("SELECT content FROM pastes WHERE id = ?");
61     $sth->execute($id);
62     my ($content) = $sth->fetchrow_array;
63     if ($content) {
64         $c->res->headers->content_type('text/plain');
65         $c->render(text => $content);
66     } else {
67         $c->res->code(404);
68         $c->render(template => 'invalid_link');
69     }
70 };
71 
72 get '/download/:id' => sub {
73     my $c = shift;
74     my $id = $c->param('id');
75     my $sth = $dbh->prepare("SELECT content FROM pastes WHERE id = ?");
76     $sth->execute($id);
77     my ($content) = $sth->fetchrow_array;
78     if ($content) {
79         $c->res->headers->content_type('text/plain');
80         $c->res->headers->content_disposition("attachment; filename=$id.txt");
81         $c->render(text => $content);
82     } else {
83         $c->res->code(404);
84         $c->render(template => 'invalid_link');
85     }
86 };
87 
88 # start the app
89 app->start;
90 
91 sub format_expires {
92     my $expires = shift;
93     my $current_time = time();
94 
95     if ($expires > $current_time) {
96         my $seconds_remaining = $expires - $current_time;
97         my $days = int($seconds_remaining / (60 * 60 * 24));
98         my $hours = int(($seconds_remaining % (60 * 60 * 24)) / (60 * 60));
99         my $minutes = int(($seconds_remaining % (60 * 60)) / 60);
100         return sprintf("%d days, %02d:%02d", $days, $hours, $minutes);
101     }
102 
103     return 'Expired';
104 }
105 
106 __DATA__
107 
108 @@ index.html.ep
109 
110 <!DOCTYPE html>
111 <html>
112 <head>
113 <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
114 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
115 <meta name="HandheldFriendly" content="true">
116     <title>KISSmo Perl Version 1.9 stable</title>
117     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
118     <style>
119         body {
120             background-color: #9f9f9f33;
121         }
122         .container {
123             max-width: 800px;
124             margin-top: 50px;
125         }
126         h1 {
127             text-align: center;
128             margin-bottom: 30px;
129         }
130         textarea {
131             width: 100%;
132             height: 300px;
133             resize: none;
134         }
135 	.btn-primary {
136             background-color: #00a6ff;
137             border-color: #00a6ff;
138         }
139         .btn-primary:hover {
140             background-color: #0069d9;
141             border-color: #0062cc;
142         }
143         .footer {
144             text-align: center;
145             margin-top: 50px;
146             background-color: #00a6ff;
147             color: #fff;
148             width: 100%;
149             position: relative;
150             bottom: 0;
151             left: 0;
152             padding: 15px;
153         }
154         .footer a {
155             color: #ffc107; /* Set the link color to bright yellow */
156         }
157     </style>
158 </head>
159 <body>
160     <nav class="navbar navbar-expand-lg navbar-light bg-light">
161         <a class="navbar-brand" href="/">KISSMO</a>
162         <ul class="navbar-nav mr-auto">
163             <li class="nav-item">
164                 <a class="nav-link" href="https://hax.al">Home</a>
165             </li>
166             <li class="nav-item">
167                 <a class="nav-link" href="/installation">Installation and Updates</a>
168             </li>
169         </ul>
170     </nav>
171     <div class="container">
172         <h1>KISSmo Perl Version 1.9 stable</h1>
173         <form method="post">
174             <div class="form-group">
175                 <textarea name="content" class="form-control" placeholder="Enter your content" rows="10"></textarea>
176             </div>
177             <div class="text-center">
178                 <button type="submit" class="btn btn-primary">Create paste</button>
179             </div>
180         </form>
181     </div>
182     <footer class="footer">
183         <p>This pastebin script has been developed by Arianit. The source code can be found at <a href="https://git.hax.al/KISSmoPerl/about/">Source code & About</a>.</p>
184     </footer>
185     <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
186     <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
187 </body>
188 </html>
189 @@ paste.html.ep
190 
191 <!DOCTYPE html>
192 <html>
193 <head>
194 <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
195 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
196 <meta name="HandheldFriendly" content="true">
197     <title>Paste</title>
198     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
199     <style>
200         body {
201             background-color: #9f9f9f33;
202         }
203         .container {
204             max-width: 800px;
205             margin-top: 50px;
206         }
207         h1 {
208             text-align: center;
209             margin-bottom: 30px;
210         }
211         pre {
212             background-color: #fff;
213             border: 1px solid #ccc;
214             padding: 15px;
215         }
216         .footer {
217             text-align: center;
218             margin-top: 50px;
219             background-color: #00a6ff;
220             color: #fff;
221             width: 100%;
222             position: relative;
223             bottom: 0;
224             left: 0;
225             padding: 15px;
226         }
227         .footer a {
228             color: #ffc107; /* Set the link color to bright yellow */
229         }
230     </style>
231 </head>
232 <body>
233     <nav class="navbar navbar-expand-lg navbar-light bg-light">
234         <a class="navbar-brand" href="/">KISSMO</a>
235         <ul class="navbar-nav mr-auto">
236             <li class="nav-item">
237                 <a class="nav-link" href="https://hax.al">Home</a>
238             </li>
239             <li class="nav-item">
240                 <a class="nav-link" href="/installation">Installation and Updates</a>
241             </li>
242         </ul>
243     </nav>
244     <div class="container">
245         <h1>Paste</h1>
246         <pre><%= $paste->{content} %></pre>
247         <a href="/raw/<%= $paste->{id} %>" class="btn btn-primary">RAW</a>
248         <a href="/download/<%= $paste->{id} %>" class="btn btn-primary">Download</a>
249         <p>Expires: <%= $paste->{expires_human} %></p>
250     </div>
251     <footer class="footer">
252         <p>This pastebin script has been developed by Arianit. The source code can be found at <a href="https://github.com/hedho">GitHub</a>.</p>
253     </footer>
254     <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
255     <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
256 </body>
257 </html>
258 @@ invalid_content.html.ep
259 
260 <!DOCTYPE html>
261 <html>
262 <head>
263 <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
264 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
265 <meta name="HandheldFriendly" content="true">
266     <title>Invalid Content</title>
267     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
268     <style>
269         body {
270             background-color: #9f9f9f33;
271         }
272         .container {
273             max-width: 800px;
274             margin-top: 50px;
275         }
276         h1 {
277             text-align: center;
278             margin-bottom: 30px;
279         }
280         .alert {
281             margin-top: 30px;
282         }
283         .footer {
284             text-align: center;
285             margin-top: 50px;
286             background-color: #00a6ff;
287             color: #fff;
288             width: 100%;
289             position: relative;
290             bottom: 0;
291             left: 0;
292             padding: 15px;
293         }
294         .footer a {
295             color: #ffc107; /* Set the link color to bright yellow */
296         }
297     </style>
298 </head>
299 <body>
300     <nav class="navbar navbar-expand-lg navbar-light bg-light">
301         <a class="navbar-brand" href="/">KISSMO</a>
302         <ul class="navbar-nav mr-auto">
303             <li class="nav-item">
304                 <a class="nav-link" href="https://hax.al">Home</a>
305             </li>
306             <li class="nav-item">
307                 <a class="nav-link" href="/installation">Installation and Updates</a>
308             </li>
309         </ul>
310     </nav>
311     <div class="container">
312         <h1>Invalid Content</h1>
313         <div class="alert alert-danger" role="alert">
314             Please enter valid content.
315         </div>
316     </div>
317     <footer class="footer">
318         <p>This pastebin script has been developed by Arianit. The source code can be found at <a href="https://github.com/hedho/KISSmoPerl">GitHub</a>.</p>
319     </footer>
320     <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
321     <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
322 </body>
323 </html>
324 @@ invalid_link.html.ep
325 
326 <!DOCTYPE html>
327 <html>
328 <head>
329 <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
330 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
331 <meta name="HandheldFriendly" content="true">
332     <title>Invalid Link</title>
333     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
334     <style>
335         body {
336             background-color: #9f9f9f33;
337         }
338         .container {
339             max-width: 800px;
340             margin-top: 50px;
341         }
342         h1 {
343             text-align: center;
344             margin-bottom: 30px;
345         }
346         .alert {
347             margin-top: 30px;
348         }
349         .footer {
350             text-align: center;
351             margin-top: 50px;
352             background-color: #00a6ff;
353             color: #fff;
354             width: 100%;
355             position: relative;
356             bottom: 0;
357             left: 0;
358             padding: 15px;
359         }
360         .footer a {
361             color: #ffc107; /* Set the link color to bright yellow */
362         }
363     </style>
364 </head>
365 <body>
366     <nav class="navbar navbar-expand-lg navbar-light bg-light">
367         <a class="navbar-brand" href="/">KISSMO</a>
368         <ul class="navbar-nav mr-auto">
369             <li class="nav-item">
370                 <a class="nav-link" href="https://hax.al">Home</a>
371             </li>
372             <li class="nav-item">
373                 <a class="nav-link" href="/installation">Installation and Updates</a>
374             </li>
375         </ul>
376     </nav>
377     <div class="container">
378         <h1>Invalid Link</h1>
379         <div class="alert alert-danger" role="alert">
380             The link you requested is invalid or has expired.
381         </div>
382     </div>
383     <footer class="footer">
384         <p>This pastebin script has been developed by Arianit. The source code can be found at <a href="https://github.com/hedho/KISSmoPerl">GitHub</a>.</p>
385     </footer>
386     <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
387     <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
388 </body>
389 </html>
390 @@ not_found.html.ep
391 
392 <!DOCTYPE html>
393 <html>
394 <head>
395 <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
396 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
397 <meta name="HandheldFriendly" content="true">
398     <title>Invalid Link</title>
399     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
400     <style>
401         body {
402             background-color: #9f9f9f33;
403         }
404         .container {
405             max-width: 800px;
406             margin-top: 50px;
407         }
408         h1 {
409             text-align: center;
410             margin-bottom: 30px;
411         }
412         .alert {
413             margin-top: 30px;
414         }
415         .footer {
416             text-align: center;
417             margin-top: 50px;
418             background-color: #00a6ff;
419             color: #fff;
420             width: 100%;
421             position: relative;
422             bottom: 0;
423             left: 0;
424             padding: 15px;
425         }
426         .footer a {
427             color: #ffc107; /* Set the link color to bright yellow */
428         }
429     </style>
430 </head>
431 <body>
432     <nav class="navbar navbar-expand-lg navbar-light bg-light">
433         <a class="navbar-brand" href="/">KISSMO</a>
434         <ul class="navbar-nav mr-auto">
435             <li class="nav-item">
436                 <a class="nav-link" href="https://hax.al">Home</a>
437             </li>
438             <li class="nav-item">
439                 <a class="nav-link" href="/installation">Installation and Updates</a>
440             </li>
441         </ul>
442     </nav>
443     <div class="container">
444         <h1>Not Found</h1>
445         <div class="alert alert-danger" role="alert">
446             The page you requested was not found.
447         </div>
448     </div>
449     <footer class="footer">
450         <p>This pastebin script has been developed by Arianit. The source code can be found at <a href="https://github.com/hedho/KISSmoPerl">GitHub</a>.</p>
451     </footer>
452     <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
453     <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
454 </body>
455 </html>
456 
457 @@ installation.html.ep
458 
459 <!DOCTYPE html>
460 <html>
461 <head>
462 <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
463 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
464 <meta name="HandheldFriendly" content="true">
465     <title>Installation and Updates</title>
466     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
467     <style>
468         body {
469             background-color: #9f9f9f33;
470         }
471         .container {
472             max-width: 800px;
473             margin-top: 50px;
474         }
475         h1 {
476             text-align: center;
477             margin-bottom: 30px;
478         }
479         .installation-instructions {
480             margin-top: 30px;
481         }
482         .footer {
483             text-align: center;
484             margin-top: 50px;
485             background-color: #00a6ff;
486             color: #fff;
487             width: 100%;
488             position: relative;
489             bottom: 0;
490             left: 0;
491             padding: 15px;
492         }
493         .footer a {
494             color: #ffc107; /* Set the link color to bright yellow */
495         }
496     </style>
497 </head>
498 <body>
499     <nav class="navbar navbar-expand-lg navbar-light bg-light">
500         <a class="navbar-brand" href="/">KISSMO</a>
501         <ul class="navbar-nav mr-auto">
502             <li class="nav-item">
503                 <a class="nav-link" href="https://hax.al">Home</a>
504             </li>
505             <li class="nav-item">
506                 <a class="nav-link" href="/installation">Installation and Updates</a>
507             </li>
508         </ul>
509     </nav>
510     <div class="container">
511         <h1>Installation and Updates</h1>
512         <div class="installation-instructions">
513             <h2>KISSmo Perl Pastebin</h2>
514 
515 <p>KISSmo Perl Pastebin is a simple pastebin service implemented in Perl using the Mojolicious framework. It allows users to create and share plain text snippets or code snippets easily. The service stores the pasted content in an SQLite database and provides various features such as expiration of pastes, viewing and downloading pastes, and raw access to the content.</p>
516 
517 <h3>Prerequisites</h3>
518 
519 <p>To run KISSmo Perl Pastebin, the following dependencies are required:</p>
520 
521 <ul>
522 <li>Perl (5.10.1 or higher)</li>
523 <li>Mojolicious framework</li>
524 <li>DBI module</li>
525 <li>File::Slurp module</li>
526 <li>SQLite database</li>
527 </ul>
528 
529 <p>Make sure you have Perl installed on your system and install the required modules using the CPAN or CPANM package manager.</p>
530 
531 <h3>Installation</h3>
532 
533 <ol>
534 <li>Clone the KISSmo Perl Pastebin repository from GitHub:</li>
535 
536 <pre><code>$ git clone https://github.com/hedho/KISSmoPerl.git</code></pre>
537 
538 <li>Change to the project directory:</li>
539 
540 <pre><code>$ cd KISSmoPerl</code></pre>
541 
542 <li>Install the required Perl modules:</li>
543 
544 <pre><code>$ cpan Mojolicious DBI File::Slurp</code></pre>
545 
546 <li>Create an SQLite database file named <code>pastes.db</code>:</li>
547 
548 <pre><code>$ touch pastes.db</code></pre>
549 
550 <pre><code>$ mkdir pastes</code></pre>
551 </ol>
552 
553 <h3>Configuration</h3>
554 
555 <p>The configuration for KISSmo Perl Pastebin is handled through the Perl script itself. You can modify the script directly to customize the behavior and appearance of the pastebin service. Some of the configurable options include:</p>
556 
557 <ul>
558 <li>Database settings: You can modify the database connection parameters (<code>dbname</code>, <code>username</code>, <code>password</code>) in the line <code>$dbh-&gt;connect("dbi:SQLite:dbname=pastes.db","","", { RaiseError =&gt; 1, AutoCommit =&gt; 1 });</code> to match your environment.</li>
559 </ul>
560 
561 <h3>Running the Service</h3>
562 
563 <p>To start the KISSmo Perl Pastebin service, run the following command:</p>
564 
565 <pre><code>$ ./pastebin.pl daemon</code></pre>
566 
567 <p>The service will start running on the default port (3000) on your local machine. You can access the pastebin service by opening a web browser and visiting <a href="http://localhost:3000">http://localhost:3000</a>.</p>
568 
569 <h3>Usage</h3>
570 
571 <ol>
572 <li>Home Page: The home page provides a simple form where you can enter your content. The content can be any plain text or code snippet that you want to share. Enter the content in the provided textarea and click on the "Create paste" button.</li>
573 <li>View Paste: After creating a paste, you will be redirected to a page that displays the paste details. The content of the paste will be shown along with options to view the raw content or download the paste as a text file. The expiration time of the paste is also displayed.</li>
574 <li>Raw Content: Clicking on the "RAW" button will display the raw content of the paste in plain text format.</li>
575 <li>Download: Clicking on the "Download" button will prompt you to download the paste as a text file. The file will be named with the paste ID followed by the <code>.txt</code> extension.</li>
576 </ol>
577 
578 <h3>Customization</h3>
579 
580 <p>If you want to customize the appearance or behavior of the pastebin service, you can modify the templates located in the <code>__DATA__</code> section of the Perl script. The templates are written in Embedded Perl (EP) format and use HTML for markup. You can modify the HTML, CSS, and JavaScript code to match your requirements.</p>
581 
582 <h3>Maintenance</h3>
583 
584 <p>To manage the pastes stored in the database, you can use any SQLite database management tool or interact directly with the <code>pastes.db</code> file using the SQLite command-line tool.</p>
585 
586 <h3>Conclusion</h3>
587 
588 <p>KISSmo Perl Pastebin is a lightweight and easy-to-use pastebin service written in Perl. It provides a simple web interface for creating, sharing, and managing plain text.</p>
589 
590 <br />
591 <a href="https://www.buymeacoffee.com/arianit"><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&emoji=☕&slug=arianit&button_colour=FFDD00&font_colour=000000&font_family=Cookie&outline_colour=000000&coffee_colour=ffffff" /></a>
592 <br />
593 Source link:<br />
594 <br />
595 <a href="https://www.buymeacoffee.com/arianit">https://www.buymeacoffee.com/arianit</a></p>
596 
597             <!-- Add the installation instructions here -->
598             ...
599         </div>
600     </div>
601     <footer class="footer">
602         <p>This pastebin script has been developed by Arianit. The source code can be found at <a href="https://github.com/hedho/KISSmoPerl">GitHub</a>.</p>
603     </footer>
604     <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
605     <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
606 </body>
607 </html>