smsq/includes/functions.php

186 lines
3.8 KiB
PHP
Raw Permalink Normal View History

2017-11-15 05:23:00 +01:00
<?php
function generate_uuid() {
if (function_exists('random_bytes')) {
$data=random_bytes(16);
}
else {
$data=openssl_random_pseudo_bytes(16);
}
$data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100
$data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}
function check_phone_number($number) {
if (preg_match('/^\+?[0-9]{10,}$/iu',$number))
return true;
return false;
}
function check_sms_text($text) {
if (is_string($text) && !empty($text))
return true;
return false;
}
function check_integer($int) {
if (preg_match('/^[0-9]+$/iu',$int))
return true;
return false;
}
$frag_states=array('Delivered','Sent');
function check_frag_state($state) {
global $frag_states;
if (in_array($state, $frag_states))
return true;
return false;
}
function check_uuid($uuid) {
if (preg_match('/^[0-9A-F]{8}\-[0-9A-F]{4}\-[0-9A-F]{4}\-[0-9A-F]{4}\-[0-9A-F]{12}$/i',$uuid))
return true;
return false;
}
2017-11-19 18:27:57 +01:00
function send_sms($number, $text) {
$status=false;
$msg=false;
if (check_phone_number($number) && check_sms_text($text)) {
logging('INFO','New outgoing message for '.$number);
$uuid = create_outgoing_msg($number, $text);
if (check_uuid($uuid)) {
$msg=$uuid;
if(handle_outgoing_msg($uuid)===True) {
$status='pushed';
}
else {
$status='pending';
}
}
else {
$status='error';
$msg='Error creating your outgoing message';
}
}
else {
$status='error';
$msg='Invalid parameters';
}
return array($status, $msg);
}
2017-11-15 05:23:00 +01:00
/*
* From LdapSaisie
*/
/*
* Check email
*/
function check_email($value,$domain=NULL,$checkDns=true) {
$regex = '/^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/';
if (!preg_match($regex, $value)) {
return false;
}
$nd = explode('@', $value);
$nd=$nd[1];
if ($domain) {
if(is_array($domain)) {
if (!in_array($nd,$domain)) {
return false;
}
}
else {
if($nd!=$domain) {
return false;
}
}
}
if ($checkDns && function_exists('checkdnsrr')) {
if (!(checkdnsrr($nd, 'MX') || checkdnsrr($nd, 'A'))) {
return false;
}
}
return true;
}
/**
* Supprime les accents d'une chaine
*
* @param[in] $string La chaine originale
*
* @retval string La chaine sans les accents
*/
function withoutAccents($string){
$replaceAccent = Array(
"à" => "a",
"á" => "a",
"â" => "a",
"ã" => "a",
"ä" => "a",
"ç" => "c",
"è" => "e",
"é" => "e",
"ê" => "e",
"ë" => "e",
"ì" => "i",
"í" => "i",
"î" => "i",
"ï" => "i",
"ñ" => "n",
"ò" => "o",
"ó" => "o",
"ô" => "o",
"õ" => "o",
"ö" => "o",
"ù" => "u",
"ú" => "u",
"û" => "u",
"ü" => "u",
"ý" => "y",
"ÿ" => "y",
"À" => "A",
"Á" => "A",
"Â" => "A",
"Ã" => "A",
"Ä" => "A",
"Ç" => "C",
"È" => "E",
"É" => "E",
"Ê" => "E",
"Ë" => "E",
"Ì" => "I",
"Í" => "I",
"Î" => "I",
"Ï" => "I",
"Ñ" => "N",
"Ò" => "O",
"Ó" => "O",
"Ô" => "O",
"Õ" => "O",
"Ö" => "O",
"Ù" => "U",
"Ú" => "U",
"Û" => "U",
"Ü" => "U",
"Ý" => "Y"
);
return strtr($string, $replaceAccent);
}
function varDump($data) {
ob_start();
var_dump($data);
$data=ob_get_contents();
ob_end_clean();
return $data;
}