/** * Execute the job. * * @return bool */ public function handle() { // Set the inquiry model data. $this->inquiry->user_id = auth()->id(); $this->inquiry->uuid = uuid(); $this->inquiry->category_id = $this->category->id; $this->inquiry->title = $this->request->input('title'); $this->inquiry->description = $this->request->input('description'); if ($this->category->manager === true) { // If the category requires manager approval, we'll retrieve the manager record. $manager = User::whereHas('roles', function (Builder $query) { $query->whereName('managers'); })->findOrFail($this->request->input('manager')); $this->inquiry->manager_id = $manager->id; // We'll send the manager a notification. $notification = new Notification($manager, 'emails.inquiries.created', ['inquiry' => $this->inquiry], function (Message $message) use($manager) { $message->subject('A New Request Requires Your Approval'); $message->to($manager->email); }); } if ($this->inquiry->save()) { // If the inquiry was successfully created, we'll // send out the notification if one has been set. if (isset($notification)) { $this->dispatch($notification); } return true; } return false; }
function signup($post, $connect) { if (!empty($post['mail']) && !empty($post['password1']) && !empty($post['password1'])) { if (preg_match('/@.+\\./', $post['mail'])) { $sql = "SELECT uuid, mail, password, create_at, rank, accesstoken FROM users WHERE mail='" . htmlspecialchars($post['mail']) . "'"; $result = mysqli_query($connect, $sql); if (mysqli_num_rows($result) == 0) { if ($post['password1'] === $post['password2']) { $sql = "INSERT INTO users (uuid, mail, password, rank, create_at)\n\t\t\t\t\t\tVALUES ('" . uuid() . "', '" . $post['mail'] . "', '" . pass_hash($post['mail'], $post['password1']) . "', 0, NOW())"; if (mysqli_query($connect, $sql)) { $_SESSION['error'] = ""; return true; } else { $_SESSION['error'] = "Une erreur est survenue."; } } else { $_SESSION['error'] = "Les mots de passes de correspondent pas."; } } else { $_SESSION['error'] = "L'adresse email est déjà prise."; } } else { $_SESSION['error'] = "L'adresse email doit être correctement formatée."; } } return false; }
public function tracking() { // if we have a hash in get parameters and it is active, we create a new tracking log if (Request::has('h')) { $track = Tracking::getByHash(Request::input('h')); if ($track->isActive()) { $data = ['tracking_id' => $track->tracking_id, 'data' => json_encode(Request::except('h'))]; Tracking::log($data); } } // if we have a mail_id, we update the mail status and the date where it is opened if (Request::has(Tracking::MAIL_ID)) { if (Mail::exists(uuid('bytes', Request::input(Tracking::MAIL_ID)))) { $mail = Mail::getById(uuid('bytes', Request::input(Tracking::MAIL_ID))); if ($mail->mail_status_id != Mail::STATUS_OPENED) { $mail->mail_status_id = Mail::STATUS_OPENED; $mail->opened_at = Carbon::now(); $mail->save(); } } } header('Content-type:image/jpg'); header("Pragma: no-cache"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0, public"); header("Expires: 0"); exit; }
/** * Persist the changes. * * @param PasswordFolder $folder * * @return bool */ public function persist(PasswordFolder $folder) { $folder->user_id = Auth::user()->id; $folder->locked = true; $folder->uuid = uuid(); $folder->pin = $this->input('pin'); return $folder->save(); }
/** * saves current search * * @param string $name name to save search as * @param integer $tabledefid table definition's id * @param string $userid uuid of user */ function save($name, $tabledefid, $userid) { $uuid = getUuid($this->db, "tbld:5c9d645f-26ab-5003-b98e-89e9049f8ac3", $tabledefid); $querystatement = "\n SELECT\n `prefix`\n FROM\n `tabledefs`\n WHERE\n `uuid` = '" . $uuid . "'"; $queryresult = $this->db->query($querystatement); $therecord = $this->db->fetchArray($queryresult); $prefix = $therecord["prefix"]; $insertstatement = "\n INSERT INTO\n usersearches\n (\n userid,\n tabledefid,\n name,\n `type`,\n sqlclause,\n `uuid`\n ) VALUES (\n '" . mysql_real_escape_string($userid) . "',\n '" . mysql_real_escape_string($uuid) . "',\n '" . mysql_real_escape_string($name) . "',\n 'SCH',\n '" . addslashes($_SESSION["tableparams"][$tabledefid]["querywhereclause"]) . "',\n '" . uuid($prefix . ":") . "'\n )"; $this->db->query($insertstatement); echo "search saved"; }
function intellispireNetworkClient($repository, $channels, $isnid = null, $machineid = null) { $this->repository = $repository; $this->isnid = new isnid($isnid); $this->channels = $channels; if ($machineid) { $this->machineid = $machineid; } else { $this->machineid = uuid(); } }
public function check_uuid() { $uuid = C('version', 'uuid'); if (!empty($uuid)) { return $uuid; } else { $uuid = uuid(C('version', 'product') . '-'); \Leaps\Base\Config::modify('version', array('uuid' => $uuid)); return $uuid; } }
function let() { $config = new Config(); $config->set(MonologConfig::LOG_CHANNEL_FILE_PATH('channel1'), path('/tmp', uuid(), 'channel1.log')); $config->set(MonologConfig::LOG_CHANNEL_FILE_PATH('channel2'), path('/tmp', uuid(), 'channel2.log')); $config->set(MonologConfig::LOG_CHANNEL_LOG_LEVEL('channel1'), 'debug'); $config->set(MonologConfig::LOG_CHANNEL_LOG_LEVEL('channel2'), 'debug'); $config->set(MonologConfig::DEFAULT_CHANNEL_NAME, 'channel1'); $monologConfig = new MonologConfig($config); $this->beConstructedWith($monologConfig); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * * @return \Illuminate\Http\Response */ public function store(Request $request) { $this->validate($request, ['vote' => 'required|array|vote_count|vote_unique|sane_votes']); $user = $request->user(); if ($user->uuid === null) { $user->update(['uuid' => uuid()]); } foreach ($request->get('vote') as $vote) { Vote::create(['candidate_id' => Candidate::findOrFail($vote)->id, 'user_id' => $user->id, 'term_id' => nextTerm()->id]); } Session::flash('message', 'Your votes were successfully counted.'); return redirect('/'); }
/** * Execute creating a new batch. * * @return bool|Batch */ public function handle() { $batch = new Batch(); $batch->locked = false; $batch->session_id = Session::getId(); $batch->uuid = uuid(); $batch->lifetime = $this->lifetime; $batch->description = $this->description; $batch->name = $this->name; if ($batch->save()) { return $batch; } return false; }
/** * Insert the given attributes and set the ID on the model. * * @param \Illuminate\Database\Eloquent\Builder $query * @param array $attributes * @return void */ protected function insertAndSetId(Builder $query, $attributes) { $keyName = $this->getKeyName(); // uuid management if ($this->uuid) { $id = uuid(); $attributes[$keyName] = $id; $query->insert($attributes); // auto increment } else { $id = $query->insertGetId($attributes, $keyName); } $this->setAttribute($keyName, $id); }
function addAction() { $bind['proName'] = $_POST['proName']; $bind['proPrice'] = $_POST['proPrice']; $imagename = $_FILES['proImage']['name']; $error = $_FILES['proImage']['error']; $tmpname = $_FILES['proImage']['tmp_name']; $bind['proImage'] = uuid() . '.' . getExtesion($imagename); if ($error === UPLOAD_ERR_OK) { move_uploaded_file($tmpname, '../proimages/' . $bind['proImage']); } insert('products', $bind); $message = '添加成功'; $redirect = '<a href="addPro.html">继续添加</a>/<a href="listPro.php">返回列表页面</a>'; require_once 'thems/a.html'; }
/** * Create new file and return file key (id) * * @param string $fileName [optional] * @param string $content [optional] * @return string key */ public function create($fileName = null, $content = null) { // Create new key $key = sha1(uuid()); // Create data file $dataFilename = $this->getDataFileName($key); $this->touchFile($dataFilename); $this->write($key, $content); // Create info file $info = array('filename' => $fileName, 'datafile' => $dataFilename); $infoFilename = $this->getInfoFileName($key); $this->touchFile($infoFilename); $this->setInfo($key, $info); $this->keys[] = $key; return $key; }
public function addAdminuserHandle() { // p($_POST); // $a=uniqid(); // $a=md5(time() . mt_rand(1,1000000)); $username = trim($_POST['UserName']); $password = trim($_POST['PassWord']); $confirmpassword = trim($_POST['ConfirmPassWord']); $admuser = M('adminusers'); $data['AdminUserToken'] = trim(uuid(), '{' . '}'); $data['UserName'] = $username; $data['PassWord'] = sha1($password); if ($password != $confirmpassword) { $this->error("两次密码输入不一致,请重新输入"); } elseif ($username == '' || $password == '' || $confirmpassword == '') { $this->error("用户名或密码不能为空!"); } elseif ($admuser->add($data)) { // p($data); // die(); $this->success('管理员添加成功!'); } }
/** * 用户信息管理 * @param string $name * @param string $value * @return mix */ function user_info($name = '', $value = '') { $time = 3600 * 24; $key = cookie('identity'); if (!$key) { $key = uuid(); cookie('identity', $key, array('httponly' => true)); } $info = S($key); //清除数据 if ($name === null) { S($key, null); return null; } if (empty($value)) { if (empty($name)) { return $info; } if (isset($info[$name])) { return $info[$name]; } } else { if (empty($name)) { $info = $value; if (isset($info['password'])) { unset($info['password']); } if (isset($info['encrypt'])) { unset($info['encrypt']); } } else { $info[$name] = $value; } S($key, $info, $time); } return null; }
/** * Uploads files to the specified batch. * * @param UploadRequest $request * @param string $uuid */ public function perform(UploadRequest $request, $uuid) { // Locate the batch $batch = $this->batch->locate($uuid); // Retrieve the file from the request $file = $request->file('file'); // Double check the file instance if ($file instanceof UploadedFile) { // Validate file name length if (strlen($file->getClientOriginalName()) > 70) { abort(422, 'File name is too large'); } // Generate a file name with UUID and its extension $name = uuid() . "." . $file->getClientOriginalExtension(); // Get the storage path $path = $batch->uuid . DIRECTORY_SEPARATOR . $name; // Move the file into storage Storage::put($path, file_get_contents($file->getRealPath())); // Add the file to the batch $batch->addFile($file->getClientOriginalName(), $file->getClientMimeType(), $file->getClientSize(), $path); } else { abort(404); } }
/** * Uploads and attaches files for the current relation. * * @param Filesystem $filesystem * * @return bool|array */ public function handle(Filesystem $filesystem) { $files = $this->request->file('files'); if (is_array($files)) { $uploaded = []; foreach ($files as $file) { // Double check that we have an uploaded file instance. if ($file instanceof UploadedFile) { // Generates the unique file name. $name = implode('.', [uuid(), $file->getClientOriginalExtension()]); // Generates the complete storage path. $path = implode(DIRECTORY_SEPARATOR, [$this->path, $name]); // Try and move the uploaded file into storage. if ($filesystem->put($path, file_get_contents($file->getRealPath()))) { // Successfully moved uploaded file, create the record. $attributes = ['user_id' => auth()->id(), 'name' => $file->getClientOriginalName(), 'file_name' => $name, 'file_path' => $path]; $uploaded[] = $this->relation->create($attributes); } } } return $uploaded; } return false; }
$fax_email_connection_mailbox = $row["fax_email_connection_mailbox"]; $fax_email_inbound_subject_tag = $row["fax_email_inbound_subject_tag"]; $fax_email_outbound_subject_tag = $row["fax_email_outbound_subject_tag"]; $fax_email_outbound_authorized_senders = $row["fax_email_outbound_authorized_senders"]; $fax_caller_id_name = $row["fax_caller_id_name"]; $fax_caller_id_number = $row["fax_caller_id_number"]; $fax_forward_number = $row["fax_forward_number"]; $fax_description = $row["fax_description"]; } unset($prep_statement); } //replace the dash with a space $fax_name = str_replace("-", " ", $fax_name); //set the dialplan_uuid if (strlen($dialplan_uuid) == 0) { $dialplan_uuid = uuid(); } //show the header require_once "resources/header.php"; //advanced button js echo "<script type='text/javascript' language='JavaScript'>\n"; echo "\tfunction toggle_advanced(advanced_id) {\n"; echo "\t\t\$('#'+advanced_id).toggle();\n"; echo "\t\tif (\$('#'+advanced_id).is(':visible')) {\n"; echo "\t\t\t\$('#page').animate({scrollTop: \$('#'+advanced_id).offset().top - 80}, 'slow');\n"; echo "\t\t}\n"; echo "\t}\n"; echo "\tfunction add_sender() {\n"; echo "\t\tvar newdiv = document.createElement('div');\n"; echo "\t\tnewdiv.innerHTML = \"<input type='text' class='formfld' style='width: 225px; min-width: 225px; max-width: 225px; margin-top: 3px;' name='fax_email_outbound_authorized_senders[]' maxlength='255'>\";"; echo "\t\tdocument.getElementById('authorized_senders').appendChild(newdiv);";
/** * @return null|string */ protected function build_attachments() { $result = array(); if (count($this->attachments) == 0) { return; } foreach ($this->attachments as $file) { if (!file_exists($file)) { $file = PATH_APP . $file; if (!file_exists($file)) { continue; } } $fname = array_pop(explode('/', $file)); $data = file_get_contents($file); $content_id = uuid(); $result[] = "--{$this->boundary}"; $result[] = "Content-Type: " . mime_content_type($file) . "; name=\"{$fname}\""; $result[] = "Content-Transfer-Encoding: base64"; $result[] = "Content-ID: " . uuid(); $result[] = "Content-Disposition: attachment;"; $result[] = " filename=\"{$fname}\""; $result[] = ""; $result[] = chunk_split(base64_encode($data), 68, PHP_EOL); $result[] = ""; } if (count($result) == 0) { return null; } $message[] = "--{$this->boundary}--"; $message[] = ""; return implode(PHP_EOL, $result); }
if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { require_once "resources/header.php"; require_once "resources/persist_form_var.php"; echo "<div align='center'>\n"; echo "<table><tr><td>\n"; echo $msg . "<br />"; echo "</td></tr></table>\n"; persistformvar($_POST); echo "</div>\n"; require_once "resources/footer.php"; return; } //add or update the database if ($_POST["persistformvar"] != "true") { if ($action == "add" && permission_exists('schema_add')) { $schema_field_uuid = uuid(); $sql = "insert into v_schema_fields "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "schema_uuid, "; $sql .= "schema_field_uuid, "; $sql .= "field_label, "; $sql .= "field_name, "; $sql .= "field_type, "; $sql .= "field_value, "; $sql .= "field_list_hidden, "; $sql .= "field_search_by, "; $sql .= "field_column, "; $sql .= "field_required, "; $sql .= "field_order, "; $sql .= "field_order_tab, ";
function fax_enqueue($fax_uuid, $fax_file, $wav_file, $reply_address, $fax_uri, $fax_dtmf, $dial_string) { global $db, $db_type; $fax_task_uuid = uuid(); $dial_string .= "fax_task_uuid='" . $fax_task_uuid . "',"; $description = ''; //! @todo add description if ($db_type == "pgsql") { $date_utc_now_sql = "NOW() at time zone 'utc'"; } if ($db_type == "mysql") { $date_utc_now_sql = "UTC_TIMESTAMP()"; } if ($db_type == "sqlite") { $date_utc_now_sql = "datetime('now')"; } $sql = <<<HERE INSERT INTO v_fax_tasks( fax_task_uuid, fax_uuid, \ttask_next_time, task_lock_time, \ttask_fax_file, task_wav_file, task_uri, task_dial_string, task_dtmf, \ttask_interrupted, task_status, task_no_answer_counter, task_no_answer_retry_counter, task_retry_counter, \ttask_reply_address, task_description) VALUES (?, ?, \t{$date_utc_now_sql}, NULL, \t?, ?, ?, ?, ?, \t'false', 0, 0, 0, 0, \t?, ?); HERE; $stmt = $db->prepare($sql); $i = 0; $stmt->bindValue(++$i, $fax_task_uuid); $stmt->bindValue(++$i, $fax_uuid); $stmt->bindValue(++$i, $fax_file); $stmt->bindValue(++$i, $wav_file); $stmt->bindValue(++$i, $fax_uri); $stmt->bindValue(++$i, $dial_string); $stmt->bindValue(++$i, $fax_dtmf); $stmt->bindValue(++$i, $reply_address); $stmt->bindValue(++$i, $description); if ($stmt->execute()) { $response = 'Enqueued'; } else { //! @todo log error $response = 'Fail enqueue'; var_dump($db->errorInfo()); } unset($stmt); return $response; }
} } $request->UnsupportedRequest($unsupported); // Won't return if there was unsupported stuff. $lock_opener = $request->FailIfLocked(); if ($request->method == "LOCK") { dbg_error_log("LOCK", "Attempting to lock resource '%s'", $request->path); if ($lock_token = $request->IsLocked()) { // NOTE Assignment in if() is expected here. $sql = 'UPDATE locks SET start = current_timestamp WHERE opaquelocktoken = :lock_token'; $params = array(':lock_token' => $lock_token); } else { /** * A fresh lock */ $lock_token = uuid(); $sql = 'INSERT INTO locks ( dav_name, opaquelocktoken, type, scope, depth, owner, timeout, start ) VALUES( :dav_name, :lock_token, :type, :scope, :request_depth, :owner, :timeout::interval, current_timestamp )'; $params = array(':dav_name' => $request->path, ':lock_token' => $lock_token, ':type' => $lockinfo['type'], ':scope' => $lockinfo['scope'], ':request_depth' => $request->depth, ':owner' => $lockinfo['owner'], ':timeout' => $request->timeout . ' seconds'); header("Lock-Token: <opaquelocktoken:{$lock_token}>"); } $qry = new AwlQuery($sql, $params); $qry->Exec("LOCK", __LINE__, __FILE__); $lock_row = $request->GetLockRow($lock_token); $activelock = array(new XMLElement('locktype', new XMLElement($lock_row->type)), new XMLElement('lockscope', new XMLElement($lock_row->scope)), new XMLElement('depth', $request->GetDepthName()), new XMLElement('owner', new XMLElement('href', $lock_row->owner)), new XMLElement('timeout', 'Second-' . $request->timeout), new XMLElement('locktoken', new XMLElement('href', 'opaquelocktoken:' . $lock_token))); $response = new XMLElement("lockdiscovery", new XMLElement("activelock", $activelock), array("xmlns" => "DAV:")); } elseif ($request->method == "UNLOCK") { /** * @TODO: respond with preconditionfailed(409,'lock-token-matches-request-uri') if * there is no lock to be deleted. */
function set_country_vars($db, $x) { require "resources/countries.php"; //$country_iso=$_SESSION['domain']['country']['iso_code']; $sql = "select default_setting_value as value from v_default_settings "; $sql .= "where default_setting_name = 'iso_code' "; $sql .= "and default_setting_category = 'domain' "; $sql .= "and default_setting_subcategory = 'country' "; $sql .= "and default_setting_enabled = 'true';"; $prep_statement = $db->prepare(check_sql($sql)); if ($prep_statement) { $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); if (count($result) > 0) { $country_iso = $result[0]["value"]; } } unset($prep_statement, $sql, $result); if ($country_iso === NULL) { return; } if (isset($countries[$country_iso])) { $country = $countries[$country_iso]; // Set default Country ISO code $sql = "select count(*) as num_rows from v_vars "; $sql .= "where var_name = 'default_country' "; $sql .= "and var_cat = 'Defaults' "; $prep_statement = $db->prepare(check_sql($sql)); if ($prep_statement) { $prep_statement->execute(); $row = $prep_statement->fetch(PDO::FETCH_ASSOC); if ($row['num_rows'] == 0) { $sql = "insert into v_vars "; $sql .= "("; $sql .= "var_uuid, "; $sql .= "var_name, "; $sql .= "var_value, "; $sql .= "var_cat, "; $sql .= "var_enabled, "; $sql .= "var_order, "; $sql .= "var_description "; $sql .= ")"; $sql .= "values "; $sql .= "("; $sql .= "'" . uuid() . "', "; $sql .= "'default_country', "; $sql .= "'" . $country["isocode"] . "', "; $sql .= "'Defaults', "; $sql .= "'true', "; $sql .= "'" . $x . "', "; $sql .= "'' "; $sql .= ");"; $db->exec(check_sql($sql)); unset($sql, $row); $x++; } } unset($prep_statement, $sql); // Set default Country code $sql = "select count(*) as num_rows from v_vars "; $sql .= "where var_name = 'default_countrycode' "; $sql .= "and var_cat = 'Defaults' "; $prep_statement = $db->prepare(check_sql($sql)); if ($prep_statement) { $prep_statement->execute(); $row = $prep_statement->fetch(PDO::FETCH_ASSOC); if ($row['num_rows'] == 0) { $sql = "insert into v_vars "; $sql .= "("; $sql .= "var_uuid, "; $sql .= "var_name, "; $sql .= "var_value, "; $sql .= "var_cat, "; $sql .= "var_enabled, "; $sql .= "var_order, "; $sql .= "var_description "; $sql .= ")"; $sql .= "values "; $sql .= "("; $sql .= "'" . uuid() . "', "; $sql .= "'default_countrycode', "; $sql .= "'" . $country["countrycode"] . "', "; $sql .= "'Defaults', "; $sql .= "'true', "; $sql .= "'" . $x . "', "; $sql .= "'' "; $sql .= ");"; $db->exec(check_sql($sql)); unset($sql, $row); $x++; } } unset($prep_statement, $sql); // Set default International Direct Dialing code $sql = "select count(*) as num_rows from v_vars "; $sql .= "where var_name = 'default_exitcode' "; $sql .= "and var_cat = 'Defaults' "; $prep_statement = $db->prepare(check_sql($sql)); if ($prep_statement) { $prep_statement->execute(); $row = $prep_statement->fetch(PDO::FETCH_ASSOC); if ($row['num_rows'] == 0) { $sql = "insert into v_vars "; $sql .= "("; $sql .= "var_uuid, "; $sql .= "var_name, "; $sql .= "var_value, "; $sql .= "var_cat, "; $sql .= "var_enabled, "; $sql .= "var_order, "; $sql .= "var_description "; $sql .= ")"; $sql .= "values "; $sql .= "("; $sql .= "'" . uuid() . "', "; $sql .= "'default_exitcode', "; $sql .= "'" . $country["exitcode"] . "', "; $sql .= "'Defaults', "; $sql .= "'true', "; $sql .= "'" . $x . "', "; $sql .= "'' "; $sql .= ");"; $db->exec(check_sql($sql)); unset($sql, $row); $x++; } } unset($prep_statement, $sql); unset($countries); } }
if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { require_once "resources/header.php"; require_once "resources/persist_form_var.php"; echo "<div align='center'>\n"; echo "<table><tr><td>\n"; echo $msg . "<br />"; echo "</td></tr></table>\n"; persistformvar($_POST); echo "</div>\n"; require_once "resources/footer.php"; return; } //add or update the database if ($_POST["persistformvar"] != "true") { if ($action == "add" && permission_exists('invoice_add')) { $invoice_uuid = uuid(); $sql = "insert into v_invoices "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "invoice_uuid, "; $sql .= "invoice_number, "; $sql .= "invoice_type, "; $sql .= "contact_uuid_from, "; $sql .= "contact_uuid_to, "; $sql .= "invoice_notes, "; $sql .= "invoice_date "; $sql .= ")"; $sql .= "values "; $sql .= "("; $sql .= "'{$domain_uuid}', "; $sql .= "'{$invoice_uuid}', ";
if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { require_once "resources/header.php"; require_once "resources/persist_form_var.php"; echo "<div align='center'>\n"; echo "<table><tr><td>\n"; echo $msg . "<br />"; echo "</td></tr></table>\n"; persistformvar($_POST); echo "</div>\n"; require_once "resources/footer.php"; return; } //add or update the database if ($_POST["persistformvar"] != "true") { if ($action == "add") { $contact_note_uuid = uuid(); $sql = "insert into v_contact_notes "; $sql .= "("; $sql .= "contact_note_uuid, "; $sql .= "contact_uuid, "; $sql .= "contact_note, "; $sql .= "domain_uuid, "; $sql .= "last_mod_date, "; $sql .= "last_mod_user "; $sql .= ")"; $sql .= "values "; $sql .= "("; $sql .= "'{$contact_note_uuid}', "; $sql .= "'{$contact_uuid}', "; $sql .= "'{$contact_note}', "; $sql .= "'{$domain_uuid}', ";
<?php //libxml_use_internal_errors(true); error_reporting(E_ALL); $uuid = uuid(); $key1 = 'http://bems.ee.eng.chula.ac.th/eng4/fl13/north/room_server/z1/sensor1/monitor/temperature'; $key2 = 'http://bems.ee.eng.chula.ac.th/eng4/fl13/north/room_server/z1/sensor1/monitor/humidity'; $temp = fetchdata($key1, $uuid); var_dump($temp); function fetchdata($keyid, $uuid) { $mydata = "<?xml version='1.0' encoding='UTF-8'?>\n<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>\n<soapenv:Body>\n<ns2:queryRQ xmlns:ns2='http://soap.fiap.org/'>\n<transport xmlns='http://gutp.jp/fiap/2009/11/'>\n<header>\n<query id='" . $uuid . "' type='storage'>\n<key id='{$keyid}' attrName='time' select='maximum' />\n</query>\n</header>\n</transport>\n</ns2:queryRQ>\n</soapenv:Body>\n</soapenv:Envelope>"; $url = "http://161.200.90.122/axis2/services/FIAPStorage"; $headers = array("Content-type: text/xml", "Content-length: " . strlen($mydata), "SOAPAction: http://soap.fiap.org/query"); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_POSTFIELDS, $mydata); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_VERBOSE, 0); $data = curl_exec($ch); if ($data === false) { $error = curl_error($ch); echo $error; die('error occured'); } else { $xml = simplexml_load_string($data); $ns = $xml->getNamespaces(true); $child = (string) $xml->children($ns['soapenv'])->Body->children($ns['ns2'])->queryRS->children($ns[''])->transport->body->point->value;
echo "\t\t\t<option value='" . $row . "'>" . $row . "</option>\n"; } $previous_category = $category; $x++; } echo "\t\t</select>\n"; echo "\t\t<br />\n"; echo "\t\t" . $text['description-time_zone'] . "<br />\n"; echo "\t</td>\n"; echo "\t</tr>\n"; if (file_exists($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . '/app/api/app_config.php')) { echo "\t<tr>"; echo "\t\t<td class='vncell' valign='top'>" . $text['label-api_key'] . "</td>"; echo "\t\t<td class='vtable'>\n"; echo "\t\t\t<input type=\"text\" class='formfld' name=\"api_key\" id='api_key' value=\"" . $api_key . "\" >"; echo "\t\t\t<input type='button' class='btn' value='" . $text['button-generate'] . "' onclick=\"getElementById('api_key').value='" . uuid() . "';\">"; if (strlen($text['description-api_key']) > 0) { echo "\t\t\t<br />" . $text['description-api_key'] . "<br />\n"; } echo "\t\t</td>"; echo "\t</tr>"; } echo "<tr>\n"; echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n"; echo "\t" . $text['label-enabled'] . "\n"; echo "</td>\n"; echo "<td class='vtable' align='left'>\n"; echo "\t<select class='formfld' name='user_enabled'>\n"; echo "\t\t<option value='true'>" . $text['option-true'] . "</option>\n"; echo "\t\t<option value='false' " . ($user_enabled != "true" ? "selected='selected'" : null) . ">" . $text['option-false'] . "</option>\n"; echo "\t</select>\n";
function render() { //debug $debug = $_REQUEST['debug']; // array //get the variables $domain_uuid = $this->domain_uuid; $device_template = $this->device_template; $template_dir = $this->template_dir; $mac = $this->mac; $file = $this->file; //get the device template if (strlen($_REQUEST['template']) > 0) { $device_template = $_REQUEST['template']; $search = array('..', '/./'); $device_template = str_replace($search, "", $device_template); $device_template = str_replace('//', '/', $device_template); } //remove ../ and slashes in the file name $search = array('..', '/', '\\', '/./', '//'); $file = str_replace($search, "", $file); //get the domain_name if (strlen($domain_name) == 0) { $sql = "SELECT domain_name FROM v_domains "; $sql .= "WHERE domain_uuid=:domain_uuid "; $prep_statement = $this->db->prepare(check_sql($sql)); if ($prep_statement) { //use the prepared statement $prep_statement->bindParam(':domain_uuid', $domain_uuid); $prep_statement->execute(); $row = $prep_statement->fetch(); unset($prep_statement); //set the variables from values in the database $domain_name = $row["domain_name"]; } } //build the provision array foreach ($_SESSION['provision'] as $key => $val) { if (strlen($val['var']) > 0) { $value = $val['var']; } if (strlen($val['text']) > 0) { $value = $val['text']; } $provision[$key] = $value; } //check to see if the mac_address exists in devices if (strlen($_REQUEST['user_id']) == 0 || strlen($_REQUEST['userid']) == 0) { if ($this->mac_exists($mac)) { //get the device_template if (strlen($device_template) == 0) { $sql = "SELECT * FROM v_devices "; $sql .= "WHERE device_mac_address=:mac "; //$sql .= "WHERE device_mac_address= '$mac' "; $prep_statement_2 = $this->db->prepare(check_sql($sql)); if ($prep_statement_2) { //use the prepared statement $prep_statement_2->bindParam(':mac', $mac); $prep_statement_2->execute(); $row = $prep_statement_2->fetch(); //set the variables from values in the database $device_uuid = $row["device_uuid"]; $device_label = $row["device_label"]; if (strlen($row["device_vendor"]) > 0) { $device_vendor = strtolower($row["device_vendor"]); } $device_model = $row["device_model"]; $device_firmware_version = $row["device_firmware_version"]; $device_provision_enable = $row["device_provision_enable"]; $device_template = $row["device_template"]; $device_profile_uuid = $row["device_profile_uuid"]; $device_description = $row["device_description"]; } } //find a template that was defined on another phone and use that as the default. if (strlen($device_template) == 0) { $sql = "SELECT * FROM v_devices "; $sql .= "WHERE domain_uuid=:domain_uuid "; $sql .= "limit 1 "; $prep_statement_3 = $this->db->prepare(check_sql($sql)); if ($prep_statement_3) { $prep_statement_3->bindParam(':domain_uuid', $domain_uuid); $prep_statement_3->execute(); $row = $prep_statement_3->fetch(); $device_label = $row["device_label"]; $device_vendor = strtolower($row["device_vendor"]); $device_model = $row["device_model"]; $device_firmware_version = $row["device_firmware_version"]; $device_provision_enable = $row["device_provision_enable"]; $device_template = $row["device_template"]; $device_profile_uuid = $row["device_profile_uuid"]; $device_description = $row["device_description"]; } } } else { //use the user_agent to pre-assign a template for 1-hit provisioning. Enter the a unique string to match in the user agent, and the template it should match. $template_list = array("Linksys/SPA-2102" => "linksys/spa2102", "Linksys/SPA-3102" => "linksys/spa3102", "Linksys/SPA-9212" => "linksys/spa921", "Cisco/SPA301" => "cisco/spa301", "Cisco/SPA301D" => "cisco/spa302d", "Cisco/SPA303" => "cisco/spa303", "Cisco/SPA501G" => "cisco/spa501g", "Cisco/SPA502G" => "cisco/spa502g", "Cisco/SPA504G" => "cisco/spa504g", "Cisco/SPA508G" => "cisco/spa508g", "Cisco/SPA509G" => "cisco/spa509g", "Cisco/SPA512G" => "cisco/spa512g", "Cisco/SPA514G" => "cisco/spa514g", "Cisco/SPA525G2" => "cisco/spa525g2", "snom300-SIP" => "snom/300", "snom320-SIP" => "snom/320", "snom360-SIP" => "snom/360", "snom370-SIP" => "snom/370", "snom820-SIP" => "snom/820", "snom-m3-SIP" => "snom/m3", "yealink SIP-T20" => "yealink/t20", "yealink SIP-T22" => "yealink/t22", "yealink SIP-T26" => "yealink/t26", "Yealink SIP-T32" => "yealink/t32", "HW GXP1450" => "grandstream/gxp1450", "HW GXP2124" => "grandstream/gxp2124", "HW GXV3140" => "grandstream/gxv3140", "HW GXV3175" => "grandstream/gxv3175", "Wget/1.11.3" => "konftel/kt300ip"); foreach ($template_list as $key => $val) { if (stripos($_SERVER['HTTP_USER_AGENT'], $key) !== false) { $device_template = $val; break; } } unset($template_list); //mac address does not exist in the table so add it if ($_SESSION['provision']['auto_insert_enabled']['boolean'] == "true" and strlen($domain_uuid) > 0) { $device_uuid = uuid(); $sql = "INSERT INTO v_devices "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "device_uuid, "; $sql .= "device_mac_address, "; $sql .= "device_vendor, "; $sql .= "device_model, "; $sql .= "device_provision_enable, "; $sql .= "device_template, "; $sql .= "device_description "; $sql .= ") "; $sql .= "VALUES "; $sql .= "("; $sql .= "'" . $domain_uuid . "', "; $sql .= "'{$device_uuid}', "; $sql .= "'{$mac}', "; $sql .= "'{$device_vendor}', "; $sql .= "'', "; $sql .= "'true', "; $sql .= "'{$device_template}', "; $sql .= "'auto {$_SERVER['HTTP_USER_AGENT']}' "; $sql .= ")"; $this->db->exec(check_sql($sql)); unset($sql); } } } //alternate device_uuid if (strlen($device_uuid) > 0) { $sql = "SELECT * FROM v_devices "; $sql .= "WHERE device_uuid = '" . $device_uuid . "' "; $prep_statement_3 = $this->db->prepare(check_sql($sql)); if ($prep_statement_3) { $prep_statement_3->execute(); $row = $prep_statement_3->fetch(); $device_uuid_alternate = $row["device_uuid_alternate"]; if (is_uuid($device_uuid_alternate)) { //override the original device_uuid $device_uuid = $device_uuid_alternate; //get the new devices information $sql = "SELECT * FROM v_devices "; $sql .= "WHERE device_uuid = '" . $device_uuid . "' "; $prep_statement_4 = $this->db->prepare(check_sql($sql)); if ($prep_statement_4) { $prep_statement_4->execute(); $row = $prep_statement_4->fetch(); $device_label = $row["device_label"]; $device_vendor = strtolower($row["device_vendor"]); $device_firmware_version = $row["device_firmware_version"]; $device_provision_enable = $row["device_provision_enable"]; //keep the original template $device_profile_uuid = $row["device_profile_uuid"]; $device_description = $row["device_description"]; } unset($prep_statement_4); } } unset($prep_statement_3); } //get the device settings table in the provision category and update the provision array if (strlen($device_uuid) > 0) { $sql = "SELECT * FROM v_device_settings "; $sql .= "WHERE device_uuid = '" . $device_uuid . "' "; $sql .= "AND device_setting_enabled = 'true' "; $prep_statement = $this->db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $result_count = count($result); foreach ($result as $row) { $key = $row['device_setting_subcategory']; $value = $row['device_setting_value']; $provision[$key] = $value; } unset($prep_statement); } //initialize a template object $view = new template(); if (strlen($_SESSION['provision']['template_engine']['text']) > 0) { $view->engine = $_SESSION['provision']['template_engine']['text']; //raintpl, smarty, twig } else { $view->engine = "smarty"; } $view->template_dir = $template_dir . "/" . $device_template . "/"; $view->cache_dir = $_SESSION['server']['temp']['dir']; $view->init(); //replace the variables in the template in the future loop through all the line numbers to do a replace for each possible line number //get the time zone $time_zone_name = $_SESSION['domain']['time_zone']['name']; if (strlen($time_zone_name) > 0) { $time_zone_offset_raw = get_time_zone_offset($time_zone_name) / 3600; $time_zone_offset_hours = floor($time_zone_offset_raw); $time_zone_offset_minutes = ($time_zone_offset_raw - $time_zone_offset_hours) * 60; $time_zone_offset_minutes = number_pad($time_zone_offset_minutes, 2); if ($time_zone_offset_raw > 0) { $time_zone_offset_hours = number_pad($time_zone_offset_hours, 2); $time_zone_offset_hours = "+" . $time_zone_offset_hours; } else { $time_zone_offset_hours = str_replace("-", "", $time_zone_offset_hours); $time_zone_offset_hours = "-" . number_pad($time_zone_offset_hours, 2); } $time_zone_offset = $time_zone_offset_hours . ":" . $time_zone_offset_minutes; $view->assign("time_zone_offset", $time_zone_offset); } //create a mac address with back slashes for backwards compatability $mac_dash = substr($mac, 0, 2) . '-' . substr($mac, 2, 2) . '-' . substr($mac, 4, 2) . '-' . substr($mac, 6, 2) . '-' . substr($mac, 8, 2) . '-' . substr($mac, 10, 2); //get the contacts array and add to the template engine if (strlen($device_uuid) > 0 and strlen($domain_uuid) > 0 and $_SESSION['provision']['directory']['boolean'] == "true") { //get contacts from the database $sql = "select c.contact_organization, c.contact_name_given, c.contact_name_family, p.phone_number, p.phone_extension "; $sql .= "from v_contacts as c, v_contact_phones as p "; $sql .= "where c.domain_uuid = '" . $domain_uuid . "' "; $sql .= "and c.contact_uuid = p.contact_uuid "; $sql .= "and p.phone_type_voice = '1' "; $sql .= "order by c.contact_organization desc, c.contact_name_given asc, c.contact_name_family asc "; $prep_statement = $this->db->prepare(check_sql($sql)); $prep_statement->execute(); $contacts = $prep_statement->fetchAll(PDO::FETCH_NAMED); unset($prep_statement, $sql); //assign the contacts array $view->assign("contacts", $contacts); } //get the provisioning information from device lines table if (strlen($device_uuid) > 0) { //get the device lines array $sql = "select * from v_device_lines "; $sql .= "where device_uuid = '" . $device_uuid . "' "; $sql .= "and (enabled = 'true' or enabled is null or enabled = '') "; $prep_statement = $this->db->prepare(check_sql($sql)); $prep_statement->execute(); $device_lines = $prep_statement->fetchAll(PDO::FETCH_NAMED); //assign the keys array $view->assign("lines", $device_lines); //set the variables foreach ($device_lines as $row) { //set the variables $line_number = $row['line_number']; $register_expires = $row['register_expires']; $sip_transport = strtolower($row['sip_transport']); $sip_port = $row['sip_port']; //set defaults if (strlen($register_expires) == 0) { $register_expires = "120"; } if (strlen($sip_transport) == 0) { $sip_transport = "tcp"; } if (strlen($sip_port) == 0) { if ($line_number == "" || $line_number == "1") { $sip_port = "5060"; } else { $sip_port = "506" . ($line_number + 1); } } //set a lines array index is the line number $lines[$line_number]['register_expires'] = $register_expires; $lines[$line_number]['sip_transport'] = strtolower($sip_transport); $lines[$line_number]['sip_port'] = $sip_port; $lines[$line_number]['server_address'] = $row["server_address"]; $lines[$line_number]['outbound_proxy'] = $row["outbound_proxy"]; $lines[$line_number]['display_name'] = $row["display_name"]; $lines[$line_number]['auth_id'] = $row["auth_id"]; $lines[$line_number]['user_id'] = $row["user_id"]; $lines[$line_number]['password'] = $row["password"]; //assign the variables $view->assign("server_address_" . $line_number, $row["server_address"]); $view->assign("outbound_proxy_" . $line_number, $row["outbound_proxy"]); $view->assign("display_name_" . $line_number, $row["display_name"]); $view->assign("auth_id_" . $line_number, $row["auth_id"]); $view->assign("user_id_" . $line_number, $row["user_id"]); $view->assign("user_password_" . $line_number, $row["password"]); $view->assign("sip_transport_" . $line_number, $sip_transport); $view->assign("sip_port_" . $line_number, $sip_port); $view->assign("register_expires_" . $line_number, $register_expires); } unset($prep_statement); } //get the provisioning information from device keys if (strlen($device_uuid) > 0) { //get the device keys array $sql = "SELECT * FROM v_device_keys "; $sql .= "WHERE ("; $sql .= "device_uuid = '" . $device_uuid . "' "; if (strlen($device_profile_uuid) > 0) { $sql .= "or device_profile_uuid = '" . $device_profile_uuid . "' "; } $sql .= ") "; //$sql .= "AND domain_uuid = '".$domain_uuid."' "; $sql .= "ORDER BY device_key_category asc, device_key_id asc, device_uuid desc"; $prep_statement = $this->db->prepare(check_sql($sql)); $prep_statement->execute(); $device_keys = $prep_statement->fetchAll(PDO::FETCH_NAMED); //rebuild the array to allow profile keys to be overridden by keys assigned to this device $x = 0; $previous_category = ''; $previous_id = ''; foreach ($device_keys as $row) { //set the variables if ($row['device_key_category'] == $previous_category && $row['device_key_id'] == $previous_id) { $device_keys[$x]['device_key_override'] = "true"; $device_keys[$x]['device_key_message'] = "value=" . $device_keys[$x - 1]['device_key_value'] . "&label=" . $device_keys[$x - 1]['device_key_label']; unset($device_keys[$x - 1]); } $device_keys[$x]['device_key_category'] = $row['device_key_category']; $device_keys[$x]['device_key_id'] = $row['device_key_id']; //1 $device_keys[$x]['device_key_type'] = $row['device_key_type']; //line, memory, expansion $device_keys[$x]['device_key_line'] = $row['device_key_line']; $device_keys[$x]['device_key_value'] = $row['device_key_value']; //1 $device_keys[$x]['device_key_extension'] = $row['device_key_extension']; $device_keys[$x]['device_key_label'] = $row['device_key_label']; //label if (is_uuid($row['device_profile_uuid'])) { $device_keys[$x]['device_key_owner'] = "profile"; } else { $device_keys[$x]['device_key_owner'] = "device"; } //set previous values $previous_category = $row['device_key_category']; $previous_id = $row['device_key_id']; //increment the key $x++; } } //debug information if ($debug == "array") { echo "<pre>\n"; print_r($device_keys); echo "<pre>\n"; exit; } //assign the keys array $view->assign("keys", $device_keys); //set the variables foreach ($device_keys as $row) { //set the variables $device_key_category = $row['device_key_category']; $device_key_id = $row['device_key_id']; //1 $device_key_type = $row['device_key_type']; //line $device_key_line = $row['device_key_line']; $device_key_value = $row['device_key_value']; //1 $device_key_extension = $row['device_key_extension']; $device_key_label = $row['device_key_label']; //label //set the line key $x = $device_key_line; //add a simple variable with the index if ($x === 0 || $x === 1) { $device_key_value = str_replace("\${user_id}", $lines[$x]['user_id'], $device_key_value); $device_key_value = str_replace("\${auth_id}", $lines[$x]['auth_id'], $device_key_value); $device_key_value = str_replace("\${extension}", $lines[$x]['user_id'], $device_key_value); $device_key_value = str_replace("\${password}", $lines[$x]['password'], $device_key_value); $device_key_value = str_replace("\${register_expires}", $lines[$x]['register_expires'], $device_key_value); $device_key_value = str_replace("\${sip_transport}", $lines[$x]['sip_transport'], $device_key_value); $device_key_value = str_replace("\${sip_port}", $lines[$x]['sip_port'], $device_key_value); $device_key_value = str_replace("\${server_address}", $lines[$x]['server_address'], $device_key_value); $device_key_value = str_replace("\${outbound_proxy}", $lines[$x]['outbound_proxy'], $device_key_value); $device_key_value = str_replace("\${display_name}", $lines[$x]['display_name'], $device_key_value); $device_key_extension = str_replace("\${user_id}", $lines[$x]['user_id'], $device_key_extension); $device_key_extension = str_replace("\${auth_id}", $lines[$x]['auth_id'], $device_key_extension); $device_key_extension = str_replace("\${extension}", $lines[$x]['user_id'], $device_key_extension); $device_key_extension = str_replace("\${password}", $lines[$x]['password'], $device_key_extension); $device_key_extension = str_replace("\${register_expires}", $lines[$x]['register_expires'], $device_key_extension); $device_key_extension = str_replace("\${sip_transport}", $lines[$x]['sip_transport'], $device_key_extension); $device_key_extension = str_replace("\${sip_port}", $lines[$x]['sip_port'], $device_key_extension); $device_key_extension = str_replace("\${server_address}", $lines[$x]['server_address'], $device_key_extension); $device_key_extension = str_replace("\${outbound_proxy}", $lines[$x]['outbound_proxy'], $device_key_extension); $device_key_extension = str_replace("\${display_name}", $lines[$x]['display_name'], $device_key_extension); $device_key_label = str_replace("\${user_id}", $lines[$x]['user_id'], $device_key_label); $device_key_label = str_replace("\${auth_id}", $lines[$x]['auth_id'], $device_key_label); $device_key_label = str_replace("\${extension}", $lines[$x]['user_id'], $device_key_label); $device_key_label = str_replace("\${password}", $lines[$x]['password'], $device_key_label); $device_key_label = str_replace("\${register_expires}", $lines[$x]['register_expires'], $device_key_label); $device_key_label = str_replace("\${sip_transport}", $lines[$x]['sip_transport'], $device_key_label); $device_key_label = str_replace("\${sip_port}", $lines[$x]['sip_port'], $device_key_label); $device_key_label = str_replace("\${server_address}", $lines[$x]['server_address'], $device_key_label); $device_key_label = str_replace("\${outbound_proxy}", $lines[$x]['outbound_proxy'], $device_key_label); $device_key_label = str_replace("\${display_name}", $lines[$x]['display_name'], $device_key_label); } //add variables with the index $device_key_value = str_replace("\${user_id_{$x}}", $lines[$x]['user_id'], $device_key_value); $device_key_value = str_replace("\${auth_id_{$x}}", $lines[$x]['auth_id'], $device_key_value); $device_key_value = str_replace("\${extension_{$x}}", $lines[$x]['user_id'], $device_key_value); $device_key_value = str_replace("\${password_{$x}}", $lines[$x]['password'], $device_key_value); $device_key_value = str_replace("\${register_expires_{$x}}", $lines[$x]['register_expires'], $device_key_value); $device_key_value = str_replace("\${sip_transport_{$x}}", $lines[$x]['sip_transport'], $device_key_value); $device_key_value = str_replace("\${sip_port_{$x}}", $lines[$x]['sip_port'], $device_key_value); $device_key_value = str_replace("\${server_address_{$x}}", $lines[$x]['server_address'], $device_key_value); $device_key_value = str_replace("\${outbound_proxy_{$x}}", $lines[$x]['outbound_proxy'], $device_key_value); $device_key_value = str_replace("\${display_name_{$x}}", $lines[$x]['display_name'], $device_key_value); $device_key_extension = str_replace("\${user_id_{$x}}", $lines[$x]['user_id'], $device_key_label); $device_key_extension = str_replace("\${auth_id_{$x}}", $lines[$x]['auth_id'], $device_key_label); $device_key_extension = str_replace("\${extension_{$x}}", $lines[$x]['user_id'], $device_key_label); $device_key_extension = str_replace("\${password_{$x}}", $lines[$x]['password'], $device_key_label); $device_key_extension = str_replace("\${register_expires_{$x}}", $lines[$x]['register_expires'], $device_key_label); $device_key_extension = str_replace("\${sip_transport_{$x}}", $lines[$x]['sip_transport'], $device_key_label); $device_key_extension = str_replace("\${sip_port_{$x}}", $lines[$x]['sip_port'], $device_key_label); $device_key_extension = str_replace("\${server_address_{$x}}", $lines[$x]['server_address'], $device_key_label); $device_key_extension = str_replace("\${outbound_proxy_{$x}}", $lines[$x]['outbound_proxy'], $device_key_label); $device_key_extension = str_replace("\${display_name_{$x}}", $lines[$x]['display_name'], $device_key_label); $device_key_label = str_replace("\${user_id_{$x}}", $lines[$x]['user_id'], $device_key_label); $device_key_label = str_replace("\${auth_id_{$x}}", $lines[$x]['auth_id'], $device_key_label); $device_key_label = str_replace("\${extension_{$x}}", $lines[$x]['user_id'], $device_key_label); $device_key_label = str_replace("\${password_{$x}}", $lines[$x]['password'], $device_key_label); $device_key_label = str_replace("\${register_expires_{$x}}", $lines[$x]['register_expires'], $device_key_label); $device_key_label = str_replace("\${sip_transport_{$x}}", $lines[$x]['sip_transport'], $device_key_label); $device_key_label = str_replace("\${sip_port_{$x}}", $lines[$x]['sip_port'], $device_key_label); $device_key_label = str_replace("\${server_address_{$x}}", $lines[$x]['server_address'], $device_key_label); $device_key_label = str_replace("\${outbound_proxy_{$x}}", $lines[$x]['outbound_proxy'], $device_key_label); $device_key_label = str_replace("\${display_name_{$x}}", $lines[$x]['display_name'], $device_key_label); //add general variables $device_key_value = str_replace("\${domain_name}", $domain_name, $device_key_value); $device_key_extension = str_replace("\${domain_name}", $domain_name, $device_key_extension); $device_key_label = str_replace("\${domain_name}", $domain_name, $device_key_label); //grandstream modes are different based on the category if ($device_vendor == "grandstream") { if ($device_key_category == "line") { switch ($device_key_type) { case "line": $device_key_type = "0"; break; case "shared line": $device_key_type = "1"; break; case "speed dial": $device_key_type = "10"; break; case "blf": $device_key_type = "11"; break; case "presence watcher": $device_key_type = "12"; break; case "eventlist blf": $device_key_type = "13"; break; case "speed dial active": $device_key_type = "14"; break; case "dial dtmf": $device_key_type = "15"; break; case "voicemail": $device_key_type = "16"; break; case "call return": $device_key_type = "17"; break; case "transfer": $device_key_type = "18"; break; case "call park": $device_key_type = "19"; break; case "intercom": $device_key_type = "20"; break; case "ldap search": $device_key_type = "21"; break; } } if ($device_key_category == "memory") { switch ($device_key_type) { case "speed dial": $device_key_type = "0"; break; case "blf": $device_key_type = "1"; break; case "presence watcher": $device_key_type = "2"; break; case "eventlist blf": $device_key_type = "3"; break; case "speed dial active": $device_key_type = "4"; break; case "dial dtmf": $device_key_type = "5"; break; case "voicemail": $device_key_type = "6"; break; case "call return": $device_key_type = "7"; break; case "transfer": $device_key_type = "8"; break; case "call park": $device_key_type = "9"; break; case "intercom": $device_key_type = "10"; break; case "ldap search": $device_key_type = "11"; break; } } } //assign the variables if (strlen($device_key_category) == 0) { $view->assign("key_id_" . $device_key_id, $device_key_id); $view->assign("key_type_" . $device_key_id, $device_key_type); $view->assign("key_line_" . $device_key_id, $device_key_line); $view->assign("key_value_" . $device_key_id, $device_key_value); $view->assign("key_extension_" . $device_key_id, $device_key_extension); $view->assign("key_label_" . $device_key_id, $device_key_label); } else { $view->assign($device_key_category . "_key_id_" . $device_key_id, $device_key_id); $view->assign($device_key_category . "_key_type_" . $device_key_id, $device_key_type); $view->assign($device_key_category . "_key_line_" . $device_key_id, $device_key_line); $view->assign($device_key_category . "_key_value_" . $device_key_id, $device_key_value); $view->assign($device_key_category . "_key_extension_" . $device_key_id, $device_key_extension); $view->assign($device_key_category . "_key_label_" . $device_key_id, $device_key_label); } } unset($prep_statement); //set the mac address in the correct format switch (strtolower($device_vendor)) { case "aastra": $mac = strtoupper($mac); break; case "snom": $mac = strtolower($mac); break; case "polycom": $mac = strtolower($mac); break; default: $mac = strtolower($mac); $mac = substr($mac, 0, 2) . '-' . substr($mac, 2, 2) . '-' . substr($mac, 4, 2) . '-' . substr($mac, 6, 2) . '-' . substr($mac, 8, 2) . '-' . substr($mac, 10, 2); } //replace the variables in the template in the future loop through all the line numbers to do a replace for each possible line number $view->assign("mac", $mac); $view->assign("label", $device_label); $view->assign("firmware_version", $device_firmware_version); $view->assign("domain_name", $domain_name); $view->assign("project_path", PROJECT_PATH); $view->assign("server1_address", $server1_address); $view->assign("proxy1_address", $proxy1_address); $view->assign("user_id", $user_id); $view->assign("password", $password); $view->assign("template", $device_template); //replace the dynamic provision variables that are defined in default, domain, and device settings foreach ($provision as $key => $val) { $view->assign($key, $val); } //set the template directory if (strlen($provision["template_dir"]) > 0) { $template_dir = $provision["template_dir"]; } //if the domain name directory exists then only use templates from it if (is_dir($template_dir . '/' . $domain_name)) { $device_template = $domain_name . '/' . $device_template; } //if $file is not provided then look for a default file that exists if (strlen($file) == 0) { if (file_exists($template_dir . "/" . $device_template . "/{\$mac}")) { $file = "{\$mac}"; } elseif (file_exists($template_dir . "/" . $device_template . "/{\$mac}.xml")) { $file = "{\$mac}.xml"; } elseif (file_exists($template_dir . "/" . $device_template . "/{\$mac}.cfg")) { $file = "{\$mac}.cfg"; } else { echo "file not found"; exit; } } else { //make sure the file exists if (!file_exists($template_dir . "/" . $device_template . "/" . $file)) { echo "file not found"; if ($_SESSION['provision']['debug']['boolean'] == 'true') { echo ":{$template_dir}/{$device_template}/{$file}<br/>"; echo "template_dir: {$template_dir}<br/>"; echo "device_template: {$device_template}<br/>"; echo "file: {$file}"; } exit; } } //output template to string for header processing $file_contents = $view->render($file); //log file for testing if ($_SESSION['provision']['debug']['boolean'] == 'true') { $tmp_file = "/tmp/provisioning_log.txt"; $fh = fopen($tmp_file, 'w') or die("can't open file"); $tmp_string = $mac . "\n"; fwrite($fh, $tmp_string); fclose($fh); } //returned the rendered template return $file_contents; }
$a_resource =& $config['hast']['hastresource']; if (isset($uuid) && FALSE !== ($cnid = array_search_ex($uuid, $a_resource, "uuid"))) { $pconfig['uuid'] = $a_resource[$cnid]['uuid']; $pconfig['name'] = $a_resource[$cnid]['name']; $pconfig['auxparam'] = ""; if (isset($a_resource[$cnid]['auxparam']) && is_array($a_resource[$cnid]['auxparam'])) { $pconfig['auxparam'] = implode("\n", $a_resource[$cnid]['auxparam']); } $pconfig['aname'] = $a_resource[$cnid]['aname']; $pconfig['apath'] = $a_resource[$cnid]['apath']; $pconfig['aremoteaddr'] = $a_resource[$cnid]['aremoteaddr']; $pconfig['bname'] = $a_resource[$cnid]['bname']; $pconfig['bpath'] = $a_resource[$cnid]['bpath']; $pconfig['bremoteaddr'] = $a_resource[$cnid]['bremoteaddr']; } else { $pconfig['uuid'] = uuid(); $pconfig['name'] = ""; $pconfig['auxparam'] = ""; $pconfig['aname'] = ""; $pconfig['apath'] = ""; $pconfig['aremoteaddr'] = ""; $pconfig['bname'] = ""; $pconfig['bpath'] = ""; $pconfig['bremoteaddr'] = ""; } if ($_POST) { unset($input_errors); $pconfig = $_POST; if (isset($_POST['Cancel']) && $_POST['Cancel']) { header("Location: services_hast_resource.php"); exit;
$sql .= "last_mod_date = now(), "; $sql .= "last_mod_user = '******'username'] . "' "; $sql .= "where domain_uuid = '" . $domain_uuid . "' "; $sql .= "and contact_uuid = '" . $contact_uuid . "' "; $db->exec(check_sql($sql)); unset($sql); //if primary, unmark other primary numbers if ($address_primary) { $sql = "update v_contact_addresses set address_primary = 0 "; $sql .= "where domain_uuid = '" . $domain_uuid . "' "; $sql .= "and contact_uuid = '" . $contact_uuid . "' "; $db->exec(check_sql($sql)); unset($sql); } if ($action == "add") { $contact_address_uuid = uuid(); $sql = "insert into v_contact_addresses "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "contact_uuid, "; $sql .= "contact_address_uuid, "; $sql .= "address_type, "; $sql .= "address_label, "; $sql .= "address_street, "; $sql .= "address_extended, "; $sql .= "address_community, "; $sql .= "address_locality, "; $sql .= "address_region, "; $sql .= "address_postal_code, "; $sql .= "address_country, "; $sql .= "address_latitude, ";