From: <abe...@us...> - 2013-02-18 00:08:26
|
Revision: 5958 http://astlinux.svn.sourceforge.net/astlinux/?rev=5958&view=rev Author: abelbeck Date: 2013-02-18 00:08:17 +0000 (Mon, 18 Feb 2013) Log Message: ----------- openvpn, add optional TLS-Auth support for server and client Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/openvpn.php branches/1.0/package/webinterface/altweb/admin/openvpnclient.php branches/1.0/package/webinterface/altweb/common/openssl-openvpn.php branches/1.0/package/webinterface/altweb/common/openssl-openvpnclient.php branches/1.0/package/webinterface/altweb/common/openssl.php Modified: branches/1.0/package/webinterface/altweb/admin/openvpn.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/openvpn.php 2013-02-16 20:53:24 UTC (rev 5957) +++ branches/1.0/package/webinterface/altweb/admin/openvpn.php 2013-02-18 00:08:17 UTC (rev 5958) @@ -223,6 +223,12 @@ fwrite($fp, "### Key File\n".$value."\n"); $value = 'OVPN_DH="'.$openssl['dh_pem'].'"'; fwrite($fp, "### DH File\n".$value."\n"); + if ($_POST['tls_auth'] === 'yes' && openvpnCREATEtls_auth($openssl)) { + $value = 'OVPN_TA="'.$openssl['key_dir'].'/ta.key"'; + } else { + $value = 'OVPN_TA=""'; + } + fwrite($fp, "### TLS-Auth File\n".$value."\n"); if (! is_null($disabled)) { if (count($disabled) > 0) { $value = 'OVPN_VALIDCLIENTS="'; @@ -256,8 +262,15 @@ $value = isset($_POST['dh']) ? trim($_POST['dh']) : $base.'/dh1024.pem'; $value = 'OVPN_DH="'.$value.'"'; fwrite($fp, "### DH File\n".$value."\n"); + if ($_POST['tls_auth'] === 'yes') { + $value = isset($_POST['ta']) ? trim($_POST['ta']) : $base.'/ta.key'; + $value = 'OVPN_TA="'.$value.'"'; + } else { + $value = 'OVPN_TA=""'; + } + fwrite($fp, "### TLS-Auth File\n".$value."\n"); } - + fwrite($fp, "### gui.openvpn.conf - end ###\n"); fclose($fp); @@ -285,7 +298,7 @@ // Function: ovpnProfile // -function ovpnProfile($db, $ca_file) { +function ovpnProfile($db, $ssl, &$ta_file) { $default = array ( 'client', @@ -297,6 +310,13 @@ 'verb 3' ); + $ca_file = $ssl['key_dir'].'/ca.crt'; + if (($ta_file = getVARdef($db, 'OVPN_TA')) !== '') { + if (! is_file($ta_file)) { + $ta_file = ''; + } + } + if (($server_hostname = getVARdef($db, 'OVPN_HOSTNAME')) === '') { $server_hostname = get_HOSTNAME_DOMAIN(); } @@ -319,6 +339,9 @@ if (($cipher = getVARdef($db, 'OVPN_CIPHER')) !== '') { $str .= "cipher $cipher\n"; } + if ($ta_file !== '') { + $str .= "key-direction 1\n"; + } foreach ($default as $value) { $str .= "$value\n"; } @@ -327,6 +350,13 @@ $str .= $caStr; $str .= "</ca>\n"; } + if ($ta_file !== '') { + if (($taStr = @file_get_contents($ta_file)) !== FALSE) { + $str .= "<tls-auth>\n"; + $str .= $taStr; + $str .= "</tls-auth>\n"; + } + } return($str); } @@ -382,7 +412,8 @@ } elseif (isset($_POST['submit_new_client'])) { if (($value = trim($_POST['new_client'])) !== '') { if (preg_match('/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/', $value)) { - if (! is_file($openssl['key_dir'].'/'.$value.'.crt') && + if ($value !== 'ta' && + ! is_file($openssl['key_dir'].'/'.$value.'.crt') && ! is_file($openssl['key_dir'].'/'.$value.'.key')) { if (opensslCREATEclientCert($value, $openssl)) { $disabled = isset($_POST['disabled']) ? $_POST['disabled'] : NULL; @@ -425,9 +456,14 @@ $p12pass = opensslRANDOMpass(12); if (($p12 = opensslPKCS12str($openssl, $value, $p12pass)) !== '') { $zip->addFromString($value.'/'.$value.'.p12', $p12); - if (($ovpn = ovpnProfile($db, $openssl['key_dir'].'/ca.crt')) !== FALSE) { + if (($ovpn = ovpnProfile($db, $openssl, $tls_auth_file)) !== FALSE) { $zip->addFromString($value.'/'.$value.'.ovpn', $ovpn); - $zip->addFromString($value.'/README.txt', opensslREADMEstr('ovpn', $value, $p12pass)); + if ($tls_auth_file !== '') { + $zip->addFile($tls_auth_file, $value.'/'.$value.'-ta.key'); + $zip->addFromString($value.'/README.txt', opensslREADMEstr('ovpn-ta', $value, $p12pass)); + } else { + $zip->addFromString($value.'/README.txt', opensslREADMEstr('ovpn', $value, $p12pass)); + } } else { $zip->addFromString($value.'/README.txt', opensslREADMEstr('p12', $value, $p12pass)); } @@ -524,22 +560,6 @@ putHtml('</td></tr>'); putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); - putHtml('Auth Method:'); - putHtml('</td><td style="text-align: left;" colspan="2">'); - if (($auth_method = getVARdef($db, 'OVPN_USER_PASS_VERIFY')) === '') { - $auth_method = 'no'; - } - putHtml('<select name="auth_method" onchange="auth_method_change()">'); - foreach ($auth_method_menu as $key => $value) { - $sel = ($auth_method === $key) ? ' selected="selected"' : ''; - putHtml('<option value="'.$key.'"'.$sel.'>'.$value.'</option>'); - } - putHtml('</select>'); - putHtml('</td><td style="text-align: left;" colspan="2">'); - putHtml('<input type="submit" value="User/Pass" name="submit_user_pass" class="button" />'); - putHtml('</td></tr>'); - - putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); putHtml('Protocol:'); putHtml('</td><td style="text-align: left;" colspan="1">'); $protocol = getVARdef($db, 'OVPN_PROTOCOL'); @@ -628,6 +648,38 @@ putHtml('</td></tr>'); putHtml('<tr class="dtrow0"><td class="dialogText" style="text-align: left;" colspan="6">'); + putHtml('<strong>Authentication:</strong>'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); + putHtml('Auth Method:'); + putHtml('</td><td style="text-align: left;" colspan="2">'); + if (($auth_method = getVARdef($db, 'OVPN_USER_PASS_VERIFY')) === '') { + $auth_method = 'no'; + } + putHtml('<select name="auth_method" onchange="auth_method_change()">'); + foreach ($auth_method_menu as $key => $value) { + $sel = ($auth_method === $key) ? ' selected="selected"' : ''; + putHtml('<option value="'.$key.'"'.$sel.'>'.$value.'</option>'); + } + putHtml('</select>'); + putHtml('</td><td style="text-align: left;" colspan="2">'); + putHtml('<input type="submit" value="User/Pass" name="submit_user_pass" class="button" />'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); + putHtml('Extra TLS-Auth:'); + putHtml('</td><td style="text-align: left;" colspan="4">'); + $tls_auth = getVARdef($db, 'OVPN_TA'); + putHtml('<select name="tls_auth">'); + $sel = ($tls_auth === '') ? ' selected="selected"' : ''; + putHtml('<option value=""'.$sel.'>No</option>'); + $sel = ($tls_auth !== '') ? ' selected="selected"' : ''; + putHtml('<option value="yes"'.$sel.'>Yes</option>'); + putHtml('</select>'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow0"><td class="dialogText" style="text-align: left;" colspan="6">'); putHtml('<strong>Firewall Options:</strong>'); putHtml('</td></tr>'); putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); @@ -812,6 +864,12 @@ } putHtml('<input type="text" size="64" maxlength="128" value="'.$value.'" name="dh" />'); putHtml('</td></tr>'); + putHtml('<tr class="dtrow1"><td style="text-align: right;">'); + putHtml('TLS-Auth File:'); + putHtml('</td><td style="text-align: left;" colspan="5">'); + $value = getVARdef($db, 'OVPN_TA'); + putHtml('<input type="text" size="64" maxlength="128" value="'.$value.'" name="ta" />'); + putHtml('</td></tr>'); } putHtml('</table>'); Modified: branches/1.0/package/webinterface/altweb/admin/openvpnclient.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/openvpnclient.php 2013-02-16 20:53:24 UTC (rev 5957) +++ branches/1.0/package/webinterface/altweb/admin/openvpnclient.php 2013-02-18 00:08:17 UTC (rev 5958) @@ -40,7 +40,7 @@ ); $nscerttype_menu = array ( - '' => 'None', + '' => 'No', 'server' => 'Server' ); @@ -112,6 +112,12 @@ fwrite($fp, "### CERT File\n".$value."\n"); $value = 'OVPNC_KEY="'.$openssl['client_key'].'"'; fwrite($fp, "### Key File\n".$value."\n"); + if ($_POST['tls_auth'] === 'yes' && is_file($openssl['tls_auth_key'])) { + $value = 'OVPNC_TA="'.$openssl['tls_auth_key'].'"'; + } else { + $value = 'OVPNC_TA=""'; + } + fwrite($fp, "### TLS-Auth File\n".$value."\n"); } fwrite($fp, "### gui.openvpnclient.conf - end ###\n"); @@ -141,6 +147,7 @@ $result = 2; } } elseif (isset($_FILES['creds'])) { + $tls_auth_key = TRUE; $result = 1; foreach ($_FILES['creds']['error'] as $key => $error) { if ($error == 0) { @@ -159,7 +166,7 @@ break; } } elseif (stripos($name, '.key', $len) !== FALSE) { - if ($key !== 'client_key') { + if ($key !== 'client_key' && $key !== 'tls_auth_key') { $result = 23; break; } @@ -170,6 +177,8 @@ } elseif ($error == 1 || $error == 2) { $result = 20; break; + } elseif ($key === 'tls_auth_key') { // TLS-Auth is optional + $tls_auth_key = FALSE; } else { $result = 21; break; @@ -180,13 +189,15 @@ if ($openssl !== FALSE) { $result = 30; foreach ($_FILES['creds']['tmp_name'] as $key => $tmp_name) { - if (! move_uploaded_file($tmp_name, $openssl[$key])) { - $result = 3; - break; + if ($key !== 'tls_auth_key' || $tls_auth_key) { + if (! move_uploaded_file($tmp_name, $openssl[$key])) { + $result = 3; + break; + } + if ($key === 'client_key' || $key === 'tls_auth_key') { + chmod($openssl[$key], 0600); + } } - if ($key === 'client_key') { - chmod($openssl[$key], 0600); - } } } } @@ -219,7 +230,7 @@ } elseif ($result == 20) { putHtml('<p style="color: red;">File size is not reasonable for a cert or key.</p>'); } elseif ($result == 21) { - putHtml('<p style="color: red;">All three files, CA, Cert and Key must be defined.</p>'); + putHtml('<p style="color: red;">The three files, CA, Cert and Key must be defined. The TLS-Auth Key is optional.</p>'); } elseif ($result == 22) { putHtml('<p style="color: red;">Invalid suffix, only files ending with .crt and .key are allowed.</p>'); } elseif ($result == 23) { @@ -322,23 +333,13 @@ putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); putHtml('Device:'); - putHtml('</td><td style="text-align: left;" colspan="1">'); + putHtml('</td><td style="text-align: left;" colspan="4">'); putHtml('<select name="device">'); $sel = (getVARdef($db, 'OVPNC_DEV') === 'tun2') ? ' selected="selected"' : ''; putHtml('<option value="tun2"'.$sel.'>tun2</option>'); $sel = (getVARdef($db, 'OVPNC_DEV') === 'tun3') ? ' selected="selected"' : ''; putHtml('<option value="tun3"'.$sel.'>tun3</option>'); putHtml('</select>'); - putHtml('</td><td style="text-align: right;" colspan="1">'); - putHtml('nsCertType:'); - putHtml('</td><td style="text-align: left;" colspan="2">'); - $nscerttype = getVARdef($db, 'OVPNC_NSCERTTYPE'); - putHtml('<select name="nscerttype">'); - foreach ($nscerttype_menu as $key => $value) { - $sel = ($nscerttype === $key) ? ' selected="selected"' : ''; - putHtml('<option value="'.$key.'"'.$sel.'>'.$value.'</option>'); - } - putHtml('</select>'); putHtml('</td></tr>'); putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); @@ -355,6 +356,34 @@ putHtml('</td></tr>'); putHtml('<tr class="dtrow0"><td class="dialogText" style="text-align: left;" colspan="6">'); + putHtml('<strong>Authentication:</strong>'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); + putHtml('Require nsCertType:'); + putHtml('</td><td style="text-align: left;" colspan="4">'); + $nscerttype = getVARdef($db, 'OVPNC_NSCERTTYPE'); + putHtml('<select name="nscerttype">'); + foreach ($nscerttype_menu as $key => $value) { + $sel = ($nscerttype === $key) ? ' selected="selected"' : ''; + putHtml('<option value="'.$key.'"'.$sel.'>'.$value.'</option>'); + } + putHtml('</select>'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); + putHtml('Extra TLS-Auth:'); + putHtml('</td><td style="text-align: left;" colspan="4">'); + $tls_auth = getVARdef($db, 'OVPNC_TA'); + putHtml('<select name="tls_auth">'); + $sel = ($tls_auth === '') ? ' selected="selected"' : ''; + putHtml('<option value=""'.$sel.'>No</option>'); + $sel = ($tls_auth !== '') ? ' selected="selected"' : ''; + putHtml('<option value="yes"'.$sel.'>Yes</option>'); + putHtml('</select>'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow0"><td class="dialogText" style="text-align: left;" colspan="6">'); putHtml('<strong>Client Mode:</strong>'); putHtml('</td></tr>'); putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); @@ -379,9 +408,9 @@ putHtml('</form>'); if (opensslOPENVPNCis_valid($openssl)) { - putHtml('<p style="color: green;">Client Credentials are defined.</p>'); + putHtml('<p style="color: green;">Required Client Credentials are defined.</p>'); } else { - putHtml('<p style="color: red;">Not all Client Credential files are defined.</p>'); + putHtml('<p style="color: red;">Not all required Client Credential files are defined.</p>'); } putHtml('<form method="post" action="'.$myself.'" enctype="multipart/form-data">'); @@ -400,6 +429,10 @@ putHtml('</td><td style="text-align: left;">'); putHtml(getCREDinfo($openssl, 'client_key', $str).'<input type="file" name="creds[client_key]" />'); putHtml('</td></tr><tr class="dtrow1"><td style="text-align: right;">'); + putHtml('TLS-Auth Key:'); + putHtml('</td><td style="text-align: left;">'); + putHtml(getCREDinfo($openssl, 'tls_auth_key', $str).'<input type="file" name="creds[tls_auth_key]" />'); + putHtml('</td></tr><tr class="dtrow1"><td style="text-align: right;">'); if ($CName !== '') { putHtml('CN:'); putHtml('</td><td style="text-align: left;">'); Modified: branches/1.0/package/webinterface/altweb/common/openssl-openvpn.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/openssl-openvpn.php 2013-02-16 20:53:24 UTC (rev 5957) +++ branches/1.0/package/webinterface/altweb/common/openssl-openvpn.php 2013-02-18 00:08:17 UTC (rev 5958) @@ -140,4 +140,22 @@ chmod($ssl['dh_pem'], 0644); return(TRUE); } + +// Function: openvpnCREATEtls_auth() +// +function openvpnCREATEtls_auth($ssl) { + + $ta_file = $ssl['key_dir'].'/ta.key'; + + if (is_file($ta_file)) { + return(TRUE); + } + shell('openvpn --genkey --secret '.$ta_file.' >/dev/null 2>/dev/null', $status); + if ($status != 0) { + @unlink($ta_file); + return(FALSE); + } + chmod($ta_file, 0600); + return(TRUE); +} ?> Modified: branches/1.0/package/webinterface/altweb/common/openssl-openvpnclient.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/openssl-openvpnclient.php 2013-02-16 20:53:24 UTC (rev 5957) +++ branches/1.0/package/webinterface/altweb/common/openssl-openvpnclient.php 2013-02-18 00:08:17 UTC (rev 5958) @@ -23,6 +23,7 @@ $ssl['ca_crt'] = $ssl['key_dir'].'/ca.crt'; $ssl['client_crt'] = $ssl['key_dir'].'/client.crt'; $ssl['client_key'] = $ssl['key_dir'].'/client.key'; + $ssl['tls_auth_key'] = $ssl['key_dir'].'/ta.key'; if (! is_dir($ssl['base_dir'])) { if (! @mkdir($ssl['base_dir'], 0755)) { @@ -70,7 +71,7 @@ function opensslDELETEclientkeys($ssl) { if ($ssl !== FALSE) { - $types = array ('ca_crt', 'client_crt', 'client_key'); + $types = array ('ca_crt', 'client_crt', 'client_key', 'tls_auth_key'); foreach ($types as $type) { if (is_file($ssl[$type])) { @unlink($ssl[$type]); Modified: branches/1.0/package/webinterface/altweb/common/openssl.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/openssl.php 2013-02-16 20:53:24 UTC (rev 5957) +++ branches/1.0/package/webinterface/altweb/common/openssl.php 2013-02-18 00:08:17 UTC (rev 5958) @@ -251,12 +251,16 @@ $readme .= "$commonName.crt - This client's public key certificate, signed by ca.crt.\n\n"; $readme .= "$commonName.key - This client's private key.\n"; $readme .= "Note: File '$commonName.key' is not encrypted and must be kept secure.\n\n"; - if ($type === 'p12' || $type === 'ovpn') { + if ($type === 'p12' || $type === 'ovpn' || $type === 'ovpn-ta') { $readme .= "$commonName.p12 - A password protected PKCS#12 container combining the credentials from the above three files.\n\n"; $readme .= "PKCS#12 Container Password: $pass\n"; $readme .= "Keep it secure.\n\n"; - if ($type === 'ovpn') { + if ($type === 'ovpn' || $type === 'ovpn-ta') { $readme .= "$commonName.ovpn - OpenVPN certificate profile, use with file '$commonName.p12' for client devices.\n\n"; + if ($type === 'ovpn-ta') { + $readme .= "$commonName-ta.key - TLS-Auth key which adds an additional HMAC signature to all SSL/TLS handshake packets.\n"; + $readme .= "Note: File '$commonName-ta.key' is not encrypted and must be kept secure.\n\n"; + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <abe...@us...> - 2013-02-21 01:35:52
|
Revision: 5962 http://astlinux.svn.sourceforge.net/astlinux/?rev=5962&view=rev Author: abelbeck Date: 2013-02-21 01:35:45 +0000 (Thu, 21 Feb 2013) Log Message: ----------- web interface, create two flavors of OpenVPN certificate profiles, one with cert/key, the other without Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/openvpn.php branches/1.0/package/webinterface/altweb/common/openssl.php Modified: branches/1.0/package/webinterface/altweb/admin/openvpn.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/openvpn.php 2013-02-18 21:58:39 UTC (rev 5961) +++ branches/1.0/package/webinterface/altweb/admin/openvpn.php 2013-02-21 01:35:45 UTC (rev 5962) @@ -307,7 +307,7 @@ // Function: ovpnProfile // -function ovpnProfile($db, $ssl, &$ta_file) { +function ovpnProfile($db, $ssl, $client, &$ta_file) { $default = array ( 'client', @@ -362,6 +362,18 @@ $str .= $caStr; $str .= "</ca>\n"; } + if ($client !== '') { + if (($certStr = @file_get_contents($ssl['key_dir'].'/'.$client.'.crt')) !== FALSE) { + $str .= "<cert>\n"; + $str .= $certStr; + $str .= "</cert>\n"; + } + if (($keyStr = @file_get_contents($ssl['key_dir'].'/'.$client.'.key')) !== FALSE) { + $str .= "<key>\n"; + $str .= $keyStr; + $str .= "</key>\n"; + } + } if ($ta_file !== '') { if (($taStr = @file_get_contents($ta_file)) !== FALSE) { $str .= "<tls-auth>\n"; @@ -468,8 +480,13 @@ $p12pass = opensslRANDOMpass(12); if (($p12 = opensslPKCS12str($openssl, $value, $p12pass)) !== '') { $zip->addFromString($value.'/'.$value.'.p12', $p12); - if (($ovpn = ovpnProfile($db, $openssl, $tls_auth_file)) !== FALSE) { - $zip->addFromString($value.'/'.$value.'.ovpn', $ovpn); + if (($ovpn = ovpnProfile($db, $openssl, $value, $tls_auth_file)) !== FALSE) { + $zip->addFromString($value.'/openvpn-cert-key/'.$value.'.ovpn', $ovpn); + if (($ovpn = preg_filter('/<cert>.*<\/cert>/s', '', $ovpn)) !== NULL) { + if (($ovpn = preg_filter('/<key>.*<\/key>/s', '', $ovpn)) !== NULL) { + $zip->addFromString($value.'/openvpn-nocert-nokey/'.$value.'.ovpn', $ovpn); + } + } if ($tls_auth_file !== '') { $zip->addFile($tls_auth_file, $value.'/'.$value.'-ta.key'); $zip->addFromString($value.'/README.txt', opensslREADMEstr('ovpn-ta', $value, $p12pass)); Modified: branches/1.0/package/webinterface/altweb/common/openssl.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/openssl.php 2013-02-18 21:58:39 UTC (rev 5961) +++ branches/1.0/package/webinterface/altweb/common/openssl.php 2013-02-21 01:35:45 UTC (rev 5962) @@ -256,11 +256,16 @@ $readme .= "PKCS#12 Container Password: $pass\n"; $readme .= "Keep it secure.\n\n"; if ($type === 'ovpn' || $type === 'ovpn-ta') { - $readme .= "$commonName.ovpn - OpenVPN certificate profile, use with file '$commonName.p12' for client devices.\n\n"; if ($type === 'ovpn-ta') { $readme .= "$commonName-ta.key - TLS-Auth key which adds an additional HMAC signature to all SSL/TLS handshake packets.\n"; $readme .= "Note: File '$commonName-ta.key' is not encrypted and must be kept secure.\n\n"; } + $readme .= "Directory 'openvpn-cert-key':\n"; + $readme .= "$commonName.ovpn - OpenVPN certificate profile, contains client certificate and private key.\n"; + $readme .= "Note: File 'openvpn-cert-key/$commonName.ovpn' is not encrypted and must be kept secure.\n\n"; + + $readme .= "Directory 'openvpn-nocert-nokey':\n"; + $readme .= "$commonName.ovpn - OpenVPN certificate profile, use with file '$commonName.p12' for client devices.\n\n"; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <abe...@us...> - 2013-02-25 17:47:03
|
Revision: 5970 http://astlinux.svn.sourceforge.net/astlinux/?rev=5970&view=rev Author: abelbeck Date: 2013-02-25 17:46:56 +0000 (Mon, 25 Feb 2013) Log Message: ----------- web interface, OpenVPN Server - add 'openvpn-pkcs12' format for desktop clients where the added security of a password protected local private key is desired Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/openvpn.php branches/1.0/package/webinterface/altweb/common/openssl.php Modified: branches/1.0/package/webinterface/altweb/admin/openvpn.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/openvpn.php 2013-02-24 17:23:04 UTC (rev 5969) +++ branches/1.0/package/webinterface/altweb/admin/openvpn.php 2013-02-25 17:46:56 UTC (rev 5970) @@ -484,6 +484,11 @@ if (($ovpn = preg_filter('/<cert>.*<\/cert>/s', '', $ovpn)) !== NULL) { if (($ovpn = preg_filter('/<key>.*<\/key>/s', '', $ovpn)) !== NULL) { $zip->addFromString($value.'/openvpn-nocert-nokey/'.$value.'.ovpn', $ovpn); + if (($ovpn = preg_filter('/<ca>.*<\/ca>/s', '', $ovpn)) !== NULL) { + $ovpn .= "pkcs12 $value.p12\n"; + $zip->addFromString($value.'/openvpn-pkcs12/'.$value.'.ovpn', $ovpn); + $zip->addFromString($value.'/openvpn-pkcs12/'.$value.'.p12', $p12); + } } } if ($tls_auth_file !== '') { Modified: branches/1.0/package/webinterface/altweb/common/openssl.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/openssl.php 2013-02-24 17:23:04 UTC (rev 5969) +++ branches/1.0/package/webinterface/altweb/common/openssl.php 2013-02-25 17:46:56 UTC (rev 5970) @@ -260,12 +260,16 @@ $readme .= "$commonName-ta.key - TLS-Auth key which adds an additional HMAC signature to all SSL/TLS handshake packets.\n"; $readme .= "Note: File '$commonName-ta.key' is not encrypted and must be kept secure.\n\n"; } - $readme .= "Directory 'openvpn-cert-key':\n"; - $readme .= "$commonName.ovpn - OpenVPN certificate profile, contains client certificate and private key.\n"; + $readme .= "Folder: 'openvpn-cert-key'\n"; + $readme .= "$commonName.ovpn - OpenVPN CA-CERT-KEY profile, contains client certificate and private key.\n"; $readme .= "Note: File 'openvpn-cert-key/$commonName.ovpn' is not encrypted and must be kept secure.\n\n"; - $readme .= "Directory 'openvpn-nocert-nokey':\n"; - $readme .= "$commonName.ovpn - OpenVPN certificate profile, use with file '$commonName.p12' for client devices.\n\n"; + $readme .= "Folder: 'openvpn-nocert-nokey'\n"; + $readme .= "$commonName.ovpn - OpenVPN CA profile, use separately with the above '$commonName.p12' file for client devices.\n\n"; + + $readme .= "Folder: 'openvpn-pkcs12'\n"; + $readme .= "$commonName.ovpn - OpenVPN profile, use paired with the file '$commonName.p12'.\n"; + $readme .= "$commonName.p12 - A password protected PKCS#12 container, use paired with the file '$commonName.ovpn'.\n\n"; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <abe...@us...> - 2013-03-11 04:00:32
|
Revision: 5985 http://astlinux.svn.sourceforge.net/astlinux/?rev=5985&view=rev Author: abelbeck Date: 2013-03-11 04:00:21 +0000 (Mon, 11 Mar 2013) Log Message: ----------- web interface, add new SQL-Data tab to edit the '/mnt/kd/asterisk-odbc.sqlite3' database Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/prefs.php branches/1.0/package/webinterface/altweb/common/header.php branches/1.0/package/webinterface/altweb/common/license-packages.txt branches/1.0/package/webinterface/altweb/common/topics.info Added Paths: ----------- branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php branches/1.0/package/webinterface/altweb/admin/sqldata.php branches/1.0/package/webinterface/altweb/common/phpliteadmin.css branches/1.0/package/webinterface/altweb/common/sqldata.sql Added: branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php (rev 0) +++ branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php 2013-03-11 04:00:21 UTC (rev 5985) @@ -0,0 +1,4634 @@ +<?php + +// +// Project: phpLiteAdmin (http://phpliteadmin.googlecode.com) +// Version: 1.9.3.3 +// Summary: PHP-based admin tool to manage SQLite2 and SQLite3 databases on the web +// Last updated: 2013-01-14 +// Developers: +// Dane Iracleous (dan...@gm...) +// Ian Aldrighetti (ian...@gm...) +// George Flanagin & Digital Gaslight, Inc (ge...@di...) +// Christopher Kramer (cra...@gm...) +// +// +// Copyright (C) 2013 phpLiteAdmin +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// +/////////////////////////////////////////////////////////////////////////// + +//please report any bugs you encounter to http://code.google.com/p/phpliteadmin/issues/list + +//AstLinux// Restrict to 'admin' user. +function getPHPusername() +{ + if (isset($_SERVER['REMOTE_USER'])) { + $str_R = $_SERVER['REMOTE_USER']; + } else { + $str_R = ''; + } + return($str_R); +} +if (($global_user = getPHPusername()) !== 'admin') { + echo '<p style="color: red;">User "'.$global_user.'" does not have permission to access the "phpliteadmin" tab.</p>'; + exit; +} +//AstLinux// end of restrict to 'admin' user. + + +//BEGIN USER-DEFINED VARIABLES +////////////////////////////// + +//password to gain access +//AstLinux// Password ignored. +$password = "astlinux"; + +//directory relative to this file to search for databases (if false, manually list databases in the $databases variable) +$directory = false; + +//whether or not to scan the subdirectories of the above directory infinitely deep +$subdirectories = false; + +//if the above $directory variable is set to false, you must specify the databases manually in an array as the next variable +//if any of the databases do not exist as they are referenced by their path, they will be created automatically +$databases = array +( + array + ( + "path"=> "/mnt/kd/asterisk-odbc.sqlite3", + "name"=> "Asterisk" + ) +); + +//a list of custom functions that can be applied to columns in the databases +//make sure to define every function below if it is not a core PHP function +$custom_functions = array('md5', 'md5rev', 'sha1', 'sha1rev', 'time', 'mydate', 'strtotime', 'myreplace'); + +//define all the non-core custom functions +function md5rev($value) +{ + return strrev(md5($value)); +} +function sha1rev($value) +{ + return strrev(sha1($value)); +} +function mydate($value) +{ + return date("g:ia n/j/y", intval($value)); +} +function myreplace($value) +{ + return preg_replace("/[^A-Za-z0-9]/", "", strval($value)); +} + +//changing the following variable allows multiple phpLiteAdmin installs to work under the same domain. +//AstLinux// +$cookie_name = 'astlinux-db-2013'; + +//whether or not to put the app in debug mode where errors are outputted +$debug = false; + +// the user is allowed to create databases with only these extensions +$allowed_extensions = array('db','db3','sqlite','sqlite3'); + +//////////////////////////// +//END USER-DEFINED VARIABLES + + +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +//there is no reason for the average user to edit anything below this comment +//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +session_start(); //don't mess with this - required for the login session +//AstLinux// Use /etc/timezone for the timezone +//date_default_timezone_set(date_default_timezone_get()); //needed to fix STRICT warnings about timezone issues +function system_timezone() { + if (($tz = trim(@file_get_contents('/etc/timezone'))) === '') { + $tz = @date_default_timezone_get(); + } + return ($tz); +} +date_default_timezone_set(system_timezone()); +//AstLinux// end of timezone additions + +if($debug==true) +{ + ini_set("display_errors", 1); + error_reporting(E_STRICT | E_ALL); +} + +$startTimeTot = microtime(true); //start the timer to record page load time + +//the salt and password encrypting is probably unnecessary protection but is done just for the sake of being very secure +//create a random salt for this session if a cookie doesn't already exist for it +if(!isset($_SESSION[$cookie_name.'_salt']) && !isset($_COOKIE[$cookie_name.'_salt'])) +{ + $n = rand(10e16, 10e20); + $_SESSION[$cookie_name.'_salt'] = base_convert($n, 10, 36); +} +else if(!isset($_SESSION[$cookie_name.'_salt']) && isset($_COOKIE[$cookie_name.'_salt'])) //session doesn't exist, but cookie does so grab it +{ + $_SESSION[$cookie_name.'_salt'] = $_COOKIE[$cookie_name.'_salt']; +} + +//constants +define("PROJECT", "phpLiteAdmin"); +define("VERSION", "1.9.3.3"); +define("PAGE", basename(__FILE__)); +define("COOKIENAME", $cookie_name); +define("SYSTEMPASSWORD", $password); // Makes things easier. +define("SYSTEMPASSWORDENCRYPTED", md5($password."_".$_SESSION[$cookie_name.'_salt'])); //extra security - salted and encrypted password used for checking +//AstLinux// Force PDO +define("FORCETYPE", 'PDO'); //force the extension that will be used (set to false in almost all circumstances except debugging) + + +//data types array +$types = array("INTEGER", "REAL", "TEXT", "BLOB"); +define("DATATYPES", serialize($types)); + +//available SQLite functions array (don't add anything here or there will be problems) +$functions = array("abs", "hex", "length", "lower", "ltrim", "random", "round", "rtrim", "trim", "typeof", "upper"); +define("FUNCTIONS", serialize($functions)); +define("CUSTOM_FUNCTIONS", serialize($custom_functions)); + +//function that allows SQL delimiter to be ignored inside comments or strings +function explode_sql($delimiter, $sql) +{ + $ign = array('"' => '"', "'" => "'", "/*" => "*/", "--" => "\n"); // Ignore sequences. + $out = array(); + $last = 0; + $slen = strlen($sql); + $dlen = strlen($delimiter); + $i = 0; + while($i < $slen) + { + // Split on delimiter + if($slen - $i >= $dlen && substr($sql, $i, $dlen) == $delimiter) + { + array_push($out, substr($sql, $last, $i - $last)); + $last = $i + $dlen; + $i += $dlen; + continue; + } + // Eat comments and string literals + foreach($ign as $start => $end) + { + $ilen = strlen($start); + if($slen - $i >= $ilen && substr($sql, $i, $ilen) == $start) + { + $i+=strlen($start); + $elen = strlen($end); + while($i < $slen) + { + if($slen - $i >= $elen && substr($sql, $i, $elen) == $end) + { + // SQL comment characters can be escaped by doubling the character. This recognizes and skips those. + if($start == $end && $slen - $i >= $elen*2 && substr($sql, $i, $elen*2) == $end.$end) + { + $i += $elen * 2; + continue; + } + else + { + $i += $elen; + continue 3; + } + } + $i++; + } + continue 2; + } + } + $i++; + } + if($last < $slen) + array_push($out, substr($sql, $last, $slen - $last)); + return $out; +} + +//function to scan entire directory tree and subdirectories +function dir_tree($dir) +{ + $path = ''; + $stack[] = $dir; + while($stack) + { + $thisdir = array_pop($stack); + if($dircont = scandir($thisdir)) + { + $i=0; + while(isset($dircont[$i])) + { + if($dircont[$i] !== '.' && $dircont[$i] !== '..') + { + $current_file = $thisdir.DIRECTORY_SEPARATOR.$dircont[$i]; + if(is_file($current_file)) + { + $path[] = $thisdir.DIRECTORY_SEPARATOR.$dircont[$i]; + } + elseif (is_dir($current_file)) + { + $path[] = $thisdir.DIRECTORY_SEPARATOR.$dircont[$i]; + $stack[] = $current_file; + } + } + $i++; + } + } + } + return $path; +} + +//the function echo the help [?] links to the documentation +function helpLink($name) +{ + return "<a href='javascript:void' onclick='openHelp(\"".$name."\");' class='helpq' title='Help: ".$name."'>[?]</a>"; +} + +// function to encode value into HTML just like htmlentities, but with adjusted default settings +function htmlencode($value, $flags=ENT_QUOTES, $encoding ="UTF-8") +{ + return htmlentities($value, $flags, $encoding); +} + +// 22 August 2011: gkf added this function to support display of +// default values in the form used to INSERT new data. +function deQuoteSQL($s) +{ + return trim(trim($s), "'"); +} + +// checks the (new) name of a database file +function checkDbName($name) +{ + global $allowed_extensions; + $info = pathinfo($name); + if(isset($info['extension']) && !in_array($info['extension'], $allowed_extensions)) + { + return false; + } else + { + return (!is_file($name) && !is_dir($name)); + } + +} + +// check whether a path is a db managed by this tool +// requires that $databases is already filled! +// returns the key of the db if managed, false otherwise. +function isManagedDB($path) +{ + global $databases; + foreach($databases as $db_key => $database) + { + if($path == $database['path']) + { + // a db we manage. Thats okay. + // return the key. + return $db_key; + } + } + // not a db we manage! + return false; +} + +// +// Authorization class +// Maintains user's logged-in state and security of application +// +class Authorization +{ + public function grant($remember) + { + if($remember) //user wants to be remembered, so set a cookie + { + $expire = time()+60*60*24*30; //set expiration to 1 month from now + setcookie(COOKIENAME, SYSTEMPASSWORD, $expire); + setcookie(COOKIENAME."_salt", $_SESSION[COOKIENAME.'_salt'], $expire); + } + else + { + //user does not want to be remembered, so destroy any potential cookies + setcookie(COOKIENAME, "", time()-86400); + setcookie(COOKIENAME."_salt", "", time()-86400); + unset($_COOKIE[COOKIENAME]); + unset($_COOKIE[COOKIENAME.'_salt']); + } + + $_SESSION[COOKIENAME.'password'] = SYSTEMPASSWORDENCRYPTED; + } + public function revoke() + { + //destroy everything - cookies and session vars + setcookie(COOKIENAME, "", time()-86400); + setcookie(COOKIENAME."_salt", "", time()-86400); + unset($_COOKIE[COOKIENAME]); + unset($_COOKIE[COOKIENAME.'_salt']); + session_unset(); + session_destroy(); + } + public function isAuthorized() + { + // Is this just session long? (What!?? -DI) + if((isset($_SESSION[COOKIENAME.'password']) && $_SESSION[COOKIENAME.'password'] == SYSTEMPASSWORDENCRYPTED) || (isset($_COOKIE[COOKIENAME]) && isset($_COOKIE[COOKIENAME.'_salt']) && md5($_COOKIE[COOKIENAME]."_".$_COOKIE[COOKIENAME.'_salt']) == SYSTEMPASSWORDENCRYPTED)) + return true; + else + { + return false; + } + } +} + +// +// Database class +// Generic database abstraction class to manage interaction with database without worrying about SQLite vs. PHP versions +// +class Database +{ + protected $db; //reference to the DB object + protected $type; //the extension for PHP that handles SQLite + protected $data; + protected $lastResult; + protected $fns; + + public function __construct($data) + { + $this->data = $data; + $this->fns = array(); + try + { + if(!file_exists($this->data["path"]) && !is_writable(dirname($this->data["path"]))) //make sure the containing directory is writable if the database does not exist + { + echo "<div class='confirm' style='margin:20px;'>"; + echo "The database, '".htmlencode($this->data["path"])."', does not exist and cannot be created because the containing directory, '".htmlencode(dirname($this->data["path"]))."', is not writable. The application is unusable until you make it writable."; + //AstLinux// + //echo "<form action='".PAGE."' method='post'>"; + //echo "<input type='submit' value='Log Out' name='logout' class='btn'/>"; + //echo "</form>"; + echo "</div><br/>"; + exit(); + } + + $ver = $this->getVersion(); + + switch(true) + { + case (FORCETYPE=="PDO" || ((FORCETYPE==false || $ver!=-1) && class_exists("PDO") && ($ver==-1 || $ver==3))): + $this->db = new PDO("sqlite:".$this->data['path']); + if($this->db!=NULL) + { + $this->type = "PDO"; + $cfns = unserialize(CUSTOM_FUNCTIONS); + for($i=0; $i<sizeof($cfns); $i++) + { + $this->db->sqliteCreateFunction($cfns[$i], $cfns[$i], 1); + $this->addUserFunction($cfns[$i]); + } + break; + } + case (FORCETYPE=="SQLite3" || ((FORCETYPE==false || $ver!=-1) && class_exists("SQLite3") && ($ver==-1 || $ver==3))): + $this->db = new SQLite3($this->data['path']); + if($this->db!=NULL) + { + $cfns = unserialize(CUSTOM_FUNCTIONS); + for($i=0; $i<sizeof($cfns); $i++) + { + $this->db->createFunction($cfns[$i], $cfns[$i], 1); + $this->addUserFunction($cfns[$i]); + } + $this->type = "SQLite3"; + break; + } + case (FORCETYPE=="SQLiteDatabase" || ((FORCETYPE==false || $ver!=-1) && class_exists("SQLiteDatabase") && ($ver==-1 || $ver==2))): + $this->db = new SQLiteDatabase($this->data['path']); + if($this->db!=NULL) + { + $cfns = unserialize(CUSTOM_FUNCTIONS); + for($i=0; $i<sizeof($cfns); $i++) + { + $this->db->createFunction($cfns[$i], $cfns[$i], 1); + $this->addUserFunction($cfns[$i]); + } + $this->type = "SQLiteDatabase"; + break; + } + default: + $this->showError(); + exit(); + } + } + catch(Exception $e) + { + $this->showError(); + exit(); + } + } + + public function getUserFunctions() + { + return $this->fns; + } + + public function addUserFunction($name) + { + array_push($this->fns, $name); + } + + public function getError() + { + if($this->type=="PDO") + { + $e = $this->db->errorInfo(); + return $e[2]; + } + else if($this->type=="SQLite3") + { + return $this->db->lastErrorMsg(); + } + else + { + return sqlite_error_string($this->db->lastError()); + } + } + + public function showError() + { + $classPDO = class_exists("PDO"); + $classSQLite3 = class_exists("SQLite3"); + $classSQLiteDatabase = class_exists("SQLiteDatabase"); + if($classPDO) + $strPDO = "installed"; + else + $strPDO = "not installed"; + if($classSQLite3) + $strSQLite3 = "installed"; + else + $strSQLite3 = "not installed"; + if($classSQLiteDatabase) + $strSQLiteDatabase = "installed"; + else + $strSQLiteDatabase = "not installed"; + echo "<div class='confirm' style='margin:20px;'>"; + echo "There was a problem setting up your database, ".$this->getPath().". An attempt will be made to find out what's going on so you can fix the problem more easily.<br/><br/>"; + echo "<i>Checking supported SQLite PHP extensions...<br/><br/>"; + echo "<b>PDO</b>: ".$strPDO."<br/>"; + echo "<b>SQLite3</b>: ".$strSQLite3."<br/>"; + echo "<b>SQLiteDatabase</b>: ".$strSQLiteDatabase."<br/><br/>...done.</i><br/><br/>"; + if(!$classPDO && !$classSQLite3 && !$classSQLiteDatabase) + echo "It appears that none of the supported SQLite library extensions are available in your installation of PHP. You may not use ".PROJECT." until you install at least one of them."; + else + { + if(!$classPDO && !$classSQLite3 && $this->getVersion()==3) + echo "It appears that your database is of SQLite version 3 but your installation of PHP does not contain the necessary extensions to handle this version. To fix the problem, either delete the database and allow ".PROJECT." to create it automatically or recreate it manually as SQLite version 2."; + else if(!$classSQLiteDatabase && $this->getVersion()==2) + echo "It appears that your database is of SQLite version 2 but your installation of PHP does not contain the necessary extensions to handle this version. To fix the problem, either delete the database and allow ".PROJECT." to create it automatically or recreate it manually as SQLite version 3."; + else + echo "The problem cannot be diagnosed properly. Please file an issue report at http://phpliteadmin.googlecode.com."; + } + echo "</div><br/>"; + } + + public function __destruct() + { + if($this->db) + $this->close(); + } + + //get the exact PHP extension being used for SQLite + public function getType() + { + return $this->type; + } + + //get the name of the database + public function getName() + { + return $this->data["name"]; + } + + //get the filename of the database + public function getPath() + { + return $this->data["path"]; + } + + //get the version of the database + public function getVersion() + { + if(file_exists($this->data['path'])) //make sure file exists before getting its contents + { + $content = strtolower(file_get_contents($this->data['path'], NULL, NULL, 0, 40)); //get the first 40 characters of the database file + $p = strpos($content, "** this file contains an sqlite 2"); //this text is at the beginning of every SQLite2 database + if($p!==false) //the text is found - this is version 2 + return 2; + else + return 3; + } + else //return -1 to indicate that it does not exist and needs to be created + { + return -1; + } + } + + //get the size of the database + public function getSize() + { + return round(filesize($this->data["path"])*0.0009765625, 1)." KB"; + } + + //get the last modified time of database + public function getDate() + { + return date("g:ia \o\\n F j, Y", filemtime($this->data["path"])); + } + + //get number of affected rows from last query + public function getAffectedRows() + { + if($this->type=="PDO") + return $this->lastResult->rowCount(); + else if($this->type=="SQLite3") + return $this->db->changes(); + else if($this->type=="SQLiteDatabase") + return $this->db->changes(); + } + + public function close() + { + if($this->type=="PDO") + $this->db = NULL; + else if($this->type=="SQLite3") + $this->db->close(); + else if($this->type=="SQLiteDatabase") + $this->db = NULL; + } + + public function beginTransaction() + { + $this->query("BEGIN"); + } + + public function commitTransaction() + { + $this->query("COMMIT"); + } + + public function rollbackTransaction() + { + $this->query("ROLLBACK"); + } + + //generic query wrapper + public function query($query, $ignoreAlterCase=false) + { + global $debug; + if(strtolower(substr(ltrim($query),0,5))=='alter' && $ignoreAlterCase==false) //this query is an ALTER query - call the necessary function + { + preg_match("/^\s*ALTER\s+TABLE\s+\"((?:[^\"]|\"\")+)\"\s+(.*)$/i",$query,$matches); + if(!isset($matches[1]) || !isset($matches[2])) + { + if($debug) echo "<span title='".htmlencode($query)."' onclick='this.innerHTML=\"".htmlencode(str_replace('"','\"',$query))."\"' style='cursor:pointer'>SQL?</span><br />"; + return false; + } + $tablename = str_replace('""','"',$matches[1]); + $alterdefs = $matches[2]; + if($debug) echo "ALTER TABLE QUERY=(".htmlencode($query)."), tablename=($tablename), alterdefs=($alterdefs)<hr>"; + $result = $this->alterTable($tablename, $alterdefs); + } + else //this query is normal - proceed as normal + { + $result = $this->db->query($query); + if($debug) echo "<span title='".htmlencode($query)."' onclick='this.innerHTML=\"".htmlencode(str_replace('"','\"',$query))."\"' style='cursor:pointer'>SQL?</span><br />"; + } + if(!$result) + return false; + $this->lastResult = $result; + return $result; + } + + //wrapper for an INSERT and returns the ID of the inserted row + public function insert($query) + { + $result = $this->query($query); + if($this->type=="PDO") + return $this->db->lastInsertId(); + else if($this->type=="SQLite3") + return $this->db->lastInsertRowID(); + else if($this->type=="SQLiteDatabase") + return $this->db->lastInsertRowid(); + } + + //returns an array for SELECT + public function select($query, $mode="both") + { + $result = $this->query($query); + if(!$result) //make sure the result is valid + return NULL; + if($this->type=="PDO") + { + if($mode=="assoc") + $mode = PDO::FETCH_ASSOC; + else if($mode=="num") + $mode = PDO::FETCH_NUM; + else + $mode = PDO::FETCH_BOTH; + return $result->fetch($mode); + } + else if($this->type=="SQLite3") + { + if($mode=="assoc") + $mode = SQLITE3_ASSOC; + else if($mode=="num") + $mode = SQLITE3_NUM; + else + $mode = SQLITE3_BOTH; + return $result->fetchArray($mode); + } + else if($this->type=="SQLiteDatabase") + { + if($mode=="assoc") + $mode = SQLITE_ASSOC; + else if($mode=="num") + $mode = SQLITE_NUM; + else + $mode = SQLITE_BOTH; + return $result->fetch($mode); + } + } + + //returns an array of arrays after doing a SELECT + public function selectArray($query, $mode="both") + { + $result = $this->query($query); + if(!$result) //make sure the result is valid + return NULL; + if($this->type=="PDO") + { + if($mode=="assoc") + $mode = PDO::FETCH_ASSOC; + else if($mode=="num") + $mode = PDO::FETCH_NUM; + else + $mode = PDO::FETCH_BOTH; + return $result->fetchAll($mode); + } + else if($this->type=="SQLite3") + { + if($mode=="assoc") + $mode = SQLITE3_ASSOC; + else if($mode=="num") + $mode = SQLITE3_NUM; + else + $mode = SQLITE3_BOTH; + $arr = array(); + $i = 0; + while($res = $result->fetchArray($mode)) + { + $arr[$i] = $res; + $i++; + } + return $arr; + } + else if($this->type=="SQLiteDatabase") + { + if($mode=="assoc") + $mode = SQLITE_ASSOC; + else if($mode=="num") + $mode = SQLITE_NUM; + else + $mode = SQLITE_BOTH; + return $result->fetchAll($mode); + } + } + + + // SQlite supports multiple ways of surrounding names in quotes: + // single-quotes, double-quotes, backticks, square brackets. + // As sqlite does not keep this strict, we also need to be flexible here. + // This function generates a regex that matches any of the possibilities. + private function sqlite_surroundings_preg($name,$preg_quote=true,$notAllowedIfNone="'\"") + { + if($name=="*" || $name=="+") + { + $nameSingle = "(?:[^']|'')".$name; + $nameDouble = "(?:[^\"]|\"\")".$name; + $nameBacktick = "(?:[^`]|``)".$name; + $nameSquare = "(?:[^\]]|\]\])".$name; + $nameNo = "[^".$notAllowedIfNone."]".$name; + } + else + { + if($preg_quote) $name = preg_quote($name,"/"); + + $nameSingle = str_replace("'","''",$name); + $nameDouble = str_replace('"','""',$name); + $nameBacktick = str_replace('`','``',$name); + $nameSquare = str_replace(']',']]',$name); + $nameNo = $name; + } + + $preg = "(?:'".$nameSingle."'|". // single-quote surrounded or not in quotes (correct SQL for values/new names) + $nameNo."|". // not surrounded (correct SQL if not containing reserved words, spaces or some special chars) + "\"".$nameDouble."\"|". // double-quote surrounded (correct SQL for identifiers) + "`".$nameBacktick."`|". // backtick surrounded (MySQL-Style) + "\[".$nameSquare."\])"; // square-bracket surrounded (MS Access/SQL server-Style) + return $preg; + } + + // function that is called for an alter table statement in a query + // code borrowed with permission from http://code.jenseng.com/db/ + // this has been completely debugged / rewritten by Christopher Kramer + public function alterTable($table, $alterdefs) + { + global $debug; + if($debug) echo "ALTER TABLE: table=($table), alterdefs=($alterdefs)<hr>"; + if($alterdefs != '') + { + $recreateQueries = array(); + $tempQuery = "SELECT sql,name,type FROM sqlite_master WHERE tbl_name = ".$this->quote($table)." ORDER BY type DESC"; + $result = $this->query($tempQuery); + $resultArr = $this->selectArray($tempQuery); + if($this->type=="PDO") + $result->closeCursor(); + if(sizeof($resultArr)<1) + return false; + for($i=0; $i<sizeof($resultArr); $i++) + { + $row = $resultArr[$i]; + if($row['type'] != 'table') + { + // store the CREATE statements of triggers and indexes to recreate them later + $recreateQueries[] = $row['sql']."; "; + if($debug) echo "recreate=(".$row['sql'].";)<hr />"; + } + else + { + // ALTER the table + $tmpname = 't'.time(); + $origsql = $row['sql']; + $createtemptableSQL = "CREATE TEMPORARY TABLE ".$this->quote($tmpname)." ". + preg_replace("/^\s*CREATE\s+TABLE\s+".$this->sqlite_surroundings_preg($table)."\s*(\(.*)$/i", '$1', $origsql, 1); + if($debug) echo "createtemptableSQL=($createtemptableSQL)<hr>"; + $createindexsql = array(); + preg_match_all("/(?:DROP|ADD|CHANGE|RENAME TO)\s+(?:\"(?:[^\"]|\"\")+\"|'(?:[^']|'')+')((?:[^,')]|'[^']*')+)?/i",$alterdefs,$matches); + $defs = $matches[0]; + + $get_oldcols_query = "PRAGMA table_info(".$this->quote_id($table).")"; + $result_oldcols = $this->selectArray($get_oldcols_query); + $newcols = array(); + $coltypes = array(); + foreach($result_oldcols as $column_info) + { + $newcols[$column_info['name']] = $column_info['name']; + $coltypes[$column_info['name']] = $column_info['type']; + } + $newcolumns = ''; + $oldcolumns = ''; + reset($newcols); + while(list($key, $val) = each($newcols)) + { + $newcolumns .= ($newcolumns?', ':'').$this->quote_id($val); + $oldcolumns .= ($oldcolumns?', ':'').$this->quote_id($key); + } + $copytotempsql = 'INSERT INTO '.$this->quote_id($tmpname).'('.$newcolumns.') SELECT '.$oldcolumns.' FROM '.$this->quote_id($table); + $dropoldsql = 'DROP TABLE '.$this->quote_id($table); + $createtesttableSQL = $createtemptableSQL; + if(count($defs)<1) + { + if($debug) echo "ERROR: defs<1<hr />"; + return false; + } + foreach($defs as $def) + { + if($debug) echo "def=$def<hr />"; + $parse_def = preg_match("/^(DROP|ADD|CHANGE|RENAME TO)\s+(?:\"((?:[^\"]|\"\")+)\"|'((?:[^']|'')+)')((?:\s+'((?:[^']|'')+)')?\s+(TEXT|INTEGER|BLOB|REAL).*)?\s*$/i",$def,$matches); + if($parse_def===false) + { + if($debug) echo "ERROR: !parse_def<hr />"; + return false; + } + if(!isset($matches[1])) + { + if($debug) echo "ERROR: !isset(matches[1])<hr />"; + return false; + } + $action = strtolower($matches[1]); + if($action == 'add' || $action == 'rename to') + $column = str_replace("''","'",$matches[3]); // enclosed in '' + else + $column = str_replace('""','"',$matches[2]); // enclosed in "" + + $column_escaped = str_replace("'","''",$column); + + if($debug) echo "action=($action), column=($column), column_escaped=($column_escaped)<hr />"; + + /* we build a regex that devides the CREATE TABLE statement parts: + Part example Group Explanation + 1. CREATE TABLE t... ( $1 + 2. 'col1' ..., 'col2' ..., 'colN' ..., $3 (with col1-colN being columns that are not changed and listed before the col to change) + 3. 'colX' ..., - (with colX being the column to change/drop) + 4. 'colX+1' ..., ..., 'colK') $5 (with colX+1-colK being columns after the column to change/drop) + */ + $preg_create_table = "\s*(CREATE\s+TEMPORARY\s+TABLE\s+'?".preg_quote($tmpname,"/")."'?\s*\()"; // This is group $1 (keep unchanged) + $preg_column_definiton = "\s*".$this->sqlite_surroundings_preg("+",false," '\"\[`")."(?:\s+".$this->sqlite_surroundings_preg("*",false,"'\",`\[) ").")+"; // catches a complete column definition, even if it is + // 'column' TEXT NOT NULL DEFAULT 'we have a comma, here and a double ''quote!' + if($debug) echo "preg_column_definition=(".$preg_column_definiton.")<hr />"; + $preg_columns_before = // columns before the one changed/dropped (keep) + "(?:". + "(". // group $2. Keep this one unchanged! + "(?:". + "$preg_column_definiton,\s*". // column definition + comma + ")*". // there might be any number of such columns here + $preg_column_definiton. // last column definition + ")". // end of group $2 + ",\s*" // the last comma of the last column before the column to change. Do not keep it! + .")?"; // there might be no columns before + if($debug) echo "preg_columns_before=(".$preg_columns_before.")<hr />"; + $preg_columns_after = "(,\s*([^)]+))?"; // the columns after the column to drop. This is group $3 (drop) or $4(change) (keep!) + // we could remove the comma using $6 instead of $5, but then we might have no comma at all. + // Keeping it leaves a problem if we drop the first column, so we fix that case in another regex. + $table_new = $table; + + switch($action) + { + case 'add': + if(!isset($matches[4])) + { + return false; + } + $new_col_definition = "'$column_escaped' ".$matches[4]; + $preg_pattern_add = "/^".$preg_create_table."(.*)\\)\s*$/"; + // append the column definiton in the CREATE TABLE statement + $newSQL = preg_replace($preg_pattern_add, '$1$2, ', $createtesttableSQL).$new_col_definition.')'; + if($debug) + { + echo $createtesttableSQL."<hr>"; + echo $newSQL."<hr>"; + echo $preg_pattern_add."<hr>"; + } + if($newSQL==$createtesttableSQL) // pattern did not match, so column removal did not succed + return false; + $createtesttableSQL = $newSQL; + break; + case 'change': + if(!isset($matches[5]) || !isset($matches[6])) + { + return false; + } + $new_col_name = $matches[5]; + $new_col_type = $matches[6]; + $new_col_definition = "'$new_col_name' $new_col_type"; + $preg_column_to_change = "\s*".$this->sqlite_surroundings_preg($column)."(?:\s+".preg_quote($coltypes[$column]).")?(\s+(?:".$this->sqlite_surroundings_preg("*",false,",'\")`\[").")+)?"; + // replace this part (we want to change this column) + // group $3 contains the column constraints (keep!). the name & data type is replaced. + $preg_pattern_change = "/^".$preg_create_table.$preg_columns_before.$preg_column_to_change.$preg_columns_after."\s*\\)\s*$/"; + + // replace the column definiton in the CREATE TABLE statement + $newSQL = preg_replace($preg_pattern_change, '$1$2,'.strtr($new_col_definition, array('\\' => '\\\\', '$' => '\$')).'$3$4)', $createtesttableSQL); + // remove comma at the beginning if the first column is changed + // probably somebody is able to put this into the first regex (using lookahead probably). + $newSQL = preg_replace("/^\s*(CREATE\s+TEMPORARY\s+TABLE\s+'".preg_quote($tmpname,"/")."'\s+\(),\s*/",'$1',$newSQL); + if($debug) + { + echo "preg_column_to_change=(".$preg_column_to_change.")<hr />"; + echo $createtesttableSQL."<hr />"; + echo $newSQL."<hr />"; + echo $preg_pattern_change."<hr />"; + + } + if($newSQL==$createtesttableSQL || $newSQL=="") // pattern did not match, so column removal did not succed + return false; + $createtesttableSQL = $newSQL; + $newcols[$column] = str_replace("''","'",$new_col_name); + break; + case 'drop': + $preg_column_to_drop = "\s*".$this->sqlite_surroundings_preg($column)."\s+(?:".$this->sqlite_surroundings_preg("*",false,",')\"\[`").")+"; // delete this part (we want to drop this column) + $preg_pattern_drop = "/^".$preg_create_table.$preg_columns_before.$preg_column_to_drop.$preg_columns_after."\s*\\)\s*$/"; + + // remove the column out of the CREATE TABLE statement + $newSQL = preg_replace($preg_pattern_drop, '$1$2$3)', $createtesttableSQL); + // remove comma at the beginning if the first column is removed + // probably somebody is able to put this into the first regex (using lookahead probably). + $newSQL = preg_replace("/^\s*(CREATE\s+TEMPORARY\s+TABLE\s+'".preg_quote($tmpname,"/")."'\s+\(),\s*/",'$1',$newSQL); + if($debug) + { + echo $createtesttableSQL."<hr>"; + echo $newSQL."<hr>"; + echo $preg_pattern_drop."<hr>"; + } + if($newSQL==$createtesttableSQL || $newSQL=="") // pattern did not match, so column removal did not succed + return false; + $createtesttableSQL = $newSQL; + unset($newcols[$column]); + break; + case 'rename to': + // don't change column definition at all + $newSQL = $createtesttableSQL; + // only change the name of the table + $table_new = $column; + break; + default: + if($default) echo 'ERROR: unknown alter operation!<hr />'; + return false; + } + } + $droptempsql = 'DROP TABLE '.$this->quote_id($tmpname); + + $createnewtableSQL = "CREATE TABLE ".$this->quote($table_new)." ".preg_replace("/^\s*CREATE\s+TEMPORARY\s+TABLE\s+'?".str_replace("'","''",preg_quote($tmpname,"/"))."'?\s+(.*)$/i", '$1', $createtesttableSQL, 1); + + $newcolumns = ''; + $oldcolumns = ''; + reset($newcols); + while(list($key,$val) = each($newcols)) + { + $newcolumns .= ($newcolumns?', ':'').$this->quote_id($val); + $oldcolumns .= ($oldcolumns?', ':'').$this->quote_id($key); + } + $copytonewsql = 'INSERT INTO '.$this->quote_id($table_new).'('.$newcolumns.') SELECT '.$oldcolumns.' FROM '.$this->quote_id($tmpname); + } + } + $alter_transaction = 'BEGIN; '; + $alter_transaction .= $createtemptableSQL.'; '; //create temp table + $alter_transaction .= $copytotempsql.'; '; //copy to table + $alter_transaction .= $dropoldsql.'; '; //drop old table + $alter_transaction .= $createnewtableSQL.'; '; //recreate original table + $alter_transaction .= $copytonewsql.'; '; //copy back to original table + $alter_transaction .= $droptempsql.'; '; //drop temp table + + $preg_index="/^\s*(CREATE\s+(?:UNIQUE\s+)?INDEX\s+(?:".$this->sqlite_surroundings_preg("+",false," '\"\[`")."\s*)*ON\s+)(".$this->sqlite_surroundings_preg($table).")(\s*\((?:".$this->sqlite_surroundings_preg("+",false," '\"\[`")."\s*)*\)\s*;)\s*$/i"; + for($i=0; $i<sizeof($recreateQueries); $i++) + { + // recreate triggers / indexes + if($table == $table_new) + { + // we had no RENAME TO, so we can recreate indexes/triggers just like the original ones + $alter_transaction .= $recreateQueries[$i]; + } else + { + // we had a RENAME TO, so we need to exchange the table-name in the CREATE-SQL of triggers & indexes + // first let's try if it's an index... + $recreate_queryIndex = preg_replace($preg_index, '$1'.$this->quote_id(strtr($table_new, array('\\' => '\\\\', '$' => '\$'))).'$3 ', $recreateQueries[$i]); + if($recreate_queryIndex!=$recreateQueries[$i] && $recreate_queryIndex != NULL) + { + // the CREATE INDEX regex did match + $alter_transaction .= $recreate_queryIndex; + } else + { + // the CREATE INDEX regex did not match, so we try if it's a CREATE TRIGGER + + $recreate_queryTrigger = $recreateQueries[$i]; + // TODO: IMPLEMENT + + $alter_transaction .= $recreate_queryTrigger; + } + } + } + $alter_transaction .= 'COMMIT;'; + if($debug) echo $alter_transaction; + return $this->multiQuery($alter_transaction); + } + } + + //multiple query execution + public function multiQuery($query) + { + $error = "Unknown error."; + if($this->type=="PDO") + { + $success = $this->db->exec($query); + if(!$success) $error = implode(" - ", $this->db->errorInfo()); + } + else if($this->type=="SQLite3") + { + $success = $this->db->exec($query); + if(!$success) $error = $this->db->lastErrorMsg(); + } + else + { + $success = $this->db->queryExec($query, $error); + } + if(!$success) + { + return "Error in query: '".htmlencode($error)."'"; + } + else + { + return true; + } + } + + //get number of rows in table + public function numRows($table) + { + $result = $this->select("SELECT Count(*) FROM ".$this->quote_id($table)); + return $result[0]; + } + + //correctly escape a string to be injected into an SQL query + public function quote($value) + { + if($this->type=="PDO") + { + // PDO quote() escapes and adds quotes + return $this->db->quote($value); + } + else if($this->type=="SQLite3") + { + return "'".$this->db->escapeString($value)."'"; + } + else + { + return "'".sqlite_escape_string($value)."'"; + } + } + + //correctly escape an identifier (column / table / trigger / index name) to be injected into an SQL query + public function quote_id($value) + { + // double-quotes need to be escaped by doubling them + $value = str_replace('"','""',$value); + return '"'.$value.'"'; + } + + + //import sql + public function import_sql($query) + { + return $this->multiQuery($query); + } + + //import csv + public function import_csv($filename, $table, $field_terminate, $field_enclosed, $field_escaped, $null, $fields_in_first_row) + { + // CSV import implemented by Christopher Kramer - http://www.christosoft.de + $csv_handle = fopen($filename,'r'); + $csv_insert = "BEGIN;\n"; + $csv_number_of_rows = 0; + // PHP requires enclosure defined, but has no problem if it was not used + if($field_enclosed=="") $field_enclosed='"'; + // PHP requires escaper defined + if($field_escaped=="") $field_escaped='\\'; + while(!feof($csv_handle)) + { + $csv_data = fgetcsv($csv_handle, 0, $field_terminate, $field_enclosed, $field_escaped); + if($csv_data[0] != NULL || count($csv_data)>1) + { + $csv_number_of_rows++; + if($fields_in_first_row && $csv_number_of_rows==1) continue; + $csv_col_number = count($csv_data); + $csv_insert .= "INSERT INTO ".$this->quote_id($table)." VALUES ("; + foreach($csv_data as $csv_col => $csv_cell) + { + if($csv_cell == $null) $csv_insert .= "NULL"; + else + { + $csv_insert.= $this->quote($csv_cell); + } + if($csv_col == $csv_col_number-2 && $csv_data[$csv_col+1]=='') + { + // the CSV row ends with the separator (like old phpliteadmin exported) + break; + } + if($csv_col < $csv_col_number-1) $csv_insert .= ","; + } + $csv_insert .= ");\n"; + + if($csv_number_of_rows > 5000) + { + $csv_insert .= "COMMIT;\nBEGIN;\n"; + $csv_number_of_rows = 0; + } + } + } + $csv_insert .= "COMMIT;"; + fclose($csv_handle); + return $this->multiQuery($csv_insert); + + } + + //export csv + public function export_csv($tables, $field_terminate, $field_enclosed, $field_escaped, $null, $crlf, $fields_in_first_row) + { + $field_enclosed = stripslashes($field_enclosed); + $query = "SELECT * FROM sqlite_master WHERE type='table' or type='view' ORDER BY type DESC"; + $result = $this->selectArray($query); + for($i=0; $i<sizeof($result); $i++) + { + $valid = false; + for($j=0; $j<sizeof($tables); $j++) + { + if($result[$i]['tbl_name']==$tables[$j]) + $valid = true; + } + if($valid) + { + $query = "PRAGMA table_info(".$this->quote_id($result[$i]['tbl_name']).")"; + $temp = $this->selectArray($query); + $cols = array(); + for($z=0; $z<sizeof($temp); $z++) + $cols[$z] = $temp[$z][1]; + if($fields_in_first_row) + { + for($z=0; $z<sizeof($cols); $z++) + { + echo $field_enclosed.$cols[$z].$field_enclosed; + // do not terminate the last column! + if($z < sizeof($cols)-1) + echo $field_terminate; + } + echo "\r\n"; + } + $query = "SELECT * FROM ".$this->quote_id($result[$i]['tbl_name']); + $arr = $this->selectArray($query, "assoc"); + for($z=0; $z<sizeof($arr); $z++) + { + for($y=0; $y<sizeof($cols); $y++) + { + $cell = $arr[$z][$cols[$y]]; + if($crlf) + { + $cell = str_replace("\n","", $cell); + $cell = str_replace("\r","", $cell); + } + $cell = str_replace($field_terminate,$field_escaped.$field_terminate,$cell); + $cell = str_replace($field_enclosed,$field_escaped.$field_enclosed,$cell); + // do not enclose NULLs + if($cell == NULL) + echo $null; + else + echo $field_enclosed.$cell.$field_enclosed; + // do not terminate the last column! + if($y < sizeof($cols)-1) + echo $field_terminate; + } + if($z<sizeof($arr)-1) + echo "\r\n"; + } + if($i<sizeof($result)-1) + echo "\r\n"; + } + } + } + + //export sql + public function export_sql($tables, $drop, $structure, $data, $transaction, $comments) + { + if($comments) + { + echo "----\r\n"; + echo "-- phpLiteAdmin database dump (http://phpliteadmin.googlecode.com)\r\n"; + echo "-- phpLiteAdmin version: ".VERSION."\r\n"; + echo "-- Exported on ".date('M jS, Y, h:i:sA')."\r\n"; + echo "-- Database file: ".$this->getPath()."\r\n"; + echo "----\r\n"; + } + $query = "SELECT * FROM sqlite_master WHERE type='table' OR type='index' OR type='view' OR type='trigger' ORDER BY type='trigger', type='index', type='view', type='table'"; + $result = $this->selectArray($query); + + if($transaction) + echo "BEGIN TRANSACTION;\r\n"; + + //iterate through each table + for($i=0; $i<sizeof($result); $i++) + { + $valid = false; + for($j=0; $j<sizeof($tables); $j++) + { + if($result[$i]['tbl_name']==$tables[$j]) + $valid = true; + } + if($valid) + { + if($drop) + { + if($comments) + { + echo "\r\n----\r\n"; + echo "-- Drop ".$result[$i]['type']." for ".$result[$i]['name']."\r\n"; + echo "----\r\n"; + } + echo "DROP ".strtoupper($result[$i]['type'])." ".$this->quote_id($result[$i]['name']).";\r\n"; + } + if($structure) + { + if($comments) + { + echo "\r\n----\r\n"; + if($result[$i]['type']=="table" || $result[$i]['type']=="view") + echo "-- ".ucfirst($result[$i]['type'])." structure for ".$result[$i]['tbl_name']."\r\n"; + else // index or trigger + echo "-- Structure for ".$result[$i]['type']." ".$result[$i]['name']." on table ".$result[$i]['tbl_name']."\r\n"; + echo "----\r\n"; + } + echo $result[$i]['sql'].";\r\n"; + } + if($data && $result[$i]['type']=="table") + { + $query = "SELECT * FROM ".$this->quote_id($result[$i]['tbl_name']); + $arr = $this->selectArray($query, "assoc"); + + if($comments) + { + echo "\r\n----\r\n"; + echo "-- Data dump for ".$result[$i]['tbl_name'].", a total of ".sizeof($arr)." rows\r\n"; + echo "----\r\n"; + } + $query = "PRAGMA table_info(".$this->quote_id($result[$i]['tbl_name']).")"; + $temp = $this->selectArray($query); + $cols = array(); + $cols_quoted = array(); + $vals = array(); + for($z=0; $z<sizeof($temp); $z++) + { + $cols[$z] = $temp[$z][1]; + $cols_quoted[$z] = $this->quote_id($temp[$z][1]); + } + for($z=0; $z<sizeof($arr); $z++) + { + for($y=0; $y<sizeof($cols); $y++) + { + if(!isset($vals[$z])) + $vals[$z] = array(); + if($arr[$z][$cols[$y]] === NULL) + $vals[$z][$cols[$y]] = 'NULL'; + else + $vals[$z][$cols[$y]] = $this->quote($arr[$z][$cols[$y]]); + } + } + for($j=0; $j<sizeof($vals); $j++) + echo "INSERT INTO ".$this->quote_id($result[$i]['tbl_name'])." (".implode(",", $cols_quoted).") VALUES (".implode(",", $vals[$j]).");\r\n"; + } + } + } + if($transaction) + echo "COMMIT;\r\n"; + } +} + +$auth = new Authorization(); //create authorization object +//AstLinux// Disable authorization, always grant permission. +if(! $auth->isAuthorized()) { + $auth->grant(true); +} +// +//if(isset($_POST['logout'])) //user has attempted to log out +// $auth->revoke(); +//else if(isset($_POST['login']) || isset($_POST['proc_login'])) //user has attempted to log in +//{ +// $_POST['login'] = true; +// +// if($_POST['password']==SYSTEMPASSWORD) //make sure passwords match before granting authorization +// { +// if(isset($_POST['remember'])) +// $auth->grant(true); +// else +// $auth->grant(false); +// } +//} + +if($auth->isAuthorized()) +{ + + //user is creating a new Database + if(isset($_POST['new_dbname']) && $auth->isAuthorized()) + { + $str = preg_replace('@[^\w-.]@','', $_POST['new_dbname']); + $dbname = $str; + $dbpath = $str; + if(checkDbName($dbname)) + { + $tdata = array(); + $tdata['name'] = $dbname; + $tdata['path'] = $directory.DIRECTORY_SEPARATOR.$dbpath; + $td = new Database($tdata); + $td->query("VACUUM"); + } else + { + if(is_file($dbname) || is_dir($dbname)) $dbexists = true; + else $extension_not_allowed=true; + } + } + + + //if the user wants to scan a directory for databases, do so + if($directory!==false) + { + if($directory[strlen($directory)-1]==DIRECTORY_SEPARATOR) //if user has a trailing slash in the directory, remove it + $directory = substr($directory, 0, strlen($directory)-1); + + if(is_dir($directory)) //make sure the directory is valid + { + if($subdirectories===true) + $arr = dir_tree($directory); + else + $arr = scandir($directory); + $databases = array(); + $j = 0; + for($i=0; $i<sizeof($arr); $i++) //iterate through all the files in the databases + { + if($subdirectories===false) + $arr[$i] = $directory.DIRECTORY_SEPARATOR.$arr[$i]; + + if(!is_file($arr[$i])) continue; + $con = file_get_contents($arr[$i], NULL, NULL, 0, 60); + if(strpos($con, "** This file contains an SQLite 2.1 database **", 0)!==false || strpos($con, "SQLite format 3", 0)!==false) + { + $databases[$j]['path'] = $arr[$i]; + if($subdirectories===false) + $databases[$j]['name'] = basename($arr[$i]); + else + $databases[$j]['name'] = $arr[$i]; + // 22 August 2011: gkf fixed bug 49. + $perms = 0; + $perms += is_readable($databases[$j]['path']) ? 4 : 0; + $perms += is_writeable($databases[$j]['path']) ? 2 : 0; + switch($perms) + { + case 6: $perms = "[rw] "; break; + case 4: $perms = "[r ] "; break; + case 2: $perms = "[ w] "; break; // God forbid, but it might happen. + default: $perms = "[ ] "; break; + } + $databases[$j]['perms'] = $perms; + $j++; + } + } + // 22 August 2011: gkf fixed bug #50. + sort($databases); + if(isset($tdata)) + { + foreach($databases as $db_id => $database) + { + if($database['path'] == $tdata['path']) + { + $_SESSION[COOKIENAME.'currentDB'] = $database; + break; + } + } + } + } + else //the directory is not valid - display error and exit + { + echo "<div class='confirm' style='margin:20px;'>"; + echo "The directory you specified to scan for databases does not exist or is not a directory."; + echo "</div>"; + exit(); + } + } + else + { + for($i=0; $i<sizeof($databases); $i++) + { + if(!file_exists($databases[$i]['path'])) + continue; //skip if file not found ! - probably a warning can be displayed - later + $perms = 0; + $perms += is_readable($databases[$i]['path']) ? 4 : 0; + $perms += is_writeable($databases[$i]['path']) ? 2 : 0; + switch($perms) + { + case 6: $perms = "[rw] "; break; + case 4: $perms = "[r ] "; break; + case 2: $perms = "[ w] "; break; // God forbid, but it might happen. + default: $perms = "[ ] "; break; + } + $databases[$i]['perms'] = $perms; + } + sort($databases); + } + + //user is deleting a database + if(isset($_GET['database_delete'])) + { + $dbpath = $_POST['database_delete']; + // check whether $dbpath really is a db we manage + $checkDB = isManagedDB($dbpath); + if($checkDB !== false) + { + unlink($dbpath); + unset($_SESSION[COOKIENAME.'currentDB']); + unset($databases[$checkDB]); + } else die('You can only delete databases managed by this tool!'); + } + + //user is renaming a database + if(isset($_GET['database_rename'])) + { + $oldpath = $_POST['oldname']; + $newpath = $_POST['newname']; + $oldpath_parts = pathinfo($oldpath); + $newpath_parts = pathinfo($newpath); + // only rename? + $newpath = $oldpath_parts['dirname'].DIRECTORY_SEPARATOR.basename($_POST['newname']); + if($newpath != $_POST['newname'] && $subdirectories) + { + // it seems that the file should not only be renamed but additionally moved. + // we need to make sure it stays within $directory... + $new_realpath = realpath($newpath_parts['dirname']).DIRECTORY_SEPARATOR; + $directory_realpath = realpath($directory).DIRECTORY_SEPARATOR; + echo $_POST['newname']."=>".$new_realpath."<br>"; + echo $directory_realpath."<br>"; + if(strpos($new_realpath, $directory_realpath)===0) + { + // its okay, the new directory is within $directory + $newpath = $_POST['newname']; + } + else die('You either tried to move the database into a directory where it cannot be managed anylonger, or the check if you did this failed because of missing rights.'); + } + + if(checkDbName($newpath)) + { + $checkDB = isManagedDB($oldpath); + if($checkDB !==false ) + { + copy($oldpath, $newpath); + unlink($oldpath); + $databases[$checkDB]['path'] = $newpath; + $databases[$checkDB]['name'] = basename($newpath); + $_SESSION[COOKIENAME.'currentDB'] = $databases[$checkDB]; + $justrenamed = true; + } + else die('You can only rename databases managed by this tool!'); + } + else + { + if(is_file($newpath) || is_dir($newpath)) $dbexists = true; + else $extension_not_allowed = true; + } + } + + + //user is downloading the exported database file + if(isset($_POST['export'])) + { + if($_POST['export_type']=="sql") + { + header('Content-Type: text/sql'); + header('Content-Disposition: attachment; filename="'.$_POST['filename'].'.'.$_POST['export_type'].'";'); + if(isset($_POST['tables'])) + $tables = $_POST['tables']; + else + { + $tables = array(); + $tables[0] = $_POST['single_table']; + } + $drop = isset($_POST['drop']); + $structure = isset($_POST['structure']); + $data = isset($_POST['data']); + $transaction = isset($_POST['transaction']); + $comments = isset($_POST['comments']); + $db = new Database($_SESSION[COOKIENAME.'currentDB']); + echo $db->export_sql($tables, $drop, $structure, $data, $transaction, $comments); + } + else if($_POST['export_type']=="csv") + { + header("Content-type: application/csv"); + header('Content-Disposition: attachment; filename="'.$_POST['filename'].'.'.$_POST['export_type'].'";'); + header("Pragma: no-cache"); + header("Expires: 0"); + if(isset($_POST['tables'])) + $tables = $_POST['tables']; + else + { + $tables = array(); + $tables[0] = $_POST['single_table']; + } + $field_terminate = $_POST['export_csv_fieldsterminated']; + $field_enclosed = $_POST['export_csv_fieldsenclosed']; + $field_escaped = $_POST['export_csv_fieldsescaped']; + $null = $_POST['export_csv_replacenull']; + $crlf = isset($_POST['export_csv_crlf']); + $fields_in_first_row = isset($_POST['export_csv_fieldnames']); + $db = new Database($_SESSION[COOKIENAME.'currentDB']); + echo $db->export_csv($tables, $field_terminate, $field_enclosed, $field_escaped, $null, $crlf, $fields_in_first_row); + } + exit(); + } + + //user is importing a file + if(isset($_POST['import'])) + { + $db = new Database($_SESSION[COOKIENAME.'currentDB']); + //AstLinux// missing file fix. + if ($_FILES["file"]["tmp_name"] !== '') { + if($_POST['import_type']=="sql") + { + $data = file_get_contents($_FILES["file"]["tmp_name"]); + $importSuccess = $db->import_sql($data); + } + else + { + $field_terminate = $_POST['import_csv_fieldsterminated']; + $field_enclosed = $_POST['import_csv_fieldsenclosed']; + $field_escaped = $_POST['import_csv_fieldsescaped']; + $null = $_POST['import_csv_replacenull']; + $fields_in_first_row = isset($_POST['import_csv_fieldnames']); + $importSuccess = $db->import_csv($_FILES["file"]["tmp_name"], $_POST['single_table'], $field_terminate, $field_enclosed, $field_escaped, $null, $fields_in_first_row); + } + } + else + { + $importSuccess = 'No File Selected, choose a file.'; + } + //AstLinux// end of missing file fix. + } +} + +header('Content-Type: text/html; charset=utf-8'); + +// here begins the HTML. +?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> +<!-- Copyright <?php echo date("Y"); ?> phpLiteAdmin (http://phpliteadmin.googlecode.com) --> +<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /> +<title><?php echo PROJECT ?></title> + +<?php + +//AstLinux// Remove built-in stylesheet, only use external one. +echo "<link href='/common/phpliteadmin.css' rel='stylesheet' type='text/css' />"; + +if(isset($_GET['help'])) //this page is used as the popup help section +{ + //help section array + $help = array + ( + 'SQLite Library Extensions' => + 'phpLiteAdmin uses PHP library extensions that allow interaction with SQLite databases. Currently, phpLiteAdmin supports PDO, SQLite3, and SQLiteDatabase. Both PDO and SQLite3 deal with version 3 of SQLite, while SQLiteDatabase deals with version 2. So, if your PHP installation includes more than one SQLite library extension, PDO and SQLite3 will take precedence to make use of the better technology. However, if you have existing databases that are of version 2 of SQLite, phpLiteAdmin will be forced to use SQLiteDatabase for only those databases. Not all databases need to be of the same version. During the database creation, however, the most advanced extension will be used.', + 'Creating a New Database' => + 'When you create a new database, the name you entered will be appended with the appropriate file extension (.db, .db3, .sqlite, etc.) if you do not include it yourself. The database will be created in the directory you specified as the $directory variable.', + 'Tables vs. Views' => + 'On the main database page, there is a list of tables and views. Since views are read-only, certain operations will be disabled. These disabled operations will be apparent by their omission in the location where they should appear on the row for a view. If you want to change the data for a view, you need to drop that view and create a new view with the appropriate SELECT statement that queries other existing tables. For more information, see <a href="http://en.wikipedia.org/wiki/View_(database)" target="_blank">http://en.wikipedia.org/wiki/View_(database)</a>', + 'Writing a Select Statement for a New View' => + 'When you create a new view, you must write an SQL SELECT statement that it will use as its data. A view is simply a read-only table that can be accessed and queried like a regular table, except it cannot be modified through insertion, column editing, or row editing. It is only used for conveniently fetching data.', + 'Export Structure to SQL File' => + 'During the process for exporting to an SQL file, you may choose to include the queries that create the table and columns.', + 'Export Data to SQL File' => + 'During the process for exporting to an SQL file, you may choose to include the queries that populate the table(s) with the current records of the table(s).', + 'Add Drop Table to Exported SQL File' => + 'During the process for exporting to an SQL file, you may choose to include queries to DROP the existing tables before adding them so that problems do not occur when trying to create tables that already exist.', + 'Add Transaction to Exported SQL File' => + 'During the process for exporting to an SQL file, you may choose to wrap the queries around a TRANSACTION so that if an error occurs at any time during the importation process using the exported file, the database can be reverted to its previous state, preventing partially updated data from populating the database.', + 'Add Comments to Exported SQL File' => + 'During the process for exporting to an SQL file, you may choose to include comments that explain each step of the process so that a human can better understand what is happening.', + ); + ?> + </head> + <body> + <div id='help_container'> + <?php + echo "<div class='help_list'>"; + echo "<span style='font-size:18px;'>".PROJECT." v".VERSION." Help Documentation</span><br/><br/>"; + foreach((array)$help as $key => $val) + { + echo "<a href='#".$key."'>".$key."</a><br/>"; + } + echo "</div>"; + echo "<br/><br/>"; + foreach((array)$help as $key => $val) + { + echo "<div class='help_outer'>"; + echo "<a class='headd' name='".$key."'>".$key."</a>"; + echo "<div class='help_inner'>"; + echo $val; + echo "</div>"; + echo "<a class='help_top' href='#top'>Back to Top</a>"; + echo "</div>"; + } + ?> + </div> + </body> + </html> + <?php + exit(); +} +?> +<!-- JavaScript Support --> +<script type="text/javascript"> +/* <![CDATA[ */ +//initiated autoincrement checkboxes +function initAutoincrement() +{ + var i=0; + while(document.getElementById('i'+i+'_autoincrement')!=undefined) + { + document.getElementById('i'+i+'_autoincrement').disabled = true; + i++; + } +} +//makes sure autoincrement can only be selected when integer type is selected +function toggleAutoincrement(i) +{ + var type = document.getElementById('i'+i+'_type'); + var primarykey = document.getElementById('i'+i+'_primarykey'); + var autoincrement = document.getElementById('i'+i+'_autoincrement'); + if(type.value=='INTEGER' && primarykey.checked) + autoincrement.disabled = false; + else + { + autoincrement.disabled = true; + autoincrement.checked = false; + } +} +function toggleNull(i) +{ + var pk = document.getElementById('i'+i+'_primarykey'); + var notnull = document.getElementById('i'+i+'_notnull'); + if(pk.checked) + { + notnull.disabled = true; + notnull.checked = true; + } + else + { + notnull.disabled = false; + } +} +//finds and checks all checkboxes for all rows on the Browse or Structure tab for a table +function checkAll(field) +{ + var i=0; + while(document.getElementById('check_'+i)!=undefined) + { + document.getElementById('check_'+i).checked = true; + i++; + } +} +//finds and unchecks all checkboxes for all rows on the Browse or Structure tab for a table +function uncheckAll(field) +{ + var i=0; + while(document.getElementById('check_'+i)!=undefined) + { + document.getElementById('check_'+i).checked = false; + i++; + } +} +//unchecks the ignore checkbox if user has typed something into one of the fields for adding new rows +function changeIgnore(area, e, u) +{ + if(area.value!="") + { + if(document.getElementById(e)!=undefined) + document.getElementById(e).checked = false; + if(document.getElementById(u)!=undefined) + document.getElementById(u).checked = false; + } +} +//moves fields from select menu into query textarea for SQL tab +function moveFields() +{ + var fields = document.getElementById("fieldcontainer"); + var selected = new Array(); + for(var i=0; i<fields.options.length; i++) + if(fields.options[i].selected) + selected.push(fields.options[i].value); + for(var i=0; i<selected.length; i++) ... [truncated message content] |
From: <abe...@us...> - 2013-03-12 18:08:46
|
Revision: 5988 http://astlinux.svn.sourceforge.net/astlinux/?rev=5988&view=rev Author: abelbeck Date: 2013-03-12 18:08:36 +0000 (Tue, 12 Mar 2013) Log Message: ----------- web interface, various tweaks... 1) add default view for cdr-sqlite3 if /mnt/kd/cdr-sqlite3/master.db exists 2) fix view bug in phpliteadmin: https://code.google.com/p/phpliteadmin/issues/detail?id=191 3) hopefully final tweak to the sqldata.sql standard template 4) document changes in SQL-Data Tab topic info Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php branches/1.0/package/webinterface/altweb/admin/prefs.php branches/1.0/package/webinterface/altweb/admin/sqldata.php branches/1.0/package/webinterface/altweb/common/sqldata.sql branches/1.0/package/webinterface/altweb/common/topics.info Modified: branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php 2013-03-11 22:01:15 UTC (rev 5987) +++ branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php 2013-03-12 18:08:36 UTC (rev 5988) @@ -92,7 +92,7 @@ } function mydate($value) { - return date("g:ia n/j/y", intval($value)); + return date("H:i n/j/y", intval($value)); } function myreplace($value) { @@ -557,7 +557,8 @@ //get the last modified time of database public function getDate() { - return date("g:ia \o\\n F j, Y", filemtime($this->data["path"])); + //AstLinux// + return date("M d H:i:s T Y", filemtime($this->data["path"])); } //get number of affected rows from last query @@ -2988,6 +2989,8 @@ //row actions /////////////////////////////////////////////// view row case "row_view": + $is_view = isset($_GET['view']) ? '&view=1' : ''; + if(!isset($_POST['startRow'])) $_POST['startRow'] = 0; @@ -3020,14 +3023,14 @@ if($_POST['startRow']>0) { echo "<div style='float:left; overflow:hidden;'>"; - echo "<form action='".PAGE."?action=row_view&table=".urlencode($_GET['table'])."' method='post'>"; + echo "<form action='".PAGE."?action=row_view&table=".urlencode($_GET['table']).$is_view."' method='post'>"; echo "<input type='hidden' name='startRow' value='0'/>"; echo "<input type='hidden' name='numRows' value='".$_SESSION[COOKIENAME.'numRows']."'/> "; echo "<input type='submit' value='←←' name='previous' class='btn'/> "; echo "</form>"; echo "</div>"; echo "<div style='float:left; overflow:hidden; margin-right:20px;'>"; - echo "<form action='".PAGE."?action=row_view&table=".urlencode($_GET['table'])."' method='post'>"; + echo "<form action='".PAGE."?action=row_view&table=".urlencode($_GET['table']).$is_view."' method='post'>"; echo "<input type='hidden' name='startRow' value='".intval($_POST['startRow']-$_SESSION[COOKIENAME.'numRows'])."'/>"; echo "<input type='hidden' name='numRows' value='".$_SESSION[COOKIENAME.'numRows']."'/> "; echo "<input type='submit' value='←' name='previous_full' class='btn'/> "; @@ -3037,7 +3040,7 @@ //show certain number buttons echo "<div style='float:left; overflow:hidden;'>"; - echo "<form action='".PAGE."?action=row_view&table=".urlencode($_GET['table'])."' method='post'>"; + echo "<form action='".PAGE."?action=row_view&table=".urlencode($_GET['table']).$is_view."' method='post'>"; echo "<input type='submit' value='Show : ' name='show' class='btn'/> "; echo "<input type='text' name='numRows' style='width:50px;' value='".$_SESSION[COOKIENAME.'numRows']."'/> "; echo "row(s) starting from record # "; @@ -3065,14 +3068,14 @@ if(intval($_POST['startRow']+$_SESSION[COOKIENAME.'numRows'])<$rowCount) { echo "<div style='float:left; overflow:hidden; margin-left:20px; '>"; - echo "<form action='".PAGE."?action=row_view&table=".urlencode($_GET['table'])."' method='post'>"; + echo "<form action='".PAGE."?action=row_view&table=".urlencode($_GET['table']).$is_view."' method='post'>"; echo "<input type='hidden' name='startRow' value='".intval($_POST['startRow']+$_SESSION[COOKIENAME.'numRows'])."'/>"; echo "<input type='hidden' name='numRows' value='".$_SESSION[COOKIENAME.'numRows']."'/> "; echo "<input type='submit' value='→' name='next' class='btn'/> "; echo "</form>"; echo "</div>"; echo "<div style='float:left; overflow:hidden;'>"; - echo "<form action='".PAGE."?action=row_view&table=".urlencode($_GET['table'])."' method='post'>"; + echo "<form action='".PAGE."?action=row_view&table=".urlencode($_GET['table']).$is_view."' method='post'>"; echo "<input type='hidden' name='startRow' value='".intval($rowCount-$remainder)."'/>"; echo "<input type='hidden' name='numRows' value='".$_SESSION[COOKIENAME.'numRows']."'/> "; echo "<input type='submit' value='→→' name='next_full' class='btn'/> "; @@ -3126,7 +3129,7 @@ if(isset($_GET['view'])) { - echo "'".htmlencode($_GET['table'])."' is a view, which means it is a SELECT statement treated as a read-only table. You may not edit or insert records. <a href='http://en.wikipedia.org/wiki/View_(database)' target='_blank'>http://en.wikipedia.org/wiki/View_(database)</a>"; + echo "'".htmlencode($_GET['table'])."' is a view, which means it is a SELECT statement treated as a read-only table. You may not edit or insert records."; echo "<br/><br/>"; } @@ -3136,7 +3139,7 @@ if(!isset($_SESSION[COOKIENAME.'viewtype']) || $_SESSION[COOKIENAME.'viewtype']=="table") { - echo "<form action='".PAGE."?action=row_editordelete&table=".urlencode($table)."' method='post' name='checkForm'>"; + echo "<form action='".PAGE."?action=row_editordelete&table=".urlencode($table).$is_view."' method='post' name='checkForm'>"; echo "<table border='0' cellpadding='2' cellspacing='1' class='viewTable'>"; echo "<tr>"; if(!isset($_GET['view'])) @@ -3298,7 +3301,7 @@ <div id="chart_div" style="float:left;">If you can read this, it means the chart could not be generated. The data you are trying to view may not be appropriate for a chart.</div> <?php echo "<fieldset style='float:right; text-align:center;' id='chartsettingsbox'><legend><b>Chart Settings</b></legend>"; - echo "<form action='".PAGE."?action=row_view&table=".urlencode($_GET['table'])."' method='post'>"; + echo "<form action='".PAGE."?action=row_view&table=".urlencode($_GET['table']).$is_view."' method='post'>"; echo "Chart Type: <select name='charttype'>"; echo "<option value='bar'"; if($_SESSION[COOKIENAME.'charttype']=="bar") Modified: branches/1.0/package/webinterface/altweb/admin/prefs.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/prefs.php 2013-03-11 22:01:15 UTC (rev 5987) +++ branches/1.0/package/webinterface/altweb/admin/prefs.php 2013-03-12 18:08:36 UTC (rev 5988) @@ -273,6 +273,10 @@ $value = 'sqldata_create_schema = no'; fwrite($fp, $value."\n"); } + if (! isset($_POST['sqldata_create_cdr_view'])) { + $value = 'sqldata_create_cdr_view = no'; + fwrite($fp, $value."\n"); + } if (isset($_POST['users_hide_pass'])) { $value = 'users_voicemail_hide_pass = yes'; @@ -852,8 +856,12 @@ putHtml('</td></tr>'); putHtml('<tr class="dtrow1"><td style="text-align: right;">'); $sel = (getPREFdef($global_prefs, 'sqldata_create_schema') !== 'no') ? ' checked="checked"' : ''; - putHtml('<input type="checkbox" value="sqldata_create_schema" name="sqldata_create_schema"'.$sel.' /></td><td colspan="5">Create default SIP & Phone SQL Schema if not defined</td></tr>'); + putHtml('<input type="checkbox" value="sqldata_create_schema" name="sqldata_create_schema"'.$sel.' /></td><td colspan="5">Create SIP & Phone standard SQL schema</td></tr>'); + putHtml('<tr class="dtrow1"><td style="text-align: right;">'); + $sel = (getPREFdef($global_prefs, 'sqldata_create_cdr_view') !== 'no') ? ' checked="checked"' : ''; + putHtml('<input type="checkbox" value="sqldata_create_cdr_view" name="sqldata_create_cdr_view"'.$sel.' /></td><td colspan="5">Create CDR SQLite3 standard view if database exists</td></tr>'); + putHtml('<tr class="dtrow0"><td colspan="6"> </td></tr>'); putHtml('<tr class="dtrow0"><td class="dialogText" style="text-align: left;" colspan="6">'); Modified: branches/1.0/package/webinterface/altweb/admin/sqldata.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/sqldata.php 2013-03-11 22:01:15 UTC (rev 5987) +++ branches/1.0/package/webinterface/altweb/admin/sqldata.php 2013-03-12 18:08:36 UTC (rev 5988) @@ -51,6 +51,23 @@ } } $pdo_db = NULL; + + if (is_file('/mnt/kd/cdr-sqlite3/master.db') && getPREFdef($global_prefs, 'sqldata_create_cdr_view') !== 'no') { + $pdo_db = new PDO("sqlite:/mnt/kd/cdr-sqlite3/master.db"); + $pdo_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + // List all views + $view_arr = array(); + $sql = "SELECT name FROM sqlite_master WHERE type='view'"; + foreach ($pdo_db->query($sql) as $row) { + $view_arr[] = $row['name']; + } + if (! in_array('standard', $view_arr)) { + $sql = "CREATE VIEW IF NOT EXISTS 'standard' AS SELECT calldate, clid, dstchannel, dcontext, billsec, userfield FROM cdr ORDER BY calldate DESC"; + $pdo_db->exec($sql); + } + $pdo_db = NULL; + } } catch (PDOException $e) { return($e->getMessage()); } Modified: branches/1.0/package/webinterface/altweb/common/sqldata.sql =================================================================== --- branches/1.0/package/webinterface/altweb/common/sqldata.sql 2013-03-11 22:01:15 UTC (rev 5987) +++ branches/1.0/package/webinterface/altweb/common/sqldata.sql 2013-03-12 18:08:36 UTC (rev 5988) @@ -1,6 +1,6 @@ CREATE TABLE IF NOT EXISTS 'sip_users' ( - 'userid' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + 'id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 'sipuser' TEXT NOT NULL, 'lastname' TEXT, 'firstname' TEXT, @@ -16,42 +16,44 @@ ); CREATE TABLE IF NOT EXISTS 'out_context' ( - 'out_contextid' INTEGER PRIMARY KEY NOT NULL, - 'outgoing_context' TEXT NOT NULL, - 'out_cx_description' TEXT + 'id' INTEGER PRIMARY KEY NOT NULL, + 'context' TEXT NOT NULL, + 'description' TEXT ); CREATE TABLE IF NOT EXISTS 'ip_phones' ( - 'phone_id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - 'phone_type' TEXT, - 'phone_fw' TEXT, - 'phone_ip' TEXT, - 'phone_mac' TEXT, - 'userid' INTEGER + 'id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + 'type' TEXT, + 'firmware' TEXT, + 'hostname' TEXT, + 'ipv4' TEXT, + 'ipv6' TEXT, + 'mac' TEXT, + 'sipuser_id' INTEGER ); -INSERT OR IGNORE INTO "out_context" ("out_contextid","outgoing_context","out_cx_description") +INSERT OR IGNORE INTO "out_context" ("id","context","description") VALUES ('0','emergency','Emergency calls only') ; -INSERT OR IGNORE INTO "out_context" ("out_contextid","outgoing_context","out_cx_description") +INSERT OR IGNORE INTO "out_context" ("id","context","description") VALUES ('1','local_outgoing','Local calls only') ; -INSERT OR IGNORE INTO "out_context" ("out_contextid","outgoing_context","out_cx_description") +INSERT OR IGNORE INTO "out_context" ("id","context","description") VALUES ('2','local_outgoing','Unused1') ; -INSERT OR IGNORE INTO "out_context" ("out_contextid","outgoing_context","out_cx_description") +INSERT OR IGNORE INTO "out_context" ("id","context","description") VALUES ('3','national_outgoing','National calls') ; -INSERT OR IGNORE INTO "out_context" ("out_contextid","outgoing_context","out_cx_description") +INSERT OR IGNORE INTO "out_context" ("id","context","description") VALUES ('4','national_outgoing','Unused2') ; -INSERT OR IGNORE INTO "out_context" ("out_contextid","outgoing_context","out_cx_description") +INSERT OR IGNORE INTO "out_context" ("id","context","description") VALUES ('5','national_outgoing','Unused3') ; -INSERT OR IGNORE INTO "out_context" ("out_contextid","outgoing_context","out_cx_description") +INSERT OR IGNORE INTO "out_context" ("id","context","description") VALUES ('6','national_outgoing','Unused4') ; -INSERT OR IGNORE INTO "out_context" ("out_contextid","outgoing_context","out_cx_description") +INSERT OR IGNORE INTO "out_context" ("id","context","description") VALUES ('7','international_outgoing','International calls') ; Modified: branches/1.0/package/webinterface/altweb/common/topics.info =================================================================== --- branches/1.0/package/webinterface/altweb/common/topics.info 2013-03-11 22:01:15 UTC (rev 5987) +++ branches/1.0/package/webinterface/altweb/common/topics.info 2013-03-12 18:08:36 UTC (rev 5988) @@ -291,11 +291,15 @@ The SQL-Data Tab adds a web dialog to edit the SQLite3 database (added in AstLinux 1.1.1). The database exists in "/mnt/kd/asterisk-odbc.sqlite3". -The Prefs tab contains a relevant option under "SQL-Data Tab Options:". +The Prefs tab contains relevant options under "SQL-Data Tab Options:". -The "Create default SIP & Phone SQL Schema if not defined" (checked by default), -automatically creates the default table structure for the SQLite3 database. +The "Create SIP & Phone standard SQL schema" (checked by default), +automatically creates the standard table structure for the SQLite3 database. +The "Create CDR SQLite3 standard view if database exists" (checked by default), +automatically creates the standard view for the CDR SQLite3 database located +at "/mnt/kd/cdr-sqlite3/master.db" if it exists. + You can access the database via Asterisk with user defined "func_odbc" functions, where you can define customized database queries and more. A quite universal example for an entry in the "func_odbc.conf" would be: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <abe...@us...> - 2013-03-13 20:18:55
|
Revision: 5991 http://astlinux.svn.sourceforge.net/astlinux/?rev=5991&view=rev Author: abelbeck Date: 2013-03-13 20:18:48 +0000 (Wed, 13 Mar 2013) Log Message: ----------- web interface, add support for ODBC CDR file /mnt/kd/cdr-sqlite3/cdr-odbc.sqlite3 and remove recently added SQL view generation for /mnt/kd/cdr-sqlite3/master.db Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php branches/1.0/package/webinterface/altweb/admin/prefs.php branches/1.0/package/webinterface/altweb/admin/sqldata.php branches/1.0/package/webinterface/altweb/common/topics.info Modified: branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php 2013-03-13 19:43:54 UTC (rev 5990) +++ branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php 2013-03-13 20:18:48 UTC (rev 5991) @@ -72,6 +72,9 @@ "name"=> "Asterisk" ) ); +if (is_file('/mnt/kd/cdr-sqlite3/cdr-odbc.sqlite3')) { + $databases[] = array( "path"=> "/mnt/kd/cdr-sqlite3/cdr-odbc.sqlite3", "name"=> "CDR ODBC" ); +} if (is_file('/mnt/kd/cdr-sqlite3/master.db')) { $databases[] = array( "path"=> "/mnt/kd/cdr-sqlite3/master.db", "name"=> "CDR SQLite3" ); } Modified: branches/1.0/package/webinterface/altweb/admin/prefs.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/prefs.php 2013-03-13 19:43:54 UTC (rev 5990) +++ branches/1.0/package/webinterface/altweb/admin/prefs.php 2013-03-13 20:18:48 UTC (rev 5991) @@ -273,10 +273,6 @@ $value = 'sqldata_create_schema = no'; fwrite($fp, $value."\n"); } - if (! isset($_POST['sqldata_create_cdr_view'])) { - $value = 'sqldata_create_cdr_view = no'; - fwrite($fp, $value."\n"); - } if (isset($_POST['users_hide_pass'])) { $value = 'users_voicemail_hide_pass = yes'; @@ -858,10 +854,6 @@ $sel = (getPREFdef($global_prefs, 'sqldata_create_schema') !== 'no') ? ' checked="checked"' : ''; putHtml('<input type="checkbox" value="sqldata_create_schema" name="sqldata_create_schema"'.$sel.' /></td><td colspan="5">Create SIP & Phone standard SQL schema</td></tr>'); - putHtml('<tr class="dtrow1"><td style="text-align: right;">'); - $sel = (getPREFdef($global_prefs, 'sqldata_create_cdr_view') !== 'no') ? ' checked="checked"' : ''; - putHtml('<input type="checkbox" value="sqldata_create_cdr_view" name="sqldata_create_cdr_view"'.$sel.' /></td><td colspan="5">Create CDR SQLite3 standard view if database exists</td></tr>'); - putHtml('<tr class="dtrow0"><td colspan="6"> </td></tr>'); putHtml('<tr class="dtrow0"><td class="dialogText" style="text-align: left;" colspan="6">'); Modified: branches/1.0/package/webinterface/altweb/admin/sqldata.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/sqldata.php 2013-03-13 19:43:54 UTC (rev 5990) +++ branches/1.0/package/webinterface/altweb/admin/sqldata.php 2013-03-13 20:18:48 UTC (rev 5991) @@ -51,23 +51,6 @@ } } $pdo_db = NULL; - - if (is_file('/mnt/kd/cdr-sqlite3/master.db') && getPREFdef($global_prefs, 'sqldata_create_cdr_view') !== 'no') { - $pdo_db = new PDO("sqlite:/mnt/kd/cdr-sqlite3/master.db"); - $pdo_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - - // List all views - $view_arr = array(); - $sql = "SELECT name FROM sqlite_master WHERE type='view'"; - foreach ($pdo_db->query($sql) as $row) { - $view_arr[] = $row['name']; - } - if (! in_array('standard', $view_arr)) { - $sql = "CREATE VIEW IF NOT EXISTS 'standard' AS SELECT calldate, clid, dstchannel, dcontext, billsec, userfield FROM cdr ORDER BY calldate DESC"; - $pdo_db->exec($sql); - } - $pdo_db = NULL; - } } catch (PDOException $e) { return($e->getMessage()); } Modified: branches/1.0/package/webinterface/altweb/common/topics.info =================================================================== --- branches/1.0/package/webinterface/altweb/common/topics.info 2013-03-13 19:43:54 UTC (rev 5990) +++ branches/1.0/package/webinterface/altweb/common/topics.info 2013-03-13 20:18:48 UTC (rev 5991) @@ -296,10 +296,6 @@ The "Create SIP & Phone standard SQL schema" (checked by default), automatically creates the standard table structure for the SQLite3 database. -The "Create CDR SQLite3 standard view if database exists" (checked by default), -automatically creates the standard view for the CDR SQLite3 database located -at "/mnt/kd/cdr-sqlite3/master.db" if it exists. - You can access the database via Asterisk with user defined "func_odbc" functions, where you can define customized database queries and more. A quite universal example for an entry in the "func_odbc.conf" would be: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <abe...@us...> - 2013-03-16 18:26:21
|
Revision: 5997 http://astlinux.svn.sourceforge.net/astlinux/?rev=5997&view=rev Author: abelbeck Date: 2013-03-16 18:26:14 +0000 (Sat, 16 Mar 2013) Log Message: ----------- web interface, customize phpliteadmin.php more to use <input type='text' instead of <textarea for Search, Insert and Browse -> {edit} screens. Also set empty string defaults to the standard schema Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php branches/1.0/package/webinterface/altweb/common/sqldata.sql Modified: branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php 2013-03-15 22:18:51 UTC (rev 5996) +++ branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php 2013-03-16 18:26:14 UTC (rev 5997) @@ -2976,7 +2976,9 @@ if($type=="INTEGER" || $type=="REAL" || $type=="NULL") echo "<input type='text' name='".htmlencode($field)."'/>"; else - echo "<textarea name='".htmlencode($field)."' wrap='hard' rows='1' cols='60'></textarea>"; + //AstLinux// + echo "<input type='text' size='60' name='".htmlencode($field)."'/>"; + //echo "<textarea name='".htmlencode($field)."' wrap='hard' rows='1' cols='60'></textarea>"; echo "</td>"; echo "</tr>"; } @@ -3445,7 +3447,9 @@ if($scalarField) echo "<input type='text' id='row_".$j."_field_".$i."_value' name='".$j.":".$field_html."' value='".deQuoteSQL($result[$i][4])."' onblur='changeIgnore(this, \"row_".$j."_ignore\");' onclick='notNull(\"row_".$j."_field_".$i."_null\");'/>"; else - echo "<textarea id='row_".$j."_field_".$i."_value' name='".$j.":".$field_html."' rows='5' cols='60' onclick='notNull(\"row_".$j."_field_".$i."_null\");' onblur='changeIgnore(this, \"row_".$j."_ignore\");'>".deQuoteSQL($result[$i][4])."</textarea>"; + //AstLinux// + echo "<input type='text' size='60' id='row_".$j."_field_".$i."_value' name='".$j.":".$field_html."' value='".deQuoteSQL($result[$i][4])."' onblur='changeIgnore(this, \"row_".$j."_ignore\");' onclick='notNull(\"row_".$j."_field_".$i."_null\");'/>"; + //echo "<textarea id='row_".$j."_field_".$i."_value' name='".$j.":".$field_html."' rows='5' cols='60' onclick='notNull(\"row_".$j."_field_".$i."_null\");' onblur='changeIgnore(this, \"row_".$j."_ignore\");'>".deQuoteSQL($result[$i][4])."</textarea>"; echo "</td>"; echo "</tr>"; } @@ -3547,7 +3551,9 @@ if($type=="INTEGER" || $type=="REAL" || $type=="NULL") echo "<input type='text' name='".htmlencode($pks[$j]).":".htmlencode($field)."' value='".htmlencode($value)."' onblur='changeIgnore(this, \"".$j."\", \"".htmlencode($pks[$j]).":".htmlencode($field)."_null\")' />"; else - echo "<textarea name='".htmlencode($pks[$j]).":".htmlencode($field)."' wrap='hard' rows='1' cols='60' onblur='changeIgnore(this, \"".$j."\", \"".htmlencode($pks[$j]).":".htmlencode($field)."_null\")'>".htmlencode($value)."</textarea>"; + //AstLinux// + echo "<input type='text' size='60' name='".htmlencode($pks[$j]).":".htmlencode($field)."' value='".htmlencode($value)."' onblur='changeIgnore(this, \"".$j."\", \"".htmlencode($pks[$j]).":".htmlencode($field)."_null\")' />"; + //echo "<textarea name='".htmlencode($pks[$j]).":".htmlencode($field)."' wrap='hard' rows='1' cols='60' onblur='changeIgnore(this, \"".$j."\", \"".htmlencode($pks[$j]).":".htmlencode($field)."_null\")'>".htmlencode($value)."</textarea>"; echo "</td>"; echo "</tr>"; } Modified: branches/1.0/package/webinterface/altweb/common/sqldata.sql =================================================================== --- branches/1.0/package/webinterface/altweb/common/sqldata.sql 2013-03-15 22:18:51 UTC (rev 5996) +++ branches/1.0/package/webinterface/altweb/common/sqldata.sql 2013-03-16 18:26:14 UTC (rev 5997) @@ -2,33 +2,33 @@ CREATE TABLE IF NOT EXISTS 'sip_users' ( 'id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 'sipuser' TEXT NOT NULL, - 'lastname' TEXT, - 'firstname' TEXT, + 'lastname' TEXT DEFAULT '', + 'firstname' TEXT DEFAULT '', 'out_cxid' INTEGER DEFAULT 7, 'vm' INTEGER DEFAULT 0, - 'vmbox' TEXT, - 'email' TEXT, - 'ext_intern' TEXT, - 'ext_extern' TEXT, - 'fax_ext' TEXT, - 'fax_email' TEXT, - 'xmpp_jid' TEXT + 'vmbox' TEXT DEFAULT '', + 'email' TEXT DEFAULT '', + 'ext_intern' TEXT DEFAULT '', + 'ext_extern' TEXT DEFAULT '', + 'fax_ext' TEXT DEFAULT '', + 'fax_email' TEXT DEFAULT '', + 'xmpp_jid' TEXT DEFAULT '' ); CREATE TABLE IF NOT EXISTS 'out_context' ( 'id' INTEGER PRIMARY KEY NOT NULL, 'context' TEXT NOT NULL, - 'description' TEXT + 'description' TEXT DEFAULT '' ); CREATE TABLE IF NOT EXISTS 'ip_phones' ( 'id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - 'type' TEXT, - 'firmware' TEXT, - 'hostname' TEXT, - 'ipv4' TEXT, - 'ipv6' TEXT, - 'mac' TEXT, + 'type' TEXT DEFAULT '', + 'firmware' TEXT DEFAULT '', + 'hostname' TEXT DEFAULT '', + 'ipv4' TEXT DEFAULT '', + 'ipv6' TEXT DEFAULT '', + 'mac' TEXT DEFAULT '', 'sipuser_id' INTEGER ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <abe...@us...> - 2013-03-18 23:21:04
|
Revision: 6001 http://astlinux.svn.sourceforge.net/astlinux/?rev=6001&view=rev Author: abelbeck Date: 2013-03-18 23:20:53 +0000 (Mon, 18 Mar 2013) Log Message: ----------- web interface, allow all tabs to work with or without PHP 'Magic Quotes' enabled on the server: 1) Tabs that save rc.conf.d/ files strip double-quote, dollar and grave-accent characters from text input 2) Tabs that save astDB data strip double-quote character from text input 3) Prefs tab strips double-quote character from text input Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/actionlist.php branches/1.0/package/webinterface/altweb/admin/blacklist.php branches/1.0/package/webinterface/altweb/admin/cdrlog.php branches/1.0/package/webinterface/altweb/admin/cidname.php branches/1.0/package/webinterface/altweb/admin/dnshosts.php branches/1.0/package/webinterface/altweb/admin/edit.php branches/1.0/package/webinterface/altweb/admin/firewall.php branches/1.0/package/webinterface/altweb/admin/followme.php branches/1.0/package/webinterface/altweb/admin/ipsec.php branches/1.0/package/webinterface/altweb/admin/ipsecmobile.php branches/1.0/package/webinterface/altweb/admin/ipsecxauth.php branches/1.0/package/webinterface/altweb/admin/network.php branches/1.0/package/webinterface/altweb/admin/openvpn.php branches/1.0/package/webinterface/altweb/admin/openvpnclient.php branches/1.0/package/webinterface/altweb/admin/openvpnuserpass.php branches/1.0/package/webinterface/altweb/admin/pptp.php branches/1.0/package/webinterface/altweb/admin/prefs.php branches/1.0/package/webinterface/altweb/admin/siptlscert.php branches/1.0/package/webinterface/altweb/admin/sysdial.php branches/1.0/package/webinterface/altweb/admin/system.php branches/1.0/package/webinterface/altweb/admin/testmail.php branches/1.0/package/webinterface/altweb/admin/users.php branches/1.0/package/webinterface/altweb/admin/whitelist.php branches/1.0/package/webinterface/altweb/admin/xmpp.php branches/1.0/package/webinterface/altweb/admin/zabbix.php branches/1.0/package/webinterface/altweb/common/functions.php Modified: branches/1.0/package/webinterface/altweb/admin/actionlist.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/actionlist.php 2013-03-17 21:15:47 UTC (rev 6000) +++ branches/1.0/package/webinterface/altweb/admin/actionlist.php 2013-03-18 23:20:53 UTC (rev 6001) @@ -82,13 +82,11 @@ if (! $global_staff) { $result = 999; } elseif (isset($_POST['submit_add'])) { - $actionkey = trim($_POST['actionkey']); + $actionkey = tuqd($_POST['actionkey']); if (($action = $_POST['action']) === '') { - $action = trim($_POST['actiondata']); + $action = tuqd($_POST['actiondata']); } - if (($comment = trim($_POST['comment'])) !== '') { - $comment = str_replace('"', "'", stripslashes($comment)); - } + $comment = tuqd($_POST['comment']); if (strlen($actionkey) > 0) { if (($cmd = getPREFdef($global_prefs, 'actionlist_format_cmdstr')) === '') { $cmd = '^[A-Za-z0-9-]{2,20}$'; Modified: branches/1.0/package/webinterface/altweb/admin/blacklist.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/blacklist.php 2013-03-17 21:15:47 UTC (rev 6000) +++ branches/1.0/package/webinterface/altweb/admin/blacklist.php 2013-03-18 23:20:53 UTC (rev 6001) @@ -57,11 +57,9 @@ if (! $global_staff) { $result = 999; } elseif (isset($_POST['submit_add'])) { - $cidnum = trim($_POST['cidnum']); + $cidnum = tuqd($_POST['cidnum']); $action = $_POST['action']; - if (($comment = trim($_POST['comment'])) !== '') { - $comment = str_replace('"', "'", stripslashes($comment)); - } + $comment = tuqd($_POST['comment']); if (strlen($cidnum) > 0) { if (($cmd = getPREFdef($global_prefs, 'number_format_cmdstr')) === '') { $cmd = '^[2-9][0-9][0-9][2-9][0-9][0-9][0-9][0-9][0-9][0-9]$'; Modified: branches/1.0/package/webinterface/altweb/admin/cdrlog.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/cdrlog.php 2013-03-17 21:15:47 UTC (rev 6000) +++ branches/1.0/package/webinterface/altweb/admin/cdrlog.php 2013-03-18 23:20:53 UTC (rev 6001) @@ -484,7 +484,7 @@ $db['displayStart'] = 0; } if (isset($_POST['list_type_val'])) { - $search = trim(stripslashes($_POST['list_type_val'])); + $search = tuqd($_POST['list_type_val']); $search = trim($search, ' |&"'); if ($search === '') { $result = 0; Modified: branches/1.0/package/webinterface/altweb/admin/cidname.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/cidname.php 2013-03-17 21:15:47 UTC (rev 6000) +++ branches/1.0/package/webinterface/altweb/admin/cidname.php 2013-03-18 23:20:53 UTC (rev 6001) @@ -43,8 +43,8 @@ if (! $global_staff) { $result = 999; } elseif (isset($_POST['submit_add'])) { - $cidnum = trim($_POST['cidnum']); - $cidname = trim($_POST['cidname']); + $cidnum = tuqd($_POST['cidnum']); + $cidname = tuqd($_POST['cidname']); if (strlen($cidname) > 0) { if (($cmd = getPREFdef($global_prefs, 'number_format_cmdstr')) === '') { $cmd = '^[2-9][0-9][0-9][2-9][0-9][0-9][0-9][0-9][0-9][0-9]$'; Modified: branches/1.0/package/webinterface/altweb/admin/dnshosts.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/dnshosts.php 2013-03-17 21:15:47 UTC (rev 6000) +++ branches/1.0/package/webinterface/altweb/admin/dnshosts.php 2013-03-18 23:20:53 UTC (rev 6001) @@ -50,7 +50,7 @@ $value .= '~'.$db['data'][$i]['mac']; $value .= '~'; if ($db['data'][$i]['comment'] !== '') { - $value .= str_replace('~', '-', str_replace('"', "'", stripslashes($db['data'][$i]['comment']))); + $value .= str_replace('~', '-', $db['data'][$i]['comment']); } fwrite($fp, $value."\n"); } @@ -96,10 +96,10 @@ // function addDNSHOST(&$db, $id) { - $name = trim($_POST['name']); - $ip = trim($_POST['ip']); - $mac = trim($_POST['mac']); - $comment = trim($_POST['comment']); + $name = tuq($_POST['name']); + $ip = tuq($_POST['ip']); + $mac = tuq($_POST['mac']); + $comment = tuq($_POST['comment']); if ($name === '' || $ip === '') { return(FALSE); @@ -127,13 +127,13 @@ $n = count($db['data']); $id = $n; for ($i = 0; $i < $n; $i++) { - if ($db['data'][$i]['name'] === trim($_POST['name']) && $db['data'][$i]['ip'] === trim($_POST['ip'])) { + if ($db['data'][$i]['name'] === tuq($_POST['name']) && $db['data'][$i]['ip'] === tuq($_POST['ip'])) { $id = $i; break; } } - if (preg_match('/^[0-9a-fA-F][0-9a-fA-F.:]*[0-9a-fA-F]$/', trim($_POST['ip']))) { - $mac = trim($_POST['mac']); + if (preg_match('/^[0-9a-fA-F][0-9a-fA-F.:]*[0-9a-fA-F]$/', tuq($_POST['ip']))) { + $mac = tuq($_POST['mac']); if ($mac === '' || preg_match('/^[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}$/', $mac)) { if (addDNSHOST($db, $id)) { $result = saveDNSHOSTSsettings($DNSHOSTSCONFDIR, $DNSHOSTSCONFFILE, $db); Modified: branches/1.0/package/webinterface/altweb/admin/edit.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/edit.php 2013-03-17 21:15:47 UTC (rev 6000) +++ branches/1.0/package/webinterface/altweb/admin/edit.php 2013-03-18 23:20:53 UTC (rev 6001) @@ -117,8 +117,12 @@ if (! @copy($file, $tmpfile)) { return(FALSE); } - $data = stripslashes($text); - $data = str_replace(chr(13), '', $data); + if (get_magic_quotes_gpc()) { + $data = stripslashes($text); + $data = str_replace(chr(13), '', $data); + } else { + $data = str_replace(chr(13), '', $text); + } if (($ph = @fopen($file, "wb")) === FALSE) { if ($cleanup) { @unlink($tmpfile); Modified: branches/1.0/package/webinterface/altweb/admin/firewall.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/firewall.php 2013-03-17 21:15:47 UTC (rev 6000) +++ branches/1.0/package/webinterface/altweb/admin/firewall.php 2013-03-18 23:20:53 UTC (rev 6001) @@ -257,7 +257,7 @@ $value .= '~'.$db['data'][$i]['d_uport']; $value .= '~'; if ($db['data'][$i]['comment'] !== '') { - $value .= str_replace('~', '-', str_replace('"', "'", stripslashes($db['data'][$i]['comment']))); + $value .= str_replace('~', '-', $db['data'][$i]['comment']); } $value .= '~'.$db['data'][$i]['e_addr']; fwrite($fp, $value."\n"); @@ -317,16 +317,16 @@ fwrite($fp, "### Traffic Shaping\n"); $value = 'SHAPETYPE="'.$_POST['shaper_enable_type'].'"'; fwrite($fp, $value."\n"); - $value = 'EXTDOWN="'.trim($_POST['shaper_extdown']).'"'; + $value = 'EXTDOWN="'.tuq($_POST['shaper_extdown']).'"'; fwrite($fp, $value."\n"); - $value = 'EXTUP="'.trim($_POST['shaper_extup']).'"'; + $value = 'EXTUP="'.tuq($_POST['shaper_extup']).'"'; fwrite($fp, $value."\n"); - $value = 'VOIPPORTS="'.trim($_POST['shaper_voipports']).'"'; + $value = 'VOIPPORTS="'.tuq($_POST['shaper_voipports']).'"'; fwrite($fp, $value."\n"); } fwrite($fp, "### Block All Traffic\n"); - $value = 'BLOCK_HOSTS="'.trim($_POST['hosts_blocked']).'"'; + $value = 'BLOCK_HOSTS="'.tuq($_POST['hosts_blocked']).'"'; fwrite($fp, $value."\n"); if (isset($_POST['file_blocked'])) { $value = 'BLOCK_HOSTS_FILE="/mnt/kd/blocked-hosts"'; @@ -442,14 +442,14 @@ function addFWRule(&$db, $id) { $action = $_POST['action']; $proto = $_POST['proto']; - $s_addr = isset($_POST['s_addr']) ? str_replace(' ', '', $_POST['s_addr']) : ''; - $s_lport = isset($_POST['s_lport']) ? str_replace(' ', '', $_POST['s_lport']) : ''; - $s_uport = isset($_POST['s_uport']) ? str_replace(' ', '', $_POST['s_uport']) : ''; - $d_addr = isset($_POST['d_addr']) ? str_replace(' ', '', $_POST['d_addr']) : ''; - $d_lport = isset($_POST['d_lport']) ? str_replace(' ', '', $_POST['d_lport']) : ''; - $d_uport = isset($_POST['d_uport']) ? str_replace(' ', '', $_POST['d_uport']) : ''; - $e_addr = isset($_POST['e_addr']) ? str_replace(' ', '', $_POST['e_addr']) : ''; - $comment = isset($_POST['comment']) ? trim($_POST['comment']) : ''; + $s_addr = isset($_POST['s_addr']) ? str_replace(' ', '', tuq($_POST['s_addr'])) : ''; + $s_lport = isset($_POST['s_lport']) ? str_replace(' ', '', tuq($_POST['s_lport'])) : ''; + $s_uport = isset($_POST['s_uport']) ? str_replace(' ', '', tuq($_POST['s_uport'])) : ''; + $d_addr = isset($_POST['d_addr']) ? str_replace(' ', '', tuq($_POST['d_addr'])) : ''; + $d_lport = isset($_POST['d_lport']) ? str_replace(' ', '', tuq($_POST['d_lport'])) : ''; + $d_uport = isset($_POST['d_uport']) ? str_replace(' ', '', tuq($_POST['d_uport'])) : ''; + $e_addr = isset($_POST['e_addr']) ? str_replace(' ', '', tuq($_POST['e_addr'])) : ''; + $comment = isset($_POST['comment']) ? tuq($_POST['comment']) : ''; switch ($action) { case 'PASS_EXT_LOCAL': Modified: branches/1.0/package/webinterface/altweb/admin/followme.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/followme.php 2013-03-17 21:15:47 UTC (rev 6000) +++ branches/1.0/package/webinterface/altweb/admin/followme.php 2013-03-18 23:20:53 UTC (rev 6001) @@ -252,7 +252,7 @@ $result = 999; } elseif (isset($_POST['submit_add'])) { if (isset($_POST['key'])) { - $key = trim($_POST['key']); + $key = tuqd($_POST['key']); } else { $key = $global_user; } @@ -269,8 +269,8 @@ } $enabled = isset($_POST['enabled']) ? $_POST['enabled'] : array(); for ($i = 0; $i < $MAXNUM; $i++) { - $number[$i] = trim($_POST["number$i"]); - $timeout[$i] = trim($_POST["timeout$i"]); + $number[$i] = tuqd($_POST["number$i"]); + $timeout[$i] = tuqd($_POST["timeout$i"]); if ($USE_RULES && $number[$i] !== '') { if (! preg_match("/$NUMBER_FORMAT/", $number[$i])) { $result = 12; Modified: branches/1.0/package/webinterface/altweb/admin/ipsec.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/ipsec.php 2013-03-17 21:15:47 UTC (rev 6000) +++ branches/1.0/package/webinterface/altweb/admin/ipsec.php 2013-03-18 23:20:53 UTC (rev 6001) @@ -269,13 +269,13 @@ // function addTunnel(&$db, $id) { - $local_host = trim($_POST['local_host']); - $local_net = trim($_POST['local_net']); - $remote_host = trim($_POST['remote_host']); - $remote_net = trim($_POST['remote_net']); + $local_host = tuq($_POST['local_host']); + $local_net = tuq($_POST['local_net']); + $remote_host = tuq($_POST['remote_host']); + $remote_net = tuq($_POST['remote_net']); if (($method = $_POST['method']) === 'psk') { - $key = trim(stripslashes($_POST['key'])); + $key = tuq($_POST['key']); } else { $key = ''; } @@ -295,7 +295,7 @@ $p1_encrypt = $_POST['p1_encrypt']; $p1_hash = $_POST['p1_hash']; $p1_dhgroup = $_POST['p1_dhgroup']; - $p1_lifetime = trim(stripslashes($_POST['p1_lifetime'])); + $p1_lifetime = tuq($_POST['p1_lifetime']); $p2_encrypt = ''; if (isset($_POST['p2_encrypt'])) { @@ -316,9 +316,9 @@ $p2_auth = trim($p2_auth, ' ,'); $p2_pfsgroup = $_POST['p2_pfsgroup']; - $p2_lifetime = trim(stripslashes($_POST['p2_lifetime'])); + $p2_lifetime = tuq($_POST['p2_lifetime']); $nat_t = $_POST['nat_t']; - if (($auto_establish = trim(stripslashes($_POST['auto_establish']))) === 'none' ) { + if (($auto_establish = tuq($_POST['auto_establish'])) === 'none' ) { $auto_establish = ''; } @@ -356,7 +356,7 @@ $n = count($db['data']); $id = $n; for ($i = 0; $i < $n; $i++) { - if ($db['data'][$i]['remote_host'] === trim($_POST['remote_host'])) { + if ($db['data'][$i]['remote_host'] === tuq($_POST['remote_host'])) { $id = $i; break; } Modified: branches/1.0/package/webinterface/altweb/admin/ipsecmobile.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/ipsecmobile.php 2013-03-17 21:15:47 UTC (rev 6000) +++ branches/1.0/package/webinterface/altweb/admin/ipsecmobile.php 2013-03-18 23:20:53 UTC (rev 6001) @@ -159,7 +159,7 @@ $value = 'IPSECM_STATIC_ROUTES="'; fwrite($fp, "### Static Routes\n".$value."\n"); - $value = stripslashes($_POST['static_routes']); + $value = stripshellsafe($_POST['static_routes']); $value = str_replace(chr(13), '', $value); if (($value = trim($value, chr(10))) !== '') { fwrite($fp, $value."\n"); @@ -178,7 +178,7 @@ $value = 'IPSECM_P1_DHGROUP="'.$_POST['p1_dhgroup'].'"'; fwrite($fp, "### Phase 1 DH Group\n".$value."\n"); - $value = 'IPSECM_P1_LIFETIME="'.trim($_POST['p1_lifetime']).'"'; + $value = 'IPSECM_P1_LIFETIME="'.tuq($_POST['p1_lifetime']).'"'; fwrite($fp, "### Phase 1 Lifetime\n".$value."\n"); $value = ''; @@ -204,13 +204,13 @@ $value = 'IPSECM_P2_PFSGROUP="'.$_POST['p2_pfsgroup'].'"'; fwrite($fp, "### Phase 2 PFS Group\n".$value."\n"); - $value = 'IPSECM_P2_LIFETIME="'.trim($_POST['p2_lifetime']).'"'; + $value = 'IPSECM_P2_LIFETIME="'.tuq($_POST['p2_lifetime']).'"'; fwrite($fp, "### Phase 2 Lifetime\n".$value."\n"); $value = 'IPSECM_CERT_KEYSIZE="'.$_POST['key_size'].'"'; fwrite($fp, "### Private Key Size\n".$value."\n"); - $value = 'IPSECM_CERT_DNSNAME="'.str_replace(' ', '', $_POST['dns_name']).'"'; + $value = 'IPSECM_CERT_DNSNAME="'.str_replace(' ', '', tuq($_POST['dns_name'])).'"'; fwrite($fp, "### Server Cert DNS Name\n".$value."\n"); if (opensslIPSECMOBILEis_valid($openssl)) { @@ -223,16 +223,16 @@ $value = 'IPSECM_RSA_KEY="server.key"'; fwrite($fp, "### Key File\n".$value."\n"); } else { - $value = isset($_POST['path']) ? trim($_POST['path']) : '/mnt/kd/ipsec'; + $value = isset($_POST['path']) ? tuq($_POST['path']) : '/mnt/kd/ipsec'; $value = 'IPSECM_RSA_PATH="'.$value.'"'; fwrite($fp, "### Certificate Directory\n".$value."\n"); - $value = isset($_POST['ca']) ? trim($_POST['ca']) : 'ca.crt'; + $value = isset($_POST['ca']) ? tuq($_POST['ca']) : 'ca.crt'; $value = 'IPSECM_RSA_CA="'.$value.'"'; fwrite($fp, "### CA File\n".$value."\n"); - $value = isset($_POST['cert']) ? trim($_POST['cert']) : 'server.crt'; + $value = isset($_POST['cert']) ? tuq($_POST['cert']) : 'server.crt'; $value = 'IPSECM_RSA_CERT="'.$value.'"'; fwrite($fp, "### CERT File\n".$value."\n"); - $value = isset($_POST['key']) ? trim($_POST['key']) : 'server.key'; + $value = isset($_POST['key']) ? tuq($_POST['key']) : 'server.key'; $value = 'IPSECM_RSA_KEY="'.$value.'"'; fwrite($fp, "### Key File\n".$value."\n"); } @@ -269,7 +269,7 @@ } // Rebuild openssl.cnf template for new CA $key_size = $_POST['key_size']; - $dns_name = str_replace(' ', '', $_POST['dns_name']); + $dns_name = str_replace(' ', '', tuq($_POST['dns_name'])); if (($openssl = ipsecmobile_openssl($key_size, $dns_name)) !== FALSE) { if (opensslCREATEselfCert($openssl)) { if (opensslCREATEserverCert($openssl)) { @@ -290,7 +290,7 @@ $result = 2; } } elseif (isset($_POST['submit_new_client'])) { - if (($value = trim($_POST['new_client'])) !== '') { + if (($value = tuq($_POST['new_client'])) !== '') { if (preg_match('/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/', $value)) { if (! is_file($openssl['key_dir'].'/'.$value.'.crt') && ! is_file($openssl['key_dir'].'/'.$value.'.key')) { Modified: branches/1.0/package/webinterface/altweb/admin/ipsecxauth.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/ipsecxauth.php 2013-03-17 21:15:47 UTC (rev 6000) +++ branches/1.0/package/webinterface/altweb/admin/ipsecxauth.php 2013-03-18 23:20:53 UTC (rev 6001) @@ -91,25 +91,25 @@ $value = 'IPSECM_XAUTH_POOLSIZE="'.$_POST['pool_size'].'"'; fwrite($fp, "### Pool Size\n".$value."\n"); - $value = 'IPSECM_XAUTH_POOLBASE="'.trim($_POST['pool_base']).'"'; + $value = 'IPSECM_XAUTH_POOLBASE="'.tuq($_POST['pool_base']).'"'; fwrite($fp, "### Pool Base\n".$value."\n"); - $value = 'IPSECM_XAUTH_POOLMASK="'.trim($_POST['pool_mask']).'"'; + $value = 'IPSECM_XAUTH_POOLMASK="'.tuq($_POST['pool_mask']).'"'; fwrite($fp, "### Pool Mask\n".$value."\n"); - $value = 'IPSECM_XAUTH_DNS="'.trim($_POST['dns']).'"'; + $value = 'IPSECM_XAUTH_DNS="'.tuq($_POST['dns']).'"'; fwrite($fp, "### MS DNS\n".$value."\n"); - $value = 'IPSECM_XAUTH_WINS="'.trim($_POST['wins']).'"'; + $value = 'IPSECM_XAUTH_WINS="'.tuq($_POST['wins']).'"'; fwrite($fp, "### MS WINS\n".$value."\n"); - $value = 'IPSECM_XAUTH_NETWORK="'.trim($_POST['network']).'"'; + $value = 'IPSECM_XAUTH_NETWORK="'.tuq($_POST['network']).'"'; fwrite($fp, "### Network\n".$value."\n"); - $value = 'IPSECM_XAUTH_DOMAIN="'.trim($_POST['domain']).'"'; + $value = 'IPSECM_XAUTH_DOMAIN="'.tuq($_POST['domain']).'"'; fwrite($fp, "### Default Domain\n".$value."\n"); - $value = 'IPSECM_XAUTH_BANNER="'.trim($_POST['banner']).'"'; + $value = 'IPSECM_XAUTH_BANNER="'.tuq($_POST['banner']).'"'; fwrite($fp, "### Login Message\n".$value."\n"); $value = 'IPSECM_XAUTH_SAVE_PASSWD="'.$_POST['save_passwd'].'"'; @@ -125,8 +125,8 @@ // function addUserPass(&$db, $id) { - $user = str_replace(' ', '', $_POST['user']); - $pass = str_replace(' ', '', stripslashes($_POST['pass'])); + $user = str_replace(' ', '', stripshellsafe($_POST['user'])); + $pass = str_replace(' ', '', stripshellsafe($_POST['pass'])); if ($user === '') { return(FALSE); @@ -156,7 +156,7 @@ $n = count($db['data']); $id = $n; for ($i = 0; $i < $n; $i++) { - if ($db['data'][$i]['user'] === str_replace(' ', '', $_POST['user'])) { + if ($db['data'][$i]['user'] === str_replace(' ', '', stripshellsafe($_POST['user']))) { $id = $i; break; } Modified: branches/1.0/package/webinterface/altweb/admin/network.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/network.php 2013-03-17 21:15:47 UTC (rev 6000) +++ branches/1.0/package/webinterface/altweb/admin/network.php 2013-03-18 23:20:53 UTC (rev 6001) @@ -139,7 +139,7 @@ } } - $tz = ($_POST['timezone'] !== '') ? $_POST['timezone'] : trim($_POST['other_timezone']); + $tz = ($_POST['timezone'] !== '') ? $_POST['timezone'] : tuq($_POST['other_timezone']); if ($tz !== '') { if (! is_file("/usr/share/zoneinfo/$tz")) { return(103); @@ -184,28 +184,28 @@ if ($_POST['ip_type'] === 'dhcp') { $value = 'EXTIP=""'; } else { - $value = 'EXTIP="'.trim($_POST['static_ip']).'"'; + $value = 'EXTIP="'.tuq($_POST['static_ip']).'"'; } fwrite($fp, "### External Static IPv4\n".$value."\n"); if ($_POST['ip_type'] === 'dhcp') { $value = 'EXTNM=""'; } else { - $value = 'EXTNM="'.trim($_POST['mask_ip']).'"'; + $value = 'EXTNM="'.tuq($_POST['mask_ip']).'"'; } fwrite($fp, "### External Static IPv4 NetMask\n".$value."\n"); if ($_POST['ip_type'] === 'dhcp') { $value = 'EXTGW=""'; } else { - $value = 'EXTGW="'.trim($_POST['gateway_ip']).'"'; + $value = 'EXTGW="'.tuq($_POST['gateway_ip']).'"'; } fwrite($fp, "### External Static IPv4 Gateway\n".$value."\n"); if ($_POST['ip_type'] === 'dhcp') { $value = 'EXTIPV6=""'; } else { - $value = trim($_POST['static_ipv6']); + $value = tuq($_POST['static_ipv6']); if ($value !== '' && strpos($value, '/') === FALSE) { $value="$value/64"; } @@ -216,7 +216,7 @@ if ($_POST['ip_type'] === 'dhcp') { $value = 'EXTGWIPV6=""'; } else { - $value = trim($_POST['gateway_ipv6']); + $value = tuq($_POST['gateway_ipv6']); if (($pos = strpos($value, '/')) !== FALSE) { $value=substr($value, 0, $pos); } @@ -224,25 +224,25 @@ } fwrite($fp, "### External Static IPv6 Gateway\n".$value."\n"); - $value = 'PPPOEUSER="'.trim($_POST['user_pppoe']).'"'; + $value = 'PPPOEUSER="'.tuq($_POST['user_pppoe']).'"'; fwrite($fp, "### PPPoE Username\n".$value."\n"); $value = 'PPPOEPASS="'.string2RCconfig(trim($_POST['pass_pppoe'])).'"'; fwrite($fp, "### PPPoE Password\n".$value."\n"); - $value = 'HOSTNAME="'.trim($_POST['hostname']).'"'; + $value = 'HOSTNAME="'.tuq($_POST['hostname']).'"'; fwrite($fp, "### Hostname\n".$value."\n"); - $value = 'DOMAIN="'.trim($_POST['domain']).'"'; + $value = 'DOMAIN="'.tuq($_POST['domain']).'"'; fwrite($fp, "### Domain\n".$value."\n"); $value = isset($_POST['local_domain']) ? 'LOCALDNS_LOCAL_DOMAIN="yes"' : 'LOCALDNS_LOCAL_DOMAIN="no"'; fwrite($fp, "### Local Domain\n".$value."\n"); - $value = 'DNS="'.trim($_POST['dns']).'"'; + $value = 'DNS="'.tuq($_POST['dns']).'"'; fwrite($fp, "### DNS Servers\n".$value."\n"); - $value = 'VLANS="'.trim($_POST['vlans']).'"'; + $value = 'VLANS="'.tuq($_POST['vlans']).'"'; fwrite($fp, "### VLAN Interfaces\n".$value."\n"); $value = isset($_POST['vlan_cos']) ? 'VLANCOS="yes"' : 'VLANCOS=""'; @@ -251,13 +251,13 @@ $value = 'INTIF="'.$_POST['int_eth'].'"'; fwrite($fp, "### 1st LAN Interface\n".$value."\n"); - $value = 'INTIP="'.trim($_POST['int_ip']).'"'; + $value = 'INTIP="'.tuq($_POST['int_ip']).'"'; fwrite($fp, "### 1st LAN IPv4\n".$value."\n"); - $value = 'INTNM="'.trim($_POST['int_mask_ip']).'"'; + $value = 'INTNM="'.tuq($_POST['int_mask_ip']).'"'; fwrite($fp, "### 1st LAN NetMask\n".$value."\n"); - $value = trim($_POST['int_ipv6']); + $value = tuq($_POST['int_ipv6']); if ($value !== '' && strpos($value, '/') === FALSE) { $value="$value/64"; } @@ -267,13 +267,13 @@ $value = 'INT2IF="'.$_POST['int2_eth'].'"'; fwrite($fp, "### 2nd LAN Interface\n".$value."\n"); - $value = 'INT2IP="'.trim($_POST['int2_ip']).'"'; + $value = 'INT2IP="'.tuq($_POST['int2_ip']).'"'; fwrite($fp, "### 2nd LAN IPv4\n".$value."\n"); - $value = 'INT2NM="'.trim($_POST['int2_mask_ip']).'"'; + $value = 'INT2NM="'.tuq($_POST['int2_mask_ip']).'"'; fwrite($fp, "### 2nd LAN NetMask\n".$value."\n"); - $value = trim($_POST['int2_ipv6']); + $value = tuq($_POST['int2_ipv6']); if ($value !== '' && strpos($value, '/') === FALSE) { $value="$value/64"; } @@ -283,13 +283,13 @@ $value = 'INT3IF="'.$_POST['int3_eth'].'"'; fwrite($fp, "### 3rd LAN Interface\n".$value."\n"); - $value = 'INT3IP="'.trim($_POST['int3_ip']).'"'; + $value = 'INT3IP="'.tuq($_POST['int3_ip']).'"'; fwrite($fp, "### 3rd LAN IPv4\n".$value."\n"); - $value = 'INT3NM="'.trim($_POST['int3_mask_ip']).'"'; + $value = 'INT3NM="'.tuq($_POST['int3_mask_ip']).'"'; fwrite($fp, "### 3rd LAN NetMask\n".$value."\n"); - $value = trim($_POST['int3_ipv6']); + $value = tuq($_POST['int3_ipv6']); if ($value !== '' && strpos($value, '/') === FALSE) { $value="$value/64"; } @@ -299,13 +299,13 @@ $value = 'DMZIF="'.$_POST['dmz_eth'].'"'; fwrite($fp, "### DMZ Interface\n".$value."\n"); - $value = 'DMZIP="'.trim($_POST['dmz_ip']).'"'; + $value = 'DMZIP="'.tuq($_POST['dmz_ip']).'"'; fwrite($fp, "### DMZ IPv4\n".$value."\n"); - $value = 'DMZNM="'.trim($_POST['dmz_mask_ip']).'"'; + $value = 'DMZNM="'.tuq($_POST['dmz_mask_ip']).'"'; fwrite($fp, "### DMZ NetMask\n".$value."\n"); - $value = trim($_POST['dmz_ipv6']); + $value = tuq($_POST['dmz_ipv6']); if ($value !== '' && strpos($value, '/') === FALSE) { $value="$value/64"; } @@ -327,7 +327,7 @@ $value = 'NTPSERVS="us.pool.ntp.org"'; if (isset($_POST['other_ntp_server'], $_POST['ntp_server'])) { - $t_value = trim($_POST['other_ntp_server']); + $t_value = tuq($_POST['other_ntp_server']); if ($_POST['ntp_server'] !== '') { if ($t_value !== '') { $value = 'NTPSERVS="'.$_POST['ntp_server'].' '.$t_value.'"'; @@ -343,20 +343,20 @@ if ($_POST['timezone'] !== '') { $value = 'TIMEZONE="'.$_POST['timezone'].'"'; } else { - $value = 'TIMEZONE="'.trim($_POST['other_timezone']).'"'; + $value = 'TIMEZONE="'.tuq($_POST['other_timezone']).'"'; } fwrite($fp, "### UNIX Timezone\n".$value."\n"); - $value = 'SMTP_SERVER="'.trim($_POST['smtp_server']).'"'; + $value = 'SMTP_SERVER="'.tuq($_POST['smtp_server']).'"'; fwrite($fp, "### SMTP Server\n".$value."\n"); - $value = 'SMTP_DOMAIN="'.trim($_POST['smtp_domain']).'"'; + $value = 'SMTP_DOMAIN="'.tuq($_POST['smtp_domain']).'"'; fwrite($fp, "### SMTP Domain\n".$value."\n"); $value = 'SMTP_AUTH="'.$_POST['smtp_auth'].'"'; fwrite($fp, "### SMTP Authentication Type\n".$value."\n"); - $value = 'SMTP_PORT="'.trim($_POST['smtp_port']).'"'; + $value = 'SMTP_PORT="'.tuq($_POST['smtp_port']).'"'; fwrite($fp, "### SMTP TCP Port\n".$value."\n"); fwrite($fp, "### SMTP TLS\n"); @@ -379,13 +379,13 @@ $value = 'SMTP_CERTCHECK="'.$_POST['smtp_certcheck'].'"'; fwrite($fp, $value."\n"); if ($_POST['smtp_certcheck'] === 'on') { - $value = 'SMTP_CA="'.trim($_POST['smtp_ca_cert']).'"'; + $value = 'SMTP_CA="'.tuq($_POST['smtp_ca_cert']).'"'; } else { $value = 'SMTP_CA=""'; } fwrite($fp, $value."\n"); - $value = 'SMTP_USER="'.trim($_POST['smtp_user']).'"'; + $value = 'SMTP_USER="'.tuq($_POST['smtp_user']).'"'; fwrite($fp, "### SMTP Auth Username\n".$value."\n"); $value = 'SMTP_PASS="'.string2RCconfig(trim($_POST['smtp_pass'])).'"'; @@ -427,7 +427,7 @@ $value = 'UPNP_LISTEN="'.trim($x_value).'"'; fwrite($fp, "### UPnP Listen Interfaces\n".$value."\n"); - $value = 'HTTPDIR="'.trim($_POST['http_dir']).'"'; + $value = 'HTTPDIR="'.tuq($_POST['http_dir']).'"'; fwrite($fp, "### HTTP Server Directory\n".$value."\n"); $value = isset($_POST['http_cgi']) ? 'HTTPCGI="yes"' : 'HTTPCGI="no"'; @@ -439,7 +439,7 @@ $value = isset($_POST['http_accesslog']) ? 'HTTP_ACCESSLOG="yes"' : 'HTTP_ACCESSLOG="no"'; fwrite($fp, "### HTTP access logging\n".$value."\n"); - $value = 'HTTPSDIR="'.trim($_POST['https_dir']).'"'; + $value = 'HTTPSDIR="'.tuq($_POST['https_dir']).'"'; fwrite($fp, "### HTTPS Server Directory\n".$value."\n"); $value = isset($_POST['https_cgi']) ? 'HTTPSCGI="yes"' : 'HTTPSCGI="no"'; @@ -451,7 +451,7 @@ $value = isset($_POST['https_accesslog']) ? 'HTTPS_ACCESSLOG="yes"' : 'HTTPS_ACCESSLOG="no"'; fwrite($fp, "### HTTPS access logging\n".$value."\n"); - $value = 'HTTPSCERT="'.trim($_POST['https_cert']).'"'; + $value = 'HTTPSCERT="'.tuq($_POST['https_cert']).'"'; if (isset($_POST['create_cert']) && is_opensslHERE()) { if (($countryName = getPREFdef($global_prefs, 'dn_country_name_cmdstr')) === '') { $countryName = 'US'; @@ -470,7 +470,7 @@ if (($orgUnit = getPREFdef($global_prefs, 'dn_org_unit_cmdstr')) === '') { $orgUnit = 'Web Interface'; } - if (($commonName = trim($_POST['hostname'])) === '') { + if (($commonName = tuq($_POST['hostname'])) === '') { $commonName = '*'; } if (($email = getPREFdef($global_prefs, 'dn_email_address_cmdstr')) === '') { @@ -483,7 +483,7 @@ } fwrite($fp, "### HTTPS Certificate File\n".$value."\n"); - $value = 'PHONEPROV_ALLOW="'.trim($_POST['phoneprov_allow']).'"'; + $value = 'PHONEPROV_ALLOW="'.tuq($_POST['phoneprov_allow']).'"'; fwrite($fp, "### /phoneprov/ Allowed IPs\n".$value."\n"); $x_value = ''; @@ -520,18 +520,18 @@ if ($_POST['dd_service'] !== '') { $value = 'DDSERVICE="'.$_POST['dd_service'].'"'; } else { - $value = 'DDSERVICE="'.trim($_POST['other_dd_service']).'"'; + $value = 'DDSERVICE="'.tuq($_POST['other_dd_service']).'"'; } fwrite($fp, $value."\n"); if ($_POST['dd_getip'] !== '') { $value = 'DDGETIP="'.$_POST['dd_getip'].'"'; } else { - $value = 'DDGETIP="'.trim($_POST['other_dd_getip']).'"'; + $value = 'DDGETIP="'.tuq($_POST['other_dd_getip']).'"'; } fwrite($fp, $value."\n"); - $value = 'DDHOST="'.trim($_POST['dd_host']).'"'; + $value = 'DDHOST="'.tuq($_POST['dd_host']).'"'; fwrite($fp, $value."\n"); - $value = 'DDUSER="'.trim($_POST['dd_user']).'"'; + $value = 'DDUSER="'.tuq($_POST['dd_user']).'"'; fwrite($fp, $value."\n"); $value = 'DDPASS="'.string2RCconfig(trim($_POST['dd_pass'])).'"'; fwrite($fp, $value."\n"); @@ -539,13 +539,13 @@ fwrite($fp, "### Safe Asterisk - SIP Monitoring\n"); $value = 'SAFE_ASTERISK="'.$_POST['safe_asterisk'].'"'; fwrite($fp, $value."\n"); - $value = 'SAFE_ASTERISK_NOTIFY="'.trim($_POST['safe_asterisk_notify']).'"'; + $value = 'SAFE_ASTERISK_NOTIFY="'.tuq($_POST['safe_asterisk_notify']).'"'; fwrite($fp, $value."\n"); - $value = 'SAFE_ASTERISK_NOTIFY_FROM="'.trim($_POST['safe_asterisk_notify_from']).'"'; + $value = 'SAFE_ASTERISK_NOTIFY_FROM="'.tuq($_POST['safe_asterisk_notify_from']).'"'; fwrite($fp, $value."\n"); - $value = 'MONITOR_ASTERISK_SIP_TRUNKS="'.trim($_POST['monitor_sip_trunks']).'"'; + $value = 'MONITOR_ASTERISK_SIP_TRUNKS="'.tuq($_POST['monitor_sip_trunks']).'"'; fwrite($fp, $value."\n"); - $value = 'MONITOR_ASTERISK_SIP_PEERS="'.trim($_POST['monitor_sip_peers']).'"'; + $value = 'MONITOR_ASTERISK_SIP_PEERS="'.tuq($_POST['monitor_sip_peers']).'"'; fwrite($fp, $value."\n"); $value = 'MONITOR_ASTERISK_SIP_STATUS_UPDATES="'.$_POST['monitor_status_updates'].'"'; fwrite($fp, $value."\n"); @@ -559,7 +559,7 @@ if ($_POST['ups_type'] === 'usb') { $value = 'UPSDEVICE=""'; } else { - $value = 'UPSDEVICE="'.trim($_POST['ups_device']).'"'; + $value = 'UPSDEVICE="'.tuq($_POST['ups_device']).'"'; } fwrite($fp, $value."\n"); } else { @@ -570,9 +570,9 @@ $value = 'UPSDEVICE=""'; fwrite($fp, $value."\n"); } - $value = 'UPS_NOTIFY="'.trim($_POST['ups_notify']).'"'; + $value = 'UPS_NOTIFY="'.tuq($_POST['ups_notify']).'"'; fwrite($fp, $value."\n"); - $value = 'UPS_NOTIFY_FROM="'.trim($_POST['ups_notify_from']).'"'; + $value = 'UPS_NOTIFY_FROM="'.tuq($_POST['ups_notify_from']).'"'; fwrite($fp, $value."\n"); $value = 'UPS_KILL_POWER="'.$_POST['ups_kill_power'].'"'; fwrite($fp, $value."\n"); Modified: branches/1.0/package/webinterface/altweb/admin/openvpn.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/openvpn.php 2013-03-17 21:15:47 UTC (rev 6000) +++ branches/1.0/package/webinterface/altweb/admin/openvpn.php 2013-03-18 23:20:53 UTC (rev 6001) @@ -166,7 +166,7 @@ $value = 'OVPN_DEV="'.$_POST['device'].'"'; fwrite($fp, "### Device\n".$value."\n"); - $value = 'OVPN_PORT="'.trim($_POST['port']).'"'; + $value = 'OVPN_PORT="'.tuq($_POST['port']).'"'; fwrite($fp, "### Port Number\n".$value."\n"); $value = 'OVPN_PROTOCOL="'.$_POST['protocol'].'"'; @@ -187,16 +187,16 @@ $value = 'OVPN_AUTH="'.$_POST['auth_hmac'].'"'; fwrite($fp, "### Auth HMAC\n".$value."\n"); - $value = 'OVPN_TUNNEL_HOSTS="'.trim($_POST['tunnel_external_hosts']).'"'; + $value = 'OVPN_TUNNEL_HOSTS="'.tuq($_POST['tunnel_external_hosts']).'"'; fwrite($fp, "### Allowed External Hosts\n".$value."\n"); - $value = 'OVPN_HOSTNAME="'.trim($_POST['server_hostname']).'"'; + $value = 'OVPN_HOSTNAME="'.tuq($_POST['server_hostname']).'"'; fwrite($fp, "### Server Hostname\n".$value."\n"); - $value = 'OVPN_SERVER="'.trim($_POST['server']).'"'; + $value = 'OVPN_SERVER="'.tuq($_POST['server']).'"'; fwrite($fp, "### Server IPv4 Network\n".$value."\n"); - $value = 'OVPN_SERVERV6="'.trim($_POST['serverv6']).'"'; + $value = 'OVPN_SERVERV6="'.tuq($_POST['serverv6']).'"'; fwrite($fp, "### Server IPv6 Network\n".$value."\n"); $value = 'OVPN_TOPOLOGY="'.$_POST['topology'].'"'; @@ -204,7 +204,7 @@ $value = 'OVPN_PUSH="'; fwrite($fp, "### Server Push\n".$value."\n"); - $value = stripslashes($_POST['push']); + $value = stripshellsafe($_POST['push']); $value = str_replace(chr(13), '', $value); if (($value = trim($value, chr(10))) !== '') { fwrite($fp, $value."\n"); @@ -213,7 +213,7 @@ $value = 'OVPN_OTHER="'; fwrite($fp, "### Raw Commands\n".$value."\n"); - $value = stripslashes($_POST['other']); + $value = stripshellsafe($_POST['other']); $value = str_replace(chr(13), '', $value); if (($value = trim($value, chr(10))) !== '') { fwrite($fp, $value."\n"); @@ -259,20 +259,20 @@ } } else { $base = '/mnt/kd/openvpn/easy-rsa/keys'; - $value = isset($_POST['ca']) ? trim($_POST['ca']) : $base.'/ca.crt'; + $value = isset($_POST['ca']) ? tuq($_POST['ca']) : $base.'/ca.crt'; $value = 'OVPN_CA="'.$value.'"'; fwrite($fp, "### CA File\n".$value."\n"); - $value = isset($_POST['cert']) ? trim($_POST['cert']) : $base.'/server.crt'; + $value = isset($_POST['cert']) ? tuq($_POST['cert']) : $base.'/server.crt'; $value = 'OVPN_CERT="'.$value.'"'; fwrite($fp, "### CERT File\n".$value."\n"); - $value = isset($_POST['key']) ? trim($_POST['key']) : $base.'/server.key'; + $value = isset($_POST['key']) ? tuq($_POST['key']) : $base.'/server.key'; $value = 'OVPN_KEY="'.$value.'"'; fwrite($fp, "### Key File\n".$value."\n"); - $value = isset($_POST['dh']) ? trim($_POST['dh']) : $base.'/dh1024.pem'; + $value = isset($_POST['dh']) ? tuq($_POST['dh']) : $base.'/dh1024.pem'; $value = 'OVPN_DH="'.$value.'"'; fwrite($fp, "### DH File\n".$value."\n"); if ($_POST['tls_auth'] === 'yes') { - $value = isset($_POST['ta']) ? trim($_POST['ta']) : $base.'/ta.key'; + $value = isset($_POST['ta']) ? tuq($_POST['ta']) : $base.'/ta.key'; $value = 'OVPN_TA="'.$value.'"'; } else { $value = 'OVPN_TA=""'; @@ -433,7 +433,7 @@ $result = 2; } } elseif (isset($_POST['submit_new_client'])) { - if (($value = trim($_POST['new_client'])) !== '') { + if (($value = tuq($_POST['new_client'])) !== '') { if (preg_match('/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/', $value)) { if ($value !== 'ta' && ! is_file($openssl['key_dir'].'/'.$value.'.crt') && Modified: branches/1.0/package/webinterface/altweb/admin/openvpnclient.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/openvpnclient.php 2013-03-17 21:15:47 UTC (rev 6000) +++ branches/1.0/package/webinterface/altweb/admin/openvpnclient.php 2013-03-18 23:20:53 UTC (rev 6001) @@ -101,7 +101,7 @@ $value = 'OVPNC_DEV="'.$_POST['device'].'"'; fwrite($fp, "### Device\n".$value."\n"); - $value = 'OVPNC_PORT="'.trim($_POST['port']).'"'; + $value = 'OVPNC_PORT="'.tuq($_POST['port']).'"'; fwrite($fp, "### Port Number\n".$value."\n"); $value = 'OVPNC_PROTOCOL="'.$_POST['protocol'].'"'; @@ -122,8 +122,8 @@ $value = 'OVPNC_AUTH="'.$_POST['auth_hmac'].'"'; fwrite($fp, "### Auth HMAC\n".$value."\n"); - if ($_POST['auth_method'] === 'yes' && trim($_POST['auth_user']) !== '' && trim($_POST['auth_pass']) !== '') { - $value = 'OVPNC_USER_PASS="'.trim($_POST['auth_user']).' '.string2RCconfig(trim($_POST['auth_pass'])).'"'; + if ($_POST['auth_method'] === 'yes' && tuq($_POST['auth_user']) !== '' && trim($_POST['auth_pass']) !== '') { + $value = 'OVPNC_USER_PASS="'.tuq($_POST['auth_user']).' '.string2RCconfig(trim($_POST['auth_pass'])).'"'; } else { $value = 'OVPNC_USER_PASS=""'; } @@ -132,15 +132,15 @@ $value = 'OVPNC_NSCERTTYPE="'.$_POST['nscerttype'].'"'; fwrite($fp, "### nsCertType\n".$value."\n"); - $value = 'OVPNC_REMOTE="'.trim($_POST['remote']).'"'; + $value = 'OVPNC_REMOTE="'.tuq($_POST['remote']).'"'; fwrite($fp, "### Server Network\n".$value."\n"); - $value = 'OVPNC_SERVER="'.trim($_POST['server']).'"'; + $value = 'OVPNC_SERVER="'.tuq($_POST['server']).'"'; fwrite($fp, "### Server Network\n".$value."\n"); $value = 'OVPNC_OTHER="'; fwrite($fp, "### Raw Commands\n".$value."\n"); - $value = stripslashes($_POST['other']); + $value = stripshellsafe($_POST['other']); $value = str_replace(chr(13), '', $value); if (($value = trim($value, chr(10))) !== '') { fwrite($fp, $value."\n"); Modified: branches/1.0/package/webinterface/altweb/admin/openvpnuserpass.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/openvpnuserpass.php 2013-03-17 21:15:47 UTC (rev 6000) +++ branches/1.0/package/webinterface/altweb/admin/openvpnuserpass.php 2013-03-18 23:20:53 UTC (rev 6001) @@ -89,8 +89,8 @@ // function addUserPass(&$db, $id) { - $user = str_replace(' ', '', $_POST['user']); - $pass = str_replace(' ', '', stripslashes($_POST['pass'])); + $user = str_replace(' ', '', stripshellsafe($_POST['user'])); + $pass = str_replace(' ', '', stripshellsafe($_POST['pass'])); if ($user === '') { return(FALSE); @@ -120,7 +120,7 @@ $n = count($db['data']); $id = $n; for ($i = 0; $i < $n; $i++) { - if ($db['data'][$i]['user'] === str_replace(' ', '', $_POST['user'])) { + if ($db['data'][$i]['user'] === str_replace(' ', '', stripshellsafe($_POST['user']))) { $id = $i; break; } Modified: branches/1.0/package/webinterface/altweb/admin/pptp.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/pptp.php 2013-03-17 21:15:47 UTC (rev 6000) +++ branches/1.0/package/webinterface/altweb/admin/pptp.php 2013-03-18 23:20:53 UTC (rev 6001) @@ -128,9 +128,9 @@ fwrite($fp, '"'."\n"); $pool = $_POST['pool_num']; - if (($value = str_replace(' ', '', $_POST['pool_remote'])) !== '') { + if (($value = str_replace(' ', '', tuq($_POST['pool_remote']))) !== '') { $pool .= ' '.$value; - if (($value = str_replace(' ', '', $_POST['pool_server'])) !== '') { + if (($value = str_replace(' ', '', tuq($_POST['pool_server']))) !== '') { $pool .= ' '.$value; } else { $pool = ''; @@ -142,7 +142,7 @@ fwrite($fp, "### PPTP Address Pool\n".$value."\n"); if ($pool !== '') { - $value = 'PPTP_SUBNET="'.str_replace(' ', '', $_POST['subnet']).'"'; + $value = 'PPTP_SUBNET="'.str_replace(' ', '', tuq($_POST['subnet'])).'"'; } else { $value = 'PPTP_SUBNET=""'; } @@ -151,19 +151,19 @@ $value = 'PPTP_VERBOSITY="'.$_POST['verbosity'].'"'; fwrite($fp, "### Log Verbosity\n".$value."\n"); - $value = 'PPTP_DNS="'.trim($_POST['dns']).'"'; + $value = 'PPTP_DNS="'.tuq($_POST['dns']).'"'; fwrite($fp, "### MS DNS\n".$value."\n"); - $value = 'PPTP_WINS="'.trim($_POST['wins']).'"'; + $value = 'PPTP_WINS="'.tuq($_POST['wins']).'"'; fwrite($fp, "### MS WINS\n".$value."\n"); - $value = 'PPTP_TUNNEL_EXTERNAL_HOSTS="'.trim($_POST['tunnel_external_hosts']).'"'; + $value = 'PPTP_TUNNEL_EXTERNAL_HOSTS="'.tuq($_POST['tunnel_external_hosts']).'"'; fwrite($fp, "### Allow External Hosts for Tunnel\n".$value."\n"); - $value = 'PPTP_ALLOW_HOSTS="'.trim($_POST['allow_hosts']).'"'; + $value = 'PPTP_ALLOW_HOSTS="'.tuq($_POST['allow_hosts']).'"'; fwrite($fp, "### Allow Hosts\n".$value."\n"); - $value = 'PPTP_DENY_HOSTS="'.trim($_POST['deny_hosts']).'"'; + $value = 'PPTP_DENY_HOSTS="'.tuq($_POST['deny_hosts']).'"'; fwrite($fp, "### Deny Hosts\n".$value."\n"); $value = 'PPTP_DENY_LOG="'.$_POST['deny_log'].'"'; @@ -179,8 +179,8 @@ // function addUserPass(&$db, $id) { - $user = str_replace(' ', '', $_POST['user']); - $pass = str_replace(' ', '', stripslashes($_POST['pass'])); + $user = str_replace(' ', '', stripshellsafe($_POST['user'])); + $pass = str_replace(' ', '', stripshellsafe($_POST['pass'])); if ($user === '') { return(FALSE); @@ -210,7 +210,7 @@ $n = count($db['data']); $id = $n; for ($i = 0; $i < $n; $i++) { - if ($db['data'][$i]['user'] === str_replace(' ', '', $_POST['user'])) { + if ($db['data'][$i]['user'] === str_replace(' ', '', stripshellsafe($_POST['user']))) { $id = $i; break; } Modified: branches/1.0/package/webinterface/altweb/admin/prefs.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/prefs.php 2013-03-17 21:15:47 UTC (rev 6000) +++ branches/1.0/package/webinterface/altweb/admin/prefs.php 2013-03-18 23:20:53 UTC (rev 6001) @@ -104,11 +104,11 @@ $value = 'status_custom_asterisk_status = yes'; fwrite($fp, $value."\n"); } - if (($value = trim($_POST['asterisk_name'])) !== '') { + if (($value = tuqp($_POST['asterisk_name'])) !== '') { $value = 'status_custom_asterisk_name_cmdstr = "'.$value.'"'; fwrite($fp, $value."\n"); } - if (($value = trim($_POST['asterisk_cmd'])) !== '') { + if (($value = tuqp($_POST['asterisk_cmd'])) !== '') { $value = 'status_custom_asterisk_cmdstr = "'.$value.'"'; fwrite($fp, $value."\n"); } @@ -124,11 +124,11 @@ $value = 'status_show_firewall_states = yes'; fwrite($fp, $value."\n"); } - if (($value = trim($_POST['firewall_sports'])) !== '') { + if (($value = tuqp($_POST['firewall_sports'])) !== '') { $value = 'status_firewall_sports_cmdstr = "'.$value.'"'; fwrite($fp, $value."\n"); } - if (($value = trim($_POST['firewall_dports'])) !== '') { + if (($value = tuqp($_POST['firewall_dports'])) !== '') { $value = 'status_firewall_dports_cmdstr = "'.$value.'"'; fwrite($fp, $value."\n"); } @@ -144,7 +144,7 @@ $value = 'status_show_system_logs = no'; fwrite($fp, $value."\n"); } - if (($value = trim($_POST['exclude_logs'])) !== '') { + if (($value = tuqp($_POST['exclude_logs'])) !== '') { $value = 'status_exclude_logs_cmdstr = "'.$value.'"'; fwrite($fp, $value."\n"); } @@ -169,37 +169,37 @@ $value = 'status_asterisk_manager = no'; fwrite($fp, $value."\n"); } - $value = 'status_active_chan_cmdstr = "'.trim($_POST['active_cmd']).'"'; + $value = 'status_active_chan_cmdstr = "'.tuqp($_POST['active_cmd']).'"'; fwrite($fp, $value."\n"); - $value = 'status_voicemail_users_cmdstr = "'.trim($_POST['voicemail_cmd']).'"'; + $value = 'status_voicemail_users_cmdstr = "'.tuqp($_POST['voicemail_cmd']).'"'; fwrite($fp, $value."\n"); - $value = 'status_dahdi_status_cmdstr = "'.trim($_POST['dahdi_cmd']).'"'; + $value = 'status_dahdi_status_cmdstr = "'.tuqp($_POST['dahdi_cmd']).'"'; fwrite($fp, $value."\n"); - $value = 'status_jabber_status_cmdstr = "'.trim($_POST['jabber_cmd']).'"'; + $value = 'status_jabber_status_cmdstr = "'.tuqp($_POST['jabber_cmd']).'"'; fwrite($fp, $value."\n"); - $value = 'sysdial_ext_prefix_cmdstr = "'.trim($_POST['ext_prefix']).'"'; + $value = 'sysdial_ext_prefix_cmdstr = "'.tuqp($_POST['ext_prefix']).'"'; fwrite($fp, $value."\n"); $value = 'sysdial_ext_digits_cmdstr = "'.$_POST['ext_digits'].'"'; fwrite($fp, $value."\n"); - $value = 'number_format_cmdstr = "'.trim($_POST['num_format']).'"'; + $value = 'number_format_cmdstr = "'.tuqp($_POST['num_format']).'"'; fwrite($fp, $value."\n"); - $value = 'number_error_cmdstr = "'.trim($_POST['num_error']).'"'; + $value = 'number_error_cmdstr = "'.tuqp($_POST['num_error']).'"'; fwrite($fp, $value."\n"); - $value = 'blacklist_action_menu_cmdstr = "'.trim($_POST['blacklist_menu']).'"'; + $value = 'blacklist_action_menu_cmdstr = "'.tuqp($_POST['blacklist_menu']).'"'; fwrite($fp, $value."\n"); - $value = 'whitelist_action_menu_cmdstr = "'.trim($_POST['whitelist_menu']).'"'; + $value = 'whitelist_action_menu_cmdstr = "'.tuqp($_POST['whitelist_menu']).'"'; fwrite($fp, $value."\n"); - $value = 'actionlist_format_cmdstr = "'.trim($_POST['actionlist_key_format']).'"'; + $value = 'actionlist_format_cmdstr = "'.tuqp($_POST['actionlist_key_format']).'"'; fwrite($fp, $value."\n"); - $value = 'actionlist_error_cmdstr = "'.trim($_POST['actionlist_key_error']).'"'; + $value = 'actionlist_error_cmdstr = "'.tuqp($_POST['actionlist_key_error']).'"'; fwrite($fp, $value."\n"); - $value = 'actionlist_action_menu_cmdstr = "'.trim($_POST['actionlist_menu']).'"'; + $value = 'actionlist_action_menu_cmdstr = "'.tuqp($_POST['actionlist_menu']).'"'; fwrite($fp, $value."\n"); - $value = trim($_POST['cidname_maxlen']); + $value = tuqp($_POST['cidname_maxlen']); if ($value > 7 && $value != 15) { $value = 'cidname_maxlen_cmdstr = "'.$value.'"'; fwrite($fp, $value."\n"); @@ -207,15 +207,15 @@ $value = 'followme_numbers_displayed = "'.$_POST['followme_maxnum'].'"'; fwrite($fp, $value."\n"); - if (($value = trim($_POST['followme_menu'])) !== '') { + if (($value = tuqp($_POST['followme_menu'])) !== '') { $value = 'followme_schedule_menu_cmdstr = "'.$value.'"'; fwrite($fp, $value."\n"); } - if (($value = trim($_POST['followme_number_context'])) !== '') { + if (($value = tuqp($_POST['followme_number_context'])) !== '') { $value = 'followme_number_context_cmdstr = "'.$value.'"'; fwrite($fp, $value."\n"); } - if (($value = trim($_POST['followme_music_class'])) !== '') { + if (($value = tuqp($_POST['followme_music_class'])) !== '') { $value = 'followme_music_class_cmdstr = "'.$value.'"'; fwrite($fp, $value."\n"); } @@ -224,7 +224,7 @@ fwrite($fp, $value."\n"); } - if (($value = str_replace(' ', '', $_POST['meetme_redirect'])) !== '') { + if (($value = str_replace(' ', '', tuqp($_POST['meetme_redirect']))) !== '') { $value = 'meetme_redirect_path_cmdstr = "'.$value.'"'; fwrite($fp, $value."\n"); } @@ -235,7 +235,7 @@ $value = 'cdrlog_default_format = "'.$_POST['cdr_default'].'"'; fwrite($fp, $value."\n"); - $value = 'cdrlog_log_file_cmdstr = "'.trim($_POST['cdr_logfile']).'"'; + $value = 'cdrlog_log_file_cmdstr = "'.tuqp($_POST['cdr_logfile']).'"'; fwrite($fp, $value."\n"); if (isset($_POST['cdr_databases'])) { $value = 'cdrlog_databases_show = yes'; @@ -282,21 +282,21 @@ $value = 'users_voicemail_delete_vmdata = yes'; fwrite($fp, $value."\n"); } - $value = 'users_voicemail_context_cmdstr = "'.trim($_POST['voicemail_context']).'"'; + $value = 'users_voicemail_context_cmdstr = "'.tuqp($_POST['voicemail_context']).'"'; fwrite($fp, $value."\n"); - $value = 'users_voicemail_reload_cmdstr = "'.trim($_POST['voicemail_reload']).'"'; + $value = 'users_voicemail_reload_cmdstr = "'.tuqp($_POST['voicemail_reload']).'"'; fwrite($fp, $value."\n"); if (isset($_POST['bak_files'])) { $value = 'edit_keep_bak_files = yes'; fwrite($fp, $value."\n"); } - $value = trim($_POST['text_cols']); + $value = tuqp($_POST['text_cols']); if ($value > 79 && $value != 95 && $value < 161) { $value = 'edit_text_cols_cmdstr = "'.$value.'"'; fwrite($fp, $value."\n"); } - $value = trim($_POST['text_rows']); + $value = tuqp($_POST['text_rows']); if ($value > 19 && $value != 30 && $value < 61) { $value = 'edit_text_rows_cmdstr = "'.$value.'"'; fwrite($fp, $value."\n"); @@ -316,11 +316,11 @@ } $value = 'system_reboot_timer_adjust = "'.$_POST['reboot_timer'].'"'; fwrite($fp, $value."\n"); - $value = 'system_asterisk_reload_cmdstr = "'.trim($_POST['asterisk_reload']).'"'; + $value = 'system_asterisk_reload_cmdstr = "'.tuqp($_POST['asterisk_reload']).'"'; fwrite($fp, $value."\n"); - $value = 'system_firmware_repository_url = "'.trim($_POST['repository_url']).'"'; + $value = 'system_firmware_repository_url = "'.tuqp($_POST['repository_url']).'"'; fwrite($fp, $value."\n"); - $value = 'system_asterisk_sounds_url = "'.trim($_POST['sounds_url']).'"'; + $value = 'system_asterisk_sounds_url = "'.tuqp($_POST['sounds_url']).'"'; fwrite($fp, $value."\n"); if (($value = trim(preg_replace('/[^a-zA-Z]+/', '', $_POST['dn_country_name']))) !== '') { @@ -355,17 +355,17 @@ fwrite($fp, $value."\n"); } - $value = 'title_name_cmdstr = "'.trim($_POST['title_name']).'"'; + $value = 'title_name_cmdstr = "'.tuqp($_POST['title_name']).'"'; fwrite($fp, $value."\n"); - if (($value = trim($_POST['external_url_link'])) !== '') { + if (($value = tuqp($_POST['external_url_link'])) !== '') { $value = 'external_url_link_cmdstr = "'.$value.'"'; fwrite($fp, $value."\n"); } - if (($value = trim($_POST['external_url_name'])) !== '') { + if (($value = tuqp($_POST['external_url_name'])) !== '') { $value = 'external_url_name_cmdstr = "'.$value.'"'; fwrite($fp, $value."\n"); } - if (($value = trim($_POST['external_cli_link'])) !== '') { + if (($value = tuqp($_POST['external_cli_link'])) !== '') { $value = 'external_cli_link_cmdstr = "'.$value.'"'; fwrite($fp, $value."\n"); } Modified: branches/1.0/package/webinterface/altweb/admin/siptlscert.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/siptlscert.php 2013-03-17 21:15:47 UTC (rev 6000) +++ branches/1.0/package/webinterface/altweb/admin/siptlscert.php 2013-03-18 23:20:53 UTC (rev 6001) @@ -101,7 +101,7 @@ $value = 'SIPTLSCERT_CERT_KEYSIZE="'.$_POST['key_size'].'"'; fwrite($fp, "### Private Key Size\n".$value."\n"); - $value = 'SIPTLSCERT_CERT_DNSNAME="'.str_replace(' ', '', $_POST['dns_name']).'"'; + $value = 'SIPTLSCERT_CERT_DNSNAME="'.str_replace(' ', '', tuq($_POST['dns_name'])).'"'; fwrite($fp, "### Server Cert DNS Name\n".$value."\n"); fwrite($fp, "### gui.siptlscert.conf - end ###\n"); @@ -131,7 +131,7 @@ } // Rebuild openssl.cnf template for new CA $key_size = $_POST['key_size']; - $dns_name = str_replace(' ', '', $_POST['dns_name']); + $dns_name = str_replace(' ', '', tuq($_POST['dns_name'])); if (($openssl = siptlscert_openssl($key_size, $dns_name)) !== FALSE) { if (opensslCREATEselfCert($openssl)) { if (opensslCREATEserverCert($openssl)) { @@ -144,7 +144,7 @@ $result = 2; } // } elseif (isset($_POST['submit_new_client'])) { -// if (($value = trim($_POST['new_client'])) !== '') { +// if (($value = tuq($_POST['new_client'])) !== '') { // if (preg_match('/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/', $value)) { // if (! is_file($openssl['key_dir'].'/'.$value.'.crt') && // ! is_file($openssl['key_dir'].'/'.$value.'.key')) { Modified: branches/1.0/package/webinterface/altweb/admin/sysdial.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/sysdial.php 2013-03-17 21:15:47 UTC (rev 6000) +++ branches/1.0/package/webinterface/altweb/admin/sysdial.php 2013-03-18 23:20:53 UTC (rev 6001) @@ -44,8 +44,8 @@ if (! $global_staff) { $result = 999; } elseif (isset($_POST['submit_add'])) { - $speeddial = trim($_POST['speeddial']); - $speeddialname = trim($_POST['speeddialname']); + $speeddial = tuqd($_POST['speeddial']); + $speeddialname = tuqd($_POST['speeddialname']); $ext_1x00 = (isset($_POST['ext_1x00'])) ? $_POST['ext_1x00'] : ''; $ext_11x0 = $_POST['ext_11x0']; $ext_110x = $_POST['ext_110x']; Modified: branches/1.0/package/webinterface/altweb/admin/system.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/system.php 2013-03-17 21:15:47 UTC (rev 6000) +++ branches/1.0/package/webinterface/altweb/admin/system.php 2013-03-18 23:20:53 UTC (rev 6001) @@ -139,10 +139,10 @@ $result = 999; } elseif (isset($_POST['submit_password'])) { if (isset($_POST['pass1'])) { - $pass1 = trim($_POST['pass1']); + $pass1 = tuqd($_POST['pass1']); } if (isset($_POST['pass2'])) { - $pass2 = trim($_POST['pass2']); + $pass2 = tuqd($_POST['pass2']); } if (($user = $_POST['user_pass']) !== '') { $result = genHTpasswd($user, $pass1, $pass2, 3); Modified: branches/1.0/package/webinterface/altweb/admin/testmail.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/testmail.php 2013-03-17 21:15:47 UTC (rev 6000) +++ branches/1.0/package/webinterface/altweb/admin/testmail.php 2013-03-18 23:20:53 UTC (rev 6001) @@ -55,8 +55,8 @@ if (! $global_admin) { $result = 999; } elseif (isset($_POST['submit_send_email'])) { - $to = trim($_POST['to_email']); - $from = trim($_POST['from_email']); + $to = tuqd($_POST['to_email']); + $from = tuqd($_POST['from_email']); if ($to !== '') { // Sanitize to and from if (preg_match('/^[a-zA-Z0-9._@-]*$/', $to) && preg_match('/^[a-zA-Z0-9._@-]*$/', $from)) { Modified: branches/1.0/package/webinterface/altweb/admin/users.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/users.php 2013-03-17 21:15:47 UTC (rev 6000) +++ branches/1.0/package/webinterface/altweb/admin/users.php 2013-03-18 23:20:53 UTC (rev 6001) @@ -140,14 +140,14 @@ if (! $global_staff) { $result = 999; } elseif (isset($_POST['submit_add'])) { - $mailbox = trim($_POST['mailbox']); - $password = trim($_POST['password']); + $mailbox = tuq($_POST['mailbox']); + $password = tuq($_POST['password']); if (preg_match('/^[0-9][0-9]*$/', $mailbox)) { if (preg_match('/^[-*0-9][*0-9]*$/', $password)) { - $name = trim($_POST['name']); - $email = trim($_POST['email']); - $pager = trim($_POST['pager']); - $options = trim($_POST['options']); + $name = tuq($_POST['name']); + $email = tuq($_POST['email']); + $pager = tuq($_POST['pager']); + $options = tuq($_POST['options']); if (addVMmailbox($context, $mailbox, $password, $name, $email, $pager, $options, $VOICEMAILCONF) == 0) { $result = 10; } else { Modified: branches/1.0/package/webinterface/altweb/admin/whitelist.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/whitelist.php 2013-03-17 21:15:47 UTC (rev 6000) +++ branches/1.0/package/webinterface/altweb/admin/whitelist.php 2013-03-18 23:20:53 UTC (rev 6001) @@ -63,11 +63,9 @@ if (! $global_staff) { $result = 999; } elseif (isset($_POST['submit_add'])) { - $cidnum = trim($_POST['cidnum']); + $cidnum = tuqd($_POST['cidnum']); $action = $_POST['action']; - if (($comment = trim($_POST['comment'])) !== '') { - $comment = str_replace('"', "'", stripslashes($comment)); - } + $comment = tuqd($_POST['comment']); if (strlen($cidnum) > 0) { if (($cmd = getPREFdef($global_prefs, 'number_format_cmdstr')) === '') { $cmd = '^[2-9][0-9][0-9][2-9][0-9][0-9][0-9][0-9][0-9][0-9]$'; Modified: branches/1.0/package/webinterface/altweb/admin/xmpp.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/xmpp.php 2013-03-17 21:15:47 UTC (rev 6000) +++ branches/1.0/package/webinterface/altweb/admin/xmpp.php 2013-03-18 23:20:53 UTC (rev 6001) @@ -108,10 +108,10 @@ $value = 'XMPP_SYSLOG="'.$_POST['verbosity'].'"'; fwrite($fp, "### Log Syslog\n".$value."\n"); - $value = 'XMPP_C2S_PORT="'.trim($_POST['xmpp_c2s_port']).'"'; + $value = 'XMPP_C2S_PORT="'.tuq($_POST['xmpp_c2s_port']).'"'; fwrite($fp, "### Client to Server TCP Port\n".$value."\n"); - $value = 'XMPP_S2S_PORT="'.trim($_POST['xmpp_s2s_port']).'"'; + $value = 'XMPP_S2S_PORT="'.tuq($_POST['xmpp_s2s_port']).'"'; fwrite($fp, "### Server to Server TCP Port\n".$value."\n"); $value = 'XMPP_GROUPS="'.$_POST['xmpp_groups'].'"'; @@ -120,19 +120,19 @@ $value = 'XMPP_C2S_IDLE_TIMEOUT="'.$_POST['idle_timeout'].'"'; fwrite($fp, "### Dead Client Timeout\n".$value."\n"); - $value = 'XMPP_HOSTNAME="'.trim($_POST['xmpp_hostname']).'"'; + $value = 'XMPP_HOSTNAME="'.tuq($_POST['xmpp_hostname']).'"'; fwrite($fp, "### XMPP VirtualHost\n".$value."\n"); - $value = 'XMPP_ADMIN_USERS="'.trim($_POST['xmpp_admin_users']).'"'; + $value = 'XMPP_ADMIN_USERS="'.tuq($_POST['xmpp_admin_users']).'"'; fwrite($fp, "### Admin Users\n".$value."\n"); - $value = 'XMPP_ENABLE_MODULES="'.trim($_POST['xmpp_enable_modules']).'"'; + $value = 'XMPP_ENABLE_MODULES="'.tuq($_POST['xmpp_enable_modules']).'"'; fwrite($fp, "### Enable Additional Modules\n".$value."\n"); - $value = 'XMPP_DISABLE_MODULES="'.trim($_POST['xmpp_disable_modules']).'"'; + $value = 'XMPP_DISABLE_MODULES="'.tuq($_POST['xmpp_disable_modules']).'"'; fwrite($fp, "### Disable Default Modules\n".$value."\n"); - $value = 'XMPP_CONFERENCE="'.trim($_POST['xmpp_conference']).'"'; + $value = 'XMPP_CONFERENCE="'.tuq($_POST['xmpp_conference']).'"'; fwrite($fp, "### Multi-User Chat Conference\n".$value."\n"); $value = 'XMPP_CERT=""'; @@ -151,8 +151,8 @@ // function changeUserPass() { - $user = str_replace(' ', '', $_POST['user']); - $pass = str_replace(' ', '', stripslashes($_POST['pass'])); + $user = str_replace(' ', '', stripshellsafe($_POST['user'])); + $pass = str_replace(' ', '', stripshellsafe($_POST['pass'])); if ($user === '') { return(FALSE); @@ -173,8 +173,8 @@ // function addUserPass() { - $user = str_replace(' ', '', $_POST['user']); - $pass = str_replace(' ', '', stripslashes($_POST['pass'])); + $... [truncated message content] |
From: <abe...@us...> - 2013-03-19 23:46:22
|
Revision: 6002 http://astlinux.svn.sourceforge.net/astlinux/?rev=6002&view=rev Author: abelbeck Date: 2013-03-19 23:46:10 +0000 (Tue, 19 Mar 2013) Log Message: ----------- web interface, version bump of phpliteadmin to 1.9.4.1 and new style css Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php branches/1.0/package/webinterface/altweb/common/phpliteadmin.css Modified: branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php 2013-03-18 23:20:53 UTC (rev 6001) +++ branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php 2013-03-19 23:46:10 UTC (rev 6002) @@ -2,14 +2,16 @@ // // Project: phpLiteAdmin (http://phpliteadmin.googlecode.com) -// Version: 1.9.3.3 +// Version: 1.9.4.1 // Summary: PHP-based admin tool to manage SQLite2 and SQLite3 databases on the web -// Last updated: 2013-01-14 +// Last updated: 2013-03-18 // Developers: // Dane Iracleous (dan...@gm...) // Ian Aldrighetti (ian...@gm...) // George Flanagin & Digital Gaslight, Inc (ge...@di...) -// Christopher Kramer (cra...@gm...) +// Christopher Kramer (cra...@gm..., http://en.christosoft.de) +// Ayman Teryaki (http://havalite.com) +// Dreadnaut (dre...@gm..., http://dreadnaut.altervista.org) // // // Copyright (C) 2013 phpLiteAdmin @@ -43,18 +45,36 @@ } if (($global_user = getPHPusername()) !== 'admin') { echo '<p style="color: red;">User "'.$global_user.'" does not have permission to access the "phpliteadmin" tab.</p>'; - exit; + exit(); } //AstLinux// end of restrict to 'admin' user. - //BEGIN USER-DEFINED VARIABLES ////////////////////////////// +// These are the default configuration value for phpLiteAdmin and will be overridden +// by the optional configuration file. Feel free to edit below if you want to use +// phpLiteAdmin as a single file; otherwise, rename phpliteadmin.config.sample.php to +// phpliteadmin.config.php and edit it. +// +// Please see http://code.google.com/p/phpliteadmin/wiki/Configuration for more details + //password to gain access -//AstLinux// Password ignored. -$password = "astlinux"; +$password = ''; +// Theme! If you want to change theme, save the CSS file in same folder of phpliteadmin or in folder 'themes' +$theme = 'phpliteadmin.css'; + +// the default language! If you want to change it, save the language file in same folder of phpliteadmin or in folder 'languages' +// More about localizations (downloads, how to translate etc.): http://code.google.com/p/phpliteadmin/wiki/Localization +$language = 'en'; + +// set default number of rows. You need to relog after changing the number +$rowsNum = 30; + +// reduce string characters by a number bigger than 10 +$charsNum = 300; + //directory relative to this file to search for databases (if false, manually list databases in the $databases variable) $directory = false; @@ -80,31 +100,13 @@ } //AstLinux// end of define database files + //a list of custom functions that can be applied to columns in the databases //make sure to define every function below if it is not a core PHP function -$custom_functions = array('md5', 'md5rev', 'sha1', 'sha1rev', 'time', 'mydate', 'strtotime', 'myreplace'); +$custom_functions = array('md5', 'sha1', 'time', 'strtotime'); -//define all the non-core custom functions -function md5rev($value) -{ - return strrev(md5($value)); -} -function sha1rev($value) -{ - return strrev(sha1($value)); -} -function mydate($value) -{ - return date("H:i n/j/y", intval($value)); -} -function myreplace($value) -{ - return preg_replace("/[^A-Za-z0-9]/", "", strval($value)); -} - //changing the following variable allows multiple phpLiteAdmin installs to work under the same domain. -//AstLinux// -$cookie_name = 'astlinux-db-2013'; +$cookie_name = 'pla3412'; //whether or not to put the app in debug mode where errors are outputted $debug = false; @@ -115,14 +117,319 @@ //////////////////////////// //END USER-DEFINED VARIABLES +// load optional configuration file +//$config_filename = './phpliteadmin.config.php'; +//if (is_readable($config_filename)) { +// include_once $config_filename; +//} + +// Start English language-texts +// Read our wiki on how to translate: http://code.google.com/p/phpliteadmin/wiki/Localization +$lang = array( + "direction" => "LTR", + "date_format" => 'M d H:i:s T Y', //AstLinux// + "ver" => "version", + "for" => "for", + "to" => "to", + "go" => "Go", + "yes" => "Yes", + "sql" => "SQL", + "csv" => "CSV", + "csv_tbl" => "Table that CSV pertains to", + "srch" => "Search", + "srch_again" => "Do Another Search", + "login" => "Log In", + "logout" => "Logout", + "view" => "View", + "confirm" => "Confirm", + "cancel" => "Cancel", + "save_as" => "Save As", + "options" => "Options", + "no_opt" => "No options", + "help" => "Help", + "installed" => "installed", + "not_installed" => "not installed", + "done" => "done", + "insert" => "Insert", + "export" => "Export", + "import" => "Import", + "rename" => "Rename", + "empty" => "Empty", + "drop" => "Drop", + "tbl" => "Table", + "chart" => "Chart", + "err" => "ERROR", + "act" => "Action", + "rec" => "Records", + "col" => "Column", + "cols" => "Columns", + "rows" => "row(s)", + "edit" => "Edit", + "del" => "Delete", + "add" => "Add", + "backup" => "Backup database file", + "before" => "Before", + "after" => "After", + "passwd" => "Password", + "passwd_incorrect" => "Incorrect password.", + "chk_ext" => "Checking supported SQLite PHP extensions", + "autoincrement" => "Autoincrement", + "not_null" => "Not NULL", + "attention" => "Attention", + + "sqlite_ext" => "SQLite extension", + "sqlite_ext_support" => "It appears that none of the supported SQLite library extensions are available in your installation of PHP. You may not use %s until you install at least one of them.", + "sqlite_v" => "SQLite version", + "sqlite_v_error" => "It appears that your database is of SQLite version %s but your installation of PHP does not contain the necessary extensions to handle this version. To fix the problem, either delete the database and allow %s to create it automatically or recreate it manually as SQLite version %s.", + "report_issue" => "The problem cannot be diagnosed properly. Please file an issue report at", + "sqlite_limit" => "Due to the limitations of SQLite, only the field name and data type can be modified.", + + "php_v" => "PHP version", + + "db_dump" => "database dump", + "db_f" => "database file", + "db_ch" => "Change Database", + "db_event" => "Database Event", + "db_name" => "Database name", + "db_rename" => "Rename Database", + "db_renamed" => "Database '%s' has been renamed to", + "db_del" => "Delete Database", + "db_path" => "Path to database", + "db_size" => "Size of database", + "db_mod" => "Database last modified", + "db_create" => "Create New Database", + "db_vac" => "The database, '%s', has been VACUUMed.", + "db_not_writeable" => "The database, '%s', does not exist and cannot be created because the containing directory, '%s', is not writable. The application is unusable until you make it writable.", + "db_setup" => "There was a problem setting up your database, %s. An attempt will be made to find out what's going on so you can fix the problem more easily", + "db_exists" => "A database, other file or directory of the name '%s' already exists.", + + "exported" => "Exported", + "struct" => "Structure", + "struct_for" => "structure for", + "on_tbl" => "on table", + "data_dump" => "Data dump for", + "backup_hint" => "Hint: To backup your database, the easiest way is to %s.", + "backup_hint_linktext" => "download the database-file", + "total_rows" => "a total of %s rows", + "total" => "Total", + "not_dir" => "The directory you specified to scan for databases does not exist or is not a directory.", + "bad_php_directive" => "It appears that the PHP directive, 'register_globals' is enabled. This is bad. You need to disable it before continuing.", + "page_gen" => "Page generated in %s seconds.", + "powered" => "Powered by", + "remember" => "Remember me", + "no_db" => "Welcome to %s. It appears that you have selected to scan a directory for databases to manage. However, %s could not find any valid SQLite databases. You may use the form below to create your first database.", + "no_db2" => "The directory you specified does not contain any existing databases to manage, and the directory is not writable. This means you can't create any new databases using %s. Either make the directory writable or manually upload databases to the directory.", + + "create" => "Create", + "created" => "has been created", + "create_tbl" => "Create new table", + "create_tbl_db" => "Create new table on database", + "create_trigger" => "Creating new trigger on table", + "create_index" => "Creating new index on table", + "create_index1" => "Create Index", + "create_view" => "Create new view on database", + + "trigger" => "Trigger", + "triggers" => "Triggers", + "trigger_name" => "Trigger name", + "trigger_act" => "Trigger Action", + "trigger_step" => "Trigger Steps (semicolon terminated)", + "when_exp" => "WHEN expression (type expression without 'WHEN')", + "index" => "Index", + "indexes" => "Indexes", + "index_name" => "Index name", + "name" => "Name", + "unique" => "Unique", + "seq_no" => "Seq. No.", + "emptied" => "has been emptied", + "dropped" => "has been dropped", + "renamed" => "has been renamed to", + "altered" => "has been altered successfully", + "inserted" => "inserted", + "deleted" => "deleted", + "affected" => "affected", + "blank_index" => "Index name must not be blank.", + "one_index" => "You must specify at least one index column.", + "docu" => "Documentation", + "license" => "License", + "proj_site" => "Project Site", + "bug_report" => "This may be a bug that needs to be reported at", + "return" => "Return", + "browse" => "Browse", + "fld" => "Field", + "fld_num" => "Number of Fields", + "fields" => "Fields", + "type" => "Type", + "operator" => "Operator", + "val" => "Value", + "update" => "Update", + "comments" => "Comments", + + "specify_fields" => "You must specify the number of table fields.", + "specify_tbl" => "You must specify a table name.", + "specify_col" => "You must specify a column.", + + "tbl_exists" => "Table of the same name already exists.", + "show" => "Show", + "show_rows" => "Showing %s row(s). ", + "showing" => "Showing", + "showing_rows" => "Showing rows", + "query_time" => "(Query took %s sec)", + "syntax_err" => "There is a problem with the syntax of your query (Query was not executed)", + "run_sql" => "Run SQL query/queries on database '%s'", + + "ques_empty" => "Are you sure you want to empty the table '%s'?", + "ques_drop" => "Are you sure you want to drop the table '%s'?", + "ques_drop_view" => "Are you sure you want to drop the view '%s'?", + "ques_del_rows" => "Are you sure you want to delete row(s) %s from table '%s'?", + "ques_del_db" => "Are you sure you want to delete the database '%s'?", + "ques_del_col" => "Are you sure you want to delete column(s) %s from table '%s'?", + "ques_del_index" => "Are you sure you want to delete index '%s'?", + "ques_del_trigger" => "Are you sure you want to delete trigger '%s'?", + + "export_struct" => "Export with structure", + "export_data" => "Export with data", + "add_drop" => "Add DROP TABLE", + "add_transact" => "Add TRANSACTION", + "fld_terminated" => "Fields terminated by", + "fld_enclosed" => "Fields enclosed by", + "fld_escaped" => "Fields escaped by", + "fld_names" => "Field names in first row", + "rep_null" => "Replace NULL by", + "rem_crlf" => "Remove CRLF characters within fields", + "put_fld" => "Put field names in first row", + "null_represent" => "NULL represented by", + "import_suc" => "Import was successful.", + "import_into" => "Import into", + "import_f" => "File to import", + "rename_tbl" => "Rename table '%s' to", + + "rows_records" => "row(s) starting from record # ", + "rows_aff" => "row(s) affected. ", + + "as_a" => "as a", + "readonly_tbl" => "'%s' is a view, which means it is a SELECT statement treated as a read-only table. You may not edit or insert records.", + "chk_all" => "Check All", + "unchk_all" => "Uncheck All", + "with_sel" => "With Selected", + + "no_tbl" => "No table in database.", + "no_chart" => "If you can read this, it means the chart could not be generated. The data you are trying to view may not be appropriate for a chart.", + "no_rows" => "There are no rows in the table for the range you selected.", + "no_sel" => "You did not select anything.", + + "chart_type" => "Chart Type", + "chart_bar" => "Bar Chart", + "chart_pie" => "Pie Chart", + "chart_line" => "Line Chart", + "lbl" => "Labels", + "empty_tbl" => "This table is empty.", + "click" => "Click here", + "insert_rows" => "to insert rows.", + "restart_insert" => "Restart insertion with ", + "ignore" => "Ignore", + "func" => "Function", + "new_insert" => "Insert As New Row", + "save_ch" => "Save Changes", + "def_val" => "Default Value", + "prim_key" => "Primary Key", + "tbl_end" => "field(s) at end of table", + "query_used_table" => "Query used to create this table", + "query_used_view" => "Query used to create this view", + "create_index2" => "Create an index on", + "create_trigger2" => "Create a new trigger", + "new_fld" => "Adding new field(s) to table '%s'", + "add_flds" => "Add Fields", + "edit_col" => "Editing column '%s'", + "vac" => "Vacuum", + "vac_desc" => "Large databases sometimes need to be VACUUMed to reduce their footprint on the server. Click the button below to VACUUM the database '%s'.", + "event" => "Event", + "each_row" => "For Each Row", + "define_index" => "Define index properties", + "dup_val" => "Duplicate values", + "allow" => "Allowed", + "not_allow" => "Not Allowed", + "asc" => "Ascending", + "desc" => "Descending", + "warn0" => "You have been warned.", + "warn_passwd" => "You are using the default password, which can be dangerous. You can change it easily at the top of %s.", + "warn_dumbass" => "You didn't change the value dumbass ;-)", + "sel_state" => "Select Statement", + "delimit" => "Delimiter", + "back_top" => "Back to Top", + "choose_f" => "Choose File", + "instead" => "Instead of", + "define_in_col" => "Define index column(s)", + + "delete_only_managed" => "You can only delete databases managed by this tool!", + "rename_only_managed" => "You can only rename databases managed by this tool!", + "db_moved_outside" => "You either tried to move the database into a directory where it cannot be managed anylonger, or the check if you did this failed because of missing rights.", + "extension_not_allowed" => "The extension you provided is not within the list of allowed extensions. Please use one of the following extensions", + "add_allowed_extension" => "You can add extensions to this list by adding your extension to \$allowed_extensions in the configuration.", + "directory_not_writable" => "The database-file itself is writable, but to write into it, the containing directory needs to be writable as well. This is because SQLite puts temporary files in there for locking.", + "tbl_inexistent" => "Table %s does not exist", + + // errors that can happen when ALTER TABLE fails. You don't necessarily have to translate these. + "alter_failed" => "Altering of Table %s failed", + "alter_tbl_name_not_replacable" => "could not replace the table name with the temporary one", + "alter_no_def" => "no ALTER definition", + "alter_parse_failed" =>"failed to parse ALTER definition", + "alter_action_not_recognized" => "ALTER action could not be recognized", + "alter_no_add_col" => "no column to add detected in ALTER statement", + "alter_pattern_mismatch"=>"Pattern did not match on your original CREATE TABLE statement", + "alter_col_not_recognized" => "could not recognize new or old column name", + "alter_unknown_operation" => "Unknown ALTER operation!", + + /* Help documentation */ + "help_doc" => "Help Documentation", + "help1" => "SQLite Library Extensions", + "help1_x" => "%s uses PHP library extensions that allow interaction with SQLite databases. Currently, %s supports PDO, SQLite3, and SQLiteDatabase. Both PDO and SQLite3 deal with version 3 of SQLite, while SQLiteDatabase deals with version 2. So, if your PHP installation includes more than one SQLite library extension, PDO and SQLite3 will take precedence to make use of the better technology. However, if you have existing databases that are of version 2 of SQLite, %s will be forced to use SQLiteDatabase for only those databases. Not all databases need to be of the same version. During the database creation, however, the most advanced extension will be used.", + "help2" => "Creating a New Database", + "help2_x" => "When you create a new database, the name you entered will be appended with the appropriate file extension (.db, .db3, .sqlite, etc.) if you do not include it yourself. The database will be created in the directory you specified as the \$directory variable.", + "help3" => "Tables vs. Views", + "help3_x" => "On the main database page, there is a list of tables and views. Since views are read-only, certain operations will be disabled. These disabled operations will be apparent by their omission in the location where they should appear on the row for a view. If you want to change the data for a view, you need to drop that view and create a new view with the appropriate SELECT statement that queries other existing tables. For more information, see <a href='http://en.wikipedia.org/wiki/View_(database)' target='_blank'>http://en.wikipedia.org/wiki/View_(database)</a>", + "help4" => "Writing a Select Statement for a New View", + "help4_x" => "When you create a new view, you must write an SQL SELECT statement that it will use as its data. A view is simply a read-only table that can be accessed and queried like a regular table, except it cannot be modified through insertion, column editing, or row editing. It is only used for conveniently fetching data.", + "help5" => "Export Structure to SQL File", + "help5_x" => "During the process for exporting to an SQL file, you may choose to include the queries that create the table and columns.", + "help6" => "Export Data to SQL File", + "help6_x" => "During the process for exporting to an SQL file, you may choose to include the queries that populate the table(s) with the current records of the table(s).", + "help7" => "Add Drop Table to Exported SQL File", + "help7_x" => "During the process for exporting to an SQL file, you may choose to include queries to DROP the existing tables before adding them so that problems do not occur when trying to create tables that already exist.", + "help8" => "Add Transaction to Exported SQL File", + "help8_x" => "During the process for exporting to an SQL file, you may choose to wrap the queries around a TRANSACTION so that if an error occurs at any time during the importation process using the exported file, the database can be reverted to its previous state, preventing partially updated data from populating the database.", + "help9" => "Add Comments to Exported SQL File", + "help9_x" => "During the process for exporting to an SQL file, you may choose to include comments that explain each step of the process so that a human can better understand what is happening." + + ); + + //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //there is no reason for the average user to edit anything below this comment //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -session_start(); //don't mess with this - required for the login session +//constants 1 +define("PROJECT", "phpLiteAdmin"); +define("VERSION", "1.9.4.1"); +define("PAGE", basename(__FILE__)); +//AstLinux// Force PDO +define("FORCETYPE", "PDO"); //force the extension that will be used (set to false in almost all circumstances except debugging) +define("SYSTEMPASSWORD", $password); // Makes things easier. +define('PROJECT_URL','http://phpliteadmin.googlecode.com'); +define('PROJECT_BUGTRACKER_LINK','<a href="http://code.google.com/p/phpliteadmin/issues/list" target="_blank">http://code.google.com/p/phpliteadmin/issues/list</a>'); + +// Resource output (css and javascript files) +// we get out of the main code as soon as possible, without inizializing the session +if (isset($_GET['resource'])) { + Resources::output($_GET['resource']); + exit(); +} + +// don't mess with this - required for the login session +ini_set('session.cookie_httponly', '1'); +session_start(); //AstLinux// Use /etc/timezone for the timezone -//date_default_timezone_set(date_default_timezone_get()); //needed to fix STRICT warnings about timezone issues function system_timezone() { if (($tz = trim(@file_get_contents('/etc/timezone'))) === '') { $tz = @date_default_timezone_get(); @@ -136,33 +443,45 @@ { ini_set("display_errors", 1); error_reporting(E_STRICT | E_ALL); +} else +{ + @ini_set("display_errors", 0); } -$startTimeTot = microtime(true); //start the timer to record page load time +// start the timer to record page load time +$pageTimer = new MicroTimer(); -//the salt and password encrypting is probably unnecessary protection but is done just for the sake of being very secure -//create a random salt for this session if a cookie doesn't already exist for it -if(!isset($_SESSION[$cookie_name.'_salt']) && !isset($_COOKIE[$cookie_name.'_salt'])) -{ - $n = rand(10e16, 10e20); - $_SESSION[$cookie_name.'_salt'] = base_convert($n, 10, 36); +// load language file +if($language != 'en') { + if(is_file('languages/lang_'.$language.'.php')) + include('languages/lang_'.$language.'.php'); + elseif(is_file('lang_'.$language.'.php')) + include('lang_'.$language.'.php'); } -else if(!isset($_SESSION[$cookie_name.'_salt']) && isset($_COOKIE[$cookie_name.'_salt'])) //session doesn't exist, but cookie does so grab it -{ - $_SESSION[$cookie_name.'_salt'] = $_COOKIE[$cookie_name.'_salt']; +// version-number added so after updating, old session-data is not used anylonger +// cookies names cannot contain symbols, except underscores +define("COOKIENAME", preg_replace('/[^a-zA-Z0-9_]/', '_', $cookie_name . '_' . VERSION) ); + +// stripslashes if MAGIC QUOTES is turned on +// This is only a workaround. Please better turn off magic quotes! +// This code is from http://php.net/manual/en/security.magicquotes.disabling.php +if (get_magic_quotes_gpc()) { + $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST); + while (list($key, $val) = each($process)) { + foreach ($val as $k => $v) { + unset($process[$key][$k]); + if (is_array($v)) { + $process[$key][stripslashes($k)] = $v; + $process[] = &$process[$key][stripslashes($k)]; + } else { + $process[$key][stripslashes($k)] = stripslashes($v); + } + } + } + unset($process); } -//constants -define("PROJECT", "phpLiteAdmin"); -define("VERSION", "1.9.3.3"); -define("PAGE", basename(__FILE__)); -define("COOKIENAME", $cookie_name); -define("SYSTEMPASSWORD", $password); // Makes things easier. -define("SYSTEMPASSWORDENCRYPTED", md5($password."_".$_SESSION[$cookie_name.'_salt'])); //extra security - salted and encrypted password used for checking -//AstLinux// Force PDO -define("FORCETYPE", 'PDO'); //force the extension that will be used (set to false in almost all circumstances except debugging) - //data types array $types = array("INTEGER", "REAL", "TEXT", "BLOB"); define("DATATYPES", serialize($types)); @@ -263,7 +582,8 @@ //the function echo the help [?] links to the documentation function helpLink($name) { - return "<a href='javascript:void' onclick='openHelp(\"".$name."\");' class='helpq' title='Help: ".$name."'>[?]</a>"; + global $lang; + return "<a href='".PAGE."?help=1' onclick='openHelp(\"".$name."\"); return false;' class='helpq' title='".$lang['help'].": ".$name."' target='_blank'><span>[?]</span></a>"; } // function to encode value into HTML just like htmlentities, but with adjusted default settings @@ -279,6 +599,23 @@ return trim(trim($s), "'"); } +// reduce string chars +function subString($str) +{ + global $charsNum; + if($charsNum > 10){ + if(strlen($str)>$charsNum) $str = substr($str, 0, $charsNum).'...'; + } + return $str; +} + +function getRowId($table, $where=''){ + global $db; + $query = "SELECT ROWID FROM ".$db->quote_id($table).$where; + $result = $db->selectArray($query); + return $result; +} + // checks the (new) name of a database file function checkDbName($name) { @@ -319,45 +656,100 @@ // class Authorization { - public function grant($remember) + private $authorized; + private $login_failed; + private $system_password_encrypted; + + public function __construct() { - if($remember) //user wants to be remembered, so set a cookie + // the salt and password encrypting is probably unnecessary protection but is done just + // for the sake of being very secure + if(!isset($_SESSION[COOKIENAME.'_salt']) && !isset($_COOKIE[COOKIENAME.'_salt'])) { - $expire = time()+60*60*24*30; //set expiration to 1 month from now - setcookie(COOKIENAME, SYSTEMPASSWORD, $expire); - setcookie(COOKIENAME."_salt", $_SESSION[COOKIENAME.'_salt'], $expire); + // create a random salt for this session if a cookie doesn't already exist for it + $_SESSION[COOKIENAME.'_salt'] = self::generateSalt(20); } - else + else if(!isset($_SESSION[COOKIENAME.'_salt']) && isset($_COOKIE[COOKIENAME.'_salt'])) { - //user does not want to be remembered, so destroy any potential cookies - setcookie(COOKIENAME, "", time()-86400); - setcookie(COOKIENAME."_salt", "", time()-86400); - unset($_COOKIE[COOKIENAME]); - unset($_COOKIE[COOKIENAME.'_salt']); + // session doesn't exist, but cookie does so grab it + $_SESSION[COOKIENAME.'_salt'] = $_COOKIE[COOKIENAME.'_salt']; } - $_SESSION[COOKIENAME.'password'] = SYSTEMPASSWORDENCRYPTED; + // salted and encrypted password used for checking + $this->system_password_encrypted = md5(SYSTEMPASSWORD."_".$_SESSION[COOKIENAME.'_salt']); + + $this->authorized = + // no password + SYSTEMPASSWORD == '' + // correct password stored in session + || isset($_SESSION[COOKIENAME.'password']) && $_SESSION[COOKIENAME.'password'] == $this->system_password_encrypted + // correct password stored in cookie + || isset($_COOKIE[COOKIENAME]) && isset($_COOKIE[COOKIENAME.'_salt']) && md5(SYSTEMPASSWORD."_".$_COOKIE[COOKIENAME.'_salt']) == $_COOKIE[COOKIENAME]; } + + public function attemptGrant($password, $remember) + { + if ($password == SYSTEMPASSWORD) { + if ($remember) { + // user wants to be remembered, so set a cookie + $expire = time()+60*60*24*30; //set expiration to 1 month from now + setcookie(COOKIENAME, $this->system_password_encrypted, $expire, null, null, null, true); + setcookie(COOKIENAME."_salt", $_SESSION[COOKIENAME.'_salt'], $expire, null, null, null, true); + } else { + // user does not want to be remembered, so destroy any potential cookies + setcookie(COOKIENAME, "", time()-86400, null, null, null, true); + setcookie(COOKIENAME."_salt", "", time()-86400, null, null, null, true); + unset($_COOKIE[COOKIENAME]); + unset($_COOKIE[COOKIENAME.'_salt']); + } + + $_SESSION[COOKIENAME.'password'] = $this->system_password_encrypted; + $this->authorized = true; + return true; + } + + $this->login_failed = true; + return false; + } + public function revoke() { //destroy everything - cookies and session vars - setcookie(COOKIENAME, "", time()-86400); - setcookie(COOKIENAME."_salt", "", time()-86400); + setcookie(COOKIENAME, "", time()-86400, null, null, null, true); + setcookie(COOKIENAME."_salt", "", time()-86400, null, null, null, true); unset($_COOKIE[COOKIENAME]); unset($_COOKIE[COOKIENAME.'_salt']); session_unset(); session_destroy(); + $this->authorized = false; } + public function isAuthorized() { - // Is this just session long? (What!?? -DI) - if((isset($_SESSION[COOKIENAME.'password']) && $_SESSION[COOKIENAME.'password'] == SYSTEMPASSWORDENCRYPTED) || (isset($_COOKIE[COOKIENAME]) && isset($_COOKIE[COOKIENAME.'_salt']) && md5($_COOKIE[COOKIENAME]."_".$_COOKIE[COOKIENAME.'_salt']) == SYSTEMPASSWORDENCRYPTED)) - return true; - else - { - return false; + return $this->authorized; + } + + public function isFailedLogin() + { + return $this->login_failed; + } + + public function isPasswordDefault() + { + return SYSTEMPASSWORD == 'admin'; + } + + private static function generateSalt($saltSize) + { + $set = 'ABCDEFGHiJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + $setLast = strlen($set) - 1; + $salt = ''; + while ($saltSize-- > 0) { + $salt .= $set[mt_rand(0, $setLast)]; } + return $salt; } + } // @@ -371,9 +763,11 @@ protected $data; protected $lastResult; protected $fns; + protected $alterError; public function __construct($data) { + global $lang; $this->data = $data; $this->fns = array(); try @@ -381,10 +775,10 @@ if(!file_exists($this->data["path"]) && !is_writable(dirname($this->data["path"]))) //make sure the containing directory is writable if the database does not exist { echo "<div class='confirm' style='margin:20px;'>"; - echo "The database, '".htmlencode($this->data["path"])."', does not exist and cannot be created because the containing directory, '".htmlencode(dirname($this->data["path"]))."', is not writable. The application is unusable until you make it writable."; + printf($lang['db_not_writeable'], htmlencode($this->data["path"]), htmlencode(dirname($this->data["path"]))); //AstLinux// //echo "<form action='".PAGE."' method='post'>"; - //echo "<input type='submit' value='Log Out' name='logout' class='btn'/>"; + //echo "<input type='submit' value='Log Out' name='".$lang['logout']."' class='btn'/>"; //echo "</form>"; echo "</div><br/>"; exit(); @@ -457,8 +851,14 @@ public function getError() { - if($this->type=="PDO") + if($this->alterError!='') { + $error = $this->alterError; + $this->alterError = ""; + return $error; + } + else if($this->type=="PDO") + { $e = $this->db->errorInfo(); return $e[2]; } @@ -474,37 +874,38 @@ public function showError() { + global $lang; $classPDO = class_exists("PDO"); $classSQLite3 = class_exists("SQLite3"); $classSQLiteDatabase = class_exists("SQLiteDatabase"); if($classPDO) - $strPDO = "installed"; + $strPDO = $lang['installed']; else - $strPDO = "not installed"; + $strPDO = $lang['not_installed']; if($classSQLite3) - $strSQLite3 = "installed"; + $strSQLite3 = $lang['installed']; else - $strSQLite3 = "not installed"; + $strSQLite3 = $lang['not_installed']; if($classSQLiteDatabase) - $strSQLiteDatabase = "installed"; + $strSQLiteDatabase = $lang['installed']; else - $strSQLiteDatabase = "not installed"; + $strSQLiteDatabase = $lang['not_installed']; echo "<div class='confirm' style='margin:20px;'>"; - echo "There was a problem setting up your database, ".$this->getPath().". An attempt will be made to find out what's going on so you can fix the problem more easily.<br/><br/>"; - echo "<i>Checking supported SQLite PHP extensions...<br/><br/>"; + printf($lang['db_setup'], $this->getPath()); + echo ".<br/><br/><i>".$lang['chk_ext']."...<br/><br/>"; echo "<b>PDO</b>: ".$strPDO."<br/>"; echo "<b>SQLite3</b>: ".$strSQLite3."<br/>"; - echo "<b>SQLiteDatabase</b>: ".$strSQLiteDatabase."<br/><br/>...done.</i><br/><br/>"; + echo "<b>SQLiteDatabase</b>: ".$strSQLiteDatabase."<br/><br/>...".$lang['done'].".</i><br/><br/>"; if(!$classPDO && !$classSQLite3 && !$classSQLiteDatabase) - echo "It appears that none of the supported SQLite library extensions are available in your installation of PHP. You may not use ".PROJECT." until you install at least one of them."; + printf($lang['sqlite_ext_support'], PROJECT); else { if(!$classPDO && !$classSQLite3 && $this->getVersion()==3) - echo "It appears that your database is of SQLite version 3 but your installation of PHP does not contain the necessary extensions to handle this version. To fix the problem, either delete the database and allow ".PROJECT." to create it automatically or recreate it manually as SQLite version 2."; + printf($lang['sqlite_v_error'], 3, PROJECT, 2); else if(!$classSQLiteDatabase && $this->getVersion()==2) - echo "It appears that your database is of SQLite version 2 but your installation of PHP does not contain the necessary extensions to handle this version. To fix the problem, either delete the database and allow ".PROJECT." to create it automatically or recreate it manually as SQLite version 3."; + printf($lang['sqlite_v_error'], 2, PROJECT, 3); else - echo "The problem cannot be diagnosed properly. Please file an issue report at http://phpliteadmin.googlecode.com."; + echo $lang['report_issue'].' '.PROJECT_BUGTRACKER_LINK.'.'; } echo "</div><br/>"; } @@ -533,6 +934,18 @@ return $this->data["path"]; } + //is the db-file writable? + public function isWritable() + { + return $this->data["writable"]; + } + + //is the db-folder writable? + public function isDirWritable() + { + return $this->data["writable_dir"]; + } + //get the version of the database public function getVersion() { @@ -551,17 +964,17 @@ } } - //get the size of the database + //get the size of the database (in KB) public function getSize() { - return round(filesize($this->data["path"])*0.0009765625, 1)." KB"; + return round(filesize($this->data["path"])*0.0009765625, 1); } //get the last modified time of database public function getDate() { - //AstLinux// - return date("M d H:i:s T Y", filemtime($this->data["path"])); + global $lang; + return date($lang['date_format'], filemtime($this->data['path'])); } //get number of affected rows from last query @@ -732,11 +1145,12 @@ { if($name=="*" || $name=="+") { - $nameSingle = "(?:[^']|'')".$name; - $nameDouble = "(?:[^\"]|\"\")".$name; - $nameBacktick = "(?:[^`]|``)".$name; - $nameSquare = "(?:[^\]]|\]\])".$name; - $nameNo = "[^".$notAllowedIfNone."]".$name; + // use possesive quantifiers to save memory + $nameSingle = "(?:[^']$name+|'')$name+"; + $nameDouble = "(?:[^\"]$name+|\"\")$name+"; + $nameBacktick = "(?:[^`]$name+|``)$name+"; + $nameSquare = "(?:[^\]]$name+|\]\])$name+"; + $nameNo = "[^".$notAllowedIfNone."]$name"; } else { @@ -762,18 +1176,24 @@ // this has been completely debugged / rewritten by Christopher Kramer public function alterTable($table, $alterdefs) { - global $debug; + global $debug, $lang; + $this->alterError=""; + $errormsg = $lang['err'].': '.sprintf($lang['alter_failed'],htmlencode($table)).' - '; if($debug) echo "ALTER TABLE: table=($table), alterdefs=($alterdefs)<hr>"; if($alterdefs != '') { $recreateQueries = array(); - $tempQuery = "SELECT sql,name,type FROM sqlite_master WHERE tbl_name = ".$this->quote($table)." ORDER BY type DESC"; + $tempQuery = "SELECT sql,name,type FROM sqlite_master WHERE tbl_name = ".$this->quote($table); $result = $this->query($tempQuery); $resultArr = $this->selectArray($tempQuery); if($this->type=="PDO") $result->closeCursor(); if(sizeof($resultArr)<1) + { + $this->alterError = $errormsg . sprintf($lang['tbl_inexistent'], htmlencode($table)); + if($debug) echo "ERROR: unknown table<hr>"; return false; + } for($i=0; $i<sizeof($resultArr); $i++) { $row = $resultArr[$i]; @@ -788,8 +1208,16 @@ // ALTER the table $tmpname = 't'.time(); $origsql = $row['sql']; - $createtemptableSQL = "CREATE TEMPORARY TABLE ".$this->quote($tmpname)." ". - preg_replace("/^\s*CREATE\s+TABLE\s+".$this->sqlite_surroundings_preg($table)."\s*(\(.*)$/i", '$1', $origsql, 1); + $preg_remove_create_table = "/^\s*+CREATE\s++TABLE\s++".$this->sqlite_surroundings_preg($table)."\s*+(\(.*+)$/is"; + $origsql_no_create = preg_replace($preg_remove_create_table, '$1', $origsql, 1); + if($debug) echo "origsql=($origsql)<br />preg_remove_create_table=($preg_remove_create_table)<hr>"; + if($origsql_no_create == $origsql) + { + $this->alterError = $errormsg . $lang['alter_tbl_name_not_replacable']; + if($debug) echo "ERROR: could not get rid of CREATE TABLE<hr />"; + return false; + } + $createtemptableSQL = "CREATE TEMPORARY TABLE ".$this->quote($tmpname)." ".$origsql_no_create; if($debug) echo "createtemptableSQL=($createtemptableSQL)<hr>"; $createindexsql = array(); preg_match_all("/(?:DROP|ADD|CHANGE|RENAME TO)\s+(?:\"(?:[^\"]|\"\")+\"|'(?:[^']|'')+')((?:[^,')]|'[^']*')+)?/i",$alterdefs,$matches); @@ -817,6 +1245,7 @@ $createtesttableSQL = $createtemptableSQL; if(count($defs)<1) { + $this->alterError = $errormsg . $lang['alter_no_def']; if($debug) echo "ERROR: defs<1<hr />"; return false; } @@ -826,11 +1255,13 @@ $parse_def = preg_match("/^(DROP|ADD|CHANGE|RENAME TO)\s+(?:\"((?:[^\"]|\"\")+)\"|'((?:[^']|'')+)')((?:\s+'((?:[^']|'')+)')?\s+(TEXT|INTEGER|BLOB|REAL).*)?\s*$/i",$def,$matches); if($parse_def===false) { + $this->alterError = $errormsg . $lang['alter_parse_failed']; if($debug) echo "ERROR: !parse_def<hr />"; return false; } if(!isset($matches[1])) { + $this->alterError = $errormsg . $lang['alter_action_not_recognized']; if($debug) echo "ERROR: !isset(matches[1])<hr />"; return false; } @@ -851,22 +1282,22 @@ 3. 'colX' ..., - (with colX being the column to change/drop) 4. 'colX+1' ..., ..., 'colK') $5 (with colX+1-colK being columns after the column to change/drop) */ - $preg_create_table = "\s*(CREATE\s+TEMPORARY\s+TABLE\s+'?".preg_quote($tmpname,"/")."'?\s*\()"; // This is group $1 (keep unchanged) - $preg_column_definiton = "\s*".$this->sqlite_surroundings_preg("+",false," '\"\[`")."(?:\s+".$this->sqlite_surroundings_preg("*",false,"'\",`\[) ").")+"; // catches a complete column definition, even if it is + $preg_create_table = "\s*+(CREATE\s++TEMPORARY\s++TABLE\s++".preg_quote($this->quote($tmpname),"/")."\s*+\()"; // This is group $1 (keep unchanged) + $preg_column_definiton = "\s*+".$this->sqlite_surroundings_preg("+",false," '\"\[`,")."(?:\s+".$this->sqlite_surroundings_preg("*",false,"'\",`\[ ").")++"; // catches a complete column definition, even if it is // 'column' TEXT NOT NULL DEFAULT 'we have a comma, here and a double ''quote!' if($debug) echo "preg_column_definition=(".$preg_column_definiton.")<hr />"; $preg_columns_before = // columns before the one changed/dropped (keep) "(?:". "(". // group $2. Keep this one unchanged! "(?:". - "$preg_column_definiton,\s*". // column definition + comma + "$preg_column_definiton,\s*+". // column definition + comma ")*". // there might be any number of such columns here $preg_column_definiton. // last column definition ")". // end of group $2 - ",\s*" // the last comma of the last column before the column to change. Do not keep it! + ",\s*+" // the last comma of the last column before the column to change. Do not keep it! .")?"; // there might be no columns before if($debug) echo "preg_columns_before=(".$preg_columns_before.")<hr />"; - $preg_columns_after = "(,\s*([^)]+))?"; // the columns after the column to drop. This is group $3 (drop) or $4(change) (keep!) + $preg_columns_after = "(,\s*(.+))?"; // the columns after the column to drop. This is group $3 (drop) or $4(change) (keep!) // we could remove the comma using $6 instead of $5, but then we might have no comma at all. // Keeping it leaves a problem if we drop the first column, so we fix that case in another regex. $table_new = $table; @@ -876,10 +1307,11 @@ case 'add': if(!isset($matches[4])) { + $this->alterError = $errormsg . ' (add) - '. $lang['alter_no_add_col']; return false; } $new_col_definition = "'$column_escaped' ".$matches[4]; - $preg_pattern_add = "/^".$preg_create_table."(.*)\\)\s*$/"; + $preg_pattern_add = "/^".$preg_create_table."(.*)\\)\s*$/s"; // append the column definiton in the CREATE TABLE statement $newSQL = preg_replace($preg_pattern_add, '$1$2, ', $createtesttableSQL).$new_col_definition.')'; if($debug) @@ -888,50 +1320,58 @@ echo $newSQL."<hr>"; echo $preg_pattern_add."<hr>"; } - if($newSQL==$createtesttableSQL) // pattern did not match, so column removal did not succed + if($newSQL==$createtesttableSQL) // pattern did not match, so column adding did not succed + { + $this->alterError = $errormsg . ' (add) - '.$lang['alter_pattern_mismatch'].'. '.$lang['bug_report'].' '.PROJECT_BUGTRACKER_LINK; return false; + } $createtesttableSQL = $newSQL; break; case 'change': if(!isset($matches[5]) || !isset($matches[6])) { + $this->alterError = $errormsg . ' (change) - '.$lang['alter_col_not_recognized']; return false; } $new_col_name = $matches[5]; $new_col_type = $matches[6]; $new_col_definition = "'$new_col_name' $new_col_type"; - $preg_column_to_change = "\s*".$this->sqlite_surroundings_preg($column)."(?:\s+".preg_quote($coltypes[$column]).")?(\s+(?:".$this->sqlite_surroundings_preg("*",false,",'\")`\[").")+)?"; + $preg_column_to_change = "\s*".$this->sqlite_surroundings_preg($column)."(?:\s+".preg_quote($coltypes[$column]).")?(\s+(?:".$this->sqlite_surroundings_preg("*",false,",'\"`\[").")+)?"; // replace this part (we want to change this column) // group $3 contains the column constraints (keep!). the name & data type is replaced. - $preg_pattern_change = "/^".$preg_create_table.$preg_columns_before.$preg_column_to_change.$preg_columns_after."\s*\\)\s*$/"; + $preg_pattern_change = "/^".$preg_create_table.$preg_columns_before.$preg_column_to_change.$preg_columns_after."\s*\\)\s*$/s"; // replace the column definiton in the CREATE TABLE statement $newSQL = preg_replace($preg_pattern_change, '$1$2,'.strtr($new_col_definition, array('\\' => '\\\\', '$' => '\$')).'$3$4)', $createtesttableSQL); // remove comma at the beginning if the first column is changed // probably somebody is able to put this into the first regex (using lookahead probably). - $newSQL = preg_replace("/^\s*(CREATE\s+TEMPORARY\s+TABLE\s+'".preg_quote($tmpname,"/")."'\s+\(),\s*/",'$1',$newSQL); + $newSQL = preg_replace("/^\s*(CREATE\s+TEMPORARY\s+TABLE\s+".preg_quote($this->quote($tmpname),"/")."\s+\(),\s*/",'$1',$newSQL); if($debug) { echo "preg_column_to_change=(".$preg_column_to_change.")<hr />"; echo $createtesttableSQL."<hr />"; echo $newSQL."<hr />"; + echo $preg_pattern_change."<hr />"; } if($newSQL==$createtesttableSQL || $newSQL=="") // pattern did not match, so column removal did not succed + { + $this->alterError = $errormsg . ' (change) - '.$lang['alter_pattern_mismatch'].'. '.$lang['bug_report'].' '.PROJECT_BUGTRACKER_LINK; return false; + } $createtesttableSQL = $newSQL; $newcols[$column] = str_replace("''","'",$new_col_name); break; case 'drop': - $preg_column_to_drop = "\s*".$this->sqlite_surroundings_preg($column)."\s+(?:".$this->sqlite_surroundings_preg("*",false,",')\"\[`").")+"; // delete this part (we want to drop this column) - $preg_pattern_drop = "/^".$preg_create_table.$preg_columns_before.$preg_column_to_drop.$preg_columns_after."\s*\\)\s*$/"; + $preg_column_to_drop = "\s*".$this->sqlite_surroundings_preg($column)."\s+(?:".$this->sqlite_surroundings_preg("*",false,",'\"\[`").")+"; // delete this part (we want to drop this column) + $preg_pattern_drop = "/^".$preg_create_table.$preg_columns_before.$preg_column_to_drop.$preg_columns_after."\s*\\)\s*$/s"; // remove the column out of the CREATE TABLE statement $newSQL = preg_replace($preg_pattern_drop, '$1$2$3)', $createtesttableSQL); // remove comma at the beginning if the first column is removed // probably somebody is able to put this into the first regex (using lookahead probably). - $newSQL = preg_replace("/^\s*(CREATE\s+TEMPORARY\s+TABLE\s+'".preg_quote($tmpname,"/")."'\s+\(),\s*/",'$1',$newSQL); + $newSQL = preg_replace("/^\s*(CREATE\s+TEMPORARY\s+TABLE\s+".preg_quote($this->quote($tmpname),"/")."\s+\(),\s*/",'$1',$newSQL); if($debug) { echo $createtesttableSQL."<hr>"; @@ -939,7 +1379,10 @@ echo $preg_pattern_drop."<hr>"; } if($newSQL==$createtesttableSQL || $newSQL=="") // pattern did not match, so column removal did not succed + { + $this->alterError = $errormsg . ' (drop) - '.$lang['alter_pattern_mismatch'].'. '.$lang['bug_report'].' '.PROJECT_BUGTRACKER_LINK; return false; + } $createtesttableSQL = $newSQL; unset($newcols[$column]); break; @@ -950,13 +1393,14 @@ $table_new = $column; break; default: - if($default) echo 'ERROR: unknown alter operation!<hr />'; + if($debug) echo 'ERROR: unknown alter operation!<hr />'; + $this->alterError = $errormsg . $lang['alter_unknown_operation']; return false; } } $droptempsql = 'DROP TABLE '.$this->quote_id($tmpname); - $createnewtableSQL = "CREATE TABLE ".$this->quote($table_new)." ".preg_replace("/^\s*CREATE\s+TEMPORARY\s+TABLE\s+'?".str_replace("'","''",preg_quote($tmpname,"/"))."'?\s+(.*)$/i", '$1', $createtesttableSQL, 1); + $createnewtableSQL = "CREATE TABLE ".$this->quote($table_new)." ".preg_replace("/^\s*CREATE\s+TEMPORARY\s+TABLE\s+'?".str_replace("'","''",preg_quote($tmpname,"/"))."'?\s+(.*)$/is", '$1', $createtesttableSQL, 1); $newcolumns = ''; $oldcolumns = ''; @@ -1039,11 +1483,36 @@ } } + + // checks whether a table has a primary key + public function hasPrimaryKey($table) + { + $query = "PRAGMA table_info(".$this->quote_id($table).")"; + $table_info = $this->selectArray($query); + foreach($table_info as $row_id => $row_data) + { + if($row_data['pk']) + { + return true; + } + + } + return false; + } + //get number of rows in table - public function numRows($table) + public function numRows($table, $dontTakeLong = false) { - $result = $this->select("SELECT Count(*) FROM ".$this->quote_id($table)); - return $result[0]; + // as Count(*) can be slow on huge tables without PK, + // if $dontTakeLong is set and the size is > 2MB only count() if there is a PK + if(!$dontTakeLong || $this->getSize() <= 2000 || $this->hasPrimaryKey($table)) + { + $result = $this->select("SELECT Count(*) FROM ".$this->quote_id($table)); + return $result[0]; + } else + { + return '?'; + } } //correctly escape a string to be injected into an SQL query @@ -1064,7 +1533,7 @@ } } - //correctly escape an identifier (column / table / trigger / index name) to be injected into an SQL query + //correctly escape an identifier (column / table / trigger / index name) to be injected into an SQL query public function quote_id($value) { // double-quotes need to be escaped by doubling them @@ -1131,7 +1600,7 @@ //export csv public function export_csv($tables, $field_terminate, $field_enclosed, $field_escaped, $null, $crlf, $fields_in_first_row) { - $field_enclosed = stripslashes($field_enclosed); + $field_enclosed = $field_enclosed; $query = "SELECT * FROM sqlite_master WHERE type='table' or type='view' ORDER BY type DESC"; $result = $this->selectArray($query); for($i=0; $i<sizeof($result); $i++) @@ -1195,13 +1664,14 @@ //export sql public function export_sql($tables, $drop, $structure, $data, $transaction, $comments) { + global $lang; if($comments) { echo "----\r\n"; - echo "-- phpLiteAdmin database dump (http://phpliteadmin.googlecode.com)\r\n"; - echo "-- phpLiteAdmin version: ".VERSION."\r\n"; - echo "-- Exported on ".date('M jS, Y, h:i:sA')."\r\n"; - echo "-- Database file: ".$this->getPath()."\r\n"; + echo "-- ".PROJECT." ".$lang['db_dump']." (".PROJECT_URL.")\r\n"; + echo "-- ".PROJECT." ".$lang['ver'].": ".VERSION."\r\n"; + echo "-- ".$lang['exported'].": ".date($lang['date_format'])."\r\n"; + echo "-- ".$lang['db_f'].": ".$this->getPath()."\r\n"; echo "----\r\n"; } $query = "SELECT * FROM sqlite_master WHERE type='table' OR type='index' OR type='view' OR type='trigger' ORDER BY type='trigger', type='index', type='view', type='table'"; @@ -1226,7 +1696,7 @@ if($comments) { echo "\r\n----\r\n"; - echo "-- Drop ".$result[$i]['type']." for ".$result[$i]['name']."\r\n"; + echo "-- ".$lang['drop']." ".$result[$i]['type']." ".$lang['for']." ".$result[$i]['name']."\r\n"; echo "----\r\n"; } echo "DROP ".strtoupper($result[$i]['type'])." ".$this->quote_id($result[$i]['name']).";\r\n"; @@ -1237,9 +1707,9 @@ { echo "\r\n----\r\n"; if($result[$i]['type']=="table" || $result[$i]['type']=="view") - echo "-- ".ucfirst($result[$i]['type'])." structure for ".$result[$i]['tbl_name']."\r\n"; + echo "-- ".ucfirst($result[$i]['type'])." ".$lang['struct_for']." ".$result[$i]['tbl_name']."\r\n"; else // index or trigger - echo "-- Structure for ".$result[$i]['type']." ".$result[$i]['name']." on table ".$result[$i]['tbl_name']."\r\n"; + echo "-- ".$lang['struct_for']." ".$result[$i]['type']." ".$result[$i]['name']." ".$lang['on_tbl']." ".$result[$i]['tbl_name']."\r\n"; echo "----\r\n"; } echo $result[$i]['sql'].";\r\n"; @@ -1252,7 +1722,7 @@ if($comments) { echo "\r\n----\r\n"; - echo "-- Data dump for ".$result[$i]['tbl_name'].", a total of ".sizeof($arr)." rows\r\n"; + echo "-- ".$lang['data_dump']." ".$result[$i]['tbl_name'].", ".sprintf($lang['total_rows'], sizeof($arr))."\r\n"; echo "----\r\n"; } $query = "PRAGMA table_info(".$this->quote_id($result[$i]['tbl_name']).")"; @@ -1288,50 +1758,45 @@ } $auth = new Authorization(); //create authorization object -//AstLinux// Disable authorization, always grant permission. -if(! $auth->isAuthorized()) { - $auth->grant(false); -} -// -//if(isset($_POST['logout'])) //user has attempted to log out + +//AstLinux// +// check if user has attempted to log out +//if (isset($_POST['logout'])) // $auth->revoke(); -//else if(isset($_POST['login']) || isset($_POST['proc_login'])) //user has attempted to log in -//{ -// $_POST['login'] = true; -// -// if($_POST['password']==SYSTEMPASSWORD) //make sure passwords match before granting authorization -// { -// if(isset($_POST['remember'])) -// $auth->grant(true); -// else -// $auth->grant(false); -// } -//} +// check if user has attempted to log in +//else if (isset($_POST['login']) && isset($_POST['password'])) +// $auth->attemptGrant($_POST['password'], isset($_POST['remember'])); -if($auth->isAuthorized()) +if ($auth->isAuthorized()) { //user is creating a new Database - if(isset($_POST['new_dbname']) && $auth->isAuthorized()) + if(isset($_POST['new_dbname'])) { - $str = preg_replace('@[^\w-.]@','', $_POST['new_dbname']); - $dbname = $str; - $dbpath = $str; - if(checkDbName($dbname)) + if($_POST['new_dbname']=='') { - $tdata = array(); - $tdata['name'] = $dbname; - $tdata['path'] = $directory.DIRECTORY_SEPARATOR.$dbpath; - $td = new Database($tdata); - $td->query("VACUUM"); - } else + // TODO: Display an error message (do NOT echo here. echo below in the html-body!) + } + else { - if(is_file($dbname) || is_dir($dbname)) $dbexists = true; - else $extension_not_allowed=true; + $str = preg_replace('@[^\w-.]@','', $_POST['new_dbname']); + $dbname = $str; + $dbpath = $str; + if(checkDbName($dbname)) + { + $tdata = array(); + $tdata['name'] = $dbname; + $tdata['path'] = $directory.DIRECTORY_SEPARATOR.$dbpath; + $td = new Database($tdata); + $td->query("VACUUM"); + } else + { + if(is_file($dbname) || is_dir($dbname)) $dbexists = true; + else $extension_not_allowed=true; + } } } - //if the user wants to scan a directory for databases, do so if($directory!==false) { @@ -1351,7 +1816,7 @@ if($subdirectories===false) $arr[$i] = $directory.DIRECTORY_SEPARATOR.$arr[$i]; - if(!is_file($arr[$i])) continue; + if(@!is_file($arr[$i])) continue; $con = file_get_contents($arr[$i], NULL, NULL, 0, 60); if(strpos($con, "** This file contains an SQLite 2.1 database **", 0)!==false || strpos($con, "SQLite format 3", 0)!==false) { @@ -1360,18 +1825,9 @@ $databases[$j]['name'] = basename($arr[$i]); else $databases[$j]['name'] = $arr[$i]; - // 22 August 2011: gkf fixed bug 49. - $perms = 0; - $perms += is_readable($databases[$j]['path']) ? 4 : 0; - $perms += is_writeable($databases[$j]['path']) ? 2 : 0; - switch($perms) - { - case 6: $perms = "[rw] "; break; - case 4: $perms = "[r ] "; break; - case 2: $perms = "[ w] "; break; // God forbid, but it might happen. - default: $perms = "[ ] "; break; - } - $databases[$j]['perms'] = $perms; + $databases[$j]['writable'] = is_writable($databases[$j]['path']); + $databases[$j]['writable_dir'] = is_writable(dirname($databases[$j]['path'])); + $databases[$j]['readable'] = is_readable($databases[$j]['path']); $j++; } } @@ -1391,9 +1847,7 @@ } else //the directory is not valid - display error and exit { - echo "<div class='confirm' style='margin:20px;'>"; - echo "The directory you specified to scan for databases does not exist or is not a directory."; - echo "</div>"; + echo "<div class='confirm' style='margin:20px;'>".$lang['not_dir']."</div>"; exit(); } } @@ -1403,20 +1857,15 @@ { if(!file_exists($databases[$i]['path'])) continue; //skip if file not found ! - probably a warning can be displayed - later - $perms = 0; - $perms += is_readable($databases[$i]['path']) ? 4 : 0; - $perms += is_writeable($databases[$i]['path']) ? 2 : 0; - switch($perms) - { - case 6: $perms = "[rw] "; break; - case 4: $perms = "[r ] "; break; - case 2: $perms = "[ w] "; break; // God forbid, but it might happen. - default: $perms = "[ ] "; break; - } - $databases[$i]['perms'] = $perms; + $databases[$i]['writable'] = is_writable($databases[$i]['path']); + $databases[$i]['writable_dir'] = is_writable(dirname($databases[$i]['path'])); + $databases[$i]['readable'] = is_readable($databases[$i]['path']); } sort($databases); } + // we now have the $databases array set. Check whethet currentDB is a managed Db (is in this array) + if(isset($_SESSION[COOKIENAME.'currentDB']) && isManagedDB($_SESSION[COOKIENAME.'currentDB']['path']) === false) + unset($_SESSION[COOKIENAME.'currentDB']); //user is deleting a database if(isset($_GET['database_delete'])) @@ -1429,7 +1878,7 @@ unlink($dbpath); unset($_SESSION[COOKIENAME.'currentDB']); unset($databases[$checkDB]); - } else die('You can only delete databases managed by this tool!'); + } else die($lang['err'].': '.$lang['delete_only_managed']); } //user is renaming a database @@ -1447,14 +1896,12 @@ // we need to make sure it stays within $directory... $new_realpath = realpath($newpath_parts['dirname']).DIRECTORY_SEPARATOR; $directory_realpath = realpath($directory).DIRECTORY_SEPARATOR; - echo $_POST['newname']."=>".$new_realpath."<br>"; - echo $directory_realpath."<br>"; if(strpos($new_realpath, $directory_realpath)===0) { // its okay, the new directory is within $directory $newpath = $_POST['newname']; } - else die('You either tried to move the database into a directory where it cannot be managed anylonger, or the check if you did this failed because of missing rights.'); + else die($lang['err'].': '.$lang['db_moved_outside']); } if(checkDbName($newpath)) @@ -1462,14 +1909,13 @@ $checkDB = isManagedDB($oldpath); if($checkDB !==false ) { - copy($oldpath, $newpath); - unlink($oldpath); + rename($oldpath, $newpath); $databases[$checkDB]['path'] = $newpath; $databases[$checkDB]['name'] = basename($newpath); $_SESSION[COOKIENAME.'currentDB'] = $databases[$checkDB]; $justrenamed = true; } - else die('You can only rename databases managed by this tool!'); + else die($lang['err'].': '.$lang['rename_only_managed']); } else { @@ -1477,8 +1923,8 @@ else $extension_not_allowed = true; } } + - //user is downloading the exported database file if(isset($_POST['export'])) { @@ -1562,46 +2008,44 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> -<!-- Copyright <?php echo date("Y"); ?> phpLiteAdmin (http://phpliteadmin.googlecode.com) --> +<!-- Copyright <?php echo date("Y").' '.PROJECT.' ('.PROJECT_URL.')'; ?> --> <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /> +<link rel="shortcut icon" href="<?php echo PAGE ?>?resource=favicon" /> <title><?php echo PROJECT ?></title> <?php +//AstLinux// use external style sheet. +echo "<link href='/common/phpliteadmin.css' rel='stylesheet' type='text/css' />", PHP_EOL; +//if(isset($_GET['theme'])) $theme = basename($_GET['theme']); +// +// allow themes to be dropped in subfolder "themes" +//if(is_file('themes/'.$theme)) $theme = 'themes/'.$theme; +// +//if (file_exists($theme)) +// // an external stylesheet exists - import it +// echo "<link href='{$theme}' rel='stylesheet' type='text/css' />", PHP_EOL; +//else +// // only use the default stylesheet if an external one does not exist +// echo "<link href='", PAGE, "?resource=css' rel='stylesheet' type='text/css' />", PHP_EOL; +// +//AstLinux// -//AstLinux// Remove built-in stylesheet, only use external one. -echo "<link href='/common/phpliteadmin.css' rel='stylesheet' type='text/css' />"; - if(isset($_GET['help'])) //this page is used as the popup help section { //help section array $help = array ( - 'SQLite Library Extensions' => - 'phpLiteAdmin uses PHP library extensions that allow interaction with SQLite databases. Currently, phpLiteAdmin supports PDO, SQLite3, and SQLiteDatabase. Both PDO and SQLite3 deal with version 3 of SQLite, while SQLiteDatabase deals with version 2. So, if your PHP installation includes more than one SQLite library extension, PDO and SQLite3 will take precedence to make use of the better technology. However, if you have existing databases that are of version 2 of SQLite, phpLiteAdmin will be forced to use SQLiteDatabase for only those databases. Not all databases need to be of the same version. During the database creation, however, the most advanced extension will be used.', - 'Creating a New Database' => - 'When you create a new database, the name you entered will be appended with the appropriate file extension (.db, .db3, .sqlite, etc.) if you do not include it yourself. The database will be created in the directory you specified as the $directory variable.', - 'Tables vs. Views' => - 'On the main database page, there is a list of tables and views. Since views are read-only, certain operations will be disabled. These disabled operations will be apparent by their omission in the location where they should appear on the row for a view. If you want to change the data for a view, you need to drop that view and create a new view with the appropriate SELECT statement that queries other existing tables. For more information, see <a href="http://en.wikipedia.org/wiki/View_... [truncated message content] |
From: <abe...@us...> - 2013-03-20 17:05:23
|
Revision: 6004 http://astlinux.svn.sourceforge.net/astlinux/?rev=6004&view=rev Author: abelbeck Date: 2013-03-20 17:05:16 +0000 (Wed, 20 Mar 2013) Log Message: ----------- web interface, set php.ini: magic_quotes_gpc = Off Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/php.ini branches/1.0/package/webinterface/altweb/admin/system.php branches/1.0/package/webinterface/altweb/admin/testmail.php branches/1.0/package/webinterface/altweb/php.ini Modified: branches/1.0/package/webinterface/altweb/admin/php.ini =================================================================== --- branches/1.0/package/webinterface/altweb/admin/php.ini 2013-03-20 13:35:58 UTC (rev 6003) +++ branches/1.0/package/webinterface/altweb/admin/php.ini 2013-03-20 17:05:16 UTC (rev 6004) @@ -1,3 +1,4 @@ +magic_quotes_gpc = Off display_errors = On output_buffering = On post_max_size = 10M @@ -5,5 +6,4 @@ session.gc_maxlifetime = 1440 session.gc_probability = 100 session.gc_divisor = 100 -max_execution_time = 120 - +max_execution_time = 300 Modified: branches/1.0/package/webinterface/altweb/admin/system.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/system.php 2013-03-20 13:35:58 UTC (rev 6003) +++ branches/1.0/package/webinterface/altweb/admin/system.php 2013-03-20 17:05:16 UTC (rev 6004) @@ -87,7 +87,7 @@ $str = 'No Action.'; if (isset($_GET['result_str'])) { - $str = stripslashes(rawurldecode($_GET['result_str'])); + $str = rawurldecode($_GET['result_str']); } if ($result == 100) { $color = 'green'; Modified: branches/1.0/package/webinterface/altweb/admin/testmail.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/testmail.php 2013-03-20 13:35:58 UTC (rev 6003) +++ branches/1.0/package/webinterface/altweb/admin/testmail.php 2013-03-20 17:05:16 UTC (rev 6004) @@ -40,7 +40,7 @@ $str = 'No Action.'; if (isset($_GET['result_str'])) { - $str = stripslashes(rawurldecode($_GET['result_str'])); + $str = rawurldecode($_GET['result_str']); } if ($result == 100) { $color = 'green'; Modified: branches/1.0/package/webinterface/altweb/php.ini =================================================================== --- branches/1.0/package/webinterface/altweb/php.ini 2013-03-20 13:35:58 UTC (rev 6003) +++ branches/1.0/package/webinterface/altweb/php.ini 2013-03-20 17:05:16 UTC (rev 6004) @@ -1,3 +1,4 @@ +magic_quotes_gpc = Off display_errors = On output_buffering = On post_max_size = 10M @@ -5,5 +6,4 @@ session.gc_maxlifetime = 1440 session.gc_probability = 100 session.gc_divisor = 100 -max_execution_time = 120 - +max_execution_time = 300 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <abe...@us...> - 2013-03-21 04:12:55
|
Revision: 6010 http://astlinux.svn.sourceforge.net/astlinux/?rev=6010&view=rev Author: abelbeck Date: 2013-03-21 04:12:48 +0000 (Thu, 21 Mar 2013) Log Message: ----------- web interface, remove the 'resource' code from phpliteadmin.php and add phpliteadmin.js Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/edit.php branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php Added Paths: ----------- branches/1.0/package/webinterface/altweb/common/phpliteadmin.js Modified: branches/1.0/package/webinterface/altweb/admin/edit.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/edit.php 2013-03-20 21:21:28 UTC (rev 6009) +++ branches/1.0/package/webinterface/altweb/admin/edit.php 2013-03-21 04:12:48 UTC (rev 6010) @@ -353,7 +353,7 @@ } putHtml("</center>"); ?> - <script language="JavaScript" type="text/javascript" src="../common/murmurhash3_gc.js"></script> + <script language="JavaScript" type="text/javascript" src="/common/murmurhash3_gc.js"></script> <script language="JavaScript" type="text/javascript"> //<![CDATA[ var old_textSize; Modified: branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php 2013-03-20 21:21:28 UTC (rev 6009) +++ branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php 2013-03-21 04:12:48 UTC (rev 6010) @@ -420,11 +420,7 @@ define('PROJECT_BUGTRACKER_LINK','<a href="http://code.google.com/p/phpliteadmin/issues/list" target="_blank">http://code.google.com/p/phpliteadmin/issues/list</a>'); // Resource output (css and javascript files) -// we get out of the main code as soon as possible, without inizializing the session -if (isset($_GET['resource'])) { - Resources::output($_GET['resource']); - exit(); -} +//AstLinux// Remove all 'resource' related code, use external files instead // don't mess with this - required for the login session ini_set('session.cookie_httponly', '1'); @@ -2010,7 +2006,6 @@ <head> <!-- Copyright <?php echo date("Y").' '.PROJECT.' ('.PROJECT_URL.')'; ?> --> <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /> -<link rel="shortcut icon" href="<?php echo PAGE ?>?resource=favicon" /> <title><?php echo PROJECT ?></title> <?php @@ -2071,7 +2066,7 @@ } ?> <!-- JavaScript Support --> -<script type='text/javascript' src='<?php echo PAGE ?>?resource=javascript'></script> +<script type='text/javascript' src='/common/phpliteadmin.js'></script> </head> <body style="direction:<?php echo $lang['direction']; ?>;"> <?php @@ -5037,75 +5032,4 @@ } - -/* class Resources (issue #157) - outputs secondary files, such as css and javascript - data is stored gzipped (gzencode) and encoded (base64_encode) -*/ - -class Resources { - - private static $_resources = array( - 'css' => array( - 'mime' => 'text/css', - 'data' => 'H4sIAAAAAAAAA91XTY/jNgz9KwMEvcWGnXQGGfvUPQQ99dR7IFt0LIxseSUlmazh/15KlhPF9nxlWyxQBAESSqLIR/KRygQ9txWRe1YnUdoQSlm9x1+FqHVQkIrxc/KHZIQv/wR+BM1yslSkVoECyYp+m2I/IIl/b17TXHAhk0UURWlG8pe9FIeaBk4KEWTFUyqOIAsuTgk5aJF2YYYW7HTGHzRth/ufm9eHFX6f+y/u4lDoHe44MarLJI4iIyXtcOF6m2p41QGFXEiimaiTWtSQ5gepcEMjWK1B4omkNPdfzj1t066UbQlsX+okRqWZkBQkIuC2ZFk244uRXkz5DXXEUxAfUdsVn5XBZ6qoWOeQQ2884WxfJzlYU30orUmBFk1gYAgkoeygrH5vSRoX/LWgEj8Ct6EXm31GwzvLVotd7xYlEFzkrH5R7dTA3l/UoLWoEAY84nvuNHsBchIH23WL0mcOiRKc0UFk3ezlNoyDmdZFT+6l32oWXpdzdt+pD3ImODUBe1hgIijMlNaD2lP4ZDAw27jYC39PV67erJhrKdzCs7L5yurmoJcKOOR6aRAlEkj7yVKbcY6YTzqFeCqZwfgaB+eMF7V3s8iKB7/XF7/CTCOUo3q7rLi6mzqR53naFQw4VaAvBBD/dAp97MJMMT6bD2Z+jiEhrEaDLwbZAC5MYv5Fjm2Foe2tWD36mR/da/TElu12O2i91NiXItSFRwanv0nG4UFLn13j3hWBQf8mXh2lPlpKdVlrScLysxP0tOBLkCsS6/q/6fDnnVtUGJ/2vrtvk+w9Q3rg32Jdtzoh3i+Scq/mPV7ud1yp+UPqDjWNZ2qteIY1rP1mY8+MaXRIO2uST+wuDfpawDtWc3dMGtrP3dE3oTsjPeH9e6x4s6t8oRSRUAomqy+7QYkq4cOMdfYgXCRrKVMNJ+ck4yJ/uWnJt75txv5v7i7mG5KwYw8XRCdG66hWvN7dCMXsoCaB48R2xJxBSok9qxztzQ9Orvn9otnIIL1rJCgF9H+A+DwJumZOoSAHrn8Z1CXw5nvrVW48DNausmshK8LtwMqb3bR3R+Oy/0SXmyG2onDG7MRBz84yXs/GS92jYm0b6xR7p4szpW+nDHfOPY8M/9F2NFxOeG0+BT9FX//thO68ZPV0mOpXMNjjAhqgIhleiVCnPhl7z40uPBFZo8JlSHGm1rAMoWr0Gf9K0QzCHc3c9C6RSbtQMQoZkTttJqNxWnUhyU10+tXl8A9VjJ+XiKd9GxkX6wPnwwths9mgpDB4exliciOaf6J2/wAraB0Fgw8AAA==', - ), - 'javascript' => array( - 'mime' => 'text/javascript', - 'data' => 'H4sIAAAAAAAAC8VWbW/bNhD+Kw6HNhKkqSq2T9WIICu8zWhRDG2+DUNAUSeJiEyqFBXXS/3fdyTlFymx463A9sWW7v157nhU2UtuhJIzIYW57o0SkmtYgjRB+HDP9IzRNFvVooGgULy3iqQCM2+czc/rRREQQSIWkVt26E3CC9rLAkohoQgf/qFvUoiO5Q0U1OgeMhZFm025rdSoqmpgXGvui+X0VKIcE5l1CyTMrHHxrHGrxZLp9R2sBxf2rMsESCbK4IKFDxpMr+WsZE0HG5Tx5J41PVBKFh9u5r/OP5KXL4uE18DvLF1sT4B3Afw5lHpatg6D0ZSiD33TBMwzk5+snD0F9jSZ1kUqIzGHh5nvy+eTQvmuUPvqwfApxH31zvgaa8/PHkHncotVnTl2e/tRaZNJw///pRRHyKQWXjNZwaKSSkOQxzzGxjrW3SBdUELc+7E0/Lxq+KSIzYmQZwKc4tocgFqqe/hFQFN0u21zlKfS2nElDcN8ejejElaza63ZOgizUunAD3ua5T+xRLU2S5c0ICtTZ3kUOY52ij/yP5MOGuDGT23bd/VY68gNseJRZD6OKDvQ5tq8ZXjKA/K5B71GPxJfksuI2yga2oZxCF6RVxVKyWUYoS48IGIco4prT0d5lI5qu5DKpONaNc2NagdGUvcvaBCUAzrM8Mkwbb5+nUpwAaUkvCJlSd7sG72zuSICyBvXttAdcoEOKAofyqREa2ybSwb0sW+CS5AZ+GjHFs0gsc12Se3MM82QdU3i70tP8kBpmHEKiYEvZhD4bTGkxjKxT3SKYrPxvQmGWGHS9XlntJBVkMZ8u+6fUvN4mn94p3lURwVWw6N62+7/hoBjhnyrmstipEitwqcNwsd8Peo5zw5EGMwJBjQ4k/uBomw/objrt/fJ2Sd95zys+htsa8DifDiFu/viWMA8HHpBSHbCZnTZePznWD99ac6/tEqb7hROAs5mWBO33We8AZPOrBuwwfGorymRSsLxoicReHf/jRHc9TEJkDeK35EpvsXyeXxi+a34xhH+Db5xhHPwqRbkb9C0Ftrvqu3btxgMdHB5VaOUvv7uMmIxsRazT372SegWh1V3wIdrdxfvMIYb2q3dSshCrRKbzypiYpRqcqZpGvujg88dfR1jfcxGsnLDTN95G8TY+ycNnfjLDiM+r0RhavpjmsY1iKo29IcUN/Pko+i9uLOXv7/6GR7w94t38xfkuY/fHLfq9iS9INHwHOHzZpP9DYY8LKACDAAA', - ), - 'favicon' => array( - 'mime' => 'image/x-icon', - 'data' => 'H4sIAAAAAAAAA2NgYARCAQEGIKnAoMHCwCDGwMCgAcRAIaAIRJxYwM/FlQqkhInWgAYEeXgmAylZcvUL8fEdBFIeZGhlFObnd+Lk5LzKysq6D8hPBomRYgAfN3cYkHovISz8H0i/BeKNQCxIrH4RXl5vIHUSpB9qBgjvAGJ+YvRLCgra8HJxHQLpFeDlXYNkjj2xbuDh4KgE2QuMh7NA+hDUDe+AOJEY/dAw+Aiyl4OVdStUPwg/ZSAyXoF+OAh2Az//GSB9EsmMKiK94QxSD3IDME6PAtmfoPpfAbEaEfqZgHgrzAwgvRPJDZ1EukEeiB+D9LCxsYHccBOq/xiR+kEgDoh/AvFfpPRwgQT9IOAIxI8YEO4vI1E/CCgD8TogzkOXAAAwF/00PgQAAA==', - ), - ); - - // override the internal resource with an external file - public static function useExternal($resource, $filename) - { - if (isset(self::$_resources[$resource]) && is_readable($filename)) { - self::$_resources[$resource]['file'] = $filename; - } - } - - // outputs the specified resource, if defined in this class. - // the main script should do no further output after calling this function. - public static function output($resource) - { - if (isset(self::$_resources[$resource])) { - $res =& self::$_resources[$resource]; - - // use last-modified time as etag; etag must be quoted - $etag = '"' . filemtime(isset($res['file']) ? $res['file'] : PAGE) . '"'; - - // check headers for matching etag; if etag hasn't changed, use the cached version - if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag) { - header('HTTP/1.0 304 Not Modified'); - return; - } - - header('Etag: ' . $etag); - - // cache file for at most 30 days - header('Cache-control: max-age=2592000'); - - // output resource - header('Content-type: ' . $res['mime']); - - if (isset($res['file'])) { - readfile($res['file']); - } else { - if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) { - header('Content-encoding: gzip'); - echo base64_decode($res['data']); - } else { - // browser does not accept gzipped data, decompress - echo gzdecode(base64_decode($res['data'])); - } - } - } - } - -} - -# - eof - +?> Added: branches/1.0/package/webinterface/altweb/common/phpliteadmin.js =================================================================== --- branches/1.0/package/webinterface/altweb/common/phpliteadmin.js (rev 0) +++ branches/1.0/package/webinterface/altweb/common/phpliteadmin.js 2013-03-21 04:12:48 UTC (rev 6010) @@ -0,0 +1,169 @@ +//initiated autoincrement checkboxes +function initAutoincrement() +{ + var i=0; + while(document.getElementById('i'+i+'_autoincrement')!=undefined) + { + document.getElementById('i'+i+'_autoincrement').disabled = true; + i++; + } +} +//makes sure autoincrement can only be selected when integer type is selected +function toggleAutoincrement(i) +{ + var type = document.getElementById('i'+i+'_type'); + var primarykey = document.getElementById('i'+i+'_primarykey'); + var autoincrement = document.getElementById('i'+i+'_autoincrement'); + if(!autoincrement) return false; + if(type.value=='INTEGER' && primarykey.checked) + autoincrement.disabled = false; + else + { + autoincrement.disabled = true; + autoincrement.checked = false; + } +} +function toggleNull(i) +{ + var pk = document.getElementById('i'+i+'_primarykey'); + var notnull = document.getElementById('i'+i+'_notnull'); + if(pk.checked) + { + notnull.disabled = true; + notnull.checked = true; + } + else + { + notnull.disabled = false; + } +} +//finds and checks all checkboxes for all rows on the Browse or Structure tab for a table +function checkAll(field) +{ + var i=0; + while(document.getElementById('check_'+i)!=undefined) + { + document.getElementById('check_'+i).checked = true; + i++; + } +} +//finds and unchecks all checkboxes for all rows on the Browse or Structure tab for a table +function uncheckAll(field) +{ + var i=0; + while(document.getElementById('check_'+i)!=undefined) + { + document.getElementById('check_'+i).checked = false; + i++; + } +} +//unchecks the ignore checkbox if user has typed something into one of the fields for adding new rows +function changeIgnore(area, e, u) +{ + if(area.value!="") + { + if(document.getElementById(e)!=undefined) + document.getElementById(e).checked = false; + if(document.getElementById(u)!=undefined) + document.getElementById(u).checked = false; + } +} +//moves fields from select menu into query textarea for SQL tab +function moveFields() +{ + var fields = document.getElementById("fieldcontainer"); + var selected = new Array(); + for(var i=0; i<fields.options.length; i++) + if(fields.options[i].selected) + selected.push(fields.options[i].value); + for(var i=0; i<selected.length; i++) + insertAtCaret("queryval", '"'+selected[i].replace(/"/g,'""')+'"'); +} +//helper function for moveFields +function insertAtCaret(areaId,text) +{ + var txtarea = document.getElementById(areaId); + var scrollPos = txtarea.scrollTop; + var strPos = 0; + var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ? "ff" : (document.selection ? "ie" : false )); + if(br=="ie") + { + txtarea.focus(); + var range = document.selection.createRange(); + range.moveStart ('character', -txtarea.value.length); + strPos = range.text.length; + } + else if(br=="ff") + strPos = txtarea.selectionStart; + + var front = (txtarea.value).substring(0,strPos); + var back = (txtarea.value).substring(strPos,txtarea.value.length); + txtarea.value=front+text+back; + strPos = strPos + text.length; + if(br=="ie") + { + txtarea.focus(); + var range = document.selection.createRange(); + range.moveStart ('character', -txtarea.value.length); + range.moveStart ('character', strPos); + range.moveEnd ('character', 0); + range.select(); + } + else if(br=="ff") + { + txtarea.selectionStart = strPos; + txtarea.selectionEnd = strPos; + txtarea.focus(); + } + txtarea.scrollTop = scrollPos; +} + +function notNull(checker) +{ + document.getElementById(checker).checked = false; +} + +function disableText(checker, textie) +{ + if(checker.checked) + { + document.getElementById(textie).value = ""; + document.getElementById(textie).disabled = true; + } + else + { + document.getElementById(textie).disabled = false; + } +} + +function toggleExports(val) +{ + document.getElementById("exportoptions_sql").style.display = "none"; + document.getElementById("exportoptions_csv").style.display = "none"; + + document.getElementById("exportoptions_"+val).style.display = "block"; +} + +function toggleImports(val) +{ + document.getElementById("importoptions_sql").style.display = "none"; + document.getElementById("importoptions_csv").style.display = "none"; + + document.getElementById("importoptions_"+val).style.display = "block"; +} + +function openHelp(section) +{ + PopupCenter('?help=1#'+section, "Help Section"); +} +var helpsec = false; +function PopupCenter(pageURL, title) +{ + helpsec = window.open(pageURL, title, "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=300"); +} +function checkLike(srchField, selOpt){ + if(selOpt=="LIKE%"){ + var textArea = document.getElementById(srchField); + textArea.value = "%" + textArea.value + "%"; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <abe...@us...> - 2013-03-30 18:51:20
|
Revision: 6029 http://astlinux.svn.sourceforge.net/astlinux/?rev=6029&view=rev Author: abelbeck Date: 2013-03-30 18:51:11 +0000 (Sat, 30 Mar 2013) Log Message: ----------- web interface, Firewall tab, Traffic Shaping - Downlink Speed, set 'Disabled' by default and clarify Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/firewall.php branches/1.0/package/webinterface/altweb/common/license-packages.txt Modified: branches/1.0/package/webinterface/altweb/admin/firewall.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/firewall.php 2013-03-30 13:55:16 UTC (rev 6028) +++ branches/1.0/package/webinterface/altweb/admin/firewall.php 2013-03-30 18:51:11 UTC (rev 6029) @@ -317,7 +317,10 @@ fwrite($fp, "### Traffic Shaping\n"); $value = 'SHAPETYPE="'.$_POST['shaper_enable_type'].'"'; fwrite($fp, $value."\n"); - $value = 'EXTDOWN="'.tuq($_POST['shaper_extdown']).'"'; + if (($value = tuq($_POST['shaper_extdown'])) === '' || $_POST['shaper_extdown_enable'] === 'no') { + $value = '0'; + } + $value = 'EXTDOWN="'.$value.'"'; fwrite($fp, $value."\n"); $value = 'EXTUP="'.tuq($_POST['shaper_extup']).'"'; fwrite($fp, $value."\n"); @@ -915,11 +918,17 @@ putHtml('<tr class="dtrow1"><td width="175" style="text-align: right;">'); putHtml('Downlink Speed:'); putHtml('</td><td style="text-align: left;">'); - if (($value = getVARdef($vars, 'EXTDOWN')) === '') { - $value = '4000'; + if ((int)($value = getVARdef($vars, 'EXTDOWN')) == 0) { + $value = ''; } putHtml('<input type="text" size="8" maxlength="6" value="'.$value.'" name="shaper_extdown" />'); - putHtml('K bits-per-second</td></tr>'); + putHtml('<select name="shaper_extdown_enable">'); + $sel = ($value === '') ? ' selected="selected"' : ''; + putHtml('<option value="no"'.$sel.'>Disabled</option>'); + $sel = ($value !== '') ? ' selected="selected"' : ''; + putHtml('<option value="yes"'.$sel.'>K bits-per-second</option>'); + putHtml('</select>'); + putHtml('</td></tr>'); putHtml('<tr class="dtrow1"><td style="text-align: right;">'); putHtml('Uplink Speed:'); putHtml('</td><td style="text-align: left;">'); @@ -927,12 +936,15 @@ $value = '800'; } putHtml('<input type="text" size="8" maxlength="6" value="'.$value.'" name="shaper_extup" />'); - putHtml('K bits-per-second</td></tr>'); + putHtml('<select name="shaper_extup_enable">'); + putHtml('<option value="yes">K bits-per-second</option>'); + putHtml('</select>'); + putHtml('</td></tr>'); putHtml('<tr class="dtrow1"><td style="text-align: right;">'); putHtml('VoIP UDP Ports:'); putHtml('</td><td style="text-align: left;">'); if (($value = getVARdef($vars, 'VOIPPORTS')) === '') { - $value = '4569 16384:16639'; + $value = '16384:16639'; } putHtml('<input type="text" size="56" maxlength="128" value="'.$value.'" name="shaper_voipports" />'); putHtml('</td></tr>'); Modified: branches/1.0/package/webinterface/altweb/common/license-packages.txt =================================================================== --- branches/1.0/package/webinterface/altweb/common/license-packages.txt 2013-03-30 13:55:16 UTC (rev 6028) +++ branches/1.0/package/webinterface/altweb/common/license-packages.txt 2013-03-30 18:51:11 UTC (rev 6029) @@ -38,6 +38,7 @@ SILK CODEC~Copyright (c) 2010-2012 Skype and/or Microsoft. All rights reserved. Licensed via Digium, Inc. SpanDSP~Copyright (c) 2003-2012 Steve Underwood <st...@co...>. All rights reserved. Prosody~Copyright (c) 2008-2010 Matthew Wild and Waqas Hussain. +clix~Copyright (c) 2008-2013 Matthew Wild. Lua~Copyright (c) 1994-2012 Lua.org, PUC-Rio. All rights reserved. perl~Copyright (c) 1987-2012 by Larry Wall, et al. phpliteadmin~Copyright (c) 2011-2013 phpLiteAdmin (http://phpliteadmin.googlecode.com) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <abe...@us...> - 2013-04-10 15:38:13
|
Revision: 6042 http://sourceforge.net/p/astlinux/code/6042 Author: abelbeck Date: 2013-04-10 15:38:09 +0000 (Wed, 10 Apr 2013) Log Message: ----------- web interface, A new ConfBridge tab has been added, hidden by default. Similar to the MeetMe tab. Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/prefs.php branches/1.0/package/webinterface/altweb/common/header.php branches/1.0/package/webinterface/altweb/common/version.php Added Paths: ----------- branches/1.0/package/webinterface/altweb/admin/confbridge.php Added: branches/1.0/package/webinterface/altweb/admin/confbridge.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/confbridge.php (rev 0) +++ branches/1.0/package/webinterface/altweb/admin/confbridge.php 2013-04-10 15:38:09 UTC (rev 6042) @@ -0,0 +1,382 @@ +<?php + +// Copyright (C) 2012-2013 Lonnie Abelbeck +// This is free software, licensed under the GNU General Public License +// version 3 as published by the Free Software Foundation; you can +// redistribute it and/or modify it under the terms of the GNU +// General Public License; and comes with ABSOLUTELY NO WARRANTY. + +// confbridge.php for AstLinux +// 04-09-2013 +// + +$myself = $_SERVER['PHP_SELF']; + +require_once '../common/functions.php'; + +$isASTERISKv1_x = isASTERISKv1_x(); + +// Function: getASTERISKversion +// +function getASTERISKversion() { + + $list = explode(' ', trim(shell_exec('/usr/sbin/asterisk -V'))); + return($list[1]); +} + +// Function: isASTERISKv1_x +// +function isASTERISKv1_x() { + + $list = explode('.', getASTERISKversion()); + if ((int)$list[0] < 10) { + return(TRUE); + } + return(FALSE); +} + +// Function: userRedirect +// +function userRedirect($chan, $path) { + + $list = explode(',', $path); + + $cont = isset($list[0]) ? $list[0] : 'default'; + $ext = isset($list[1]) ? $list[1] : 's'; + $prio = isset($list[2]) ? $list[2] : '1'; + + if (($socket = @fsockopen('127.0.0.1', '5038', $errno, $errstr, 5)) === FALSE) { + return(FALSE); + } + fputs($socket, "Action: login\r\n"); + fputs($socket, "Username: webinterface\r\n"); + fputs($socket, "Secret: webinterface\r\n"); + fputs($socket, "Events: off\r\n\r\n"); + + fputs($socket, "Action: redirect\r\n"); + fputs($socket, "Context: $cont\r\n"); + fputs($socket, "Channel: $chan\r\n"); + fputs($socket, "Exten: $ext\r\n"); + fputs($socket, "Priority: $prio\r\n\r\n"); + + fputs($socket, "Action: logoff\r\n\r\n"); + + stream_set_timeout($socket, 5); + $info = stream_get_meta_data($socket); + while (! feof($socket) && ! $info['timed_out']) { + $line = fgets($socket, 256); + $info = stream_get_meta_data($socket); + if (strncasecmp($line, 'Response: Error', 15) == 0) { + while (! feof($socket) && ! $info['timed_out']) { + fgets($socket, 256); + $info = stream_get_meta_data($socket); + } + fclose($socket); + return(FALSE); + } + if (strncasecmp($line, 'Message: Redirect successful', 28) == 0) { + break; + } + } + while (! feof($socket) && ! $info['timed_out']) { + fgets($socket, 256); + $info = stream_get_meta_data($socket); + } + fclose($socket); + + sleep(1); + return(0); +} + +// Function: userMute +// +function userMute($user, $mute) { + + if (strpos($user, ',') === FALSE) { + return(FALSE); + } + $ips = explode(',', $user, 2); + $status = asteriskCMD('confbridge '.$mute.' '.$ips[0].' '.rawurldecode($ips[1]), ''); + if ($status != 0) { + return(FALSE); + } + return(0); +} + +// Function: userKick +// +function userKick($user) { + + if (strpos($user, ',') === FALSE) { + return(FALSE); + } + $ips = explode(',', $user, 2); + $status = asteriskCMD('confbridge kick '.$ips[0].' '.rawurldecode($ips[1]), ''); + if ($status != 0) { + return(FALSE); + } + + sleep(5); + return(0); +} + +// Function: confLock +// +function confLock($conf, $lock) { + + $status = asteriskCMD('confbridge '.$lock.' '.$conf, ''); + if ($status != 0) { + return(FALSE); + } + return(0); +} + +// Function: getCONFBRIDGErooms +// +function getCONFBRIDGErooms() { + $id = 0; + $cmd = 'confbridge list'; + + $tmpfile = tempnam("/tmp", "PHP_"); + $status = asteriskCMD($cmd, $tmpfile); + if ($status == 0) { + $ph = @fopen($tmpfile, "r"); + while (! feof($ph)) { + if ($line = trim(fgets($ph, 1024))) { + if (preg_match('/^([0-9]+) +([0-9]+) +([0-9]+) +([a-z]+).*$/', $line, $ips)) { + $rooms[$id]['room'] = $ips[1]; + $rooms[$id]['locked'] = ($ips[4] === 'locked') ? '1' : '0'; + $id++; + } + } + } + fclose($ph); + } + @unlink($tmpfile); + + return($rooms); +} + +// Function: parseCONFBRIDGEdata +// +function parseCONFBRIDGEdata($room_list) { + $id = 0; + + for ($i = 0; $i < count($room_list); $i++) { + $tmpfile = tempnam("/tmp", "PHP_"); + $status = asteriskCMD('confbridge list '.$room_list[$i]['room'], $tmpfile); + if ($status == 0) { + $ph = @fopen($tmpfile, "r"); + while (! feof($ph)) { // Skip through a line beginning with a = + if ($line = fgets($ph, 1024)) { + if ($line[0] === '=') { + break; + } + } + } + while (! feof($ph)) { + if ($line = trim(fgets($ph, 1024))) { + if (preg_match('/^([^ ]+) +([^ ]+) +([^ ]+) .* ([^ ]+) *$/', $line, $ips)) { + $db['data'][$id]['room'] = $room_list[$i]['room']; + $db['data'][$id]['channel'] = $ips[1]; + $db['data'][$id]['user_profile'] = $ips[2]; + $db['data'][$id]['bridge_profile'] = $ips[3]; + $db['data'][$id]['cidnum'] = $ips[4]; + $id++; + } + } + } + fclose($ph); + } + @unlink($tmpfile); + } + + return($db); +} + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $result = 1; + if (! $global_staff) { + $result = 999; + } elseif (isset($_POST['submit_reload'])) { + header('Location: '.$myself); + exit; + } elseif (isset($_POST['submit_autorefresh'])) { + header('Location: '.$myself.'?autorefresh'); + exit; + } elseif (isset($_POST['submit_stoprefresh'])) { + header('Location: '.$myself); + exit; + } + header('Location: '.$myself.'?result='.$result); + exit; +} else { // Start of HTTP GET +$ACCESS_RIGHTS = 'staff'; +require_once '../common/header.php'; + + $autorefresh = isset($_GET['autorefresh']) ? '&autorefresh' : ''; + + $ok_redirect = TRUE; + if (isset($_GET['redirect'])) { + $redirect_path = getPREFdef($global_prefs, 'meetme_redirect_path_cmdstr'); + $ok_redirect = userRedirect(rawurldecode($_GET['redirect']), $redirect_path); + } + $ok = TRUE; + if (isset($_GET['lock'])) { + $ok = confLock($_GET['lock'], 'lock'); + } + if (isset($_GET['unlock'])) { + $ok = confLock($_GET['unlock'], 'unlock'); + } + if (isset($_GET['mute'])) { + $ok = userMute($_GET['mute'], 'mute'); + } + if (isset($_GET['unmute'])) { + $ok = userMute($_GET['unmute'], 'unmute'); + } + if (isset($_GET['kick'])) { + $ok = userKick($_GET['kick']); + } + + putHtml('<center>'); + if (isset($_GET['result'])) { + $result = $_GET['result']; + if ($result == 1) { + putHtml('<p style="color: orange;">No Action.</p>'); + } elseif ($result == 99) { + putHtml('<p style="color: red;">Action Failed.</p>'); + } elseif ($result == 999) { + putHtml('<p style="color: red;">Permission denied for user "'.$global_user.'".</p>'); + } else { + putHtml('<p> </p>'); + } + } elseif ($ok_redirect === FALSE) { + putHtml('<p style="color: red;">Asterisk Action Failed. Redirect requires "call" AMI privileges for [webinterface].</p>'); + } elseif ($ok === FALSE) { + putHtml('<p style="color: red;">Asterisk Action Failed.</p>'); + } else { + putHtml('<p> </p>'); + } + putHtml('</center>'); +?> + <script language="JavaScript" type="text/javascript"> + //<![CDATA[ + var refresh_timeout; + function auto_refresh() { + refresh_timeout = setTimeout("refresh()", 10000); // 10 seconds + } + function stop_refresh() { + if (typeof(refresh_timeout) != 'undefined') { + clearTimeout(refresh_timeout); + refresh_timeout = undefined; + } + } + function refresh() { + window.location.replace("/admin/confbridge.php?autorefresh"); + } + //]]> + </script> + <center> + <table class="layout"><tr><td><center> + <form method="post" action="<?php echo $myself;?>"> + <table width="100%" class="stdtable"> + <tr><td style="text-align: center;" colspan="5"> + <h2>ConfBridge Conference Management:</h2> + </td></tr><tr><td width="50"> + </td><td style="text-align: center;"> +<?php + if ($autorefresh === '') { + putHtml('<input type="submit" class="formbtn" value="Refresh List" name="submit_reload" />'); + } else { + putHtml('<input type="submit" class="formbtn" value="Refresh List" name="submit_autorefresh" />'); + } +?> + </td><td width="50"> + </td><td style="text-align: center;"> +<?php + if ($autorefresh === '') { + putHtml('<input type="submit" class="formbtn" value="Auto Refresh List" name="submit_autorefresh" />'); + } else { + putHtml('<input type="submit" class="formbtn" value="Stop Auto Refresh" onclick="stop_refresh()" name="submit_stoprefresh" />'); + } +?> + </td><td width="50"> + </td></tr> + </table> +<?php + if ($isASTERISKv1_x) { + $room_list = NULL; + $db = NULL; + } else { + $room_list = getCONFBRIDGErooms(); + $db = parseCONFBRIDGEdata($room_list); + } + + $channel = (getPREFdef($global_prefs, 'meetme_channel_show') === 'yes'); + + for ($rnum = 0; $rnum < count($room_list); $rnum++) { + $room = $room_list[$rnum]['room']; + putHtml('<p class="dialogText" style="text-align: left;">'); + putHtml(' <strong>Conference: </strong>'.$room.' '); + if ($room_list[$rnum]['locked'] === '0') { + echo '<a href="'.$myself.'?lock='.$room.$autorefresh.'" onclick="stop_refresh()" class="actionText">Lock</a>'; + } else { + echo '<a href="'.$myself.'?unlock='.$room.$autorefresh.'" onclick="stop_refresh()" class="actionText">Unlock</a>'; + } + putHtml('</p>'); + + putHtml('<table width="100%" class="datatable">'); + putHtml("<tr>"); + + if (($n = count($db['data'])) > 0) { + echo '<td class="dialogText" style="text-align: left; font-weight: bold;">', "CID Num", "</td>"; + echo '<td class="dialogText" style="text-align: left; font-weight: bold;">', "User Profile", "</td>"; + if ($channel) { + echo '<td class="dialogText" style="text-align: left; font-weight: bold;">', "Channel", "</td>"; + } + echo '<td class="dialogText" style="text-align: center; font-weight: bold;">', "-- Actions --", "</td>"; + for ($i = 0; $i < $n; $i++) { + $data = $db['data'][$i]; + if ($data['room'] !== $room) { // skip + continue; + } + $room_user = $data['room'].','.rawurlencode($data['channel']); + putHtml("</tr>"); + echo '<tr ', ($i % 2 == 0) ? 'class="dtrow0"' : 'class="dtrow1"', '>'; + echo '<td style="text-align: left;">', $data['cidnum'], '</td>'; + echo '<td style="text-align: left;">', $data['user_profile'], '</td>'; + if ($channel) { + echo '<td style="text-align: left;">', $data['channel'], '</td>'; + } + + echo '<td style="text-align: right; padding-top: 8px; padding-bottom: 8px;">'; + echo '<a href="'.$myself.'?mute='.$room_user.$autorefresh.'" onclick="stop_refresh()" class="actionText">Mute</a>'; + echo ' <a href="'.$myself.'?unmute='.$room_user.$autorefresh.'" onclick="stop_refresh()" class="actionText">Unmute</a>'; + echo ' <a href="'.$myself.'?redirect='.rawurlencode($data['channel']).$autorefresh.'" onclick="stop_refresh()" class="actionText">Redirect</a>'; + echo ' <a href="/admin/blacklist.php?num='.$data['cidnum'].'" onclick="stop_refresh()" class="actionText">Blacklist</a>'; + echo ' <a href="'.$myself.'?kick='.$room_user.$autorefresh.'" onclick="stop_refresh()" class="actionText">Kick</a>'; + echo '</td>'; + } + } + putHtml("</tr>"); + putHtml("</table>"); + } + if ($isASTERISKv1_x) { + putHtml('<p style="color: red;">ConfBridge is not available, Asterisk 10 or later is required.</p>'); + } elseif (count($room_list) == 0) { + putHtml('<p>No active ConfBridge conferences.</p>'); + } + putHtml("</form>"); + putHtml("</center></td></tr></table>"); + putHtml("</center>"); + if ($autorefresh !== '') { + putHtml('<script language="JavaScript" type="text/javascript">'); + putHtml('//<![CDATA['); + putHtml('auto_refresh();'); + putHtml('//]]>'); + putHtml('</script>'); + } +} // End of HTTP GET +require_once '../common/footer.php'; + +?> Property changes on: branches/1.0/package/webinterface/altweb/admin/confbridge.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Modified: branches/1.0/package/webinterface/altweb/admin/prefs.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/prefs.php 2013-04-06 01:07:19 UTC (rev 6041) +++ branches/1.0/package/webinterface/altweb/admin/prefs.php 2013-04-10 15:38:09 UTC (rev 6042) @@ -434,6 +434,10 @@ $value = 'tab_meetme_show = yes'; fwrite($fp, $value."\n"); } + if (isset($_POST['tab_confbridge'])) { + $value = 'tab_confbridge_show = yes'; + fwrite($fp, $value."\n"); + } if (! isset($_POST['tab_network'])) { $value = 'tab_network_show = no'; fwrite($fp, $value."\n"); @@ -701,7 +705,7 @@ putHtml('<tr class="dtrow0"><td colspan="6"> </td></tr>'); putHtml('<tr class="dtrow0"><td class="dialogText" style="text-align: left;" colspan="6">'); - putHtml('<strong>MeetMe Tab Options:</strong>'); + putHtml('<strong>MeetMe & ConfBridge Tab Options:</strong>'); putHtml('</td></tr>'); putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">Redirect Path:</td><td colspan="4">'); @@ -712,7 +716,7 @@ putHtml('<tr class="dtrow1"><td style="text-align: right;">'); $sel = (getPREFdef($global_prefs, 'meetme_channel_show') === 'yes') ? ' checked="checked"' : ''; - putHtml('<input type="checkbox" value="meetme_channel" name="meetme_channel"'.$sel.' /></td><td colspan="5">Display channel values in MeetMe Tab</td></tr>'); + putHtml('<input type="checkbox" value="meetme_channel" name="meetme_channel"'.$sel.' /></td><td colspan="5">Display channel values in MeetMe and ConfBridge Tabs</td></tr>'); putHtml('<tr class="dtrow0"><td colspan="6"> </td></tr>'); @@ -1027,6 +1031,10 @@ putHtml('<input type="checkbox" value="tab_meetme" name="tab_meetme"'.$sel.' /></td><td colspan="5">Show MeetMe Tab</td></tr>'); putHtml('<tr class="dtrow1"><td style="text-align: right;">'); + $sel = (getPREFdef($global_prefs, 'tab_confbridge_show') === 'yes') ? ' checked="checked"' : ''; + putHtml('<input type="checkbox" value="tab_confbridge" name="tab_confbridge"'.$sel.' /></td><td colspan="5">Show ConfBridge Tab</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: right;">'); $sel = (getPREFdef($global_prefs, 'tab_cdrlog_show') !== 'no') ? ' checked="checked"' : ''; putHtml('<input type="checkbox" value="tab_cdrlog" name="tab_cdrlog"'.$sel.' /></td><td colspan="5">Show CDR Log Tab</td></tr>'); Modified: branches/1.0/package/webinterface/altweb/common/header.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/header.php 2013-04-06 01:07:19 UTC (rev 6041) +++ branches/1.0/package/webinterface/altweb/common/header.php 2013-04-10 15:38:09 UTC (rev 6042) @@ -191,6 +191,9 @@ if ($global_staff && (getPREFdef($global_prefs, 'tab_meetme_show') === 'yes')) { putHtml('<li><a href="/admin/meetme.php"><span>MeetMe</span></a></li>'); } + if ($global_staff && (getPREFdef($global_prefs, 'tab_confbridge_show') === 'yes')) { + putHtml('<li><a href="/admin/confbridge.php"><span>ConfBridge</span></a></li>'); + } if ($global_staff && (getPREFdef($global_prefs, 'tab_cdrlog_show') !== 'no')) { putHtml('<li><a href="/admin/cdrlog.php"><span>CDR Log</span></a></li>'); } Modified: branches/1.0/package/webinterface/altweb/common/version.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/version.php 2013-04-06 01:07:19 UTC (rev 6041) +++ branches/1.0/package/webinterface/altweb/common/version.php 2013-04-10 15:38:09 UTC (rev 6042) @@ -1,6 +1,6 @@ <?php // version.php for AstLinux Alternate Web Interface -$GUI_VERSION = '1.8.22'; +$GUI_VERSION = '1.8.23'; ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <abe...@us...> - 2013-05-01 18:56:41
|
Revision: 6069 http://sourceforge.net/p/astlinux/code/6069 Author: abelbeck Date: 2013-05-01 18:56:37 +0000 (Wed, 01 May 2013) Log Message: ----------- web interface, Prefs tab, allow 'staff' user to access SQL-Data tab, disabled by default Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php branches/1.0/package/webinterface/altweb/admin/prefs.php branches/1.0/package/webinterface/altweb/admin/sqldata.php branches/1.0/package/webinterface/altweb/common/functions.php branches/1.0/package/webinterface/altweb/common/header.php Modified: branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php 2013-04-30 23:49:58 UTC (rev 6068) +++ branches/1.0/package/webinterface/altweb/admin/phpliteadmin.php 2013-05-01 18:56:37 UTC (rev 6069) @@ -33,7 +33,7 @@ //please report any bugs you encounter to http://code.google.com/p/phpliteadmin/issues/list -//AstLinux// Restrict to 'admin' user. +//AstLinux// Restrict to 'admin' or 'staff' user. function getPHPusername() { if (isset($_SERVER['REMOTE_USER'])) { @@ -43,11 +43,12 @@ } return($str_R); } -if (($global_user = getPHPusername()) !== 'admin') { +$global_user = getPHPusername(); +if ($global_user !== 'admin' && $global_user !== 'staff') { echo '<p style="color: red;">User "'.$global_user.'" does not have permission to access the "phpliteadmin" tab.</p>'; exit(); } -//AstLinux// end of restrict to 'admin' user. +//AstLinux// end of restrict to 'admin' or 'staff' user. //BEGIN USER-DEFINED VARIABLES ////////////////////////////// Modified: branches/1.0/package/webinterface/altweb/admin/prefs.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/prefs.php 2013-04-30 23:49:58 UTC (rev 6068) +++ branches/1.0/package/webinterface/altweb/admin/prefs.php 2013-05-01 18:56:37 UTC (rev 6069) @@ -398,6 +398,10 @@ $value = 'tab_sqldata_show = yes'; fwrite($fp, $value."\n"); } + if (! isset($_POST['sqldata_disable_staff'])) { + $value = 'tab_sqldata_disable_staff = no'; + fwrite($fp, $value."\n"); + } if (isset($_POST['tab_users'])) { $value = 'tab_users_show = yes'; fwrite($fp, $value."\n"); @@ -1061,6 +1065,9 @@ putHtml('<tr class="dtrow1"><td style="text-align: right;">'); $sel = (getPREFdef($global_prefs, 'tab_sqldata_show') === 'yes') ? ' checked="checked"' : ''; putHtml('<input type="checkbox" value="tab_sqldata" name="tab_sqldata"'.$sel.' /></td><td colspan="5">Show SQL-Data Tab'.includeTOPICinfo('sqldata-dialplan').'</td></tr>'); + putHtml('<tr class="dtrow1"><td> </td><td colspan="5">'); + $sel = (getPREFdef($global_prefs, 'tab_sqldata_disable_staff') !== 'no') ? ' checked="checked"' : ''; + putHtml('<input type="checkbox" value="sqldata_disable_staff" name="sqldata_disable_staff"'.$sel.' /> Disable SQL-Data Tab for "staff" user</td></tr>'); putHtml('<tr class="dtrow1"><td style="text-align: right;">'); $sel = (getPREFdef($global_prefs, 'tab_users_show') === 'yes') ? ' checked="checked"' : ''; Modified: branches/1.0/package/webinterface/altweb/admin/sqldata.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/sqldata.php 2013-04-30 23:49:58 UTC (rev 6068) +++ branches/1.0/package/webinterface/altweb/admin/sqldata.php 2013-05-01 18:56:37 UTC (rev 6069) @@ -59,13 +59,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $result = 1; - if (! $global_admin) { + if (! ($global_admin || $global_staff_enable_sqldata)) { $result = 999; } header('Location: '.$myself.'?result='.$result); exit; } else { // Start of HTTP GET -$ACCESS_RIGHTS = 'admin'; +$ACCESS_RIGHTS = $global_staff_enable_sqldata ? 'staff' : 'admin'; require_once '../common/header.php'; putHtml("<center>"); Modified: branches/1.0/package/webinterface/altweb/common/functions.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/functions.php 2013-04-30 23:49:58 UTC (rev 6068) +++ branches/1.0/package/webinterface/altweb/common/functions.php 2013-05-01 18:56:37 UTC (rev 6069) @@ -875,5 +875,6 @@ $global_staff_disable_voicemail = ($global_user === 'staff' && (getPREFdef($global_prefs, 'tab_voicemail_disable_staff') === 'yes')); $global_staff_disable_monitor = ($global_user === 'staff' && (getPREFdef($global_prefs, 'tab_monitor_disable_staff') === 'yes')); $global_staff_disable_followme = ($global_user === 'staff' && (getPREFdef($global_prefs, 'tab_followme_disable_staff') === 'yes')); +$global_staff_enable_sqldata = ($global_user === 'staff' && (getPREFdef($global_prefs, 'tab_sqldata_disable_staff') === 'no')); $global_staff_disable_staff = ($global_user === 'staff' && (getPREFdef($global_prefs, 'tab_staff_disable_staff') === 'yes')); ?> Modified: branches/1.0/package/webinterface/altweb/common/header.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/header.php 2013-04-30 23:49:58 UTC (rev 6068) +++ branches/1.0/package/webinterface/altweb/common/header.php 2013-05-01 18:56:37 UTC (rev 6069) @@ -212,7 +212,7 @@ if ($global_staff && (getPREFdef($global_prefs, 'tab_actionlist_show') === 'yes')) { putHtml('<li><a href="/admin/actionlist.php"><span>Actionlist</span></a></li>'); } - if ($global_admin && (getPREFdef($global_prefs, 'tab_sqldata_show') === 'yes')) { + if (($global_admin || $global_staff_enable_sqldata) && (getPREFdef($global_prefs, 'tab_sqldata_show') === 'yes')) { putHtml('<li><a href="/admin/sqldata.php"><span>SQL-Data</span></a></li>'); } if ($global_staff && (getPREFdef($global_prefs, 'tab_users_show') === 'yes')) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <abe...@us...> - 2013-05-26 23:14:53
|
Revision: 6106 http://sourceforge.net/p/astlinux/code/6106 Author: abelbeck Date: 2013-05-26 23:14:51 +0000 (Sun, 26 May 2013) Log Message: ----------- web interface, add new 'phone-ldap-dir.php' cgi script, similar to the 'phone-dir.php cgi script', but uses the system LDAP client settings to query the data instead of the astdb. Modified Paths: -------------- branches/1.0/package/webinterface/altweb/common/version.php Added Paths: ----------- branches/1.0/package/webinterface/altweb/phone-ldap-dir.php Modified: branches/1.0/package/webinterface/altweb/common/version.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/version.php 2013-05-26 21:51:05 UTC (rev 6105) +++ branches/1.0/package/webinterface/altweb/common/version.php 2013-05-26 23:14:51 UTC (rev 6106) @@ -1,6 +1,6 @@ <?php // version.php for AstLinux Alternate Web Interface -$GUI_VERSION = '1.8.23'; +$GUI_VERSION = '1.8.24'; ?> Added: branches/1.0/package/webinterface/altweb/phone-ldap-dir.php =================================================================== --- branches/1.0/package/webinterface/altweb/phone-ldap-dir.php (rev 0) +++ branches/1.0/package/webinterface/altweb/phone-ldap-dir.php 2013-05-26 23:14:51 UTC (rev 6106) @@ -0,0 +1,211 @@ +<?php + +// Copyright (C) 2008-2013 Lonnie Abelbeck +// This is free software, licensed under the GNU General Public License +// version 3 as published by the Free Software Foundation; you can +// redistribute it and/or modify it under the terms of the GNU +// General Public License; and comes with ABSOLUTELY NO WARRANTY. + +// phone-ldap-dir.php for AstLinux +// 25-05-2013, Convert phone-dir.php for use with LDAP +// +// Usage: https://pbx/phone-ldap-dir.php?type=generic&search= +// type= generic, polycom, aastra, yealink, snom (defaults to "generic") +// search= text to search for anywhere in name (defaults to none) + +$myself = $_SERVER['PHP_SELF']; + +$opts['type'] = isset($_GET['type']) ? $_GET['type'] : 'generic'; +$opts['search'] = isset($_GET['search']) ? $_GET['search'] : ''; + +$data = ''; + +// Function: buildData +// +function buildData($str) { + global $data; + + $data .= $str."\n"; +} + +// Function: extract_dialing_digits +// +function extract_dialing_digits($number, $type) { + // Convert human formated number to what the phone 'type' expects + + $pattern = array('/[^0-9]+/'); + $replace = array(''); + + $digits = preg_replace($pattern, $replace, $number); + + return($digits); +} + +// Function: ldap_utf8_decode +// +function ldap_utf8_decode($utf8, $type) { + // Convert LDAP UTF-8 encoding to what the phone 'type' expects + + if ($type === 'aastra') { + $str = utf8_decode($utf8); + } elseif ($type === 'yealink') { + $str = $utf8; + } elseif ($type === 'snom') { + $str = $utf8; + } else { + $str = utf8_decode($utf8); + } + return($str); +} + +// Function: LDAP_Client +// +function LDAP_Client(&$uri, &$base) { + + if (! function_exists('ldap_connect')) { + return(FALSE); + } + + $uri = ''; + $base = ''; + if (is_file($ldap_conf = '/etc/openldap/ldap.conf')) { + if (($lines = @file($ldap_conf, FILE_IGNORE_NEW_LINES)) !== FALSE) { + if (($grep = current(preg_grep('/^URI\s/', $lines))) !== FALSE) { + $uri = trim(substr($grep, 4)); + } + if (($grep = current(preg_grep('/^BASE\s/', $lines))) !== FALSE) { + $base = trim(substr($grep, 5)); + } + } + } + if ($uri === '') { + return(FALSE); + } + + if (($client = ldap_connect($uri)) !== FALSE) { + ldap_set_option($client, LDAP_OPT_PROTOCOL_VERSION, 3); + if (! ldap_bind($client)) { + ldap_close($client); + return(FALSE); + } + } + return($client); +} + +// Function: getTITLEname +// +function getTITLEname($opts) { + + $cmd = 'Directory Search: '.$opts['search']; + + return($cmd); +} + +if ($opts['type'] === 'aastra') { + buildData('<?xml version="1.0" encoding="ISO-8859-1"?>'); + buildData('<AastraIPPhoneDirectory type="string">'); + buildData('<Title>'.getTITLEname($global_prefs).'</Title>'); +} elseif ($opts['type'] === 'yealink') { + buildData('<?xml version="1.0" encoding="UTF-8"?>'); + buildData('<YealinkIPPhoneDirectory clearlight="true">'); + buildData('<Title>'.getTITLEname($opts).'</Title>'); +} elseif ($opts['type'] === 'snom') { + buildData('<?xml version="1.0" encoding="UTF-8"?>'); + buildData('<SnomIPPhoneDirectory>'); + buildData('<Title>'.getTITLEname($opts).'</Title>'); + buildData('<Prompt>Prompt</Prompt>'); +} else { + buildData('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'); + buildData('<html>'); + buildData('<head>'); + buildData('<title>'.getTITLEname($opts).'</title>'); + buildData('</head>'); + buildData('<body>'); +} + +if (($ldapconn = LDAP_Client($uri, $dn)) !== FALSE) { + + $name = $opts['search']; + $filter = "(|(sn=$name*)(givenname=$name*))"; + $justthese = array('cn', 'sn', 'givenname', 'displayname', 'telephonenumber', 'mobile', 'cellphone'); + + if (($sr = ldap_search($ldapconn, $dn, $filter, $justthese)) !== FALSE) { + ldap_sort($ldapconn, $sr, 'givenname'); + ldap_sort($ldapconn, $sr, 'sn'); + $info = ldap_get_entries($ldapconn, $sr); + + if (($n = $info['count']) > 0) { + for ($i = 0; $i < $n; $i++) { + if (($number = $info[$i]['telephonenumber'][0]) != '') { + ; + } elseif (($number = $info[$i]['mobile'][0]) != '') { + ; + } elseif (($number = $info[$i]['cellphone'][0]) != '') { + ; + } + if ($number != '') { + $number = extract_dialing_digits($number, $opts['type']); + } + + if (($value = $info[$i]['displayname'][0]) != '') { + ; + } elseif (($value = $info[$i]['cn'][0]) != '') { + ; + } elseif (($value = $info[$i]['sn'][0]) != '') { + ; + } elseif (($value = $info[$i]['givenname'][0]) != '') { + ; + } + if ($value != '') { + $value = htmlspecialchars(ldap_utf8_decode($value, $opts['type'])); + } + + if ($number != '' && $value != '') { + if ($opts['type'] === 'aastra') { + buildData('<MenuItem>'); + buildData('<Prompt>'.$value.'</Prompt>'); + buildData('<URI>'.$number.'</URI>'); + buildData('</MenuItem>'); + } elseif ($opts['type'] === 'yealink' || $opts['type'] === 'snom') { + buildData('<DirectoryEntry>'); + buildData('<Name>'.$value.'</Name>'); + buildData('<Telephone>'.$number.'</Telephone>'); + buildData('</DirectoryEntry>'); + } elseif ($opts['type'] === 'polycom') { + buildData('<p><a href="tel://'.$number.'">'.$number.'</a> '.$value.'</p>'); + } else { + buildData('<li><a href="tel://'.$number.'">'.$number.'</a> '.$value.'</li><br />'); + } + } + } + } else { + buildData('<p>No Matches</p>'); + } + } else { + buildData('<p>LDAP Search Failed</p>'); + } + ldap_close($ldapconn); +} else { + buildData('<p>LDAP Connection Failed</p>'); +} + +if ($opts['type'] === 'aastra') { + buildData('</AastraIPPhoneDirectory>'); + header('Content-Type: text/xml'); +} elseif ($opts['type'] === 'yealink') { + buildData('</YealinkIPPhoneDirectory>'); + header('Content-Type: text/xml'); +} elseif ($opts['type'] === 'snom') { + buildData('</SnomIPPhoneDirectory>'); + header('Content-Type: text/xml'); +} else { + buildData('</body>'); + buildData('</html>'); + header('Content-Type: text/html'); +} +header('Content-Length: '.strlen($data)); +ob_clean(); +flush(); +echo $data; +exit; +?> Property changes on: branches/1.0/package/webinterface/altweb/phone-ldap-dir.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <abe...@us...> - 2013-07-21 17:41:57
|
Revision: 6144 http://sourceforge.net/p/astlinux/code/6144 Author: abelbeck Date: 2013-07-21 17:41:55 +0000 (Sun, 21 Jul 2013) Log Message: ----------- web interface, FOP2 support Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/edit.php branches/1.0/package/webinterface/altweb/admin/network.php branches/1.0/package/webinterface/altweb/admin/prefs.php branches/1.0/package/webinterface/altweb/admin/setup.php branches/1.0/package/webinterface/altweb/admin/system.php branches/1.0/package/webinterface/altweb/common/functions.php branches/1.0/package/webinterface/altweb/common/header.php branches/1.0/package/webinterface/altweb/common/license-packages.txt branches/1.0/package/webinterface/altweb/common/version.php Modified: branches/1.0/package/webinterface/altweb/admin/edit.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/edit.php 2013-07-21 12:36:51 UTC (rev 6143) +++ branches/1.0/package/webinterface/altweb/admin/edit.php 2013-07-21 17:41:55 UTC (rev 6144) @@ -35,9 +35,13 @@ 'apcupsd' => 'Restart UPS Daemon', 'prosody' => 'Restart XMPP Server', 'zabbix' => 'Restart Zabbix Monitor', - 'asterisk' => 'Restart Asterisk', - 'cron' => 'Reload Cron for root' + 'asterisk' => 'Restart Asterisk' ); +if (is_addon_package('fop2')) { + $select_reload['fop2'] = 'Restart Asterisk FOP2'; + $select_reload['FOP2'] = 'Reload Asterisk FOP2'; +} +$select_reload['cron'] = 'Reload Cron for root'; $sys_label = array ( 'dnsmasq.conf' => 'DNSmasq Configuration', @@ -224,6 +228,10 @@ $result = restartPROCESS($process, 39, $result, 'init'); } elseif ($process === 'ldap') { $result = restartPROCESS($process, 40, $result, 'init'); + } elseif ($process === 'fop2') { + $result = restartPROCESS($process, 41, $result, 'init'); + } elseif ($process === 'FOP2') { + $result = restartPROCESS('fop2', 42, $result, 'reload'); } elseif ($process === 'cron') { $result = updateCRON('root', 30, $result); } @@ -264,6 +272,7 @@ $dir === '/mnt/kd/rc.conf.d' || $dir === '/mnt/kd/crontabs' || $dir === '/mnt/kd/snmp' || + $dir === '/mnt/kd/fop2' || $dir === '/mnt/kd/apcupsd' || $dir === '/mnt/kd/prosody' || $dir === '/mnt/kd/docs' || @@ -342,6 +351,10 @@ putHtml('<p style="color: green;">SNMP Server has Restarted.</p>'); } elseif ($result == 40) { putHtml('<p style="color: green;">LDAP Client Defaults has been Reloaded.</p>'); + } elseif ($result == 41) { + putHtml('<p style="color: green;">Asterisk Flash Operating Panel2 has Restarted.</p>'); + } elseif ($result == 42) { + putHtml('<p style="color: green;">Asterisk Flash Operating Panel2 has been Reloaded.</p>'); } elseif ($result == 99) { putHtml('<p style="color: red;">Action Failed.</p>'); } elseif ($result == 999) { @@ -516,6 +529,16 @@ } putHtml('</optgroup>'); } + if (is_dir('/mnt/kd/fop2') && count($globfiles = glob('/mnt/kd/fop2/*.cfg')) > 0) { + putHtml('<optgroup label="———— Flash Operating Panel2 Configs ————">'); + foreach ($globfiles as $globfile) { + if (is_file($globfile) && is_writable($globfile)) { + $sel = ($globfile === $openfile) ? ' selected="selected"' : ''; + putHtml('<option value="'.$globfile.'"'.$sel.'>'.basename($globfile).' - Asterisk FOP2 Config</option>'); + } + } + putHtml('</optgroup>'); + } $optgroup = FALSE; foreach (glob('/etc/asterisk/*.conf') as $globfile) { if (is_writable($globfile)) { Modified: branches/1.0/package/webinterface/altweb/admin/network.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/network.php 2013-07-21 12:36:51 UTC (rev 6143) +++ branches/1.0/package/webinterface/altweb/admin/network.php 2013-07-21 17:41:55 UTC (rev 6144) @@ -945,6 +945,10 @@ $result = restartPROCESS($process, 39, $result, 'init'); } elseif ($process === 'ldap') { $result = restartPROCESS($process, 40, $result, 'init'); + } elseif ($process === 'fop2') { + $result = restartPROCESS($process, 41, $result, 'init'); + } elseif ($process === 'FOP2') { + $result = restartPROCESS('fop2', 42, $result, 'reload'); } } else { $result = 2; @@ -1023,6 +1027,10 @@ putHtml('<p style="color: green;">SNMP Server has Restarted.</p>'); } elseif ($result == 40) { putHtml('<p style="color: green;">LDAP Client Defaults has been Reloaded.</p>'); + } elseif ($result == 41) { + putHtml('<p style="color: green;">Asterisk Flash Operating Panel2 has Restarted.</p>'); + } elseif ($result == 42) { + putHtml('<p style="color: green;">Asterisk Flash Operating Panel2 has been Reloaded.</p>'); } elseif ($result == 99) { putHtml('<p style="color: red;">Action Failed.</p>'); } elseif ($result == 100) { @@ -1116,6 +1124,12 @@ putHtml('<option value="zabbix"'.$sel.'>Restart Zabbix Monitor</option>'); $sel = ($reboot_restart === 'asterisk') ? ' selected="selected"' : ''; putHtml('<option value="asterisk"'.$sel.'>Restart Asterisk</option>'); + if (is_addon_package('fop2')) { + $sel = ($reboot_restart === 'fop2') ? ' selected="selected"' : ''; + putHtml('<option value="fop2"'.$sel.'>Restart Asterisk FOP2</option>'); + $sel = ($reboot_restart === 'FOP2') ? ' selected="selected"' : ''; + putHtml('<option value="FOP2"'.$sel.'>Reload Asterisk FOP2</option>'); + } putHtml('</select>'); putHtml('–'); ?> Modified: branches/1.0/package/webinterface/altweb/admin/prefs.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/prefs.php 2013-07-21 12:36:51 UTC (rev 6143) +++ branches/1.0/package/webinterface/altweb/admin/prefs.php 2013-07-21 17:41:55 UTC (rev 6144) @@ -369,7 +369,12 @@ $value = 'external_cli_link_cmdstr = "'.$value.'"'; fwrite($fp, $value."\n"); } - + + if (isset($_POST['external_fop2_https'])) { + $value = 'external_fop2_https = yes'; + fwrite($fp, $value."\n"); + } + if (isset($_POST['tab_directory'])) { $value = 'tab_directory_show = yes'; fwrite($fp, $value."\n"); @@ -1005,6 +1010,10 @@ $value = getPREFdef($global_prefs, 'external_cli_link_cmdstr'); putHtml('<input type="text" size="48" maxlength="128" value="'.$value.'" name="external_cli_link" /></td></tr>'); + putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">External FOP2 Link:</td><td colspan="4">'); + $sel = (getPREFdef($global_prefs, 'external_fop2_https') === 'yes') ? ' checked="checked"' : ''; + putHtml('<input type="checkbox" value="external_fop2_https" name="external_fop2_https"'.$sel.' /> Use HTTPS</td></tr>'); + putHtml('<tr class="dtrow1"><td style="text-align: right;">'); $sel = (getPREFdef($global_prefs, 'tab_directory_show') === 'yes') ? ' checked="checked"' : ''; putHtml('<input type="checkbox" value="tab_directory" name="tab_directory"'.$sel.' /></td><td colspan="5">Show Directory Tab</td></tr>'); Modified: branches/1.0/package/webinterface/altweb/admin/setup.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/setup.php 2013-07-21 12:36:51 UTC (rev 6143) +++ branches/1.0/package/webinterface/altweb/admin/setup.php 2013-07-21 17:41:55 UTC (rev 6144) @@ -175,7 +175,7 @@ putHtml('<tr class="dtrow1"><td style="text-align: right;"> '); putHtml('</td><td style="text-align: left;" colspan="5">'); putHtml('Unionfs Partition Size:'); - putHtml('<input type="text" size="5" maxlength="4" value="128" name="unionfs_size" />'); + putHtml('<input type="text" size="5" maxlength="4" value="256" name="unionfs_size" />'); putHtml('MBytes'); putHtml('</td></tr>'); putHtml('<tr class="dtrow1"><td style="text-align: left;" colspan="6"> </td></tr>'); Modified: branches/1.0/package/webinterface/altweb/admin/system.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/system.php 2013-07-21 12:36:51 UTC (rev 6143) +++ branches/1.0/package/webinterface/altweb/admin/system.php 2013-07-21 17:41:55 UTC (rev 6144) @@ -1,6 +1,6 @@ <?php -// Copyright (C) 2008-2012 Lonnie Abelbeck +// Copyright (C) 2008-2013 Lonnie Abelbeck // This is free software, licensed under the GNU General Public License // version 3 as published by the Free Software Foundation; you can // redistribute it and/or modify it under the terms of the GNU @@ -17,6 +17,7 @@ // 12-12-2009, Added System Shutdown/Halt // 02-01-2010, Added Asterisk Sounds upgrade, remove, show // 01-16-2011, Added runnix check, upgrade, show, revert +// 07-21-2013, Added Add-On Packages // // System location of rc.conf file $CONFFILE = '/etc/rc.conf'; @@ -63,6 +64,11 @@ 'g722' => 'g722' ); +$addon_package_type_menu = array ( + '' => 'none', + 'fop2' => 'fop2' +); + // Function: putACTIONresult // function putACTIONresult($result_str, $status) { @@ -174,7 +180,7 @@ $srcfile .= ' -e "s/^.*[.]conf$/&/p" -e "s/^webgui-prefs.txt$/&/p" -e "s/^ast.*/&/p"'; $srcfile .= ' -e "s/^blocked-hosts$/&/p" -e "s/^dnsmasq.static$/&/p" -e "s/^hosts$/&/p" -e "s/^ethers$/&/p"'; $srcfile .= ' -e "s/^rc.local$/&/p" -e "s/^rc.local.stop$/&/p" -e "s/^rc.elocal$/&/p" -e "s/^rc.ledcontrol$/&/p"'; - $srcfile .= ' -e "s/^crontabs$/&/p" -e "s/^snmp$/&/p"'; + $srcfile .= ' -e "s/^crontabs$/&/p" -e "s/^snmp$/&/p" -e "s/^fop2$/&/p"'; $srcfile .= ' -e "s/^openvpn$/&/p" -e "s/^ipsec$/&/p" -e "s/^dahdi$/&/p" -e "s/^ssl$/&/p" -e "s/^apcupsd$/&/p")'; $srcfile .= $firewall; } elseif ($backup_type === 'cdr') { @@ -328,6 +334,35 @@ header('Location: '.$myself.'?sounds_action='.$action.'&result='.$result); exit; } + } elseif (isset($_POST['addon_package_submit'])) { + $result = 99; + $action = $_POST['addon_package_action']; + if (isset($_POST['addon_package_type']) && ($_POST['addon_package_type'] !== '' || $action === 'show')) { + $type = $_POST['addon_package_type']; + $file = '/usr/sbin/upgrade-package'; + $std_err = ' 2>/dev/null'; + if ($action === 'upgrade') { + $result_str = shell($file.' '.$type.' '.$action.$std_err, $status); + putACTIONresult($result_str, $status); + exit; + } elseif ($action === 'remove') { + $result_str = shell($file.' '.$type.' '.$action.$std_err, $status); + putACTIONresult($result_str, $status); + exit; + } elseif ($action === 'show') { + $result_str = shell($file.' '.$action.$std_err, $status); + putACTIONresult($result_str, $status); + exit; + } elseif ($action === 'revert') { + $result_str = shell($file.' '.$type.' '.$action.$std_err, $status); + putACTIONresult($result_str, $status); + exit; + } + } else { + $result = 19; + header('Location: '.$myself.'?addon_package_action='.$action.'&result='.$result); + exit; + } } elseif (isset($_POST['runnix_submit'])) { $result = 99; $action = $_POST['runnix_action']; @@ -426,6 +461,12 @@ $sounds_action = 'upgrade'; } + if (isset($_GET['addon_package_action'])) { + $addon_package_action = $_GET['addon_package_action']; + } else { + $addon_package_action = 'upgrade'; + } + if (isset($_GET['runnix_action'])) { $runnix_action = $_GET['runnix_action']; } else { @@ -465,6 +506,8 @@ putHtml('<p style="color: red;">Backup Failed, error archiving unionfs partition.</p>'); } elseif ($result == 16) { putHtml('<p style="color: red;">Backup Failed, click <a href="/admin/prefs.php" class="headerText">Prefs</a>then check "Backup temporary file uses /mnt/kd/ instead of /tmp/"</p>'); + } elseif ($result == 19) { + putHtml('<p style="color: red;">No Action, select an add-on package type for this action.</p>'); } elseif ($result == 20) { putHtml('<p style="color: red;">File size must be less then 8 MBytes.</p>'); } elseif ($result == 21) { @@ -706,6 +749,32 @@ putHtml('</td></tr>'); } +if (is_file('/usr/sbin/upgrade-package')) { + putHtml('<tr><td style="text-align: center;" colspan="2">'); + putHtml('<h2>Add-On Packages:</h2>'); + putHtml('</td></tr><tr><td class="dialogText" style="text-align: center;" colspan="2">'); + putHtml('Package:'); + putHtml('<select name="addon_package_type">'); + foreach ($addon_package_type_menu as $key => $value) { + putHtml('<option value="'.$key.'">'.$value.'</option>'); + } + putHtml('</select>'); + putHtml('–'); + putHtml('<select name="addon_package_action">'); + $sel = ($addon_package_action === 'upgrade') ? ' selected="selected"' : ''; + putHtml('<option value="upgrade"'.$sel.'>Upgrade/Install</option>'); + $sel = ($addon_package_action === 'remove') ? ' selected="selected"' : ''; + putHtml('<option value="remove"'.$sel.'>Remove</option>'); + $sel = ($addon_package_action === 'show') ? ' selected="selected"' : ''; + putHtml('<option value="show"'.$sel.'>Show Installed</option>'); + $sel = ($addon_package_action === 'revert') ? ' selected="selected"' : ''; + putHtml('<option value="revert"'.$sel.'>Revert to Previous</option>'); + putHtml('</select>'); + putHtml('–'); + putHtml('<input type="submit" value="Add-On Package" name="addon_package_submit" />'); + putHtml('</td></tr>'); +} + if (is_file('/usr/sbin/upgrade-RUNNIX-image')) { putHtml('<tr><td style="text-align: center;" colspan="2">'); putHtml('<h2>RUNNIX Bootloader Upgrade:</h2>'); Modified: branches/1.0/package/webinterface/altweb/common/functions.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/functions.php 2013-07-21 12:36:51 UTC (rev 6143) +++ branches/1.0/package/webinterface/altweb/common/functions.php 2013-07-21 17:41:55 UTC (rev 6144) @@ -67,6 +67,8 @@ } elseif ($process === 'iptables') { $cmd .= ';/usr/sbin/gen-rc-conf'; $cmd .= ';service iptables restart >/dev/null 2>/dev/null'; + } elseif ($start === 'reload') { + $cmd .= ';service '.$process.' '.$start.' >/dev/null 2>/dev/null'; } else { $cmd .= ';service '.$process.' stop >/dev/null 2>/dev/null'; $cmd .= ';sleep '.$wait; @@ -703,6 +705,14 @@ return($addr); } +// Function: is_addon_package +// +function is_addon_package($pkg) { + + $pkg_dir = '/stat/var/packages/'.$pkg; + return(is_dir($pkg_dir)); +} + // Function: is_mac2vendor // function is_mac2vendor() { Modified: branches/1.0/package/webinterface/altweb/common/header.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/header.php 2013-07-21 12:36:51 UTC (rev 6143) +++ branches/1.0/package/webinterface/altweb/common/header.php 2013-07-21 17:41:55 UTC (rev 6144) @@ -98,6 +98,21 @@ return(htmlspecialchars($cmd)); } +// Function: getFOP2link +// +function getFOP2link($g_prefs) { + $cmd = ''; + if (is_addon_package('fop2')) { + if (getPREFdef($g_prefs, 'external_fop2_https') === 'yes') { + $cmd = 'https://localhost/fop2/'; + } else { + $cmd = 'http://localhost/fop2/'; + } + $cmd = url_localhost_handler($cmd); + } + return(htmlspecialchars($cmd)); +} + // Function: putUSERerror // function putUSERerror($user, $tab) { @@ -155,7 +170,8 @@ putHtml('<td><h1>'.getTITLEname($global_prefs).'</h1></td>'); $URLlink = getURLlink($global_prefs); $CLIlink = getCLIlink($global_prefs); - if ($URLlink !== '' || ($global_admin && $CLIlink !== '')) { + $FOP2link = getFOP2link($global_prefs); + if ($URLlink !== '' || ($global_admin && $CLIlink !== '') || $FOP2link !== '') { putHtml('<td style="text-align: right;">'); if ($URLlink !== '') { putHtml('<a href="'.$URLlink.'" class="headerText" target="_blank">'.getURLname($global_prefs).'</a>'); @@ -167,6 +183,9 @@ putHtml('<a href="'.$CLIlink.'" class="headerText" target="_blank">CLI</a>'); } } + if ($FOP2link !== '') { + putHtml('<a href="'.$FOP2link.'" class="headerText" target="_blank">FOP2</a>'); + } putHtml('</td>'); } putHtml('</tr></table>'); Modified: branches/1.0/package/webinterface/altweb/common/license-packages.txt =================================================================== --- branches/1.0/package/webinterface/altweb/common/license-packages.txt 2013-07-21 12:36:51 UTC (rev 6143) +++ branches/1.0/package/webinterface/altweb/common/license-packages.txt 2013-07-21 17:41:55 UTC (rev 6144) @@ -42,3 +42,4 @@ Lua~Copyright (c) 1994-2012 Lua.org, PUC-Rio. All rights reserved. perl~Copyright (c) 1987-2012 by Larry Wall, et al. phpliteadmin~Copyright (c) 2011-2013 phpLiteAdmin (http://phpliteadmin.googlecode.com) +FOP2~Copyright (c) 2009-2013 House Internet S.R.L. (http://www.fop2.com) Modified: branches/1.0/package/webinterface/altweb/common/version.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/version.php 2013-07-21 12:36:51 UTC (rev 6143) +++ branches/1.0/package/webinterface/altweb/common/version.php 2013-07-21 17:41:55 UTC (rev 6144) @@ -1,6 +1,6 @@ <?php // version.php for AstLinux Alternate Web Interface -$GUI_VERSION = '1.8.24'; +$GUI_VERSION = '1.8.25'; ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <abe...@us...> - 2013-07-21 22:52:07
|
Revision: 6145 http://sourceforge.net/p/astlinux/code/6145 Author: abelbeck Date: 2013-07-21 22:52:03 +0000 (Sun, 21 Jul 2013) Log Message: ----------- web interface, add hostname and domain backup filename option Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/openvpn.php branches/1.0/package/webinterface/altweb/admin/prefs.php branches/1.0/package/webinterface/altweb/admin/staff.php branches/1.0/package/webinterface/altweb/admin/system.php branches/1.0/package/webinterface/altweb/admin/xmpp.php branches/1.0/package/webinterface/altweb/common/functions.php Modified: branches/1.0/package/webinterface/altweb/admin/openvpn.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/openvpn.php 2013-07-21 17:41:55 UTC (rev 6144) +++ branches/1.0/package/webinterface/altweb/admin/openvpn.php 2013-07-21 22:52:03 UTC (rev 6145) @@ -126,25 +126,6 @@ 'subnet' => '[subnet] latest, requires OpenVPN 2.1+ clients' ); -// Function: get_HOSTNAME_DOMAIN -// -function get_HOSTNAME_DOMAIN() { - $hostname_domain = ''; - - // System location of gui.network.conf file - $NETCONFFILE = '/mnt/kd/rc.conf.d/gui.network.conf'; - - if (is_file($NETCONFFILE)) { - $netvars = parseRCconf($NETCONFFILE); - if (($hostname = getVARdef($netvars, 'HOSTNAME')) !== '') { - if (($domain = getVARdef($netvars, 'DOMAIN')) !== '') { - $hostname_domain = $hostname.'.'.$domain; - } - } - } - return($hostname_domain); -} - // Function: saveOVPNsettings // function saveOVPNsettings($conf_dir, $conf_file, $disabled = NULL) { Modified: branches/1.0/package/webinterface/altweb/admin/prefs.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/prefs.php 2013-07-21 17:41:55 UTC (rev 6144) +++ branches/1.0/package/webinterface/altweb/admin/prefs.php 2013-07-21 22:52:03 UTC (rev 6145) @@ -302,6 +302,10 @@ fwrite($fp, $value."\n"); } + if (isset($_POST['backup_hostname_domain'])) { + $value = 'system_backup_hostname_domain = yes'; + fwrite($fp, $value."\n"); + } if (! isset($_POST['backup_gzip'])) { $value = 'system_backup_compress_gzip = no'; fwrite($fp, $value."\n"); @@ -916,6 +920,9 @@ putHtml('<strong>System & Staff Tab Options:</strong>'); putHtml('</td></tr>'); putHtml('<tr class="dtrow1"><td style="text-align: right;">'); + $sel = (getPREFdef($global_prefs, 'system_backup_hostname_domain') === 'yes') ? ' checked="checked"' : ''; + putHtml('<input type="checkbox" value="backup_hostname_domain" name="backup_hostname_domain"'.$sel.' /></td><td colspan="5">Backup filename uses both Hostname and Domain</td></tr>'); + putHtml('<tr class="dtrow1"><td style="text-align: right;">'); $sel = (getPREFdef($global_prefs, 'system_backup_compress_gzip') !== 'no') ? ' checked="checked"' : ''; putHtml('<input type="checkbox" value="backup_gzip" name="backup_gzip"'.$sel.' /></td><td colspan="5">Backup tar archives compressed with gzip [.gz]</td></tr>'); putHtml('<tr class="dtrow1"><td style="text-align: right;">'); Modified: branches/1.0/package/webinterface/altweb/admin/staff.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/staff.php 2013-07-21 17:41:55 UTC (rev 6144) +++ branches/1.0/package/webinterface/altweb/admin/staff.php 2013-07-21 22:52:03 UTC (rev 6145) @@ -48,9 +48,17 @@ $suffix = '.tar.gz'; $tarcmd = 'tar czf '; } + if (($backup_name = get_HOSTNAME_DOMAIN()) === '') { + $backup_name = $_SERVER['SERVER_NAME']; + } + if (getPREFdef($global_prefs, 'system_backup_hostname_domain') !== 'yes') { + if (($pos = strpos($backup_name, '.')) !== FALSE) { + $backup_name = substr($backup_name, 0, $pos); + } + } $asturw = (getPREFdef($global_prefs, 'system_backup_asturw') === 'yes') ? '/mnt/kd/asturw'.$suffix : ''; $prefix = '/mnt/kd/.'; - $tmpfile = $_SERVER['SERVER_NAME'].'-'.$backup_type.'-'.date('Y-m-d').$suffix; + $tmpfile = $backup_name.'-'.$backup_type.'-'.date('Y-m-d').$suffix; $srcfile = '$(ls -1 /mnt/kd/)'; if ($asturw !== '') { $excludefile = tempnam("/tmp", "PHP_"); Modified: branches/1.0/package/webinterface/altweb/admin/system.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/system.php 2013-07-21 17:41:55 UTC (rev 6144) +++ branches/1.0/package/webinterface/altweb/admin/system.php 2013-07-21 22:52:03 UTC (rev 6145) @@ -171,9 +171,17 @@ $suffix = '.tar.gz'; $tarcmd = 'tar czf '; } + if (($backup_name = get_HOSTNAME_DOMAIN()) === '') { + $backup_name = $_SERVER['SERVER_NAME']; + } + if (getPREFdef($global_prefs, 'system_backup_hostname_domain') !== 'yes') { + if (($pos = strpos($backup_name, '.')) !== FALSE) { + $backup_name = substr($backup_name, 0, $pos); + } + } $asturw = (getPREFdef($global_prefs, 'system_backup_asturw') === 'yes') ? '/mnt/kd/asturw'.$suffix : ''; $prefix = (getPREFdef($global_prefs, 'system_backup_temp_disk') === 'yes') ? '/mnt/kd/.' : '/tmp/'; - $tmpfile = $_SERVER['SERVER_NAME'].'-'.$backup_type.'-'.date('Y-m-d').$suffix; + $tmpfile = $backup_name.'-'.$backup_type.'-'.date('Y-m-d').$suffix; $firewall = is_dir('/mnt/kd/arno-iptables-firewall/plugins') ? ' "arno-iptables-firewall/plugins"' : ''; if ($backup_type === 'basic') { $srcfile = '$(ls -1 /mnt/kd/ | sed -n -e "s/^rc.conf.d$/&/p" -e "s/^ssh_keys$/&/p"'; Modified: branches/1.0/package/webinterface/altweb/admin/xmpp.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/xmpp.php 2013-07-21 17:41:55 UTC (rev 6144) +++ branches/1.0/package/webinterface/altweb/admin/xmpp.php 2013-07-21 22:52:03 UTC (rev 6145) @@ -36,25 +36,6 @@ require_once '../common/functions.php'; -// Function: get_HOSTNAME_DOMAIN -// -function get_HOSTNAME_DOMAIN() { - $hostname_domain = ''; - - // System location of gui.network.conf file - $NETCONFFILE = '/mnt/kd/rc.conf.d/gui.network.conf'; - - if (is_file($NETCONFFILE)) { - $netvars = parseRCconf($NETCONFFILE); - if (($hostname = getVARdef($netvars, 'HOSTNAME')) !== '') { - if (($domain = getVARdef($netvars, 'DOMAIN')) !== '') { - $hostname_domain = $hostname.'.'.$domain; - } - } - } - return($hostname_domain); -} - // Function: xmppGETclients // function xmppGETclients($vars) { Modified: branches/1.0/package/webinterface/altweb/common/functions.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/functions.php 2013-07-21 17:41:55 UTC (rev 6144) +++ branches/1.0/package/webinterface/altweb/common/functions.php 2013-07-21 22:52:03 UTC (rev 6145) @@ -524,6 +524,25 @@ return($db_R); } +// Function: get_HOSTNAME_DOMAIN +// +function get_HOSTNAME_DOMAIN() { + $hostname_domain = ''; + + // System location of gui.network.conf file + $NETCONFFILE = '/mnt/kd/rc.conf.d/gui.network.conf'; + + if (is_file($NETCONFFILE)) { + $netvars = parseRCconf($NETCONFFILE); + if (($hostname = getVARdef($netvars, 'HOSTNAME')) !== '') { + if (($domain = getVARdef($netvars, 'DOMAIN')) !== '') { + $hostname_domain = $hostname.'.'.$domain; + } + } + } + return($hostname_domain); +} + // Function: asteriskURLrepo // function asteriskURLrepo() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <abe...@us...> - 2013-07-24 16:53:11
|
Revision: 6153 http://sourceforge.net/p/astlinux/code/6153 Author: abelbeck Date: 2013-07-24 16:53:09 +0000 (Wed, 24 Jul 2013) Log Message: ----------- web interface, Status tab, sort IPv4 addresses in a natural mannor Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/dnshosts.php branches/1.0/package/webinterface/altweb/common/functions.php branches/1.0/package/webinterface/altweb/common/status.inc Modified: branches/1.0/package/webinterface/altweb/admin/dnshosts.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/dnshosts.php 2013-07-24 05:04:34 UTC (rev 6152) +++ branches/1.0/package/webinterface/altweb/admin/dnshosts.php 2013-07-24 16:53:09 UTC (rev 6153) @@ -65,23 +65,6 @@ return(11); } -// Function: pad_ipv4_str -// -function pad_ipv4_str($ip) { - $str = $ip; - - if (strpos($ip, ':') === FALSE && strpos($ip, '.') !== FALSE) { - $tokens = explode('.', $ip); - if (count($tokens) == 4) { - $str = str_pad($tokens[0], 3, '0', STR_PAD_LEFT).'.'. - str_pad($tokens[1], 3, '0', STR_PAD_LEFT).'.'. - str_pad($tokens[2], 3, '0', STR_PAD_LEFT).'.'. - str_pad($tokens[3], 3, '0', STR_PAD_LEFT); - } - } - return($str); -} - // Function: parseDNSHOSTSconf // function parseDNSHOSTSconf($vars) { Modified: branches/1.0/package/webinterface/altweb/common/functions.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/functions.php 2013-07-24 05:04:34 UTC (rev 6152) +++ branches/1.0/package/webinterface/altweb/common/functions.php 2013-07-24 16:53:09 UTC (rev 6153) @@ -715,6 +715,23 @@ return($menuitems); } +// Function: pad_ipv4_str +// +function pad_ipv4_str($ip) { + $str = $ip; + + if (strpos($ip, ':') === FALSE && strpos($ip, '.') !== FALSE) { + $tokens = explode('.', $ip); + if (count($tokens) == 4) { + $str = str_pad($tokens[0], 3, '0', STR_PAD_LEFT).'.'. + str_pad($tokens[1], 3, '0', STR_PAD_LEFT).'.'. + str_pad($tokens[2], 3, '0', STR_PAD_LEFT).'.'. + str_pad($tokens[3], 3, '0', STR_PAD_LEFT); + } + } + return($str); +} + // Function: compressIPV6addr // function compressIPV6addr($addr) { Modified: branches/1.0/package/webinterface/altweb/common/status.inc =================================================================== --- branches/1.0/package/webinterface/altweb/common/status.inc 2013-07-24 05:04:34 UTC (rev 6152) +++ branches/1.0/package/webinterface/altweb/common/status.inc 2013-07-24 16:53:09 UTC (rev 6153) @@ -382,7 +382,7 @@ // Sort by IP Address if ($cid > 1) { foreach ($status['clients'] as $key => $row) { - $ip[$key] = $row['ip']; + $ip[$key] = pad_ipv4_str($row['ip']); } array_multisort($ip, SORT_ASC, SORT_STRING, $status['clients']); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <abe...@us...> - 2013-07-29 19:19:54
|
Revision: 6156 http://sourceforge.net/p/astlinux/code/6156 Author: abelbeck Date: 2013-07-29 19:19:51 +0000 (Mon, 29 Jul 2013) Log Message: ----------- web interface, Use charset encoding 'utf-8' instead of 'iso-8859-1' for all tabs. Thanks Michael Modified Paths: -------------- branches/1.0/package/webinterface/altweb/common/header.php branches/1.0/package/webinterface/altweb/info.php Modified: branches/1.0/package/webinterface/altweb/common/header.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/header.php 2013-07-25 22:26:36 UTC (rev 6155) +++ branches/1.0/package/webinterface/altweb/common/header.php 2013-07-29 19:19:51 UTC (rev 6156) @@ -1,6 +1,6 @@ <?php session_manual_gc(); -// Copyright (C) 2008-2012 Lonnie Abelbeck +// Copyright (C) 2008-2013 Lonnie Abelbeck // This is free software, licensed under the GNU General Public License // version 3 as published by the Free Software Foundation; you can // redistribute it and/or modify it under the terms of the GNU @@ -10,6 +10,7 @@ // 03-25-2008 // 07-20-2009, Add manual session garbage collection // 03-04-2011, Add custom tab support +// 07-29-2013, Use charset 'utf-8' instead of 'iso-8859-1' // Function: getCUSTOMtabs // @@ -123,12 +124,15 @@ putHtml('</body>'); putHtml('</html>'); } + +header('Content-Type: text/html; charset=utf-8'); + ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> -<!-- Copyright (C) 2008-2012 Lonnie Abelbeck --> -<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> +<!-- Copyright (C) 2008-2013 Lonnie Abelbeck --> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate" /> <meta http-equiv="Expires" content="0" /> <?php Modified: branches/1.0/package/webinterface/altweb/info.php =================================================================== --- branches/1.0/package/webinterface/altweb/info.php 2013-07-25 22:26:36 UTC (rev 6155) +++ branches/1.0/package/webinterface/altweb/info.php 2013-07-29 19:19:51 UTC (rev 6156) @@ -33,7 +33,7 @@ $tmpfile = tempnam("/tmp", "PHP_"); @exec('sed -n "/^\[\['.$topic.'\]\]/,/^\[\[/ p" '.$ifile.' | sed "/^\[\[/ d" >'.$tmpfile); -header('Content-Type: text/plain; charset=iso-8859-1'); +header('Content-Type: text/plain; charset=utf-8'); header('Content-Disposition: inline; filename="'.$topic.'.txt"'); header('Content-Transfer-Encoding: binary'); header('Content-Length: '.filesize($tmpfile)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <abe...@us...> - 2013-09-16 18:31:53
|
Revision: 6198 http://sourceforge.net/p/astlinux/code/6198 Author: abelbeck Date: 2013-09-16 18:31:49 +0000 (Mon, 16 Sep 2013) Log Message: ----------- web interface, phone-ldap-dir.php script, add Active Directory custom variable. Thanks Ingmar Modified Paths: -------------- branches/1.0/package/webinterface/altweb/common/version.php branches/1.0/package/webinterface/altweb/phone-ldap-dir.php Modified: branches/1.0/package/webinterface/altweb/common/version.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/version.php 2013-09-13 14:01:35 UTC (rev 6197) +++ branches/1.0/package/webinterface/altweb/common/version.php 2013-09-16 18:31:49 UTC (rev 6198) @@ -1,6 +1,6 @@ <?php // version.php for AstLinux Alternate Web Interface -$GUI_VERSION = '1.8.25'; +$GUI_VERSION = '1.8.26'; ?> Modified: branches/1.0/package/webinterface/altweb/phone-ldap-dir.php =================================================================== --- branches/1.0/package/webinterface/altweb/phone-ldap-dir.php 2013-09-13 14:01:35 UTC (rev 6197) +++ branches/1.0/package/webinterface/altweb/phone-ldap-dir.php 2013-09-16 18:31:49 UTC (rev 6198) @@ -8,6 +8,7 @@ // phone-ldap-dir.php for AstLinux // 25-05-2013, Convert phone-dir.php for use with LDAP +// 16-09-2013, Add Microsoft Active Directory custom variable // // Usage: https://pbx/phone-ldap-dir.php?tls&type=generic&search= // If 'tls' appears, regardless of value, start_tls is enabled (defaults to disabled) @@ -73,6 +74,7 @@ $user = ''; $pass = ''; $proto_version = 3; + $ms_ad = FALSE; // Set to TRUE for Active Directory server // end $uri = ''; @@ -95,6 +97,9 @@ if ($proto_version > 0) { ldap_set_option($client, LDAP_OPT_PROTOCOL_VERSION, $proto_version); } + if ($ms_ad) { + ldap_set_option($client, LDAP_OPT_REFERRALS, 0); + } if ($start_tls && strncmp($uri, 'ldaps://', 8)) { // Don't use together with ldaps:// if (! ldap_start_tls($client)) { ldap_close($client); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <abe...@us...> - 2013-09-23 17:58:05
|
Revision: 6202 http://sourceforge.net/p/astlinux/code/6202 Author: abelbeck Date: 2013-09-23 17:58:01 +0000 (Mon, 23 Sep 2013) Log Message: ----------- web interface, Network tab, add support for both 'inadyn' and 'ddclient' Dynamic DNS Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/edit.php branches/1.0/package/webinterface/altweb/admin/network.php branches/1.0/package/webinterface/altweb/common/license-packages.txt Modified: branches/1.0/package/webinterface/altweb/admin/edit.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/edit.php 2013-09-22 22:43:00 UTC (rev 6201) +++ branches/1.0/package/webinterface/altweb/admin/edit.php 2013-09-23 17:58:01 UTC (rev 6202) @@ -45,6 +45,7 @@ $select_reload['cron'] = 'Reload Cron for root'; $sys_label = array ( + 'ddclient.conf' => 'DDclient Dynamic DNS Config', 'dnsmasq.conf' => 'DNSmasq Configuration', 'misdn-init.conf' => 'mISDN Configuration', 'ntpd.conf' => 'NTP Time Client/Server', Modified: branches/1.0/package/webinterface/altweb/admin/network.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/network.php 2013-09-22 22:43:00 UTC (rev 6201) +++ branches/1.0/package/webinterface/altweb/admin/network.php 2013-09-23 17:58:01 UTC (rev 6202) @@ -1,6 +1,6 @@ <?php -// Copyright (C) 2008-2012 Lonnie Abelbeck +// Copyright (C) 2008-2013 Lonnie Abelbeck // This is free software, licensed under the GNU General Public License // version 3 as published by the Free Software Foundation; you can // redistribute it and/or modify it under the terms of the GNU @@ -31,6 +31,7 @@ // 12-03-2011, Added HTTP_ACCESSLOG and HTTPS_ACCESSLOG support // 01-28-2012, Added LOCALDNS_LOCAL_DOMAIN support // 07-07-2012, Added Universal Plug & Play support +// 09-23-2013, Added ddclient support // // System location of rc.conf file $CONFFILE = '/etc/rc.conf'; @@ -64,20 +65,21 @@ $select_dyndns = array ( 'User Defined >>>' => '', - 'ZoneEdit' => 'de...@zo...', + 'DNS-O-Matic' => 'de...@dn...', 'DynDNS' => 'dy...@dy...', + 'DynDNS [custom]' => 'cu...@dy...', 'DynDNS [static]' => 'st...@dy...', - 'DynDNS [custom]' => 'cu...@dy...', + 'FreeDNS' => 'de...@fr...', 'No-IP' => 'de...@no...', - 'FreeDNS' => 'de...@fr...', - 'DNS-O-Matic' => 'de...@dn...', - 'pairNIC' => 'de...@pa...' + 'pairNIC' => 'de...@pa...', + 'ZoneEdit' => 'de...@zo...' ); $select_dyndns_getip = array ( 'User Defined >>>' => '', + 'myip.dnsomatic.com' => 'myip.dnsomatic.com', + 'checkip.dyndns.org' => 'checkip.dyndns.org', 'getip.krisk.org' => 'getip.krisk.org', - 'checkip.dyndns.org' => 'checkip.dyndns.org', 'External Interface' => 'interface' ); @@ -523,6 +525,8 @@ fwrite($fp, "### IPv6 Tunnel\n".$value."\n"); fwrite($fp, "### Dynamic DNS\n"); + $value = 'DDCLIENT="'.$_POST['dd_client'].'"'; + fwrite($fp, $value."\n"); if ($_POST['dd_service'] !== '') { $value = 'DDSERVICE="'.$_POST['dd_service'].'"'; } else { @@ -1685,6 +1689,12 @@ putHtml('<tr class="dtrow0"><td class="dialogText" style="text-align: left;" colspan="6">'); putHtml('<strong>Dynamic DNS Update:</strong>'); + $dd_client = getVARdef($db, 'DDCLIENT', $cur_db); + putHtml('<select name="dd_client">'); + putHtml('<option value="inadyn">inadyn</option>'); + $sel = ($dd_client === 'ddclient') ? ' selected="selected"' : ''; + putHtml('<option value="ddclient"'.$sel.'>ddclient</option>'); + putHtml('</select>'); putHtml('</td></tr>'); putHtml('<tr class="dtrow1"><td style="text-align: left;" colspan="6">'); @@ -1708,7 +1718,7 @@ putHtml('<tr class="dtrow1"><td style="text-align: left;" colspan="6">'); putHtml('DNS Get IPv4 Address:'); if (($t_value = getVARdef($db, 'DDGETIP', $cur_db)) === '') { - $t_value = 'getip.krisk.org'; + $t_value = 'myip.dnsomatic.com'; } putHtml('<select name="dd_getip">'); foreach ($select_dyndns_getip as $key => $value) { Modified: branches/1.0/package/webinterface/altweb/common/license-packages.txt =================================================================== --- branches/1.0/package/webinterface/altweb/common/license-packages.txt 2013-09-22 22:43:00 UTC (rev 6201) +++ branches/1.0/package/webinterface/altweb/common/license-packages.txt 2013-09-23 17:58:01 UTC (rev 6202) @@ -43,3 +43,4 @@ perl~Copyright (c) 1987-2012 by Larry Wall, et al. phpliteadmin~Copyright (c) 2011-2013 phpLiteAdmin (http://phpliteadmin.googlecode.com) FOP2~Copyright (c) 2009-2013 House Internet S.R.L. (http://www.fop2.com) +ddclient~Copyright (c) 1999-2013 Paul Burry, wimpunk, et al. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <abe...@us...> - 2013-10-22 00:06:57
|
Revision: 6237 http://sourceforge.net/p/astlinux/code/6237 Author: abelbeck Date: 2013-10-22 00:06:55 +0000 (Tue, 22 Oct 2013) Log Message: ----------- web interface, add LDAP Server support Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/edit.php branches/1.0/package/webinterface/altweb/admin/network.php branches/1.0/package/webinterface/altweb/phone-ldap-dir.php Added Paths: ----------- branches/1.0/package/webinterface/altweb/admin/slapd.php Modified: branches/1.0/package/webinterface/altweb/admin/edit.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/edit.php 2013-10-18 23:04:53 UTC (rev 6236) +++ branches/1.0/package/webinterface/altweb/admin/edit.php 2013-10-22 00:06:55 UTC (rev 6237) @@ -30,6 +30,7 @@ 'racoon' => 'Restart IPsec VPN', 'pptpd' => 'Restart PPTP VPN Server', 'ldap' => 'Reload LDAP Client', + 'slapd' => 'Restart LDAP Server', 'snmpd' => 'Restart SNMP Server', 'stunnel' => 'Restart Stunnel Proxy', 'miniupnpd' => 'Restart Univ. Plug\'n\'Play', @@ -51,6 +52,7 @@ 'ntpd.conf' => 'NTP Time Client/Server', 'sshd.conf' => 'SSH Server sshd_config', 'ldap.conf' => 'LDAP Client System Defaults', + 'slapd.conf' => 'LDAP Server Configuration', 'lighttpd.conf' => 'Web Server Configuration', 'sensors.conf' => 'Lm_sensors Hardware Monitoring', 'zaptel.conf' => 'Zaptel System Config', @@ -234,6 +236,8 @@ $result = restartPROCESS($process, 41, $result, 'init'); } elseif ($process === 'FOP2') { $result = restartPROCESS('fop2', 42, $result, 'reload'); + } elseif ($process === 'slapd') { + $result = restartPROCESS($process, 43, $result, 'init'); } elseif ($process === 'cron') { $result = updateCRON('root', 30, $result); } @@ -358,6 +362,8 @@ putHtml('<p style="color: green;">Asterisk Flash Operating Panel2 has Restarted.</p>'); } elseif ($result == 42) { putHtml('<p style="color: green;">Asterisk Flash Operating Panel2 has been Reloaded.</p>'); + } elseif ($result == 43) { + putHtml('<p style="color: green;">LDAP Server has Restarted.</p>'); } elseif ($result == 99) { putHtml('<p style="color: red;">Action Failed.</p>'); } elseif ($result == 999) { Modified: branches/1.0/package/webinterface/altweb/admin/network.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/network.php 2013-10-18 23:04:53 UTC (rev 6236) +++ branches/1.0/package/webinterface/altweb/admin/network.php 2013-10-22 00:06:55 UTC (rev 6237) @@ -32,6 +32,7 @@ // 01-28-2012, Added LOCALDNS_LOCAL_DOMAIN support // 07-07-2012, Added Universal Plug & Play support // 09-23-2013, Added ddclient support +// 10-21-2013, Added LDAP server support // // System location of rc.conf file $CONFFILE = '/etc/rc.conf'; @@ -824,6 +825,14 @@ $result = saveNETWORKsettings($NETCONFDIR, $NETCONFFILE); header('Location: /admin/siptlscert.php'); exit; + } elseif (isset($_POST['submit_slapd'])) { + $result = saveNETWORKsettings($NETCONFDIR, $NETCONFFILE); + if (is_writable($file = '/mnt/kd/slapd.conf')) { + header('Location: /admin/edit.php?file='.$file); + } else { + header('Location: /admin/slapd.php'); + } + exit; } elseif (isset($_POST['submit_xmpp'])) { $result = saveNETWORKsettings($NETCONFDIR, $NETCONFFILE); header('Location: /admin/xmpp.php'); @@ -953,6 +962,8 @@ $result = restartPROCESS($process, 41, $result, 'init'); } elseif ($process === 'FOP2') { $result = restartPROCESS('fop2', 42, $result, 'reload'); + } elseif ($process === 'slapd') { + $result = restartPROCESS($process, 43, $result, 'init'); } } else { $result = 2; @@ -1035,6 +1046,8 @@ putHtml('<p style="color: green;">Asterisk Flash Operating Panel2 has Restarted.</p>'); } elseif ($result == 42) { putHtml('<p style="color: green;">Asterisk Flash Operating Panel2 has been Reloaded.</p>'); + } elseif ($result == 43) { + putHtml('<p style="color: green;">LDAP Server has Restarted.</p>'); } elseif ($result == 99) { putHtml('<p style="color: red;">Action Failed.</p>'); } elseif ($result == 100) { @@ -1114,6 +1127,8 @@ putHtml('<option value="pptpd"'.$sel.'>Restart PPTP VPN Server</option>'); $sel = ($reboot_restart === 'ldap') ? ' selected="selected"' : ''; putHtml('<option value="ldap"'.$sel.'>Reload LDAP Client</option>'); + $sel = ($reboot_restart === 'slapd') ? ' selected="selected"' : ''; + putHtml('<option value="slapd"'.$sel.'>Restart LDAP Server</option>'); $sel = ($reboot_restart === 'snmpd') ? ' selected="selected"' : ''; putHtml('<option value="snmpd"'.$sel.'>Restart SNMP Server</option>'); $sel = ($reboot_restart === 'stunnel') ? ' selected="selected"' : ''; @@ -1507,6 +1522,11 @@ putHtml('XMPP Server, Messaging and Presence:'); putHtml('<input type="submit" value="Configure XMPP" name="submit_xmpp" class="button" /></td></tr>'); + if (is_file('/etc/init.d/slapd')) { + putHtml('<tr class="dtrow1"><td style="text-align: left;" colspan="6">'); + putHtml('LDAP Server, Directory Information:'); + putHtml('<input type="submit" value="Configure LDAP Server" name="submit_slapd" class="button" /></td></tr>'); + } if (is_file('/etc/init.d/snmpd') && is_file('/mnt/kd/snmp/snmpd.conf')) { putHtml('<tr class="dtrow1"><td style="text-align: left;" colspan="6">'); putHtml('SNMP Agent Server:'); Added: branches/1.0/package/webinterface/altweb/admin/slapd.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/slapd.php (rev 0) +++ branches/1.0/package/webinterface/altweb/admin/slapd.php 2013-10-22 00:06:55 UTC (rev 6237) @@ -0,0 +1,194 @@ +<?php + +// Copyright (C) 2013 Lonnie Abelbeck +// This is free software, licensed under the GNU General Public License +// version 3 as published by the Free Software Foundation; you can +// redistribute it and/or modify it under the terms of the GNU +// General Public License; and comes with ABSOLUTELY NO WARRANTY. + +// slapd.php for AstLinux +// 10-21-2013 +// +// System location of rc.conf file +$CONFFILE = '/etc/rc.conf'; +// System location of /mnt/kd/rc.conf.d directory +$SLAPDCONFDIR = '/mnt/kd/rc.conf.d'; +// System location of gui.slapd.conf file +$SLAPDCONFFILE = '/mnt/kd/rc.conf.d/gui.slapd.conf'; + +$myself = $_SERVER['PHP_SELF']; + +require_once '../common/functions.php'; + +$anonymous_menu = array ( + 'localhost' => 'localhost only', + 'yes' => 'access enabled', + 'no' => 'access disabled' +); + +// Function: saveSLAPDsettings +// +function saveSLAPDsettings($conf_dir, $conf_file) { + $result = 11; + + if (! is_dir($conf_dir)) { + return(3); + } + if (($fp = @fopen($conf_file,"wb")) === FALSE) { + return(3); + } + fwrite($fp, "### gui.slapd.conf - start ###\n###\n"); + + $value = 'LDAP_SERVER="'.$_POST['slapd_enabled'].'"'; + fwrite($fp, "### LDAP Server Enabled\n".$value."\n"); + + $value = 'LDAP_SERVER_ANONYMOUS="'.$_POST['slapd_anonymous'].'"'; + fwrite($fp, "### LDAP Server Anonymous\n".$value."\n"); + + $value = 'LDAP_SERVER_BASEDN="'.tuq($_POST['slapd_basedn']).'"'; + fwrite($fp, "### LDAP Server Base DN\n".$value."\n"); + + $value = 'LDAP_SERVER_PASS="'.string2RCconfig(trim($_POST['slapd_admin_pass'])).'"'; + fwrite($fp, "### LDAP Server Password\n".$value."\n"); + + fwrite($fp, "### gui.slapd.conf - end ###\n"); + fclose($fp); + + return($result); +} + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $result = 1; + if (! $global_admin) { + $result = 999; + } elseif (isset($_POST['submit_save'])) { + $result = saveSLAPDsettings($SLAPDCONFDIR, $SLAPDCONFFILE); + } elseif (isset($_POST['submit_restart'])) { + $result = 99; + if (isset($_POST['confirm_restart'])) { + $result = restartPROCESS('slapd', 10, $result, 'init'); + } else { + $result = 2; + } + } elseif (isset($_POST['submit_sip_tls'])) { + $result = saveSLAPDsettings($SLAPDCONFDIR, $SLAPDCONFFILE); + header('Location: /admin/siptlscert.php'); + exit; + } + header('Location: '.$myself.'?result='.$result); + exit; +} else { // Start of HTTP GET +$ACCESS_RIGHTS = 'admin'; +require_once '../common/header.php'; + + if (is_file($SLAPDCONFFILE)) { + $db = parseRCconf($SLAPDCONFFILE); + } else { + $db = NULL; + } + + putHtml("<center>"); + if (isset($_GET['result'])) { + $result = $_GET['result']; + if ($result == 2) { + putHtml('<p style="color: red;">No Action, check "Confirm" for this action.</p>'); + } elseif ($result == 3) { + putHtml('<p style="color: red;">Error creating file.</p>'); + } elseif ($result == 10) { + putHtml('<p style="color: green;">LDAP Server has Restarted.</p>'); + } elseif ($result == 11) { + putHtml('<p style="color: green;">Settings saved, click "Restart LDAP" to apply any changed settings.</p>'); + } elseif ($result == 99) { + putHtml('<p style="color: red;">Action Failed.</p>'); + } elseif ($result == 999) { + putHtml('<p style="color: red;">Permission denied for user "'.$global_user.'".</p>'); + } else { + putHtml('<p style="color: orange;">No Action.</p>'); + } + } else { + putHtml('<p> </p>'); + } + putHtml("</center>"); +?> + <center> + <table class="layout"><tr><td><center> + <form method="post" action="<?php echo $myself;?>"> + <table width="100%" class="stdtable"> + <tr><td style="text-align: center;" colspan="2"> + <h2>LDAP Server Configuration:</h2> + </td></tr><tr><td width="240" style="text-align: center;"> + <input type="submit" class="formbtn" value="Save Settings" name="submit_save" /> + </td><td class="dialogText" style="text-align: center;"> + <input type="submit" class="formbtn" value="Restart LDAP" name="submit_restart" /> + – + <input type="checkbox" value="restart" name="confirm_restart" /> Confirm + </td></tr></table> + <table class="stdtable"> + <tr class="dtrow0"><td width="60"> </td><td width="100"> </td><td width="100"> </td><td> </td><td width="100"> </td><td width="80"> </td></tr> +<?php +if (! is_file('/mnt/kd/ssl/sip-tls/keys/server.crt') || ! is_file('/mnt/kd/ssl/sip-tls/keys/server.key')) { + putHtml('<tr class="dtrow0"><td class="dialogText" style="text-align: left;" colspan="6">'); + putHtml('<strong>Missing SIP-TLS Server Certificate:</strong> <i>(Shared with LDAP Server)</i>'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); + putHtml('Create SIP-TLS<br />Server Certificate:'); + putHtml('</td><td style="text-align: left;" colspan="4">'); + putHtml('<input type="submit" value="SIP-TLS Certificate" name="submit_sip_tls" class="button" />'); + putHtml('</td></tr>'); +} + + putHtml('<tr class="dtrow0"><td class="dialogText" style="text-align: left;" colspan="6">'); + putHtml('<strong>LDAP Directory Server:</strong>'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); + putHtml('LDAP Server:'); + putHtml('</td><td style="text-align: left;" colspan="4">'); + $slapd_enable = getVARdef($db, 'LDAP_SERVER'); + putHtml('<select name="slapd_enabled">'); + putHtml('<option value="no">disabled</option>'); + $sel = ($slapd_enable === 'yes') ? ' selected="selected"' : ''; + putHtml('<option value="yes"'.$sel.'>enabled</option>'); + putHtml('</select>'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); + putHtml('Anonymous Read-Only:'); + putHtml('</td><td style="text-align: left;" colspan="4">'); + $anonymous = getVARdef($db, 'LDAP_SERVER_ANONYMOUS'); + putHtml('<select name="slapd_anonymous">'); + foreach ($anonymous_menu as $key => $value) { + $sel = ($anonymous === $key) ? ' selected="selected"' : ''; + putHtml('<option value="'.$key.'"'.$sel.'>'.$value.'</option>'); + } + putHtml('</select>'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); + putHtml('Base DN:'); + putHtml('</td><td style="text-align: left;" colspan="4">'); + if (($value = getVARdef($db, 'LDAP_SERVER_BASEDN')) === '') { + $value = 'dc=ldap'; + } + putHtml('<input type="text" size="56" maxlength="128" name="slapd_basedn" value="'.$value.'" />'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: right;" colspan="2">'); + putHtml('Admin Password<br />cn=admin:'); + putHtml('</td><td style="text-align: left;" colspan="4">'); + $value = getVARdef($db, 'LDAP_SERVER_PASS'); + $value = htmlspecialchars(RCconfig2string($value)); + putHtml('<input type="password" size="56" maxlength="128" name="slapd_admin_pass" value="'.$value.'" />'); + putHtml('<i><br />(defaults to web interface "admin" password)</i>'); + putHtml('</td></tr>'); + + putHtml('</table>'); + putHtml('</form>'); + + putHtml('</center></td></tr></table>'); + putHtml('</center>'); +} // End of HTTP GET +require_once '../common/footer.php'; + +?> Property changes on: branches/1.0/package/webinterface/altweb/admin/slapd.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Modified: branches/1.0/package/webinterface/altweb/phone-ldap-dir.php =================================================================== --- branches/1.0/package/webinterface/altweb/phone-ldap-dir.php 2013-10-18 23:04:53 UTC (rev 6236) +++ branches/1.0/package/webinterface/altweb/phone-ldap-dir.php 2013-10-22 00:06:55 UTC (rev 6237) @@ -154,7 +154,7 @@ $name = $opts['search']; $filter = "(|(sn=$name*)(givenname=$name*))"; - $justthese = array('cn', 'sn', 'givenname', 'displayname', 'telephonenumber', 'mobile', 'cellphone'); + $justthese = array('cn', 'sn', 'givenname', 'displayname', 'telephonenumber', 'mobile', 'cellphone', 'homephone'); if (($sr = ldap_search($ldapconn, $dn, $filter, $justthese)) !== FALSE) { ldap_sort($ldapconn, $sr, 'givenname'); @@ -169,6 +169,8 @@ ; } elseif (($number = $info[$i]['cellphone'][0]) != '') { ; + } elseif (($number = $info[$i]['homephone'][0]) != '') { + ; } if ($number != '') { $number = extract_dialing_digits($number, $opts['type']); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <abe...@us...> - 2013-10-28 19:38:09
|
Revision: 6250 http://sourceforge.net/p/astlinux/code/6250 Author: abelbeck Date: 2013-10-28 19:38:06 +0000 (Mon, 28 Oct 2013) Log Message: ----------- web interface, add LDAP-AB tab for managing the LDAP Address Book Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/prefs.php branches/1.0/package/webinterface/altweb/admin/slapd.php branches/1.0/package/webinterface/altweb/admin/system.php branches/1.0/package/webinterface/altweb/common/header.php Added Paths: ----------- branches/1.0/package/webinterface/altweb/admin/ldapab.php branches/1.0/package/webinterface/altweb/common/vcard-parse-convert.php Added: branches/1.0/package/webinterface/altweb/admin/ldapab.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/ldapab.php (rev 0) +++ branches/1.0/package/webinterface/altweb/admin/ldapab.php 2013-10-28 19:38:06 UTC (rev 6250) @@ -0,0 +1,416 @@ +<?php + +// Copyright (C) 2008-2013 Lonnie Abelbeck +// This is free software, licensed under the GNU General Public License +// version 3 as published by the Free Software Foundation; you can +// redistribute it and/or modify it under the terms of the GNU +// General Public License; and comes with ABSOLUTELY NO WARRANTY. + +// ldapad.php for AstLinux +// 10-26-2013 +// +// System location of rc.conf file +$CONFFILE = '/etc/rc.conf'; + +$myself = $_SERVER['PHP_SELF']; + +require_once '../common/functions.php'; + +require_once '../common/vcard-parse-convert.php'; + +$action_menu = array ( + '' => '– select action –', + 'export' => 'Export as LDIF', + 'revert' => 'Revert to Previous' +); + +// Function: exportLDIF +// +function exportLDIF($rootpw, $ou) { + global $global_prefs; + + if ($rootpw === '') { + return(10); + } + + if (($backup_name = get_HOSTNAME_DOMAIN()) === '') { + $backup_name = $_SERVER['SERVER_NAME']; + } + if (getPREFdef($global_prefs, 'system_backup_hostname_domain') !== 'yes') { + if (($pos = strpos($backup_name, '.')) !== FALSE) { + $backup_name = substr($backup_name, 0, $pos); + } + } + $prefix = '/mnt/kd/.'; + $tmpfile = $backup_name.'-'.$ou.'-'.date('Y-m-d').'.ldif.txt'; + $bdn = trim(shell_exec('. /etc/rc.conf; echo "${LDAP_SERVER_BASEDN:-dc=ldap}"')); + + $admin = tempnam("/var/tmp", "PHP_"); + $auth = '-x -D "cn=admin,'.$bdn.'" -H ldap://127.0.0.1 -y '.$admin; + $cmd = '/usr/bin/ldapsearch '.$auth.' -b "ou='.$ou.','.$bdn.'" -LLL'; + @file_put_contents($admin, $rootpw); + shell($cmd.' >'.$prefix.$tmpfile.' 2>/dev/null', $status); + @unlink($admin); + + if ($status != 0) { + @unlink($prefix.$tmpfile); + return(($status == 49) ? 28 : 29); + } else { + header('Content-Type: text/plain'); + header('Content-Disposition: attachment; filename="'.$tmpfile.'"'); + header('Content-Length: '.filesize($prefix.$tmpfile)); + ob_clean(); + flush(); + @readfile($prefix.$tmpfile); + @unlink($prefix.$tmpfile); + exit; + } +} + +// Function: revertLDIF +// +function revertLDIF($rootpw, $ou) { + + $bdn = trim(shell_exec('. /etc/rc.conf; echo "${LDAP_SERVER_BASEDN:-dc=ldap}"')); + $ou_old = $ou.'-old'; + $ou_tmp = $ou.'-tmp'; + + if ($rootpw === '') { + return(10); + } + + $admin = tempnam("/var/tmp", "PHP_"); + $auth = '-x -D "cn=admin,'.$bdn.'" -H ldap://127.0.0.1 -y '.$admin; + $cmd = '/usr/bin/ldapsearch '.$auth.' -b "ou='.$ou_old.','.$bdn.'" -LLL "(ou='.$ou_old.')"'; + @file_put_contents($admin, $rootpw); + shell($cmd.' >/dev/null 2>/dev/null', $status); + if ($status != 0) { + @unlink($admin); + if ($status == 49) { + return(28); + } + return(31); + } else { + $cmd = '/usr/bin/ldapdelete '.$auth.' -r "ou='.$ou_tmp.','.$bdn.'"'; + $cmd .= ' >/dev/null 2>/dev/null ; '; + $cmd .= '/usr/bin/ldapmodrdn '.$auth.' -r "ou='.$ou.','.$bdn.'" "ou='.$ou_tmp.'"'; + $cmd .= ' >/dev/null 2>/dev/null ; '; + $cmd .= '/usr/bin/ldapmodrdn '.$auth.' -r "ou='.$ou_old.','.$bdn.'" "ou='.$ou.'"'; + $cmd .= ' >/dev/null 2>/dev/null ; '; + $cmd .= '/usr/bin/ldapmodrdn '.$auth.' -r "ou='.$ou_tmp.','.$bdn.'" "ou='.$ou_old.'"'; + $cmd .= ' >/dev/null 2>/dev/null ; '; + $rtn = 41; + } + shell($cmd.' >/dev/null 2>/dev/null', $status); + @unlink($admin); + if ($status != 0) { + $rtn = 99; + } + return($rtn); +} + +// Function: importLDIF +// +function importLDIF($rootpw, $ou, $name, &$count) { + + $count = 0; + $bdn = trim(shell_exec('. /etc/rc.conf; echo "${LDAP_SERVER_BASEDN:-dc=ldap}"')); + $ou_old = $ou.'-old'; + + $cmd = 'grep -qi "^dn:[^,]*ou='.$ou.','.$bdn.'$" '.$name; + shell($cmd.' >/dev/null 2>/dev/null', $status); + if ($status != 0) { + return(23); + } + if ($rootpw === '') { + return(10); + } + $count = (int)trim(shell_exec('grep -ci "^dn:" '.$name)); + + $admin = tempnam("/var/tmp", "PHP_"); + $auth = '-x -D "cn=admin,'.$bdn.'" -H ldap://127.0.0.1 -y '.$admin; + $cmd = '/usr/bin/ldapdelete '.$auth.' -r "ou='.$ou_old.','.$bdn.'"'; + $cmd .= ' >/dev/null 2>/dev/null ; '; + $cmd .= '/usr/bin/ldapmodrdn '.$auth.' -r "ou='.$ou.','.$bdn.'" "ou='.$ou_old.'"'; + $cmd .= ' >/dev/null 2>/dev/null ; '; + $cmd .= '/usr/bin/ldapadd '.$auth.' -f '.$name; + @file_put_contents($admin, $rootpw); + shell($cmd.' >/dev/null 2>/dev/null', $status); + if ($status != 0) { + if ($status == 49) { + @unlink($admin); + return(28); + } + $cmd = '/usr/bin/ldapdelete '.$auth.' -r "ou='.$ou.','.$bdn.'"'; + $cmd .= ' >/dev/null 2>/dev/null ; '; + $cmd .= '/usr/bin/ldapmodrdn '.$auth.' -r "ou='.$ou_old.','.$bdn.'" "ou='.$ou.'"'; + $rtn = 30; + } else { + @unlink($admin); + return(40); + } + shell($cmd.' >/dev/null 2>/dev/null', $status); + @unlink($admin); + if ($status != 0) { + $rtn = 99; + } + return($rtn); +} + +// Function: importVCARD +// +function importVCARD($rootpw, $ou, $name, &$count) { + + $count = 0; + $bdn = trim(shell_exec('. /etc/rc.conf; echo "${LDAP_SERVER_BASEDN:-dc=ldap}"')); + $out_file = tempnam("/mnt/kd", ".PHP_"); + + if (vcard_export($ou, $bdn, $name, $out_file) === FALSE) { + @unlink($out_file); + return(23); + } + $rtn = importLDIF($rootpw, $ou, $out_file, $count); + @unlink($out_file); + return($rtn); +} + +function vcard_export($ou, $bdn, $in_file, $out_file) { + + $options = array( + 'mailonly' => isset($_POST['opt_m']), + 'phoneonly' => isset($_POST['opt_p']), + 'sanitize' => isset($_POST['opt_s']), + 'sanitize_dash' => isset($_POST['opt_S']) + ); + + // parse a vCard file + $conv = new vcard_convert($options); + if (! $conv->fromFile($in_file)) { + return(FALSE); + } + $out = $conv->toLdif("ou=$ou,$bdn"); + $ou_dn = "dn: ou=$ou,$bdn\nobjectClass: organizationalUnit\nou: $ou\n\n"; + if (($fp = @fopen($out_file,"wb")) === FALSE) { + return(FALSE); + } + fwrite($fp, $ou_dn); + fwrite($fp, $out); + fclose($fp); + + return(TRUE); +} + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $result = 1; + $rootpw = isset($_POST['rootpw']) ? tuqd($_POST['rootpw']) : ''; + if (! $global_staff) { + $result = 999; + } elseif (isset($_POST['submit_action'])) { + $action = $_POST['addressbook_action']; + if ($action === 'export') { + $result = exportLDIF($rootpw, 'addressbook'); + } elseif ($action === 'revert') { + $result = revertLDIF($rootpw, 'addressbook'); + } else { + $result = 11; + } + } elseif (isset($_POST['submit_ldif'], $_FILES['import_ldif'])) { + $result = 1; + $error = $_FILES['import_ldif']['error']; + $tmp_name = $_FILES['import_ldif']['tmp_name']; + $name = basename($_FILES['import_ldif']['name']); + if ($error == 0) { + $size = filesize($tmp_name); + if ($size === FALSE || $size > 5000000 || $size == 0) { + $result = 20; + } else { + $suffix = '.ldif.txt'; + if (($len = strlen($name) - strlen($suffix)) < 0) { + $len = 0; + } + if (stripos($name, $suffix, $len) === FALSE) { + $result = 22; + } + } + } elseif ($error == 1 || $error == 2) { + $result = 20; + } else { + $result = 21; + } + if ($result == 1) { + $result = 99; + $name = '/mnt/kd/.import_ldif'.$suffix; + if (move_uploaded_file($tmp_name, $name)) { + $result = importLDIF($rootpw, 'addressbook', $name, $count); + } + if (is_file($name)) { + @unlink($name); + } + header('Location: '.$myself.'?result='.$result.'&count='.$count); + exit; + } + } elseif (isset($_POST['submit_vcard'], $_FILES['import_vcard'])) { + $result = 1; + $error = $_FILES['import_vcard']['error']; + $tmp_name = $_FILES['import_vcard']['tmp_name']; + $name = basename($_FILES['import_vcard']['name']); + if ($error == 0) { + $size = filesize($tmp_name); + if ($size === FALSE || $size > 5000000 || $size == 0) { + $result = 20; + } else { + $suffix = '.vcf'; + if (($len = strlen($name) - strlen($suffix)) < 0) { + $len = 0; + } + if (stripos($name, $suffix, $len) === FALSE) { + $result = 26; + } + } + } elseif ($error == 1 || $error == 2) { + $result = 20; + } else { + $result = 27; + } + if ($result == 1) { + $result = 99; + $name = '/mnt/kd/.import_vcard'.$suffix; + if (move_uploaded_file($tmp_name, $name)) { + $result = importVCARD($rootpw, 'addressbook', $name, $count); + } + if (is_file($name)) { + @unlink($name); + } + header('Location: '.$myself.'?result='.$result.'&count='.$count); + exit; + } + } + header('Location: '.$myself.'?result='.$result); + exit; +} else { // Start of HTTP GET +$ACCESS_RIGHTS = 'staff'; +require_once '../common/header.php'; + + putHtml("<center>"); + if (isset($_GET['result'])) { + $result = $_GET['result']; + if ($result == 10) { + putHtml('<p style="color: red;">"cn=admin" Password not specified.</p>'); + } elseif ($result == 11) { + putHtml('<p style="color: red;">No Action, select an action command.</p>'); + } elseif ($result == 20) { + putHtml('<p style="color: red;">File size must be less then 5 MBytes.</p>'); + } elseif ($result == 21) { + putHtml('<p style="color: red;">An input .ldif.txt file must be defined.</p>'); + } elseif ($result == 22) { + putHtml('<p style="color: red;">Invalid suffix, only LDIF files ending with .ldif.txt are allowed.</p>'); + } elseif ($result == 23) { + putHtml('<p style="color: red;">Invalid file format, no data changed.</p>'); + } elseif ($result == 24) { + putHtml('<p style="color: red;">Error importing LDAP data, no data changed.</p>'); + } elseif ($result == 26) { + putHtml('<p style="color: red;">Invalid suffix, only vCard files ending with .vcf are allowed.</p>'); + } elseif ($result == 27) { + putHtml('<p style="color: red;">An input .vcf file must be defined.</p>'); + } elseif ($result == 28) { + putHtml('<p style="color: red;">Invalid "cn=admin" credentials.</p>'); + } elseif ($result == 29) { + putHtml('<p style="color: red;">Address Book export failed.</p>'); + } elseif ($result == 30) { + putHtml('<p style="color: red;">Address Book import failed.</p>'); + } elseif ($result == 31) { + putHtml('<p style="color: red;">No previous Address Book to revert to.</p>'); + } elseif ($result == 40) { + $count = (isset($_GET['count'])) ? $_GET['count'] : '0'; + putHtml('<p style="color: green;">Successful LDAP Address Book import. Count: '.$count.' entries.</p>'); + } elseif ($result == 41) { + putHtml('<p style="color: green;">Reverted to previous LDAP Address Book.</p>'); + } elseif ($result == 99) { + putHtml('<p style="color: red;">Action Failed.</p>'); + } elseif ($result == 999) { + putHtml('<p style="color: red;">Permission denied for user "'.$global_user.'".</p>'); + } else { + putHtml('<p style="color: orange;">No Action.</p>'); + } + } else { + putHtml('<p> </p>'); + } + putHtml("</center>"); +?> + <center> + <table class="layout"><tr><td><center> + <form method="post" action="<?php echo $myself;?>" enctype="multipart/form-data"> + <table width="100%" class="stdtable"> + <tr><td style="text-align: center;" colspan="2"> + <h2>LDAP Address Book Management:</h2> + </td></tr> +<?php + +if (is_file('/var/run/slapd/slapd.pid')) { + $db = parseRCconf($CONFFILE); + + $rootpw = getVARdef($db, 'LDAP_SERVER_PASS'); + putHtml('<tr><td style="text-align: center;" colspan="2">'); + putHtml('"cn=admin" Password:'); + if ($rootpw !== '') { + putHtml('**********'); + putHtml('<input type="hidden" name="rootpw" value="'.$rootpw.'" />'); + } else { + putHtml('<input type="password" size="18" maxlength="128" name="rootpw" value="" />'); + } + putHtml('</td></tr>'); + + putHtml('<tr><td style="text-align: center;" colspan="2">'); + putHtml('<select name="addressbook_action">'); + foreach ($action_menu as $key => $value) { + putHtml('<option value="'.$key.'"'.$sel.'>'.$value.'</option>'); + } + putHtml('</select>'); + putHtml('–'); + putHtml('<input type="submit" value="LDAP Address Book" name="submit_action" />'); + putHtml('</td></tr>'); + + putHtml('<tr><td style="text-align: center;" colspan="2">'); + putHtml('<h2>Import LDIF File to Address Book:</h2>'); + putHtml('<input type="hidden" name="MAX_FILE_SIZE" value="5000000" />'); + putHtml('</td></tr><tr><td style="text-align: center;" colspan="2">'); + putHtml('<input type="file" name="import_ldif" />'); + putHtml('–'); + putHtml('<input type="submit" name="submit_ldif" value="Import LDIF" />'); + putHtml('</td></tr>'); + + putHtml('<tr><td style="text-align: center;" colspan="2">'); + putHtml('<h2>Import vCard File to Address Book:</h2>'); + putHtml('<input type="hidden" name="MAX_FILE_SIZE" value="5000000" />'); + putHtml('</td></tr>'); + putHtml('<tr><td class="dialogText" style="text-align: right;" width="60">'); + putHtml('<strong>Filter:</strong>'); + putHtml('</td><td class="dialogText">Options</td></tr>'); + putHtml('<tr><td class="dialogText" style="text-align: right;">'); + putHtml('<input type="checkbox" value="opt_s" name="opt_s" /></td><td>Sanitize phone numbers to only<br />include "+0123456789" characters</td></tr>'); + putHtml('<tr><td class="dialogText" style="text-align: right;">'); + putHtml('<input type="checkbox" value="opt_S" name="opt_S" checked="checked" /></td><td>Sanitize as above but replace<br />sequential non-numbers with a dash "-"</td></tr>'); + putHtml('<tr><td class="dialogText" style="text-align: right;">'); + putHtml('<input type="checkbox" value="opt_p" name="opt_p" /></td><td>Skip vCards without phone numbers</td></tr>'); + putHtml('<tr><td class="dialogText" style="text-align: right;">'); + putHtml('<input type="checkbox" value="opt_m" name="opt_m" /></td><td>Skip vCards without e-mail addresses</td></tr>'); + putHtml('<tr><td style="text-align: center;" colspan="2">'); + putHtml('<input type="file" name="import_vcard" />'); + putHtml('–'); + putHtml('<input type="submit" name="submit_vcard" value="Import vCard" />'); + putHtml('</td></tr>'); +} else { + putHtml('<tr><td style="text-align: center;" colspan="2">'); + putHtml('<p style="color: red;">LDAP Server is not enabled.</p>'); + putHtml('</td></tr>'); +} + + putHtml('</table>'); + putHtml('</form>'); + + putHtml("</center></td></tr></table>"); + putHtml("</center>"); +} // End of HTTP GET +require_once '../common/footer.php'; + +?> Property changes on: branches/1.0/package/webinterface/altweb/admin/ldapab.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Modified: branches/1.0/package/webinterface/altweb/admin/prefs.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/prefs.php 2013-10-25 21:27:10 UTC (rev 6249) +++ branches/1.0/package/webinterface/altweb/admin/prefs.php 2013-10-28 19:38:06 UTC (rev 6250) @@ -419,6 +419,10 @@ $value = 'tab_sqldata_disable_staff = no'; fwrite($fp, $value."\n"); } + if (isset($_POST['tab_ldapab'])) { + $value = 'tab_ldapab_show = yes'; + fwrite($fp, $value."\n"); + } if (isset($_POST['tab_users'])) { $value = 'tab_users_show = yes'; fwrite($fp, $value."\n"); @@ -1106,6 +1110,10 @@ putHtml('<input type="checkbox" value="sqldata_disable_staff" name="sqldata_disable_staff"'.$sel.' /> Disable SQL-Data Tab for "staff" user</td></tr>'); putHtml('<tr class="dtrow1"><td style="text-align: right;">'); + $sel = (getPREFdef($global_prefs, 'tab_ldapab_show') === 'yes') ? ' checked="checked"' : ''; + putHtml('<input type="checkbox" value="tab_ldapab" name="tab_ldapab"'.$sel.' /></td><td colspan="5">Show LDAP-AB Tab</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: right;">'); $sel = (getPREFdef($global_prefs, 'tab_users_show') === 'yes') ? ' checked="checked"' : ''; putHtml('<input type="checkbox" value="tab_users" name="tab_users"'.$sel.' /></td><td colspan="5">Show Users Tab</td></tr>'); Modified: branches/1.0/package/webinterface/altweb/admin/slapd.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/slapd.php 2013-10-25 21:27:10 UTC (rev 6249) +++ branches/1.0/package/webinterface/altweb/admin/slapd.php 2013-10-28 19:38:06 UTC (rev 6250) @@ -109,7 +109,7 @@ $pass2 = tuqd($_POST['pass2']); if (isset($_POST['submit_password']) || ($pass1 !== '' && $pass2 !== '')) { if (($user = $_POST['username']) !== '') { - $result = set_LDAP_user_passwd($rootpw, $pass1, $pass2, $user, 4); + $result = set_LDAP_user_passwd($rootpw, $pass1, $pass2, $user, 3); } } } @@ -250,7 +250,12 @@ putHtml('<tr><td style="text-align: right;" colspan="2">'); putHtml('"cn=admin" Password:'); putHtml('</td><td style="text-align: left;" colspan="4">'); - putHtml('<input type="password" size="56" maxlength="128" name="rootpw" value="'.$rootpw.'" />'); + if ($rootpw !== '') { + putHtml('**********'); + putHtml('<input type="hidden" name="rootpw" value="'.$rootpw.'" />'); + } else { + putHtml('<input type="password" size="18" maxlength="128" name="rootpw" value="'.$rootpw.'" />'); + } putHtml('</td></tr>'); putHtml('<tr><td style="text-align: right;" colspan="2">'); putHtml('New Password:'); Modified: branches/1.0/package/webinterface/altweb/admin/system.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/system.php 2013-10-25 21:27:10 UTC (rev 6249) +++ branches/1.0/package/webinterface/altweb/admin/system.php 2013-10-28 19:38:06 UTC (rev 6250) @@ -851,6 +851,7 @@ $var === 'DDPASS' || $var === 'GUI_FIREWALL_RULES' || $var === 'STATICHOSTS' || + $var === 'LDAP_SERVER_PASS' || $var === 'PPTP_USER_PASS' || $var === 'OVPN_USER_PASS' || $var === 'OVPNC_USER_PASS' || Modified: branches/1.0/package/webinterface/altweb/common/header.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/header.php 2013-10-25 21:27:10 UTC (rev 6249) +++ branches/1.0/package/webinterface/altweb/common/header.php 2013-10-28 19:38:06 UTC (rev 6250) @@ -238,6 +238,9 @@ if (($global_admin || $global_staff_enable_sqldata) && (getPREFdef($global_prefs, 'tab_sqldata_show') === 'yes')) { putHtml('<li><a href="/admin/sqldata.php"><span>SQL-Data</span></a></li>'); } + if ($global_staff && (getPREFdef($global_prefs, 'tab_ldapab_show') === 'yes')) { + putHtml('<li><a href="/admin/ldapab.php"><span>LDAP-AB</span></a></li>'); + } if ($global_staff && (getPREFdef($global_prefs, 'tab_users_show') === 'yes')) { putHtml('<li><a href="/admin/users.php"><span>Users</span></a></li>'); } Added: branches/1.0/package/webinterface/altweb/common/vcard-parse-convert.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/vcard-parse-convert.php (rev 0) +++ branches/1.0/package/webinterface/altweb/common/vcard-parse-convert.php 2013-10-28 19:38:06 UTC (rev 6250) @@ -0,0 +1,1974 @@ +<?php + +//AstLinux// Adapted for AstLinux - 10-11-2013 by Lonnie Abelbeck +//AstLinux// All code in one file, use name "vcard-export" +//AstLinux// Default for 'ldap' format +//AstLinux// Change -n option to -b for Base_DN +//AstLinux// Add sanitize phone numbers option, -s and -S + +/* + +-----------------------------------------------------------------------+ + | Commandline vCard converter | + | Version 0.8.7 | + | | + | Copyright (C) 2006-2012, Thomas Bruederli - Switzerland | + | Licensed under the GNU GPL | + | | + | Type './vcard-export help' for usage information | + | | + +-----------------------------------------------------------------------+ + | Author: Thomas Bruederli <th...@br...> | + +-----------------------------------------------------------------------+ + +*/ + +@ini_set('error_reporting', E_ALL&~E_NOTICE); + +// version 1.31 required + +// +// begin of Contact_Vcard_Parse.php +// + +// +----------------------------------------------------------------------+ +// | PHP version 4 | +// +----------------------------------------------------------------------+ +// | Copyright (c) 1997-2002 The PHP Group | +// +----------------------------------------------------------------------+ +// | This source file is subject to version 2.0 of the PHP license, | +// | that is bundled with this package in the file LICENSE, and is | +// | available at through the world-wide-web at | +// | http://www.php.net/license/2_02.txt. | +// | If you did not receive a copy of the PHP license and are unable to | +// | obtain it through the world-wide-web, please send a note to | +// | li...@ph... so we can mail you a copy immediately. | +// +----------------------------------------------------------------------+ +// | Authors: Paul M. Jones <pm...@ph...> | +// +----------------------------------------------------------------------+ +// +// $Id: Contact_Vcard_Parse.php,v 1.4 2005/05/28 15:40:17 pmjones Exp $ + + +/** +* +* Parser for vCards. +* +* This class parses vCard 2.1 and 3.0 sources from file or text into a +* structured array. +* +* Usage: +* +* <code> +* // include this class file +* require_once 'Contact_Vcard_Parse.php'; +* +* // instantiate a parser object +* $parse = new Contact_Vcard_Parse(); +* +* // parse a vCard file and store the data +* // in $cardinfo +* $cardinfo = $parse->fromFile('sample.vcf'); +* +* // view the card info array +* echo '<pre>'; +* print_r($cardinfo); +* echo '</pre>'; +* </code> +* +* +* @author Paul M. Jones <pm...@ph...> +* +* @package Contact_Vcard_Parse +* +* @version 1.31 +* +*/ + +class Contact_Vcard_Parse { + + + /** + * + * Reads a file for parsing, then sends it to $this->fromText() + * and returns the results. + * + * @access public + * + * @param array $filename The filename to read for vCard information. + * + * @return array An array of of vCard information extracted from the + * file. + * + * @see Contact_Vcard_Parse::fromText() + * + * @see Contact_Vcard_Parse::_fromArray() + * + */ + + function fromFile($filename, $decode_qp = true) + { + $text = $this->fileGetContents($filename); + + if ($text === false) { + return false; + } else { + // dump to, and get return from, the fromText() method. + return $this->fromText($text, $decode_qp); + } + } + + + /** + * + * Reads the contents of a file. Included for users whose PHP < 4.3.0. + * + * @access public + * + * @param array $filename The filename to read for vCard information. + * + * @return string|bool The contents of the file if it exists and is + * readable, or boolean false if not. + * + * @see Contact_Vcard_Parse::fromFile() + * + */ + + function fileGetContents($filename) + { + if (file_exists($filename) && + is_readable($filename)) { + + $text = ''; + $len = filesize($filename); + + $fp = fopen($filename, 'r'); + while ($line = fread($fp, filesize($filename))) { + $text .= $line; + } + fclose($fp); + + return $text; + + } else { + + return false; + + } + } + + + /** + * + * Prepares a block of text for parsing, then sends it through and + * returns the results from $this->fromArray(). + * + * @access public + * + * @param array $text A block of text to read for vCard information. + * + * @return array An array of vCard information extracted from the + * source text. + * + * @see Contact_Vcard_Parse::_fromArray() + * + */ + + function fromText($text, $decode_qp = true) + { + // convert all kinds of line endings to Unix-standard and get + // rid of double blank lines. + $this->convertLineEndings($text); + + // unfold lines. concat two lines where line 1 ends in \n and + // line 2 starts with a whitespace character. only removes + // the first whitespace character, leaves others in place. + $fold_regex = '(\n)([ |\t])'; + $text = preg_replace("/$fold_regex/i", "", $text); + + // massage for Macintosh OS X Address Book (remove nulls that + // Address Book puts in for unicode chars) + $text = str_replace("\x00", '', $text); + + // convert the resulting text to an array of lines + $lines = explode("\n", $text); + + // parse the array of lines and return vCard info + return $this->_fromArray($lines, $decode_qp); + } + + + /** + * + * Converts line endings in text. + * + * Takes any text block and converts all line endings to UNIX + * standard. DOS line endings are \r\n, Mac are \r, and UNIX is \n. + * + * NOTE: Acts on the text block in-place; does not return a value. + * + * @access public + * + * @param string $text The string on which to convert line endings. + * + * @return void + * + */ + + function convertLineEndings(&$text) + { + // DOS + $text = str_replace("\r\n", "\n", $text); + + // Mac + $text = str_replace("\r", "\n", $text); + } + + + /** + * + * Splits a string into an array at semicolons. Honors backslash- + * escaped semicolons (i.e., splits at ';' not '\;'). + * + * @access public + * + * @param string $text The string to split into an array. + * + * @param bool $convertSingle If splitting the string results in a + * single array element, return a string instead of a one-element + * array. + * + * @return mixed An array of values, or a single string. + * + */ + + function splitBySemi($text, $convertSingle = false) + { + // we use these double-backs (\\) because they get get converted + // to single-backs (\) by preg_split. the quad-backs (\\\\) end + // up as as double-backs (\\), which is what preg_split requires + // to indicate a single backslash (\). what a mess. + $regex = '(?<!\\\\)(\;)'; + $tmp = preg_split("/$regex/i", $text); + + // if there is only one array-element and $convertSingle is + // true, then return only the value of that one array element + // (instead of returning the array). + if ($convertSingle && count($tmp) == 1) { + return $tmp[0]; + } else { + return $tmp; + } + } + + + /** + * + * Splits a string into an array at commas. Honors backslash- + * escaped commas (i.e., splits at ',' not '\,'). + * + * @access public + * + * @param string $text The string to split into an array. + * + * @param bool $convertSingle If splitting the string results in a + * single array element, return a string instead of a one-element + * array. + * + * @return mixed An array of values, or a single string. + * + */ + + function splitByComma($text, $convertSingle = false) + { + // we use these double-backs (\\) because they get get converted + // to single-backs (\) by preg_split. the quad-backs (\\\\) end + // up as as double-backs (\\), which is what preg_split requires + // to indicate a single backslash (\). ye gods, how ugly. + $regex = '(?<!\\\\)(\,)'; + $tmp = preg_split("/$regex/i", $text); + + // if there is only one array-element and $convertSingle is + // true, then return only the value of that one array element + // (instead of returning the array). + if ($convertSingle && count($tmp) == 1) { + return $tmp[0]; + } else { + return $tmp; + } + } + + + /** + * + * Used to make string human-readable after being a vCard value. + * + * Converts... + * \: => : + * \; => ; + * \, => , + * literal \n => newline + * + * @access public + * + * @param mixed $text The text to unescape. + * + * @return void + * + */ + + function unescape(&$text) + { + if (is_array($text)) { + foreach ($text as $key => $val) { + $this->unescape($val); + $text[$key] = $val; + } + } else { + $text = str_replace('\:', ':', $text); + $text = str_replace('\;', ';', $text); + $text = str_replace('\,', ',', $text); + $text = str_replace('\n', "\n", $text); + } + } + + + /** + * + * Emulated destructor. + * + * @access private + * @return boolean true + * + */ + + function _Contact_Vcard_Parse() + { + return true; + } + + + /** + * + * Parses an array of source lines and returns an array of vCards. + * Each element of the array is itself an array expressing the types, + * parameters, and values of each part of the vCard. Processes both + * 2.1 and 3.0 vCard sources. + * + * @access private + * + * @param array $source An array of lines to be read for vCard + * information. + * + * @return array An array of of vCard information extracted from the + * source array. + * + */ + + function _fromArray($source, $decode_qp = true) + { + // the info array will hold all resulting vCard information. + $info = array(); + + // tells us whether the source text indicates the beginning of a + // new vCard with a BEGIN:VCARD tag. + $begin = false; + + // holds information about the current vCard being read from the + // source text. + $card = array(); + + // loop through each line in the source array + foreach ($source as $line) { + + // if the line is blank, skip it. + if (trim($line) == '') { + continue; + } + + // find the first instance of ':' on the line. The part + // to the left of the colon is the type and parameters; + // the part to the right of the colon is the value data. + $pos = strpos($line, ':'); + + // if there is no colon, skip the line. + if ($pos === false) { + continue; + } + + // get the left and right portions + $left = trim(substr($line, 0, $pos)); + $right = trim(substr($line, $pos+1, strlen($line))); + + // have we started yet? + if (! $begin) { + + // nope. does this line indicate the beginning of + // a new vCard? + if (strtoupper($left) == 'BEGIN' && + strtoupper($right) == 'VCARD') { + + // tell the loop that we've begun a new card + $begin = true; + } + + // regardless, loop to the next line of source. if begin + // is still false, the next loop will check the line. if + // begin has now been set to true, the loop will start + // collecting card info. + continue; + + } else { + + // yep, we've started, but we don't know how far along + // we are in the card. is this the ending line of the + // current vCard? + if (strtoupper($left) == 'END' && + strtoupper($right) == 'VCARD') { + + // yep, we're done. keep the info from the current + // card... + $info[] = $card; + + // ...and reset to grab a new card if one exists in + // the source array. + $begin = false; + $card = array(); + + } else { + + // we're not on an ending line, so collect info from + // this line into the current card. split the + // left-portion of the line into a type-definition + // (the kind of information) and parameters for the + // type. + $typedef = $this->_getTypeDef($left); + $params = $this->_getParams($left); + + // if we are decoding quoted-printable, do so now. + // QUOTED-PRINTABLE is not allowed in version 3.0, + // but we don't check for versioning, so we do it + // regardless. ;-) + $this->_decode_qp($params, $right); + + // now get the value-data from the line, based on + // the typedef + switch ($typedef) { + + case 'N': + // structured name of the person + $value = $this->_parseN($right); + break; + + case 'ADR': + // structured address of the person + $value = $this->_parseADR($right); + break; + + case 'NICKNAME': + // nicknames + $value = $this->_parseNICKNAME($right); + break; + + case 'ORG': + // organizations the person belongs to + $value = $this->_parseORG($right); + break; + + case 'CATEGORIES': + // categories to which this card is assigned + $value = $this->_parseCATEGORIES($right); + break; + + case 'GEO': + // geographic coordinates + $value = $this->_parseGEO($right); + break; + + default: + // by default, just grab the plain value. keep + // as an array to make sure *all* values are + // arrays. for consistency. ;-) + $value = array(array($right)); + break; + } + + // add the type, parameters, and value to the + // current card array. note that we allow multiple + // instances of the same type, which might be dumb + // in some cases (e.g., N). + $card[$typedef][] = array( + 'param' => $params, + 'value' => $value + ); + } + } + } + + $this->unescape($info); + return $info; + } + + + /** + * + * Takes a vCard line and extracts the Type-Definition for the line. + * + * @access private + * + * @param string $text A left-part (before-the-colon part) from a + * vCard line. + * + * @return string The type definition for the line. + * + */ + + function _getTypeDef($text) + { + // split the text by semicolons + $split = $this->splitBySemi($text); + + // only return first element (the typedef) + return strtoupper($split[0]); + } + + + /** + * + * Finds the Type-Definition parameters for a vCard line. + * + * @access private + * + * @param string $text A left-part (before-the-colon part) from a + * vCard line. + * + * @return mixed An array of parameters. + * + */ + + function _getParams($text) + { + // split the text by semicolons into an array + $split = $this->splitBySemi($text); + + // drop the first element of the array (the type-definition) + array_shift($split); + + // set up an array to retain the parameters, if any + $params = array(); + + // loop through each parameter. the params may be in the format... + // "TYPE=type1,type2,type3" + // ...or... + // "TYPE=type1;TYPE=type2;TYPE=type3" + foreach ($split as $full) { + + // split the full parameter at the equal sign so we can tell + // the parameter name from the parameter value + $tmp = explode("=", $full); + + // the key is the left portion of the parameter (before + // '='). if in 2.1 format, the key may in fact be the + // parameter value, not the parameter name. + $key = strtoupper(trim($tmp[0])); + + // get the parameter name by checking to see if it's in + // vCard 2.1 or 3.0 format. + $name = $this->_getParamName($key); + + // list of all parameter values + $listall = trim($tmp[1]); + + // if there is a value-list for this parameter, they are + // separated by commas, so split them out too. + $list = $this->splitByComma($listall); + + // now loop through each value in the parameter and retain + // it. if the value is blank, that means it's a 2.1-style + // param, and the key itself is the value. + foreach ($list as $val) { + if (trim($val) != '') { + // 3.0 formatted parameter + $params[$name][] = trim($val); + } else { + // 2.1 formatted parameter + $params[$name][] = $key; + } + } + + // if, after all this, there are no parameter values for the + // parameter name, retain no info about the parameter (saves + // ram and checking-time later). + if (count($params[$name]) == 0) { + unset($params[$name]); + } + } + + // return the parameters array. + return $params; + } + + + /** + * + * Looks at the parameters of a vCard line; if one of them is + * ENCODING[] => QUOTED-PRINTABLE then decode the text in-place. + * + * @access private + * + * @param array $params A parameter array from a vCard line. + * + * @param string $text A right-part (after-the-colon part) from a + * vCard line. + * + * @return void + * + */ + + function _decode_qp(&$params, &$text) + { + // loop through each parameter + foreach ($params as $param_key => $param_val) { + + // check to see if it's an encoding param + if (trim(strtoupper($param_key)) == 'ENCODING') { + + // loop through each encoding param value + foreach ($param_val as $enc_key => $enc_val) { + + // if any of the values are QP, decode the text + // in-place and return + if (trim(strtoupper($enc_val)) == 'QUOTED-PRINTABLE') { + $text = quoted_printable_decode($text); + return; + } + } + } + } + } + + + /** + * + * Returns parameter names from 2.1-formatted vCards. + * + * The vCard 2.1 specification allows parameter values without a + * name. The parameter name is then determined from the unique + * parameter value. + * + * Shamelessly lifted from Frank Hellwig <fr...@he...> and his + * vCard PHP project <http://vcardphp.sourceforge.net>. + * + * @access private + * + * @param string $value The first element in a parameter name-value + * pair. + * + * @return string The proper parameter name (TYPE, ENCODING, or + * VALUE). + * + */ + + function _getParamName($value) + { + static $types = array ( + 'DOM', 'INTL', 'POSTAL', 'PARCEL','HOME', 'WORK', + 'PREF', 'VOICE', 'FAX', 'MSG', 'CELL', 'PAGER', + 'BBS', 'MODEM', 'CAR', 'ISDN', 'VIDEO', + 'AOL', 'APPLELINK', 'ATTMAIL', 'CIS', 'EWORLD', + 'INTERNET', 'IBMMAIL', 'MCIMAIL', + 'POWERSHARE', 'PRODIGY', 'TLX', 'X400', + 'GIF', 'CGM', 'WMF', 'BMP', 'MET', 'PMB', 'DIB', + 'PICT', 'TIFF', 'PDF', 'PS', 'JPEG', 'QTIME', + 'MPEG', 'MPEG2', 'AVI', + 'WAVE', 'AIFF', 'PCM', + 'X509', 'PGP' + ); + + // CONTENT-ID added by pmj + static $values = array ( + 'INLINE', 'URL', 'CID', 'CONTENT-ID' + ); + + // 8BIT added by pmj + static $encodings = array ( + '7BIT', '8BIT', 'QUOTED-PRINTABLE', 'BASE64' + ); + + // changed by pmj to the following so that the name defaults to + // whatever the original value was. Frank Hellwig's original + // code was "$name = 'UNKNOWN'". + $name = $value; + + if (in_array($value, $types)) { + $name = 'TYPE'; + } elseif (in_array($value, $values)) { + $name = 'VALUE'; + } elseif (in_array($value, $encodings)) { + $name = 'ENCODING'; + } + + return $name; + } + + + /** + * + * Parses a vCard line value identified as being of the "N" + * (structured name) type-defintion. + * + * @access private + * + * @param string $text The right-part (after-the-colon part) of a + * vCard line. + * + * @return array An array of key-value pairs where the key is the + * portion-name and the value is the portion-value. The value itself + * may be an array as well if multiple comma-separated values were + * indicated in the vCard source. + * + */ + + function _parseN($text) + { + // make sure there are always at least 5 elements + $tmp = array_pad($this->splitBySemi($text), 5, ''); + return array( + $this->splitByComma($tmp[0]), // family (last) + $this->splitByComma($tmp[1]), // given (first) + $this->splitByComma($tmp[2]), // addl (middle) + $this->splitByComma($tmp[3]), // prefix + $this->splitByComma($tmp[4]) // suffix + ); + } + + + /** + * + * Parses a vCard line value identified as being of the "ADR" + * (structured address) type-defintion. + * + * @access private + * + * @param string $text The right-part (after-the-colon part) of a + * vCard line. + * + * @return array An array of key-value pairs where the key is the + * portion-name and the value is the portion-value. The value itself + * may be an array as well if multiple comma-separated values were + * indicated in the vCard source. + * + */ + + function _parseADR($text) + { + // make sure there are always at least 7 elements + $tmp = array_pad($this->splitBySemi($text), 7, ''); + return array( + $this->splitByComma($tmp[0]), // pob + $this->splitByComma($tmp[1]), // extend + $this->splitByComma($tmp[2]), // street + $this->splitByComma($tmp[3]), // locality (city) + $this->splitByComma($tmp[4]), // region (state) + $this->splitByComma($tmp[5]), // postcode (ZIP) + $this->splitByComma($tmp[6]) // country + ); + } + + + /** + * + * Parses a vCard line value identified as being of the "NICKNAME" + * (informal or descriptive name) type-defintion. + * + * @access private + * + * @param string $text The right-part (after-the-colon part) of a + * vCard line. + * + * @return array An array of nicknames. + * + */ + + function _parseNICKNAME($text) + { + return array($this->splitByComma($text)); + } + + + /** + * + * Parses a vCard line value identified as being of the "ORG" + * (organizational info) type-defintion. + * + * @access private + * + * @param string $text The right-part (after-the-colon part) of a + * vCard line. + * + * @return array An array of organizations; each element of the array + * is itself an array, which indicates primary organization and + * sub-organizations. + * + */ + + function _parseORG($text) + { + $tmp = $this->splitbySemi($text); + $list = array(); + foreach ($tmp as $val) { + $list[] = array($val); + } + + return $list; + } + + + /** + * + * Parses a vCard line value identified as being of the "CATEGORIES" + * (card-category) type-defintion. + * + * @access private + * + * @param string $text The right-part (after-the-colon part) of a + * vCard line. + * + * @return mixed An array of categories. + * + */ + + function _parseCATEGORIES($text) + { + return array($this->splitByComma($text)); + } + + + /** + * + * Parses a vCard line value identified as being of the "GEO" + * (geographic coordinate) type-defintion. + * + * @access private + * + * @param string $text The right-part (after-the-colon part) of a + * vCard line. + * + * @return mixed An array of lat-lon geocoords. + * + */ + + function _parseGEO($text) + { + // make sure there are always at least 2 elements + $tmp = array_pad($this->splitBySemi($text), 2, ''); + return array( + array($tmp[0]), // lat + array($tmp[1]) // lon + ); + } +} + +// +// end of Contact_Vcard_Parse.php +// + +// +// begin of vcard_convert.php +// + +/** + * Typedef of a vCard object + */ +class vCard +{ + var $version; + var $displayname; + var $surname; + var $firstname; + var $middlename; + var $nickname; + var $title; + var $birthday; + var $organization; + var $department; + var $jobtitle; + var $home = array(); + var $work = array(); + var $countrycode; + var $relatedname; + var $email; + var $email2; + var $email3; + var $pager; + var $mobile; + var $im = array(); + var $notes; + var $categories; + var $uid; + var $photo; +} + + +/** + * vCard to LDIF/CSV Converter Class + */ +class vcard_convert extends Contact_Vcard_Parse +{ + var $parsed = array(); + var $vcards = array(); + var $file_charset = 'ISO-8859-1'; + var $charset = 'ISO-8859-1'; + var $export_count = 0; + var $mailonly = false; + var $phoneonly = false; + var $accesscode = null; + var $sanitize = false; //AstLinux// + var $sanitize_dash = false; //AstLinux// + + + /** + * Constructor taking a list of converter properties + */ + function vcard_convert($p = array()) + { + foreach ($p as $prop => $value) + $this->$prop = $value; + } + + + /** + * Read a file and parse it + * + * @override + */ + function fromFile($filename, $decode_qp = true) + { + if (!filesize($filename) || ($text = $this->fileGetContents($filename)) === false) + return false; + + // dump to, and get return from, the fromText() method. + return $this->fromText($text, $decode_qp); + } + + /** + * Parse a given string for vCards + * + * @override + */ + function fromText($text, $decode_qp = true) + { + // check if charsets are specified (usually vcard version < 3.0 but this is not reliable) + if (preg_match('/charset=/i', substr($text, 0, 2048))) + $this->charset = null; + // try to detect charset of the whole file + else if ($encoding = vcard_convert::get_charset($text)) + $this->charset = $this->file_charset = $encoding; + + // convert document to UTF-8 + if (isset($this->charset) && $this->charset != 'UTF-8' && $this->charset != 'ISO-8859-1') + { + $text = $this->utf8_convert($text); + $this->charset = 'UTF-8'; + } + + $this->parsed = parent::fromText($text, $decode_qp); + if (!empty($this->parsed)) + { + $this->normalize(); + + // after normalize() all values should be UTF-8 + if (!isset($this->charset)) + $this->charset = 'UTF-8'; + + return count($this->cards); + } + else + return false; + } + + + /** + * Convert the abstract vCard structure into address objects + * + * @access private + */ + function normalize() + { + $this->cards = array(); + foreach($this->parsed as $i => $card) + { + $vcard = new vCard; + $vcard->version = (float)$card['VERSION'][0]['value'][0][0]; + + // convert all values to UTF-8 according to their charset param + if (!isset($this->charset)) + $card = $this->card2utf8($card); + + // extract names + $names = $card['N'][0]['value']; + $vcard->surname = trim($names[0][0]); + $vcard->firstname = trim($names[1][0]); + $vcard->middlename = trim($names[2][0]); + $vcard->title = trim($names[3][0]); + + if (empty($vcard->title) && isset($card['TITLE'])) + $vcard->title = trim($card['TITLE'][0]['value'][0][0]); + + $vcard->displayname = isset($card['FN']) ? trim($card['FN'][0]['value'][0][0]) : ''; + $vcard->nickname = isset($card['NICKNAME']) ? trim($card['NICKNAME'][0]['value'][0][0]) : ''; + + // extract notes + $vcard->notes = isset($card['NOTE']) ? ltrim($card['NOTE'][0]['value'][0][0]) : ''; + + // extract birthday and anniversary + foreach (array('BDAY' => 'birthday', 'ANNIVERSARY' => 'anniversary', 'X-ANNIVERSARY' => 'anniversary') as $vcf => $propname) + { + if (is_array($card[$vcf])) + { + $temp = preg_replace('/[\-\.\/]/', '', $card[$vcf][0]['value'][0][0]); + $vcard->$propname = array( + 'y' => substr($temp,0,4), + 'm' => substr($temp,4,2), + 'd' => substr($temp,6,2)); + } + } + + if (is_array($card['GENDER'])) + $vcard->gender = $card['GENDER'][0]['value'][0][0]; + else if (is_array($card['X-GENDER'])) + $vcard->gender = $card['X-GENDER'][0]['value'][0][0]; + + if (!empty($vcard->gender)) + $vcard->gender = strtoupper($vcard->gender[0]); + + // extract job_title + if (is_array($card['TITLE'])) + $vcard->jobtitle = $card['TITLE'][0]['value'][0][0]; + + // extract UID + if (is_array($card['UID'])) + $vcard->uid = $card['UID'][0]['value'][0][0]; + + // extract org and dep + if (is_array($card['ORG']) && ($temp = $card['ORG'][0]['value'])) + { + $vcard->organization = trim($temp[0][0]); + $vcard->department = trim($temp[1][0]); + } + + // extract urls + if (is_array($card['URL'])) + $this->parse_url($card['URL'], $vcard); + + // extract addresses + if (is_array($card['ADR'])) + $this->parse_adr($card['ADR'], $vcard); + + // extract phones + if (is_array($card['TEL'])) + $this->parse_tel($card['TEL'], $vcard); + + // read Apple Address Book proprietary fields + for ($n = 1; $n <= 9; $n++) + { + $prefix = 'ITEM'.$n; + if (is_array($card["$prefix.TEL"])) { + $this->parse_tel($card["$prefix.TEL"], $vcard); + } + if (is_array($card["$prefix.URL"])) { + $this->parse_url($card["$prefix.URL"], $vcard); + } + if (is_array($card["$prefix.ADR"])) { + $this->parse_adr($card["$prefix.ADR"], $vcard); + } + if (is_array($card["$prefix.X-ABADR"])) { + $this->parse_cc($card["$prefix.X-ABADR"], $vcard); + } + if (is_array($card["$prefix.X-ABRELATEDNAMES"])) { + $this->parse_rn($card["$prefix.X-ABRELATEDNAMES"], $vcard); + } + } + + // extract e-mail addresses + $a_email = array(); + $n = 0; + if (is_array($card['EMAIL'])) { + while (isset($card['EMAIL'][$n])) { + $a_email[] = $card['EMAIL'][$n]['value'][0][0]; + $n++; + } + } + if ($n < 2) { //as only 3 e-mail address will be exported we don't need to search for more + for ($n = 1; $n <= 9; $n++) { + if (is_array($card["ITEM$n.EMAIL"])) + { + $a_email[] = $card["ITEM$n.EMAIL"][0]['value'][0][0]; + if (isset($card["ITEM$n.EMAIL"][1])) + $a_email[] = $card["ITEM$n.EMAIL"][1]['value'][0][0]; + } + } + } + + if (count($a_email)) + $vcard->email = $a_email[0]; + if (!empty($a_email[1])) + $vcard->email2 = $a_email[1]; + if (!empty($a_email[2])) + $vcard->email3 = $a_email[2]; + + // find IM entries + if (is_array($card['X-AIM'])) + $vcard->im['aim'] = $card['X-AIM'][0]['value'][0][0]; + if (is_array($card['X-IQC'])) + $vcard->im['icq'] = $card['X-ICQ'][0]['value'][0][0]; + if (is_array($card['X-MSN'])) + $vcard->im['msn'] = $card['X-MSN'][0]['value'][0][0]; + if (is_array($card['X-JABBER'])) + $vcard->im['jabber'] = $card['X-JABBER'][0]['value'][0][0]; + + if (is_array($card['PHOTO'][0])) + $vcard->photo = array('data' => $card['PHOTO'][0]['value'][0][0], 'encoding' => $card['PHOTO'][0]['param']['ENCODING'][0], 'type' => $card['PHOTO'][0]['param']['TYPE'][0]); + + $vcard->categories = join(',', (array)$card['CATEGORIES'][0]['value'][0]); + + $this->cards[] = $vcard; + } + } + + /** + * Helper method to parse an URL node + * + * @access private + */ + function parse_url(&$node, &$vcard) + { + foreach($node as $url) + { + if (empty($url['param']['TYPE'][0]) || in_array_nc("WORK", $url['param']['TYPE']) || in_array_nc("PREF", $url['param']['TYPE'])) + $vcard->work['url'] = $url['value'][0][0]; + if (in_array_nc("HOME", $url['param']['TYPE'])) + $vcard->home['url'] = $url['value'][0][0]; + } + } + + /** + * Helper method to parse first or preferred related name node (when available) + * + * @access private + */ + function parse_rn(&$node, &$vcard) + { + foreach($node as $rn) + { + if (empty($vcard->relatedname) || in_array_nc("PREF", $rn['param']['TYPE'])) + $vcard->relatedname = $rn['value'][0][0]; + } + } + + /** + * Helper method to parse first or preferred country code (when available) + * + * @access private + */ + function parse_cc(&$node, &$vcard) + { + foreach($node as $cc) + { + if (empty($vcard->countrycode) || in_array_nc("PREF", $cc['param']['TYPE'])) + $vcard->countrycode = $cc['value'][0][0]; + } + } + + /** + * Helper method to parse an address node + * + * @access private + */ + function parse_adr(&$node, &$vcard) + { + foreach($node as $adr) + { + if (empty($adr['param']['TYPE'][0]) || in_array_nc("HOME", $adr['param']['TYPE'])) + $home = $adr['value']; + if (in_array_nc("WORK", $adr['param']['TYPE'])) + $work = $adr['value']; + } + + // values not splitted by Contact_Vcard_Parse if key is like item1.ADR + if (strstr($home[0][0], ';')) + { + $temp = explode(';', $home[0][0]); + $vcard->home += array( + 'addr1' => $temp[2], + 'city' => $temp[3], + 'state' => $temp[4], + 'zipcode' => $temp[5], + 'country' => $temp[6]); + } + else if (sizeof($home)>6) + { + $vcard->home += array( + 'addr1' => $home[2][0], + 'city' => $home[3][0], + 'state' => $home[4][0], + 'zipcode' => $home[5][0], + 'country' => $home[6][0]); + } + + // values not splitted by Contact_Vcard_Parse if key is like item1.ADR + if (strstr($work[0][0], ';')) + { + $temp = explode(';', $work[0][0]); + $vcard->work += array( + 'office' => $temp[1], + 'addr1' => $temp[2], + 'city' => $temp[3], + 'state' => $temp[4], + 'zipcode' => $temp[5], + 'country' => $temp[6]); + } + else if (sizeof($work)>6) + { + $vcard->work += array( + 'addr1' => $work[2][0], + 'city' => $work[3][0], + 'state' => $work[4][0], + 'zipcode' => $work[5][0], + 'country' => $work[6][0]); + } + } + + /** + * Helper method to parse an phone number node + * + * @access private + */ + function parse_tel(&$node, &$vcard) + { + foreach($node as $tel) + { + if (in_array_nc("PAGER", $tel['param']['TYPE'])) + $vcard->pager = $tel['value'][0][0]; + else if (in_array_nc("CELL", $tel['param']['TYPE'])) + $vcard->mobile = $tel['value'][0][0]; + else if (in_array_nc("HOME", $tel['param']['TYPE']) || + (in_array_nc("PREF", $tel['param']['TYPE']) && !in_array_nc("WORK", $tel['param']['TYPE']) && empty($vcard->home['phone']))) + { + if (in_array_nc("FAX", $tel['param']['TYPE'])) + $vcard->home['fax'] = $tel['value'][0][0]; + else + $vcard->home['phone'] = $tel['value'][0][0]; + } + else if (in_array_nc("WORK", $tel['param']['TYPE'])) + { + if(in_array_nc("FAX", $tel['param']['TYPE'])) + $vcard->work['fax'] = $tel['value'][0][0]; + else + $vcard->work['phone'] = $tel['value'][0][0]; + } + } + } + + + /** + * Convert the parsed vCard data into CSV format + */ + function toCSV($delm="\t", $add_title=true, $encoding=null) + { + $out = ''; + $this->export_count = 0; + + if ($add_title) + { + $out .= 'First Name'.$delm.'Last Name'.$delm.'Display Name'.$delm.'Nickname'.$delm.'E-mail Address'.$delm.'E-mail 2 Address'.$delm.'E-mail 3 Address'.$delm; + $out .= 'Home Phone'.$delm.'Business Phone'.$delm.'Home Fax'.$delm.'Business Fax'.$delm.'Pager'.$delm.'Mobile Phone'.$delm; + $out .= 'Home Street'.$delm.'Home Address 2'.$delm.'Home City'.$delm.'Home State'.$delm.'Home Postal Code'.$delm.'Home Country'.$delm; + $out .= 'Business Address'.$delm.'Business Address 2'.$delm.'Business City'.$delm.'Business State'.$delm.'Business Postal Code'.$delm; + $out .= 'Business Country'.$delm.'Country Code'.$delm.'Related name'.$delm.'Job Title'.$delm.'Department'.$delm.'Organization'.$delm.'Notes'.$delm. + $out .= 'Birthday'.$delm.'Anniversary'.$delm.'Gender'.$delm; + $out .= 'Web Page'.$delm.'Web Page 2'.$delm... [truncated message content] |
From: <abe...@us...> - 2013-11-15 00:31:16
|
Revision: 6277 http://sourceforge.net/p/astlinux/code/6277 Author: abelbeck Date: 2013-11-15 00:31:13 +0000 (Fri, 15 Nov 2013) Log Message: ----------- web interface, add NetStat tab support Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/edit.php branches/1.0/package/webinterface/altweb/admin/network.php branches/1.0/package/webinterface/altweb/admin/prefs.php branches/1.0/package/webinterface/altweb/common/header.php branches/1.0/package/webinterface/altweb/common/license-packages.txt Added Paths: ----------- branches/1.0/package/webinterface/altweb/admin/netstat.php Modified: branches/1.0/package/webinterface/altweb/admin/edit.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/edit.php 2013-11-14 19:59:24 UTC (rev 6276) +++ branches/1.0/package/webinterface/altweb/admin/edit.php 2013-11-15 00:31:13 UTC (rev 6277) @@ -31,6 +31,7 @@ 'pptpd' => 'Restart PPTP VPN Server', 'ldap' => 'Reload LDAP Client', 'slapd' => 'Restart LDAP Server', + 'darkstat' => 'Restart NetStat Server', 'snmpd' => 'Restart SNMP Server', 'stunnel' => 'Restart Stunnel Proxy', 'miniupnpd' => 'Restart Univ. Plug\'n\'Play', @@ -238,6 +239,8 @@ $result = restartPROCESS('fop2', 42, $result, 'reload'); } elseif ($process === 'slapd') { $result = restartPROCESS($process, 43, $result, 'init'); + } elseif ($process === 'darkstat') { + $result = restartPROCESS($process, 44, $result, 'init'); } elseif ($process === 'cron') { $result = updateCRON('root', 30, $result); } @@ -364,6 +367,8 @@ putHtml('<p style="color: green;">Asterisk Flash Operating Panel2 has been Reloaded.</p>'); } elseif ($result == 43) { putHtml('<p style="color: green;">LDAP Server has Restarted.</p>'); + } elseif ($result == 44) { + putHtml('<p style="color: green;">NetStat Server (darkstat) has Restarted.</p>'); } elseif ($result == 99) { putHtml('<p style="color: red;">Action Failed.</p>'); } elseif ($result == 999) { Added: branches/1.0/package/webinterface/altweb/admin/netstat.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/netstat.php (rev 0) +++ branches/1.0/package/webinterface/altweb/admin/netstat.php 2013-11-15 00:31:13 UTC (rev 6277) @@ -0,0 +1,71 @@ +<?php + +// Copyright (C) 2013 Lonnie Abelbeck +// This is free software, licensed under the GNU General Public License +// version 3 as published by the Free Software Foundation; you can +// redistribute it and/or modify it under the terms of the GNU +// General Public License; and comes with ABSOLUTELY NO WARRANTY. + +// netstat.php for AstLinux +// 11-14-2013 +// + +$myself = $_SERVER['PHP_SELF']; + +require_once '../common/functions.php'; + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $result = 1; + if (! $global_admin) { + $result = 999; + } + header('Location: '.$myself.'?result='.$result); + exit; +} else { // Start of HTTP GET +$ACCESS_RIGHTS = 'admin'; +require_once '../common/header.php'; + + putHtml("<center>"); + putHtml('<p> </p>'); + putHtml("</center>"); +?> + <script language="JavaScript" type="text/javascript"> + //<![CDATA[ + + function setIFheight() { + var iframe = document.getElementById("netstat"); + var winH = 460; + if (document.documentElement && document.documentElement.offsetHeight) { + winH = document.documentElement.offsetHeight; + } + if (window.innerHeight) { + winH = window.innerHeight; + } + var offset = 160; + if (iframe.getBoundingClientRect) { + offset = iframe.getBoundingClientRect().top + 22; + } + + iframe.height = winH - offset; + window.onresize = setIFheight; + } + //]]> + </script> + <center> + <table class="layoutNOpad" width="100%"><tr><td><center> +<?php + + putHtml('<table class="stdtable" width="100%"><tr><td style="text-align: center;">'); + if (is_file('/var/run/darkstat.pid')) { + echo '<iframe id="netstat" src="/admin/netstat/" frameborder="1" width="100%" onload="setIFheight();">'; + putHtml('</iframe>'); + } else { + putHtml('<p style="color: red;">The NetStat Server is not running, enable via the Network Tab.</p>'); + } + putHtml('</td></tr></table>'); + putHtml("</center></td></tr></table>"); + putHtml("</center>"); +} // End of HTTP GET +require_once '../common/footer.php'; + +?> Property changes on: branches/1.0/package/webinterface/altweb/admin/netstat.php ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Modified: branches/1.0/package/webinterface/altweb/admin/network.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/network.php 2013-11-14 19:59:24 UTC (rev 6276) +++ branches/1.0/package/webinterface/altweb/admin/network.php 2013-11-15 00:31:13 UTC (rev 6277) @@ -413,6 +413,31 @@ $value = 'CLI_PROXY_SERVER="'.$_POST['cli_proxy'].'"'; fwrite($fp, "### CLI Proxy Server\n".$value."\n"); + $value = 'NETSTAT_SERVER="'.$_POST['netstat_server'].'"'; + fwrite($fp, "### NetStat Server\n".$value."\n"); + + $x_value = ''; + if (isset($_POST['netstat_EXTIF'])) { + $x_value .= ' EXTIF'; + } + if (isset($_POST['netstat_INTIF'])) { + $x_value .= ' INTIF'; + } + if (isset($_POST['netstat_INT2IF'])) { + $x_value .= ' INT2IF'; + } + if (isset($_POST['netstat_INT3IF'])) { + $x_value .= ' INT3IF'; + } + if (isset($_POST['netstat_DMZIF'])) { + $x_value .= ' DMZIF'; + } + if ($x_value === '') { // set default + $x_value = 'EXTIF'; + } + $value = 'NETSTAT_CAPTURE="'.trim($x_value).'"'; + fwrite($fp, "### NetStat Capture Interfaces\n".$value."\n"); + $x_value = $_POST['upnp']; $tokens = explode(':', $x_value); $value = 'UPNP_ENABLE_NATPMP="'.$tokens[0].'"'; @@ -964,6 +989,8 @@ $result = restartPROCESS('fop2', 42, $result, 'reload'); } elseif ($process === 'slapd') { $result = restartPROCESS($process, 43, $result, 'init'); + } elseif ($process === 'darkstat') { + $result = restartPROCESS($process, 44, $result, 'init'); } } else { $result = 2; @@ -1048,6 +1075,8 @@ putHtml('<p style="color: green;">Asterisk Flash Operating Panel2 has been Reloaded.</p>'); } elseif ($result == 43) { putHtml('<p style="color: green;">LDAP Server has Restarted.</p>'); + } elseif ($result == 44) { + putHtml('<p style="color: green;">NetStat Server (darkstat) has Restarted.</p>'); } elseif ($result == 99) { putHtml('<p style="color: red;">Action Failed.</p>'); } elseif ($result == 100) { @@ -1129,6 +1158,8 @@ putHtml('<option value="ldap"'.$sel.'>Reload LDAP Client</option>'); $sel = ($reboot_restart === 'slapd') ? ' selected="selected"' : ''; putHtml('<option value="slapd"'.$sel.'>Restart LDAP Server</option>'); + $sel = ($reboot_restart === 'darkstat') ? ' selected="selected"' : ''; + putHtml('<option value="darkstat"'.$sel.'>Restart NetStat Server</option>'); $sel = ($reboot_restart === 'snmpd') ? ' selected="selected"' : ''; putHtml('<option value="snmpd"'.$sel.'>Restart SNMP Server</option>'); $sel = ($reboot_restart === 'stunnel') ? ' selected="selected"' : ''; @@ -1566,6 +1597,31 @@ putHtml('</td></tr>'); putHtml('<tr class="dtrow1"><td style="text-align: left;" colspan="6">'); + putHtml('NetStat Server:'); + putHtml('<select name="netstat_server">'); + putHtml('<option value="">disabled</option>'); + $value = getVARdef($db, 'NETSTAT_SERVER', $cur_db); + $sel = ($value === 'darkstat') ? ' selected="selected"' : ''; + putHtml('<option value="darkstat"'.$sel.'>enabled</option>'); + putHtml('</select>'); + putHtml(' <i>(https://'.$_SERVER['HTTP_HOST'].'/admin/netstat/ or NetStat Tab)</i>'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: left;" colspan="6">'); + putHtml('NetStat Interfaces:'); + $sel = isVARtype('NETSTAT_CAPTURE', $db, $cur_db, 'EXTIF') ? ' checked="checked"' : ''; + putHtml('<input type="checkbox" value="netstat_EXTIF" name="netstat_EXTIF"'.$sel.' /> External'); + $sel = isVARtype('NETSTAT_CAPTURE', $db, $cur_db, 'INTIF') ? ' checked="checked"' : ''; + putHtml('<input type="checkbox" value="netstat_INTIF" name="netstat_INTIF"'.$sel.' /> 1st LAN'); + $sel = isVARtype('NETSTAT_CAPTURE', $db, $cur_db, 'INT2IF') ? ' checked="checked"' : ''; + putHtml('<input type="checkbox" value="netstat_INT2IF" name="netstat_INT2IF"'.$sel.' /> 2nd LAN'); + $sel = isVARtype('NETSTAT_CAPTURE', $db, $cur_db, 'INT3IF') ? ' checked="checked"' : ''; + putHtml('<input type="checkbox" value="netstat_INT3IF" name="netstat_INT3IF"'.$sel.' /> 3rd LAN'); + $sel = isVARtype('NETSTAT_CAPTURE', $db, $cur_db, 'DMZIF') ? ' checked="checked"' : ''; + putHtml('<input type="checkbox" value="netstat_DMZIF" name="netstat_DMZIF"'.$sel.' /> DMZ'); + putHtml('</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: left;" colspan="6">'); putHtml("Universal Plug'n'Play:"); $upnp_natpmp = getVARdef($db, 'UPNP_ENABLE_NATPMP', $cur_db) === 'yes' ? 'yes' : 'no'; $upnp_upnp = getVARdef($db, 'UPNP_ENABLE_UPNP', $cur_db) === 'yes' ? 'yes' : 'no'; Modified: branches/1.0/package/webinterface/altweb/admin/prefs.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/prefs.php 2013-11-14 19:59:24 UTC (rev 6276) +++ branches/1.0/package/webinterface/altweb/admin/prefs.php 2013-11-15 00:31:13 UTC (rev 6277) @@ -475,6 +475,10 @@ $value = 'tab_cli_show = yes'; fwrite($fp, $value."\n"); } + if (isset($_POST['tab_netstat'])) { + $value = 'tab_netstat_show = yes'; + fwrite($fp, $value."\n"); + } if (! isset($_POST['tab_staff'])) { $value = 'tab_staff_disable_staff = yes'; fwrite($fp, $value."\n"); @@ -1130,6 +1134,10 @@ putHtml('<input type="checkbox" value="tab_cli" name="tab_cli"'.$sel.' /></td><td colspan="5">Show CLI Tab</td></tr>'); putHtml('<tr class="dtrow1"><td style="text-align: right;">'); + $sel = (getPREFdef($global_prefs, 'tab_netstat_show') === 'yes') ? ' checked="checked"' : ''; + putHtml('<input type="checkbox" value="tab_netstat" name="tab_netstat"'.$sel.' /></td><td colspan="5">Show NetStat Tab</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: right;">'); $sel = (getPREFdef($global_prefs, 'tab_staff_disable_staff') !== 'yes') ? ' checked="checked"' : ''; putHtml('<input type="checkbox" value="tab_staff" name="tab_staff"'.$sel.' /></td><td colspan="5">Show Staff Tab for "staff" user</td></tr>'); Modified: branches/1.0/package/webinterface/altweb/common/header.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/header.php 2013-11-14 19:59:24 UTC (rev 6276) +++ branches/1.0/package/webinterface/altweb/common/header.php 2013-11-15 00:31:13 UTC (rev 6277) @@ -261,6 +261,9 @@ if ($global_admin && (getPREFdef($global_prefs, 'tab_cli_show') === 'yes')) { putHtml('<li><a href="/admin/cli.php"><span>CLI</span></a></li>'); } + if ($global_admin && (getPREFdef($global_prefs, 'tab_netstat_show') === 'yes')) { + putHtml('<li><a href="/admin/netstat.php"><span>NetStat</span></a></li>'); + } if ($global_admin && (getPREFdef($global_prefs, 'tab_prefs_show') !== 'no')) { putHtml('<li><a href="/admin/prefs.php"><span>Prefs</span></a></li>'); } Modified: branches/1.0/package/webinterface/altweb/common/license-packages.txt =================================================================== --- branches/1.0/package/webinterface/altweb/common/license-packages.txt 2013-11-14 19:59:24 UTC (rev 6276) +++ branches/1.0/package/webinterface/altweb/common/license-packages.txt 2013-11-15 00:31:13 UTC (rev 6277) @@ -46,3 +46,4 @@ ddclient~Copyright (c) 1999-2013 Paul Burry, wimpunk, et al. vCard converter~Copyright (c) 2006-2013 Thomas Bruederli <th...@br...> OpenLDAP~Copyright (c) 1998-2013 The OpenLDAP Foundation. All rights reserved. +darkstat~Copyright (c) 2001-2013 Emil Mikulic, et al. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <abe...@us...> - 2013-11-18 23:28:51
|
Revision: 6287 http://sourceforge.net/p/astlinux/code/6287 Author: abelbeck Date: 2013-11-18 23:28:48 +0000 (Mon, 18 Nov 2013) Log Message: ----------- web interface, allow the NetStat tab to be allowed by 'admin' and 'staff' users Modified Paths: -------------- branches/1.0/package/webinterface/altweb/admin/netstat.php branches/1.0/package/webinterface/altweb/admin/prefs.php branches/1.0/package/webinterface/altweb/common/header.php Modified: branches/1.0/package/webinterface/altweb/admin/netstat.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/netstat.php 2013-11-18 23:00:00 UTC (rev 6286) +++ branches/1.0/package/webinterface/altweb/admin/netstat.php 2013-11-18 23:28:48 UTC (rev 6287) @@ -16,13 +16,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $result = 1; - if (! $global_admin) { + if (! $global_staff) { $result = 999; } header('Location: '.$myself.'?result='.$result); exit; } else { // Start of HTTP GET -$ACCESS_RIGHTS = 'admin'; +$ACCESS_RIGHTS = 'staff'; require_once '../common/header.php'; putHtml("<center>"); Modified: branches/1.0/package/webinterface/altweb/admin/prefs.php =================================================================== --- branches/1.0/package/webinterface/altweb/admin/prefs.php 2013-11-18 23:00:00 UTC (rev 6286) +++ branches/1.0/package/webinterface/altweb/admin/prefs.php 2013-11-18 23:28:48 UTC (rev 6287) @@ -1122,6 +1122,10 @@ putHtml('<input type="checkbox" value="tab_users" name="tab_users"'.$sel.' /></td><td colspan="5">Show Users Tab</td></tr>'); putHtml('<tr class="dtrow1"><td style="text-align: right;">'); + $sel = (getPREFdef($global_prefs, 'tab_netstat_show') === 'yes') ? ' checked="checked"' : ''; + putHtml('<input type="checkbox" value="tab_netstat" name="tab_netstat"'.$sel.' /></td><td colspan="5">Show NetStat Tab</td></tr>'); + + putHtml('<tr class="dtrow1"><td style="text-align: right;">'); $sel = (getPREFdef($global_prefs, 'tab_network_show') !== 'no') ? ' checked="checked"' : ''; putHtml('<input type="checkbox" value="tab_network" name="tab_network"'.$sel.' /></td><td colspan="5">Show Network Tab</td></tr>'); @@ -1134,10 +1138,6 @@ putHtml('<input type="checkbox" value="tab_cli" name="tab_cli"'.$sel.' /></td><td colspan="5">Show CLI Tab</td></tr>'); putHtml('<tr class="dtrow1"><td style="text-align: right;">'); - $sel = (getPREFdef($global_prefs, 'tab_netstat_show') === 'yes') ? ' checked="checked"' : ''; - putHtml('<input type="checkbox" value="tab_netstat" name="tab_netstat"'.$sel.' /></td><td colspan="5">Show NetStat Tab</td></tr>'); - - putHtml('<tr class="dtrow1"><td style="text-align: right;">'); $sel = (getPREFdef($global_prefs, 'tab_staff_disable_staff') !== 'yes') ? ' checked="checked"' : ''; putHtml('<input type="checkbox" value="tab_staff" name="tab_staff"'.$sel.' /></td><td colspan="5">Show Staff Tab for "staff" user</td></tr>'); Modified: branches/1.0/package/webinterface/altweb/common/header.php =================================================================== --- branches/1.0/package/webinterface/altweb/common/header.php 2013-11-18 23:00:00 UTC (rev 6286) +++ branches/1.0/package/webinterface/altweb/common/header.php 2013-11-18 23:28:48 UTC (rev 6287) @@ -244,6 +244,9 @@ if ($global_staff && (getPREFdef($global_prefs, 'tab_users_show') === 'yes')) { putHtml('<li><a href="/admin/users.php"><span>Users</span></a></li>'); } + if ($global_staff && (getPREFdef($global_prefs, 'tab_netstat_show') === 'yes')) { + putHtml('<li><a href="/admin/netstat.php"><span>NetStat</span></a></li>'); + } if (! is_null($custom_tabs = getCUSTOMtabs($global_prefs))) { foreach ($custom_tabs as $tab) { if ($tab['access'] === 'all' || ($global_staff && $tab['access'] === 'staff') @@ -261,9 +264,6 @@ if ($global_admin && (getPREFdef($global_prefs, 'tab_cli_show') === 'yes')) { putHtml('<li><a href="/admin/cli.php"><span>CLI</span></a></li>'); } - if ($global_admin && (getPREFdef($global_prefs, 'tab_netstat_show') === 'yes')) { - putHtml('<li><a href="/admin/netstat.php"><span>NetStat</span></a></li>'); - } if ($global_admin && (getPREFdef($global_prefs, 'tab_prefs_show') !== 'no')) { putHtml('<li><a href="/admin/prefs.php"><span>Prefs</span></a></li>'); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |