Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define ( 'MYSQL_HOST', '***' );
- define ( 'MYSQL_BENUTZER', '***' );
- define ( 'MYSQL_KENNWORT', '***' );
- define ( 'MYSQL_DATENBANK', '***' );
- $db_link = mysqli_connect(MYSQL_HOST, MYSQL_BENUTZER, MYSQL_KENNWORT, MYSQL_DATENBANK);
- function e($x){echo "$x\n";}
- if (mysqli_connect_errno())
- {
- file_put_contents("allConErrors", date("Y-m-d H:i:s")."\n", FILE_APPEND);
- if(file_exists("lastConError"))
- {
- $lastErr = json_decode(file_get_contents("lastConError"));
- if(abs(time() - $lastErr[0]) > $lastErr[1]*60*10)
- {
- if($handle = popen('/usr/bin/lp - 2>&1', 'w'))
- {
- fwrite($handle, date("Y-m-d H:i:s")."\nCould not connect to MySQL Server!\nStage ".$lastErr[1].", ERR#".mysqli_connect_errno());
- e(date("Y-m-d H:i:s").": Printed Connection Error");
- fclose($handle);
- }
- else
- {
- e(date("Y-m-d H:i:s").": Error: Unable to pOpen");
- }
- file_put_contents("lastConError", json_encode([time(), $lastErr[1]+1]));
- e(date("Y-m-d H:i:s").": Moved to next Error Stage");
- }
- }
- else
- {
- file_put_contents("lastConError", json_encode([time(), 1]));
- e(date("Y-m-d H:i:s").": Started Error Tracking");
- }
- exit();
- }
- @unlink("lastConError");
- function printMessage($ID, $name, $email, $text)
- {
- if($handle = popen('/usr/bin/lp -o cpi=12 - 2>&1', 'w'))
- {
- $ESC="\x1b";
- $GS="\x1d";
- # Init Printer
- fwrite($handle, $ESC);
- fwrite($handle, "@");
- # Justify C
- fwrite($handle, $ESC);
- fwrite($handle, "a");
- fwrite($handle, 1);
- # Inverted On
- fwrite($handle, $GS);
- fwrite($handle, "B");
- fwrite($handle, 1);
- fwrite($handle, " New Message #$ID \n");
- # Inverted Off
- fwrite($handle, $GS);
- fwrite($handle, "B");
- fwrite($handle, 0);
- fwrite($handle, date("Y-m-d H:i")."\n\n");
- # Justify L
- fwrite($handle, $ESC);
- fwrite($handle, "a");
- fwrite($handle, 0);
- if($name){fwrite($handle, "'$name'\n");}
- if($email){fwrite($handle, "<$email>\n");}
- fwrite($handle, "\n\r");
- fwrite($handle, "$text\n\r\n\r\n\r");
- e(date("Y-m-d H:i:s").": Printed Message #$ID");
- fclose($handle);
- }
- else
- {
- e(date("Y-m-d H:i:s").": Error: Unable to pOpen");
- }
- }
- $query = "SELECT * FROM Messages WHERE Printed is NULL";
- $res = mysqli_query($db_link, $query);
- $rows = mysqli_num_rows($res);
- e(date("Y-m-d H:i:s").": Querried $rows new Messages");
- if($res)
- {
- while($row = mysqli_fetch_array($res, MYSQLI_ASSOC))
- {
- printMessage($row["ID"], $row["Name"], $row["Email"], $row["Message"]);
- $query = "UPDATE messages SET Printed=CURRENT_TIMESTAMP() WHERE ID = ?";
- $stmt = mysqli_stmt_init($db_link);
- mysqli_stmt_prepare($stmt, $query);
- mysqli_stmt_bind_param($stmt, 'i', $row["ID"]);
- mysqli_stmt_execute($stmt);
- e(date("Y-m-d H:i:s").": Updated Message #".$row["ID"]);
- mysqli_stmt_close($stmt);
- }
- }
- else
- {
- e(date("Y-m-d H:i:s").": MySQL Error #".mysqli_errno());
- }
- mysqli_free_result($res);
- e(":EOF:");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement