Regular expression challenge parsing xml

I am parsing xml data generated by backup software for SMS and phone logs.

Most of the data appears like this:

  <sms protocol="0" address="##########" date="1495903715000" body="Ok. See you then.;-)" subject="none" ... />

For most bodies of a text message, the data follows the same pattern above: Keyword body="<string>". If the message contains single- or double-quotes, things are more complex. The software will convert a single-quote to the entity &apos; If double-quotes " are used in the body of the text message, then the text-delimiter will change from single- ' to double-quotes ", like this:

... body='Member, this win-win is for you! We&apos;re awesome, &apos;cause you&apos;re awesome. Some company was just ranked "Highest in "Customer Service" and "Purchase Experience" Satisfaction Among Wireless Providers" by J.D. Power.' 

The php script written to parse the rows of data is:

function parse_rows($rows)
    for ($a=0; $a < count($rows); $a++) {
        preg_match_all("/[a-z_]+=[\"|'](?:[^\"]*)['|\"]/",$rows[$a], $matches);
        $data[$a] = $matches[0];
    }
    return $data;
}

The preg_match_all utilised is not working well for body data that is of the exception described. It is clipping at the first instance of a double-quotation mark in mid-stream. This is the breakdown of the regex "/[a-z_]+=[\"|'](?:[^\"]*)['|\"]/"

