fsfi

source of fsf.org.in
Log | Files | Refs

index.php (1414B)


      1 <?php
      2 
      3 /**
      4  *
      5  * SPDX-License-Identifier: ISC
      6  *
      7  * Copyright © 2019 Free Software Foundation of India.
      8  *
      9  */
     10 
     11 function to() {
     12     return 'srikar@ninthfloor.org, nagarjun@gnowledge.org';
     13 }
     14 
     15 function email_valid($e) {
     16     if (preg_match('/([\w.-]+)@([\w.-]+)/', $e)) {
     17         return true;
     18     }
     19     return false;
     20 }
     21 
     22 function send($n, $e, $m) {
     23     $p = $n . ' <' . $e . '>';
     24     return mail(to(),
     25                 $p . ' sent a message to FSF India',
     26                 'Per says:' . PHP_EOL . PHP_EOL . $m
     27               . PHP_EOL . PHP_EOL . '---' . PHP_EOL
     28               . 'Message originating from ' . $_SERVER['REMOTE_ADDR']
     29     );
     30 }
     31 
     32 function em_fw($t) {
     33     return preg_replace('/^(\w+)( .+)/', '<strong>$1</strong>$2', $t);
     34 }
     35 
     36 function post() {
     37     $n = $_POST['name'];
     38     $e = $_POST['email'];
     39     $m = $_POST['msg'];
     40     $c = $_POST['c'];
     41 
     42     $errors = [];
     43     if (!email_valid($e)) {
     44         $errors[] = em_fw('Email is invalid');
     45     }
     46     if (empty($m)) {
     47         $errors[] = em_fw('Message is required');
     48     }
     49     if ($c !== '42') {
     50         $errors[] = '41 + 1 is not \'' . $c . '\'';
     51     }
     52 
     53     $sok = true;
     54     if (empty($errors)) {
     55         $sok = send($n, $e, $m);
     56     }
     57     if (!$sok) {
     58         $errors[] = 'Unable to process your submission.';
     59     }
     60 
     61     return [
     62         'ok' => empty($errors) && $sok,
     63         'errors' => $errors
     64     ];
     65 }
     66 
     67 $result = post();
     68 include(__DIR__ . '/submit.html');