"Fossies" - the Fresh Open Source Software Archive

Member "sqlgreywebinterface-1.1.8/includes/functions.inc.php" (10 Aug 2015, 5266 Bytes) of package /linux/privat/old/sqlgreywebinterface-1.1.8.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "functions.inc.php": 1.1.7_vs_1.1.8.

    1 <?php
    2 
    3 /***********************************************************
    4 SQLgrey Web Interface
    5 Filename:   functions.inc.php
    6 Purpose:    Database, navigation and other functions
    7 Version:    1.1.8
    8 ************************************************************/
    9 
   10 require "config.inc.php";
   11 
   12 // Globally used phrases.
   13 
   14 $dom_out = 'domains of recipients for whom messages are never greylisted';
   15 $email_out = 'e-mail addresses of recipients for whom messages are never greylisted';
   16 $dom_in = 'domains of recipients for whom messages are always greylisted unless they are in the optout domain table';
   17 $email_in = 'e-mail addresses of recipients for whom messages are always greylisted unless they are in the optout e-mail table';
   18 
   19 
   20 // Database functions.
   21 
   22 function do_query($query) {
   23         global $db_hostname, $db_user, $db_pass, $db_db, $db_type;
   24         /* Connecting, selecting database */
   25     if ($db_type == "mysql") {
   26         $link = new mysqli($db_hostname, $db_user, $db_pass, $db_db) or die("Error " . mysqli_error($link));
   27         $result = $link->query($query) or die("Error in the query: " . mysqli_error($link));
   28 
   29         /* Closing connection */
   30         mysqli_close($link);
   31     } elseif ($db_type == "sqlite") {
   32         $link = new SQLite3($db_hostname) or die("Error "  . $link->lastErrorMsg());
   33 
   34             $result = $link->query($query) or die("Error in the query: " . $link->lastErrorMsg() .  " - Query: " . $query );
   35 
   36         /* Closing connection */
   37         $link->close;
   38 
   39     } else {
   40         $link = pg_connect("host=$db_hostname dbname=$db_db user=$db_user password=$db_pass") or die("Could not connect to database");
   41 
   42             $result = pg_query($link, $query) or die("Query failed");
   43 
   44         /* Closing connection */
   45         pg_close($link);
   46     }
   47         return $result;
   48 }
   49 
   50 function fetch_row($result) {
   51     global $db_type;
   52     if ($db_type == "mysql") {
   53         return $result->fetch_array(MYSQLI_ASSOC);
   54     } elseif ($db_type == "sqlite") {
   55         return $result->fetchArray(SQLITE3_ASSOC);
   56     } else {
   57         return pg_fetch_assoc($result);
   58     }
   59 }
   60 
   61 
   62 // Navigation functions.
   63 
   64 function shownav($colour, $mode, $direction, $what) {
   65     // Menubar setup for all pages
   66     global $dom_out, $email_out, $dom_in, $email_in;
   67     if ($colour == 'white') {
   68         // only awl.php
   69         echo ('
   70             <ul id="navlist">
   71               <li><a href="index.php">Main menu</a></li>
   72               <li><a href="connect.php" title="hosts/domains that are currently greylisted">Waiting (greylist)</a></li>
   73               <li><a href="awl.php?mode=email"'.is_active1("email", $mode).
   74                 'title="auto-whitelisted e-mailadresses (that have passed greylisting)">E-mail addresses</a></li>
   75               <li><a href="awl.php?mode=domains"'.is_active1('domains', $mode).
   76                 'title="auto-whitelisted domains (that have passed greylisting)">Domains</a></li>
   77               <li><a href="opt_in_out.php?direction=out&amp;what=domain" title="&nbsp;'.$dom_out.'">Optout domain</a></li>
   78               <li><a href="opt_in_out.php?direction=out&amp;what=email" title="&nbsp;'.$email_out.'">Optout e-mail</a></li>
   79               <li><a href="opt_in_out.php?direction=in&amp;what=domain" title="&nbsp;'.$dom_in.'">Optin domain</a></li>
   80               <li><a href="opt_in_out.php?direction=in&amp;what=email" title="&nbsp;'.$email_in .'">Optin e-mail</a></li>
   81             </ul>
   82         ');
   83     } else {
   84         // index and connect (with dummies) and opt_in_out.
   85         echo ('
   86             <ul id="navlist">
   87               <li><a href="index.php"'.is_active2("ind", $direction, "ind", $what).'>Main menu</a></li>
   88               <li><a href="connect.php"'.is_active2("con", $direction, "con", $what).
   89                 'title="hosts/domains that are currently greylisted">Waiting (greylist)</a></li>
   90               <li><a href="awl.php?mode=email" title="auto-whitelisted e-mailadresses (that have passed greylisting)">E-mail addresses</a></li>
   91               <li><a href="awl.php?mode=domains" title="auto-whitelisted domains (that have passed greylisting)">Domains</a></li>
   92               <li><a href="opt_in_out.php?direction=out&amp;what=domain"'.is_active2("out", $direction, "domain", $what).' title="'.$dom_out.'">Optout domain</a></li>
   93               <li><a href="opt_in_out.php?direction=out&amp;what=email"'.is_active2("out", $direction, "email", $what).' title="'.$email_out.'">Optout e-mail</a></li>
   94               <li><a href="opt_in_out.php?direction=in&amp;what=domain"'.is_active2('in',$direction,'domain',$what).' title="'.$dom_in.'">Optin domain</a></li>
   95               <li><a href="opt_in_out.php?direction=in&amp;what=email"'.is_active2('in',$direction,'email',$what).' title="'.$email_in.'">Optin e-mail</a></li>
   96             </ul>
   97         ');
   98     }
   99 }
  100 
  101 function is_active1($mode, $get) {
  102     // For awl menubar items - sets item active.
  103     if ($mode == $get) {
  104         return ' id="current" ';
  105     } else {
  106         return ' ';
  107     }
  108 }
  109 
  110 function is_active2($direction, $getdir, $what, $getwhat) {
  111     // For index, connect and opt_in_out menubar items - sets item active.
  112     if (($direction == $getdir) && ($what == $getwhat)) {
  113         return ' id="current" ';
  114     } else {
  115         return ' ';
  116     }
  117 }
  118 
  119 
  120 // Other functions.
  121 
  122 function shorten_it($sendername, $nr) {
  123     //  For managing the width of the Sender name, Sender domain and Recipient columns.
  124     if (strlen($sendername) > $nr) {
  125         $sendername = substr($sendername, 0, $nr ).'<b>...</b>';
  126     }
  127     return $sendername;
  128 }
  129 
  130 function strip_millisecs($ts) {
  131     // Formats timestamp without milliseconds.
  132     global $no_millisecs;
  133     if ($no_millisecs == "yes") {
  134         $ts=strftime('%Y-%m-%d %H:%M:%S', $ts);
  135     }
  136     return $ts;
  137 }
  138 
  139 ?>