[a-z_]+= captures the key tags like 'protocol=', 'address=', 'date='
Intended [\"|'] captures the beginning of the data either single- ' or double-quotes "
Intended (?:[^\"]*) look-ahead, capturing everything that does not include a double-quote "
Intended pattern ends with ['|\"]

Can someone assist with the regex that will capture for these exceptional body= text streams?

Each value of $rows comes in like shown above:

  <sms protocol="0" address="##########" date="1495903715000" body="Ok. See you then.;-)" subject="none" ... />

The array $data is multi-dimensional. The above row would become:

$data
  ->[0]
    ->[0] = "protocol="0"" 
    ->[1] = "address="##########"" 
    ->[2] = "date="1495903715000""
    ->[3] = "body="Ok. See you then.;-)"" 
    ->[4] = "subject="none""
    .
    .
    ->[17] = "contact_name"

Variable $data is then parsed further later on.

Is there another method to convert a string like:

  <sms protocol="0" address="##########" date="1495903715000" body="Ok. See you then.;-)" subject="none" ... />

to an array like $data?

Postfix authentication problem

I am trying to set-up Postfix on my Ubuntu local web development machine for send-only e-mails using Gmail so I can test e-mails sent by a web app I am developing.

These are the steps I have followed based on a recently posted tutorial found here:

  1. Dowloaded and installed Postfix using "Internet Site" option
    The FQDN I am using is 'lhdwlamb.com'. This also appears in /etc/hosts . Excerpts of the configuration file where specified edits are needed:

    myhostname = daniel-wsT7500
    alias_maps = hash:/etc/aliases
    alias_database = hash:/etc/aliases
    myorigin = /etc/mailname
    mydestination = $myhostname, lhdwlamb.com, daniel-wsT7500, localhost.localdomain, loc$
    relayhost = [smtp.gmail.com]:587
    mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
    mailbox_size_limit = 0
    recipient_delimiter = +
    inet_interfaces = all
    inet_protocols = all

    #Enable SASL authentication
    smtp_sasl_auth_enable = yes
    smtp_sasl_security_options = noanonymous
    smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd
    smtp_tls_security_level = encrypt
    smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

  2. Obtained a Google App Password
    This is a step I found missing from several other tutorials I found. For Google account settings 2-step verification is on when using Google App password. I have also tried the old method of my regular gmail password with allow less secure apps turned on.

  3. Created as sasl_passwd file

    [smtp.gmail.com]:587 xxxxxxx@gmail.com:xxxxxxxxxxxx

(x's replace actual values for security here)

  1. The sasl_passwd file is converted to a db using sudo postmap

  2. Files sasl_passwd and sasl_passwd.db changed to root and 0600 as listed:

    ll /etc/postfix/sasl/
    total 12
    -rw------- 1 root root 55 Jan 31 17:06 sasl_passwd
    -rw------- 1 root root 12288 Jan 31 17:09 sasl_passwd.db

  3. Postfix was restarted using sudo systemctl restart postfix.

Test e-mails are not receiving by GMail. This is the result I am seeing in mail.log (xxx's for security here):

Jan 31 16:39:51 daniel-wsT7500 postfix/smtp[28260]: E8545E1313: to=<xxxxxxx@gmail.com>, relay=smtp.gmail.com[173.194.205.108]:587, delay=67, delays=65/0.12/1.4/0, dsn=4.7.8, status=deferred (SASL authentication failed; server smtp.gmail.com[173.194.205.108] said: 535-5.7.8 Username and Password not accepted. Learn more at?535 5.7.8  https://support.google.com/mail/?p=BadCredentials o5sm12089476qko.85 - gsmtp)

I have looked at the page for the link in that error message and not found anything to help with this problem.

Can anyone help with information I am missing or other problems to test for?

Thanks for taking the time to read this.

JSON result prepended with `

I am working on a project for drag and drop items in a shopping cart. For an item dropped into the cart, I am trying to implement jQuery $.ajax. The result back from the PHP is pre-pended with '`' and I can not figure out why.

This is the javascript:

$('#target').droppable({
    drop: function(event,ui) {
        var id      = $(ui.draggable).data('id');
        var aisle   = $(ui.draggable).data('aisle');
        $.ajax({
            url   : base_url+'/index.php/groceries/jquery_append_to_list',
            cache : false,
            type  : 'post',
            data  : {
                'id' : id,
                 'aisle' : aisle
            },
            success    : function(data) {
                $('#target').append('<p data-id="'+id+'" data-aisle="'+aisle+'" class="draggable">'+data.item+'</p>');
            }
        })
    }
});

This is the PHP script:

function jquery_append_to_list(){
    $id     = $this->input->post('id');
    $aisle  = $this->input->post('aisle');
    $arr    = array(
                    'r' => '1',
                   'id' => $id,
                'aisle' => $aisle,
                 'item' => 'Rye Bread');
    $data   = json_encode($arr);
    echo $data;
}

For the PHP, I am using Codeigniter as the framework. The PHP is very basic right now as I am debugging this problem so I am trying to return static response values.

The item showing up in the shopping cart is 'undefined' instead of 'Rye Bread' for the JSON array is coming into the browser as `{"r":"1","id":"7","aisle":"1","item":"Rye Bread"}.

I have stepped through the PHP with an IDE and $data is {"r":"1","id":"7","aisle":"1","item":"Rye Bread"}. Somewhere in jQuery's handling it is prepending '`' to the array.

I am using

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>

as the jQuery sources. These are the same sources I use for other projects and the returns on those .ajax calls don't come back with a '`'.

The encoding in the editors used is UTF-8. The same is declared in the metadata of the browser. Thinking it might be an encoding problem I have opened the files in different editors under Windows and Linux (Linux my main environment) and nothing has shown as unexpected to account where the '`' is coming from.

For the success part I have tried

success : function(data) {
    data = data.replace(/\`/,'');
    console.log(data);
    var item = data.item;
    console.log(item);
    $('#target').append('<p data-id="'+id+'" data-aisle="'+aisle+'" class="draggable">'+item+'</p>');
}

The array data is cleaned up and variable item still comes up as undefined.

Does anyone have an idea of what to do next?

Connecting to Mariadb with Libreoffice

I am trying to establish a connection between LibreOffice (5.4.6.2) and Mariadb (10.1.29)/mysql. I have researched various resources on the web but am stuck not being able to establish a connection

preliminary steps taken:

  • the file mariadb-java-client-2.4.0.jar is downloaded from https://downloads.mariadb.com/Connectors/java/connector-java-2.3.0/
  • JRE is installed and enabled under LibreOffice Tools > Options > Advanced
  • in that Advanced tab, Class Path is set with mariadb-java-client-2.4.0.jar (I have tried with a path /opt/mariadb-java-client-2.4.0.jar and /home/<my user name>/mariadb-java-client-2.4.0.jar)

Based on web site and youtube tutorials, the next steps are to connect via LibreOffice Base. Using the wizard:

  • Connect to an existing database MySQL is chosen from the dropdown
  • after clicking Next >>
  • Under some video and how-to tutorials, there has been a third option of Connect directly... Is this a further clue that something is not set properly?
  • I choose Connect using JDBC...and click Next >>
  • I provide the database name, the server (have tried localhost and 127.0.0.1) and port number 3306
  • for the MySQL JDBC driver class I change the string to org.mariadb.jdbc.Driver according to https://stackoverflow.com/a/41842833/7932473
  • upon clicking Test Class, a dialog with The JDBC driver could not be loaded appears

I have used JDBC connections before under LO 3.x and MySQL before Mariadb came along. Ultimately, I want to use a connection to my database for further analysis of the data using Calc. Is this still possible? If my memory is not failing me, it is possible to open a Base registered database within LO Calc.

Regular Expression to extract names

The challenge I need to resolve is getting a sub-string from strings such as those below. Each line is of an array so I am iterating and working on one line at a time in a JavaScript loop. All of the strings have the names at the start of the line:

Joe Smith will run...
Jane Jones will follow...
Bridget Burns and Jack Jones will be away...
Jack Jones, Gracie Burns and George Burns have three days in...

The sub-string I need is the name(s) at the start of each string. My JavaScript is handling an example of the first or second line adequately by:

substr   = replace(/^(\w+ \w+ )(?:.*)/g,"$1").trim();

will output Joe Smith or Jane Jones respectively.

Is there a method to extract just the names, preferably as one variable?

I have some experience with regular expressions but not enough to reliably extract what I need from examples such as these.

use of $(this) for a class

I am a novice at JavaScript an jQuery. I am writing a project and trying to incorporate $(this) to read a data attribute. Once the data attribute is determined and assigned to a variable, I intend to use that to access other form elements.

Instead of reading the data attribute as intended, clicking the button is submitting the form.

This is a code sample:

<fieldset class="new_inputs" id="new_inputs1">
    <label for="file_input_1">Input File:1</label>
    <input class="fileRenamingFormInput" name="file_input_1" id="file_input_1" type="text" value="">
    <br>
    <select class="fileRenamingFormSelect" name="destinationFile_1 id="destinationfile_1">...</select>
    <input class="fileRenamingFormFileOut" name="file_out_1" id="file_out_1" type="text" value="">
    <br>
    <textarea class="copyCommandBlock" name="copyCommandBlock1" id="copyCommandBlock1"></textarea>
    <button type="submit" class="btnGenerate" id="btnGenerate1" data-idx="1">Generate command</button>  <- Button Javascript might act on
    <button type="submit" class="btnCopy" id="btnCopy1" data-idx="1">Copy</button>
</fieldset>

<fieldset class="new_inputs" id="new_inputs2">
    <label for="file_input_2">Input File:2</label>
    <input class="fileRenamingFormInput" name="file_input_2" id="file_input_2" type="text" value="">
    <br>
    <select class="fileRenamingFormSelect" name="destinationFile_2 id="destinationfile_2">...</select>
    <input class="fileRenamingFormFileOut" name="file_out_2" id="file_out_2" type="text" value="">
    <br>
    <textarea class="copyCommandBlock" name="copyCommandBlock2" id="copyCommandBlock2"></textarea>
    <button type="submit" class="btnGenerate" id="btnGenerate2" data-idx="2">Generate command</button> <- Button Javascript might act on
    <button type="submit" class="btnCopy" id="btnCopy2" data-idx="2">Copy</button>
</fieldset>

This is the JavaScript

$("button.btnGenerate").click(function(e){
    e.preventDefault();
    var idx = $(this).data("idx");
    console.log(idx);
});

The logic I am seeking to employ is:

  • When "button.btnGenerate" is clicked, don't submit the form
  • assign data-idx to variable idx
  • once I have variable idx, I can more efficiently use it plus text strings to get form values from sibling or other form elements. For example, if var idx = 2;

    var fnIn = document.getElementById(fileinput'+'idx').value
    var fnOut = document.getElementById(fileout'+'idx').value
    var str = 'cp '+fnIn+' '+fnOut;
    document.getElementById('copyCommandBlock'+idx).value = str;

With the page loaded in the browser there could be multiple fieldsets. They are created dynamically based on the user clicking a button to add another set of fields. I am using $("button.btnGenerate") as the listening event for it is generic.

Is that selector still too generic since it is a class?

Thanks for taking the time to read this. Hope someone can help