Advertisement
mal30

Untitled

Apr 30th, 2018
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.35 KB | None | 0 0
  1. <?php
  2. session_start();
  3. if (!isset($_SESSION['email']) && !isset($_SESSION['pass'])) {
  4.   echo "<script> location.href='login.php'; </script>";
  5.   exit;
  6. }
  7. require_once 'vendor/autoload.php';
  8. require 'PHPMailer/PHPMailerAutoload.php';
  9. require 'PHPMailer/class.phpmailer.php';
  10. require 'elgamal.php';
  11. require 'DocxConversion.php';
  12.  
  13.  
  14. function send_email($msg, $sendto){
  15.  
  16.     $mail = new PHPMailer();
  17.  
  18.     // set mailer to use SMTP
  19.     $mail->IsSMTP();
  20.  
  21.     $mail->Host = 'smtp.gmail.com';  // specify main and backup server
  22.  
  23.     $mail->SMTPAuth = true;     // turn on SMTP authentication
  24.  
  25.     $mail->SMTPSecure = 'ssl';                         // Enable TLS encryption, `ssl` also accepted
  26.     $mail->Port = 465;
  27.  
  28.     $mail->Username = 'kurniawanekosaputro6@gmail.com';  // SMTP username
  29.     $mail->Password = 'kurniaone'; // SMTP password
  30.  
  31.     $mail->setFrom('kurniawanekosaputro6@gmail.com', 'kurniawan eko saputro');
  32.     $mail->addReplyTo('kurniawanekosaputro6@gmail.com', 'kurniawan eko saputro');
  33.     // below we want to set the email address we will be sending our email to.
  34.     $mail->AddAddress($sendto);
  35.  
  36.     if(isset($msg['attachment']))
  37.         $mail->AddAttachment($msg['attachment']);
  38.  
  39.     $mail->IsHTML(true);
  40.  
  41.     $mail->Subject = $msg['subject'];
  42.  
  43.     $mail->Body    = $msg['body'];
  44.     $mail->AltBody = 'undefined';
  45.  
  46.     if(!$mail->Send())
  47.     {
  48.        echo "Message could not be sent.
  49.  
  50.     ";
  51.        echo "Mailer Error: " . $mail->ErrorInfo;
  52.        exit;
  53.     }
  54.  
  55. }
  56.  
  57. $username = $_SESSION['email'];
  58. $password = $_SESSION['pass'];
  59.  
  60. // $email and $message are the data that is being
  61. // posted to this page from our html contact form
  62. $email = $_REQUEST['email'] ;
  63. $subject = $_REQUEST['subject'] ;
  64. $message = $_REQUEST['message'] ;
  65.  
  66. $file_name = $_FILES ['file-upload']['name'];
  67. $file_tmp =$_FILES['file-upload']['tmp_name'];
  68.  
  69.  
  70. if ( 0 < $_FILES['file-upload']['error'] ) {
  71.         echo 'Error: ' . $_FILES['file-upload']['error'] . '<br>';
  72.     }
  73. else {
  74.     $path = 'uploaded_file/' . $file_name;
  75.     move_uploaded_file($file_tmp, $path);
  76. }
  77.  
  78.  
  79. $key = new elgamal(0,0,0,0,0);
  80. $key->_key(10000);
  81. $p = $key->p;
  82. $g = $key->g;
  83. $x = $key->x;
  84. $y = $key->y;
  85.  
  86.  
  87. $ext = explode('.', $file_name);
  88. $ext = array_slice($ext, -1)[0];
  89.  
  90.  
  91.  
  92. switch ($ext) {
  93.     case 'txt':
  94.     //mengambil data dari txt
  95.         $myText = file_get_contents($path);
  96.  
  97.     //enkripsi
  98.         $myText = $key->_enkripsi($myText);
  99.         $message = $key->_enkripsi($message);
  100.  
  101.     //simpan ke txt
  102.         $fp=fopen($path,"w+");
  103.         fwrite($fp, $myText);
  104.         fclose($fp);
  105.         break;
  106.  
  107.   case 'xlsx':
  108.     $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader("Xlsx");
  109.     $spreadsheet = $reader->load($path);
  110.     $writer = new \PhpOffice\PhpSpreadsheet\Writer\Html($spreadsheet);
  111.     $writer->save("temp.html");
  112.  
  113.     $myText = file_get_contents('temp.html');
  114.         unlink('temp.html');
  115.  
  116.         $myText = $key->_enkripsi($myText);
  117.     print_r($myText);
  118.         // $message = $key->_enkripsi($message);
  119.  
  120.     // $fp=fopen('temp.html',"w+");
  121.     // fwrite($fp, $myText);
  122.     // fclose($fp);
  123.     //
  124.     // $reader = new \PhpOffice\PhpSpreadsheet\Reader\Html();
  125.     // $spreadsheet = $reader->load("temp.html");
  126.     // $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, "Xlsx");
  127.     // $writer->save($path);
  128.     // unlink($path);
  129.     break;
  130.  
  131.     default:
  132.     //mengambil data dari word
  133.         $reader = \PhpOffice\PhpWord\IOFactory::createReader('Word2007');
  134.         $phpWord = $reader->load($path);
  135.         // Saving the document as HTML file...
  136.         $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'HTML');
  137.         $objWriter->save('temp.html');
  138.         $myText = file_get_contents('temp.html');
  139.  
  140.         unlink('temp.html');
  141.  
  142.     //enkripsi
  143.         $myText = $key->_enkripsi($myText);
  144.         $message = $key->_enkripsi($message);
  145.  
  146.     //menyimpan ke word
  147.         $phpWord = new \PhpOffice\PhpWord\PhpWord();
  148.         $section = $phpWord->createSection();
  149.         $section->addText($myText);
  150.         $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
  151.         $objWriter->save($path);
  152.  
  153.         break;
  154. }
  155.  
  156.  
  157. $mailSubject = '[CHIPHER] '.$subject;
  158. send_email(array('subject' => $mailSubject, 'body' => $message, 'attachment' => $path), $email);
  159.  
  160. $mailSubject = '[KEY] '.$subject;
  161. $message = 'P:'.$key->p.' K:'.$key->x;
  162. send_email(array('subject' => $mailSubject, 'body' => $message), $email);
  163.  
  164. unlink($path);
  165.  
  166. echo "<script> location.href='createmsg.php'; </script>";
  167. exit;
  168.  
  169. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement